def modifier_bsdf_klemsfull(directory): relative_path = './scripts/bsdf/klemsfull.xml' klemsfull = BSDF(relative_path) dest_file = os.path.join(directory, 'modifier_bsdf_klemsfull.json') json.dumps(klemsfull.to_dict(), indent=4) with open(dest_file, 'w') as fp: json.dump(klemsfull.to_dict(), fp, indent=4)
def test_bsdf_to_json(): """Ensure that the BSDF dictionary is serialize-able to JSON.""" test_bsdf = BSDF(klems_bsdf_file) bsdf_dict = test_bsdf.to_dict() bsdf_str = json.dumps(bsdf_dict) new_bsdf = BSDF.from_dict(json.loads(bsdf_str)) os.remove(new_bsdf.bsdf_file)
def test_to_and_from_dict(): bsdf_in = BSDF(tt_bsdf_file) bsdf_in_dict = bsdf_in.to_dict() # create a new bsdf from dict bsdf_from_dict = BSDF.from_dict(bsdf_in_dict, temp_folder) # compare the files with open(bsdf_in.bsdf_file, 'r') as f1, \ open(bsdf_from_dict.bsdf_file, 'r') as f2: assert f1.read() == f2.read()
def test_bsdf(): mt = BSDF(klems_bsdf_file) assert mt.bsdf_file == os.path.normpath(klems_bsdf_file) assert list(mt.up_orientation) == [0.01, 0.01, 1.0] assert mt.identifier == 'klemsfull' assert str(mt.modifier) == 'void' assert mt.function_file == '.' assert mt.angle_basis == 'Klems Full' assert mt.transform == None
def test_assign_values(): mt = BSDF(klems_bsdf_file, identifier='klemsklems', up_orientation=(0, 0, 10), thickness=10) assert mt.bsdf_file == os.path.normpath(klems_bsdf_file) assert list(mt.up_orientation) == [0, 0, 10] assert mt.identifier == 'klemsklems' assert mt.thickness == 10
def aperture_state_abridged_bsdf(directory): relative_path = './scripts/bsdf/klemsfull.xml' mod = BSDF(relative_path) shd_state = RadianceSubFaceState(mod) pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) ap = Aperture('TestWindow', Face3D(pts)) ap.properties.radiance.dynamic_group_identifier = 'DynamicShdWindow' ap.properties.radiance.states = [shd_state] shd_state.gen_geos_from_tmtx_thickness(0.05) dest_file = os.path.join(directory, 'aperture_state_abridged_bsdf.json') with open(dest_file, 'w') as fp: json.dump(shd_state.to_dict(abridged=True), fp, indent=4)
def test_from_string(): bsdf_str = """ void BSDF klemsfull 6 0.0 ./tests/assets/klemsfull.xml 0.01 0.01 1.0 . 0 0 """ mt = BSDF.from_string(bsdf_str) assert mt.bsdf_file == os.path.normpath(klems_bsdf_file) assert list(mt.up_orientation) == [0.01, 0.01, 1.0] assert mt.identifier == 'klemsfull' assert str(mt.modifier) == 'void' assert mt.function_file == '.' assert mt.angle_basis == 'Klems Full' assert mt.transform == None
def test_update_angle_basis_on_file_change(): mt = BSDF(klems_bsdf_file) assert mt.angle_basis == 'Klems Full' mt = BSDF(tt_bsdf_file) assert mt.angle_basis == 'TensorTree'
def test_writer_to_rad_folder_multiphase(): """Test the Model to.rad_folder method with multi-phase objects like BSDFs.""" room = Room.from_box('Tiny_House_Zone', 5, 10, 3) south_face = room[3] south_face.apertures_by_ratio(0.5, 0.01) south_aperture = south_face.apertures[0] north_face = room[1] north_face.apertures_by_ratio(0.5, 0.01) north_aperture = north_face.apertures[0] folder = os.path.abspath('./tests/assets/') clear_bsdf = BSDF(os.path.join(folder, 'clear.xml')) diff_bsdf = BSDF(os.path.join(folder, 'diffuse50.xml')) clear = RadianceSubFaceState(clear_bsdf) diffuse = RadianceSubFaceState(diff_bsdf) south_aperture.properties.radiance.dynamic_group_identifier = 'SouthDynamicWindow' south_aperture.properties.radiance.states = [clear, diffuse] north_aperture.properties.radiance.dynamic_group_identifier = 'NorthDynamicWindow' north_aperture.properties.radiance.states = [clear.duplicate(), diffuse.duplicate()] north_aperture.properties.radiance.states[0].gen_geos_from_tmtx_thickness(0.1) north_aperture.properties.radiance.states[1].gen_geos_from_tmtx_thickness(0.2) model = Model('Tiny_House', [room]) folder = os.path.abspath('./tests/assets/model/rad_folder_multiphase') model.to.rad_folder(model, folder) model_folder = ModelFolder(folder) bsdf_dir = model_folder.bsdf_folder(full=True) assert os.path.isfile(os.path.join(bsdf_dir, 'clear.xml')) assert os.path.isfile(os.path.join(bsdf_dir, 'diffuse50.xml')) ap_dir = model_folder.aperture_group_folder(full=True) assert os.path.isfile(os.path.join(ap_dir, 'states.json')) group_name = south_aperture.properties.radiance.dynamic_group_identifier assert os.path.isfile(os.path.join(ap_dir, '{}..black.rad'.format(group_name))) assert os.path.isfile(os.path.join(ap_dir, '{}..mtx.rad'.format(group_name))) for i in range(len(south_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..default..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) for i in range(len(south_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..direct..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) group_name = north_aperture.properties.radiance.dynamic_group_identifier assert os.path.isfile(os.path.join(ap_dir, '{}..black.rad'.format(group_name))) for i in range(len(north_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..default..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) for i in range(len(north_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..direct..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) for i in range(len(north_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..dmtx..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) for i in range(len(north_aperture.properties.radiance.states)): d_file = (os.path.join(ap_dir, '{}..vmtx..{}.rad'.format(group_name, i))) assert os.path.isfile(d_file) # clean up the folder nukedir(folder, rmdir=True)
Returns: modifier: A BSDF modifier that can be assigned to a Honeybee geometry or Modifier Sets. """ ghenv.Component.Name = 'HB BSDF Modifier' ghenv.Component.NickName = 'BSDFMod' ghenv.Component.Message = '1.2.0' ghenv.Component.Category = 'HB-Radiance' ghenv.Component.SubCategory = '1 :: Modifiers' ghenv.Component.AdditionalHelpFromDocStrings = '2' try: # import the honeybee-radiance dependencies from honeybee_radiance.modifier.material import BSDF except ImportError as e: raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # process the vector input if _up_vec_ is not None: _up_vec_ = (_up_vec_.X, _up_vec_.Y, _up_vec_.Z) # create the modifier modifier = BSDF(_xml_file, up_orientation=_up_vec_, thickness=thickness_)