Python for light simulation

This is my script:

from honeybee.room import Room
from honeybee.radiance.recipe.daylightcoeff.gridbased.DaylightCoeffGridBased import GridBased
from ladybug.wea import Wea
from honeybee.radiance.sky import SkyMatrix

#from honeybee.radiance.recipe.pointintime.gridbased import GridBased

#from honeybee.radiance.sky.climatebased import ClimateBased

pull up the Ladybug locaiton data …

epw_file = ‘USA_MN_Duluth.727450_TMY2.epw’
wea = Wea.from_epw_file(epw_file)
sky_matrix = SkyMatrix(wea)

The boundaries of teh floorplan

Floorplan_Boundries = Room(origin=(0, 0, 0), width=50, depth=50, height=3.2,
rotation_angle=45)

rooms 1,2,3 are actual rooms inside the floorplan

room_1 = Room(origin=(1, 0, 0), width=4.2, depth=6, height=3.2,
rotation_angle=45)

room_2 = Room(origin=(10, 1, 0), width=4.2, depth=6, height=3.2,
rotation_angle=45)

room_3 = Room(origin=(10, 20, 0), width=4.2, depth=6, height=3.2,
rotation_angle=45)

add fenestration

# add a window to the back wall

room_1.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

room_2.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

room_3.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

Floorplan_Boundries.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

generate grid of test points for the actual rooms

analysis_grid_1 = room_1.generate_test_points(grid_size=1, height=0.75)

analysis_grid_2 = room_2.generate_test_points(grid_size=1, height=0.75)

analysis_grid_3 = room_3.generate_test_points(grid_size=1, height=0.75)

put the recipe together

rp = GridBased(
sky_matrix,
analysis_grids=(analysis_grid_1, analysis_grid_2, analysis_grid_3),
simulation_type=0,
hb_objects=(room_1, room_2, room_3, Floorplan_Boundries)
)

write and run the analysis

batch_file = rp.write(target_folder=r’c:\ladybug’, project_name=‘room’)
rp.run(batch_file, debug=False)

results - in this case it will be an analysis grid

result = rp.results()[0]

print the values for each point

for value in result.combined_value_by_id():
print(‘illuminance value: %d lux’ % value[0])

for pt in room_1.generate_test_points(grid_size=0.5, height=0.75):
print(pt)

I believe I am missing something with importing packages @SaeranVasanthakumar

The dots in the skymatrix.py file itself, should be fine, I’m saying that I believe the way you’re referencing that module in your particular script is incorrect. Can you share your script?

If you have installed it with pip, in your script just call the skymatrix module with:

from honeybee.radiance.sky import SkyMatrix

See how I’m referring to honeybee explicitly?

Then you can initiate it with, at minimum, a .wea file:

sky_matrix = SkyMatrix(wea)

Okay I’m reading through your posts and trying to understand what you did. Are you pulling in these modules in your script to try and generate the sky_mtx?

If so, that’s wrong. Delete all that and generate the sky_mtx like I indicated above, and try it again.

Sorry, I forgot to include the filename in the import, try:
from honeybee.radiance.sky.skymatrix import SkyMatrix

That should work.

Thanks, I still get this error

from honeybee.room import Room
File “C:\Users\fhalawa\AppData\Local\Continuum\anaconda2\lib\site-packages\honeybee\honeybee.py”, line 39
def init (self, objective, params: dict, num_bees: int = 10,
^
SyntaxError: invalid syntax

I’m not sure, @mostapha or @AntoineDao would know better then me. It looks like your Python 2 is throwing an error due to the use of type hints, which should only work with Python 3.

Also, why are you deleting and overwriting posts that I’m responding to? It’s making this thread very confusing to follow.

S

So I figured it out, I had another package called honeybee for something else, and for a reason it was confused with the other library that has a similar name. Now it is all fine. I ran the code and it worked.
The only non-answered question for me now is how to really configure this case: I have two windows on the front wall with configurations (x,y) for each. How to be able to do this. @mostapha mentioned that I can use add_fenestration_surface_by_size. How to do that? If you can tell me what code lines needed that would be great.

@SaeranVasanthakumar and @mostapha Thanks for your responses and help!

To avoid confusion, I am combining all my questions in one post.

1) When I run the yearly simulation I get all Lux values as zeros (see picture). That is not possible.

from honeybee.room import Room
from honeybee.radiance.recipe.annual.gridbased import GridBased
from ladybug.wea import Wea
from honeybee.radiance.sky.skymatrix import SkyMatrix

#pull up the Ladybug locaiton data …
epw_file = ‘USA_MN_Duluth.727450_TMY2.epw’
wea = Wea.from_epw_file(epw_file)
sky_matrix = SkyMatrix(wea)

#The boundaries of teh floorplan
Floorplan_Boundries = Room(origin=(0, 0, 0), width=50, depth=50, height=100,
rotation_angle=45)

#rooms 1,2,3 are actual rooms inside the floorplan
room_1 = Room(origin=(1, 0, 0), width=4.2, depth=6, height=100,
rotation_angle=45)

room_2 = Room(origin=(10, 1, 0), width=4.2, depth=6, height=100,
rotation_angle=45)

room_3 = Room(origin=(10, 20, 0), width=4.2, depth=6, height=100,
rotation_angle=45)

#add fenestration
room_1.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

room_2.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

room_3.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

Floorplan_Boundries.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=0.7)

#generate grid of test points for the actual rooms
analysis_grid_1 = room_1.generate_test_points(grid_size=1, height=0.75)

analysis_grid_2 = room_2.generate_test_points(grid_size=1, height=0.75)

analysis_grid_3 = room_3.generate_test_points(grid_size=1, height=0.75)

