def test_measure_to_from_dict(): """Test the serialization of Measure to and from a dictionary.""" measure_path = './tests/measure/edit_fraction_radiant_of_lighting_and_equipment' measure = Measure(measure_path) measure_dict = measure.to_dict() new_measure_path = './tests/simulation/measure_test' new_measure = Measure.from_dict(measure_dict, new_measure_path) assert os.path.isdir(measure.folder) assert os.path.isfile(measure.metadata_file) assert os.path.isfile(measure.program_file) assert measure_dict == new_measure.to_dict() nukedir(new_measure_path, True)
def test_measure_init_simple(): """Test the initialization of Measure and basic properties.""" measure_path = './tests/measure/edit_fraction_radiant_of_lighting_and_equipment' measure = Measure(measure_path) str(measure) # test the string representation # test the file paths assert measure.folder == os.path.abspath(measure_path) assert measure.metadata_file.endswith('measure.xml') assert measure.program_file.endswith('measure.rb') assert measure.resources_folder is None # test the measure attributes assert measure.type == 'ModelMeasure' assert measure.identifier == 'edit_fraction_radiant_of_lighting_and_equipment' assert measure.display_name == 'Edit Fraction Radiant of Lighting and Equipment' assert measure.description == "This measure replaces the 'Fraction Radiant' of " \ "all lights and equipment in the model with values that you specify. " \ "This is useful for thermal comfort studies where the percentage of heat " \ "transferred to the air is important." # test the measure arguments assert len(measure.arguments) == 2 str(measure.arguments[0]) # test the string representation assert measure.arguments[0].identifier == 'lightsFractRad' assert measure.arguments[0].display_name == 'Lights Fraction Radiant' assert measure.arguments[0].type == float assert measure.arguments[0].type_text == 'Double' assert not measure.arguments[0].required assert measure.arguments[0].description is None assert not measure.arguments[0].model_dependent assert measure.arguments[0].valid_choices is None # test the default values for the arguments assert measure.arguments[0].value == measure.arguments[0].default_value == 0 assert measure.arguments[1].value == measure.arguments[1].default_value == 0 assert measure.validate() # test the setting of measure arguments and make sure they get to the OSW measure.arguments[0].value = 0.25 measure.arguments[1].value = 0.25 osw_dict = measure.to_osw_dict() for arg in osw_dict['arguments'].values(): assert arg == 0.25
def test_measure_init_complex(): """Test the initialization of Measure that has a complex set of inputs.""" measure_path = './tests/measure/Create Typical DOE Building from Model' measure = Measure(measure_path) str(measure) # test the string representation assert len(measure.arguments) == 29 assert measure.arguments[0].identifier == 'template' assert measure.arguments[0].display_name == 'Target Standard' assert measure.arguments[0].type == str assert measure.arguments[0].type_text == 'Choice' assert measure.arguments[0].required assert measure.arguments[0].description is None assert not measure.arguments[0].model_dependent assert len(measure.arguments[0].valid_choices) == 6 assert measure.arguments[0].value == measure.arguments[ 0].default_value == '90.1-2010'
def test_to_openstudio_osw(): """Test to_openstudio_osw.""" # create the model room = Room.from_box('TinyHouseZone', 5, 10, 3) model = Model('TinyHouse', [room]) model_json_path = './tests/simulation/model_osw_test.json' with open(model_json_path, 'w') as fp: json.dump(model.to_dict(included_prop=['energy']), fp) # create the simulation parameter sim_par = SimulationParameter() sim_par.output.add_zone_energy_use() simpar_json_path = './tests/simulation/simpar_osw_test.json' with open(simpar_json_path, 'w') as fp: json.dump(sim_par.to_dict(), fp) # create additional measures measure_path = './tests/measure/edit_fraction_radiant_of_lighting_and_equipment' measure = Measure(measure_path) measure.arguments[0].value = 0.25 measure.arguments[1].value = 0.25 # test it without measures folder = './tests/simulation/' osw_path = os.path.join(folder, 'workflow.osw') osw = to_openstudio_osw(folder, model_json_path, simpar_json_path) assert os.path.isfile(osw_path) os.remove(osw_path) # test it with measures osw = to_openstudio_osw(folder, model_json_path, additional_measures=[measure]) assert os.path.isfile(osw_path) os.remove(osw_path) os.remove(model_json_path) os.remove(simpar_json_path)
def to_dict(self): """Convert MapperMeasure to a dictionary.""" base = Measure.to_dict(self) base['type'] = 'MapperMeasure' return base
def __init__(self, folder): """Initialize MapperMeasure.""" Measure.__init__(self, folder)
def is_measure_input(): """Check if a measure path is input to this component. This is needed because we don't know if there are default values for all required inputs until we load the measure. """ if _measure_path is None: msg = 'Input parameter _measure_path failed to collect data!' print(msg) give_warning(ghenv.Component, msg) return False return True if is_measure_input(): # load the measure measure_init = Measure(_measure_path) # transform the component or check the inputs and set defaults if ghenv.Component.Params.Input.Count == 1: # first time loading the measure transform_component(measure_init) else: # the component has already been transformed transform_name_and_description(measure_init) check_arguments_and_set_defaults(measure_init) # if the measure has all inputs that it needs, output the measure if all_required_inputs(ghenv.Component): update_measure_arguments(measure_init) measure = measure_init