Exemplo n.º 1
0
def test_program_type_lib():
    """Test that the honeybee-energy lib has been extended with new program type data."""
    assert len(prog_type_lib.PROGRAM_TYPES
               ) > 2  # should now have many more constructions

    prog_from_lib = prog_type_lib.program_type_by_name(
        prog_type_lib.PROGRAM_TYPES[0])
    assert isinstance(prog_from_lib, ProgramType)

    prog_from_lib = prog_type_lib.program_type_by_name(
        prog_type_lib.PROGRAM_TYPES[2])
    assert isinstance(prog_from_lib, ProgramType)
Exemplo n.º 2
0
def test_program_type_registry():
    """Test the program type registry."""
    for vintage in STANDARDS_REGISTRY.keys():
        for bldg_type in STANDARDS_REGISTRY[vintage].keys():
            for room_type in STANDARDS_REGISTRY[vintage][bldg_type]:
                prog_type_name = '{}::{}::{}'.format(vintage, bldg_type, room_type)
                prog_from_lib = prog_type_lib.program_type_by_name(prog_type_name)
                assert isinstance(prog_from_lib, ProgramType)
Exemplo n.º 3
0
def program_type_patient_room(directory):
    pat_room_program = program_type_by_name(
        '2013::Hospital::ICU_PatRm').duplicate()
    pat_room_program.setpoint.name = 'Humidity Controlled PatRm Setpt'
    pat_room_program.setpoint.heating_setpoint = 21
    pat_room_program.setpoint.cooling_setpoint = 24
    pat_room_program.setpoint.humidifying_setpoint = 30
    pat_room_program.setpoint.dehumidifying_setpoint = 55
    dest_file = os.path.join(directory, 'program_type_patient_room.json')
    with open(dest_file, 'w') as fp:
        json.dump(pat_room_program.to_dict(abridged=True), fp, indent=4)
Exemplo n.º 4
0
def test_model_to_dict_with_program_type():
    """Test Model.to_dict() with standards-assigned ProgramTypes."""
    pat_room_program = prog_type_lib.program_type_by_name(
        '2013::Hospital::ICU_PatRm')
    room = Room.from_box('Hospital Patient Room', 5, 10, 3)
    room.properties.energy.program_type = pat_room_program

    room.properties.energy.add_default_ideal_air()
    ideal_air = room.properties.energy.hvac.duplicate()
    ideal_air.economizer_type = 'DifferentialEnthalpy'
    ideal_air.sensible_heat_recovery = 0.81
    ideal_air.latent_heat_recovery = 0.68
    room.properties.energy.hvac = ideal_air

    pat_rm_setpoint = room.properties.energy.setpoint.duplicate()
    pat_rm_setpoint.name = 'Humidity Controlled PatRm Setpt'
    pat_rm_setpoint.heating_setpoint = 21
    pat_rm_setpoint.cooling_setpoint = 24
    pat_rm_setpoint.humidifying_setpoint = 30
    pat_rm_setpoint.dehumidifying_setpoint = 55
    room.properties.energy.setpoint = pat_rm_setpoint

    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.move_shades(Vector3D(0, 0, -0.5))

    room[0].boundary_condition = boundary_conditions.adiabatic
    room[1].boundary_condition = boundary_conditions.adiabatic
    room[2].boundary_condition = boundary_conditions.adiabatic
    room[4].boundary_condition = boundary_conditions.adiabatic
    room[5].boundary_condition = boundary_conditions.adiabatic

    model = Model('Patient Room Test Box', [room])
    model_dict = model.to_dict()

    assert model_dict['properties']['energy']['program_types'][0]['name'] == \
        '2013::Hospital::ICU_PatRm'
    assert model_dict['rooms'][0]['properties']['energy']['program_type'] == \
        '2013::Hospital::ICU_PatRm'
    assert 'setpoint' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['setpoint']['name'] == \
        'Humidity Controlled PatRm Setpt'
    assert 'hvac' in model_dict['rooms'][0]['properties']['energy']
Exemplo n.º 5
0
def model_complete_patient_room(directory):
    pat_room_program = prog_type_lib.program_type_by_name(
        '2013::Hospital::ICU_PatRm')
    room = Room.from_box('Hospital Patient Room', 5, 10, 3)
    room.properties.energy.program_type = pat_room_program

    room.properties.energy.add_default_ideal_air()
    ideal_air = room.properties.energy.hvac.duplicate()
    ideal_air.economizer_type = 'DifferentialEnthalpy'
    ideal_air.sensible_heat_recovery = 0.81
    ideal_air.latent_heat_recovery = 0.68
    room.properties.energy.hvac = ideal_air

    pat_rm_setpoint = room.properties.energy.setpoint.duplicate()
    pat_rm_setpoint.name = 'Humidity Controlled PatRm Setpt'
    pat_rm_setpoint.heating_setpoint = 21
    pat_rm_setpoint.cooling_setpoint = 24
    pat_rm_setpoint.humidifying_setpoint = 30
    pat_rm_setpoint.dehumidifying_setpoint = 55
    room.properties.energy.setpoint = pat_rm_setpoint

    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.move_shades(Vector3D(0, 0, -0.5))

    room[0].boundary_condition = boundary_conditions.adiabatic
    room[1].boundary_condition = boundary_conditions.adiabatic
    room[2].boundary_condition = boundary_conditions.adiabatic
    room[4].boundary_condition = boundary_conditions.adiabatic
    room[5].boundary_condition = boundary_conditions.adiabatic

    model = Model('Patient Room Test Box', [room])

    dest_file = os.path.join(directory, 'model_complete_patient_room.json')
    with open(dest_file, 'w') as fp:
        json.dump(model.to_dict(), fp, indent=4)