#put the recipe together
rp = GridBased(
sky_matrix,
analysis_grids=(analysis_grid_1, analysis_grid_2, analysis_grid_3),
simulation_type=0,
hb_objects=(room_1, room_2, room_3, Floorplan_Boundries)
)

#write and run the analysis
batch_file = rp.write(target_folder=r’c:\ladybug’, project_name=‘room’)
rp.run(batch_file, debug=False)

#results - in this case it will be an analysis grid
result = rp.results()[0]

#print the values for each point
for value in result.combined_value_by_id():
print(‘illuminance value: %d lux’ % value[0])

image

2) Is there any way to say “pring lux values existing in room_2 or 1”? I want to to be specific per room.

3) I want to have two windows on one surface of the floorplan with x,y coordinates, so I would be able to determine the exact location of the window. Can you send me the line of codes needed?

I would appreciate your help.

Glad you got it to work.

I think you will find it helpful to start searching and using the honeybee api docs more. They’re very comprehensive, and you’ll be a lot more effective at using honeybee in the long run using the docs.

For your particular question re: two windows, I just looked up the add_fenestration_surface method Mostapha referenced earlier, and found the relevant method here: https://www.ladybug.tools/apidoc/honeybee/honeybee.html#module-honeybee.hbsurface

And here’s an example of how to use it, from the docs: https://www.ladybug.tools/apidoc/honeybee/honeybee.html#module-honeybee.hbfensurface .

from honeybee.hbsurface import HBSurface 
from honeybee.hbfensurface import HBFenSurface

# create a surface 
pts = [(0, 0, 0), (10, 0, 0), (0, 0, 10)] 
hbsrf = HBSurface(“001”, pts, surface_type=None, is_name_set_by_user=True)

glzpts = [(1, 0, 1), (8, 0, 1), (1, 0, 8)] 
glzsrf = HBFenSurface(“glz_001”, glzpts)

# add fenestration surface to hb surface 
hbsrf.add_fenestration_surface(glzsrf)

# get full definiion of the surface including the fenestration
print(hbsrf.to_rad_string(include_materials=True))

# save the definiion to a .rad file 
hbsrf.rad_string_to_file(r”c:/ladybug/triangle.rad”, include_materials=True)

S

Thanks @SaeranVasanthakumar , I am also adding @mostapha if he had time to look through it.

Here is the issue I still have:
Even though I ran the code correctly for annual simulation and it worked, there is still an issue:
I can’t believe that all the lux values will be 0’s for the three rooms shown in my example above. When I did light simulation on one day it gave me good lighting values in general but for the yearly simulation all the values are 0’s. So I have two questions:
1) What went wrong with my code to have all lux values as zeros?
2) How to limit this analyses to the morning time between 8am-5 pm, I don’t want the results to be affected by the night time…

Here is the output of my code:

Output

Found 24 opaque surfaces.
Found 8 fenestration surfaces.
Found 0 window-groups.

For room 1:
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
For room 2:
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
For room 3:
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux
illuminance value: 0 lux

Here is the code:

from honeybee.room import Room
from honeybee.radiance.recipe.annual.gridbased import GridBased
from ladybug.wea import Wea
from honeybee.radiance.sky.skymatrix import SkyMatrix
from honeybee.hbsurface import HBSurface
from honeybee.hbfensurface import HBFenSurface

##pull up the Ladybug locaiton data …
epw_file = ‘USA_MN_Duluth.727450_TMY2.epw’
wea = Wea.from_epw_file(epw_file)
sky_matrix = SkyMatrix(wea)

#The boundaries of teh floorplan
Floorplan_Boundries = Room(origin=(0, 0, 0), width=50, depth=50, height=2,
rotation_angle=90)

#rooms 1,2,3 are actual rooms inside the floorplan
room_1 = Room(origin=(1, 0, 0), width=4.2, depth=6, height=2,
rotation_angle=90)

room_2 = Room(origin=(10, 1, 0), width=4.2, depth=6, height=2,
rotation_angle=90)

room_3 = Room(origin=(10, 20, 0), width=4.2, depth=6, height=2,
rotation_angle=90)

#add fenestration
room_1.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=1)

room_2.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=1)

room_3.add_fenestration_surface(wall_name=‘back’, width=2, height=2, sill_height=1)

Floorplan_Boundries.add_fenestration_surface(wall_name=‘back’, width=49, height=2, sill_height=1)

#generate grid of test points for the actual rooms
analysis_grid_1 = room_1.generate_test_points(grid_size=2, height=0)

analysis_grid_2 = room_2.generate_test_points(grid_size=2, height=0)

analysis_grid_3 = room_3.generate_test_points(grid_size=2, height=0)

#put the recipe together
rp = GridBased(
sky_matrix,
analysis_grids=(analysis_grid_1, analysis_grid_2, analysis_grid_3),
simulation_type=0,
hb_objects=(room_1, room_2, room_3, Floorplan_Boundries)
)

#write and run the analysis
batch_file = rp.write(target_folder=r’c:\ladybug’, project_name=‘room’)
rp.run(batch_file, debug=False)

#results for each room
result1 = rp.results()[0]
result2 = rp.results()[1]
result3 = rp.results()[2]

#print the test values for each room
for value in result1.combined_value_by_id():
print(‘illuminance value: %d lux’ % value[0])

for value in result2.combined_value_by_id():
print(‘illuminance value: %d lux’ % value[0])

for value in result3.combined_value_by_id():
print(‘illuminance value: %d lux’ % value[0])

@SaeranVasanthakumar @mostapha Hi, I just want to remind you of my question that I posted. It seems the annual simulation is not really giving me any lux values (all of them are 0). Could you please have a look at my code that I posted and let me know if something is preventing it from doing the simulation?
Thanks,