ladybug-tools / spider

:spider_web: 3D interactive analysis in your browser mostly written around the Three.js JavaScript library
http://www.ladybug.tools/spider
44 stars 15 forks source link

Add a sample Radiance folder with comments #107

Closed mostaphaRoudsari closed 6 years ago

mostaphaRoudsari commented 6 years ago

This will be the reference for @theo-armour to start experimenting results and geometry visualization.

@theo-armour, under which folder do you want me to copy the files?

theo-armour commented 6 years ago

@mostaphaRoudsari

A place to start:

https://github.com/ladybug-tools/spider/tree/master/solar-well/radiance-data-files

I look forward to experimenting with the Radiance data. Fingers crossed, we can get something fun working in the browser.

theo-armour commented 6 years ago

@mostaphaRoudsari

I see you added your first Radiance file. Yay! thank you

mostaphaRoudsari commented 6 years ago

@theo-armour,

I added the sample file and updates readme with new links. As you will see in the link Radiance has several Surface/geometry types including polygon, sphere, cone, etc.

In this sample file we just have polygons which is the most common. The structure of a polygon is:

modifier polygon id
0
0
number of values
x1 y1 z1
x2 y2 z2
x3 y3 z3
...

For instance if we want to create a rectangle with coordinates (0, 0, 0), (0, 10, 0), (10, 10, 0) and (10, 0, 0), name it ground and assign generic_material to it, then it will be written as

generic_material polygon ground
0
0
12
0 0 0
0 10 0
10 10 0
10 0 0

Radiance is pretty flexible in input structure and different people and interfaces generate the input files differently. For instance all the inputs blow will work the same as the one above.

generic_material polygon ground 0 0 12 0 0 0 0 10 0 10 10 0 10 0 0

or

generic_material polygon ground
0
0
12
    0 0 0
    0 10 0
    10 10 0
    10 0 0

We use regular expression to parse the input files and I suggest you do the same to avoid issues with importing custom files. Once you have the clean string you can split it and take the items as needed.

def parse_from_string(full_string):
    """
    separate a Radiance file string into multiple strings for each object.

    Args:
        rad_fileString: Radiance data as a single string. The string can be multiline.

    Returns:
        A list of strings. Each string represents a different Radiance Object
    """
    raw_rad_objects = re.findall(
        r'^\s*([^0-9].*(\s*[\d.-]+.*)*)',
        full_string,
        re.MULTILINE)

    rad_objects = (' '.join(radiance_object[0].split())
                   for radiance_object in raw_rad_objects)

    filtered_objects = tuple(rad_object for rad_object in rad_objects
                             if rad_object and rad_object[0] not in ['#', '!'])

    return filtered_objects
theo-armour commented 6 years ago

@mostaphaRoudsari

Thanks for the file and the tips. It all looks quite readable. I hope to get on this soon.