Exemplo n.º 6
0
def test_program_type_by_name():
    """Test that all of the program types in the library can be loaded by name."""
    for prog in prog_type_lib.PROGRAM_TYPES:
        prog_from_lib = prog_type_lib.program_type_by_name(prog)
        assert isinstance(prog_from_lib, ProgramType)
Exemplo n.º 7
0
def convert_to_hb_json(source_dir=None, dest_dir=None):
    """Convert OpenStudio standards JSON files into Honeybee JSON files.
    
    Args:
        source_dir: Directory to the cleaned OpenStudio Standards JSONs.
            Default will be the data folder in this package.
        dest_dir: Optional path to a destination directory. Default will be the
            data folder in this package.
    """
    # set default directories
    if source_dir is None:
        master_dir = local_data_dir()
        source_dir = os.path.join(master_dir, '_standards_data')
    if dest_dir is None:
        master_dir = local_data_dir()
        dest_dir = os.path.join(master_dir, 'data')

    # get all of the destination folders
    constr_dir = os.path.join(dest_dir, 'constructions')
    constrset_dir = os.path.join(dest_dir, 'constructionsets')
    sched_dir = os.path.join(dest_dir, 'schedules')
    ptype_dir = os.path.join(dest_dir, 'programtypes')

    # translate the materials and constructions to honeybee_json
    honeybee_construction_json(source_dir, constr_dir,
                               mat_lib.opaque_material_by_name,
                               'opaque_material.json')
    honeybee_construction_json(source_dir, constr_dir,
                               mat_lib.window_material_by_name,
                               'window_material.json')
    honeybee_construction_json(source_dir, constr_dir,
                               constr_lib.opaque_construction_by_name,
                               'opaque_construction.json')
    honeybee_construction_json(source_dir, constr_dir,
                               constr_lib.window_construction_by_name,
                               'window_construction.json')

    # translate the construction sets to honeybee_json
    src_constr_set_dir = os.path.join(source_dir, 'construction_set')
    for f in os.listdir(src_constr_set_dir):
        dest_file = os.path.join(constrset_dir, f)
        f_path = os.path.join(src_constr_set_dir, f)
        if os.path.isfile(f_path) and f_path.endswith('.json'):
            with open(f_path, 'r') as json_file:
                c_dict = json.load(json_file)
            hb_dict = {}
            for c_name in c_dict:
                base_dict = \
                    constrset_lib.construction_set_by_name(c_name).to_dict(abridged=True)
                del_keys = []
                for key in base_dict:
                    if base_dict[key] is None:
                        del_keys.append(key)
                    elif isinstance(base_dict[key], dict):
                        sub_del_keys = []
                        for s_key in base_dict[key]:
                            if base_dict[key][s_key] is None:
                                sub_del_keys.append(s_key)
                        for s_key in sub_del_keys:
                            del base_dict[key][s_key]
                for key in del_keys:
                    del base_dict[key]
                hb_dict[c_name] = base_dict
            with open(dest_file, 'w') as fp:
                json.dump(hb_dict, fp, indent=2)

    # translate schedules to honeybee json
    sched_json = os.path.join(source_dir, 'schedule.json')
    hb_sch_dict = {}
    with open(sched_json, 'r') as json_file:
        sch_dict = json.load(json_file)
    for sch_name in sch_dict:
        hb_sch_dict[sch_name] = sch_lib.schedule_by_name(sch_name).to_dict(
            abridged=True)
    # get a string representation and clean it further
    init_str = json.dumps(hb_sch_dict, indent=2)
    new_str = re.sub(r'\s*(\d*\.\d*),\s*', r'\1, ', init_str)
    right_bracket_str = re.sub(r'\s*(])', r'\1', new_str)
    left_bracket_str = re.sub(r'(\[)\s*', r'\1', right_bracket_str)
    newer_str = re.sub(r'\[(.\d*),\s*(.\d*)\],\s*', r'[\1, \2], ',
                       left_bracket_str)
    final_str = re.sub(r'\[(.\d*),\s*(.\d*)\]', r'[\1, \2]', newer_str)
    # write the data into a file
    sch_path = os.path.join(sched_dir, 'schedule.json')
    with open(sch_path, 'w') as fp:
        fp.write(final_str)

    # translate the program types to honeybee json
    src_ptype_dir = os.path.join(source_dir, 'program_type')
    for f in os.listdir(src_ptype_dir):
        f_path = os.path.join(src_ptype_dir, f)
        if os.path.isfile(f_path) and f_path.endswith('.json') \
                and not f_path.endswith('registry.json'):
            with open(f_path, 'r') as json_file:
                p_dict = json.load(json_file)
            hb_dict = {}
            for p_name in p_dict:
                hb_dict[p_name] = \
                    program_lib.program_type_by_name(p_name).to_dict(abridged=True)
            dest_file = os.path.join(ptype_dir, f)
            with open(dest_file, 'w') as fp:
                json.dump(hb_dict, fp, indent=2)

    # copy the program registry files over to the data folder
    for f in os.listdir(src_ptype_dir):
        f_path = os.path.join(src_ptype_dir, f)
        if os.path.isfile(f_path) and f_path.endswith('registry.json'):
            dest_file = os.path.join(ptype_dir, f)
            shutil.copy(f_path, dest_file)

    print('Successfully translated OpenStudio JSONs to Honeybee.')
Exemplo n.º 8
0
def program_type_kitchen(directory):
    kitchen = program_type_by_name(
        '2013::FullServiceRestaurant::Kitchen').duplicate()
    dest_file = os.path.join(directory, 'program_type_kitchen.json')
    with open(dest_file, 'w') as fp:
        json.dump(kitchen.to_dict(abridged=True), fp, indent=4)