Example #1
0
def test_program_type_dict_methods():
    """Test the to/from dict methods."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.00015, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.0025, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting,
                                 equipment, None, None, infiltration,
                                 ventilation, setpoint)

    prog_dict = office_program.to_dict()
    new_office_program = ProgramType.from_dict(prog_dict)
    assert new_office_program == office_program
    assert prog_dict == new_office_program.to_dict()
Example #2
0
def validate_program_type(program_type_json):
    """Validate all properties of a ProgramType or ProgramTypeAbridged JSON.

    \b
    Args:
        program_type_json: Full path to a ProgramType or ProgramTypeAbridged JSON file.
    """
    try:
        # first check the JSON against the OpenAPI specification
        with open(program_type_json) as json_file:
            data = json.load(json_file)
        if data['type'] == 'ProgramType':
            click.echo('Validating ProgramType JSON ...')
            schema_programtype.ProgramType.parse_file(program_type_json)
            click.echo('Pydantic validation passed.')
            ProgramType.from_dict(data)
            click.echo('Python re-serialization passed.')
        else:  # assume it's a ProgramTypeAbridged schema
            click.echo('Validating ProgramTypeAbridged JSON ...')
            schema_programtype.ProgramTypeAbridged.parse_file(program_type_json)
            click.echo('Pydantic validation passed.')
        # if we made it to this point, report that the object is valid
        click.echo('Congratulations! Your Program JSON is valid!')
    except Exception as e:
        _logger.exception('ProgramType validation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
def load_program_object(pro_dict):
    """Load a program object from a dictionary and add it to the _program_types dict."""
    try:
        if pro_dict['type'] == 'ProgramTypeAbridged':
            program = ProgramType.from_dict_abridged(pro_dict, _schedules)
        else:
            program = ProgramType.from_dict(pro_dict)
        program.lock()
        assert pro_dict['identifier'] not in _default_programs, 'Cannot overwrite ' \
            'default program type "{}".'.format(pro_dict['identifier'])
        _program_types[pro_dict['identifier']] = program
    except (TypeError, KeyError, ValueError):
        pass  # not a Honeybee ProgramType JSON; possibly a comment
Example #4
0
    def averaged_program_type(self, identifier=None, timestep_resolution=1):
        """Get a ProgramType that is averaged across all of the children Room2Ds.

        The weights used in the averaging process are the floor area weights and they
        account for the multipliers on the child Story objects.

        Args:
            identifier: A unique ID text string for the new averaged ProgramType.
                Must be < 100 characters and not contain any EnergyPlus special
                characters. This will be used to identify the object across a model
                and in the exported IDF. If None, the resulting ProgramType will
                use the identifier of the host Building. (Default: None)
            timestep_resolution: An optional integer for the timestep resolution
                at which the schedules will be averaged. Any schedule details
                smaller than this timestep will be lost in the averaging process.
                Default: 1.
        """
        # get the default identifier of the ProgramType if None
        identifier = identifier if identifier is not None else \
            '{}_Program'.format(self.host.identifier)

        # compute the floor area weights and programs
        flr_areas = []
        program_types = []
        for story in self.host.unique_stories:
            for room in story.room_2ds:
                flr_areas.append(room.floor_area * story.multiplier)
                program_types.append(room.properties.energy.program_type)
        total_area = sum(flr_areas)
        weights = [room_area / total_area for room_area in flr_areas]

        # compute the averaged program
        return ProgramType.average(
            identifier, program_types, weights, timestep_resolution)
Example #5
0
def building_program_type_by_identifier(building_type):
    """Get a program_type representing the program mix of a building_type.

    Args:
        building_type: A text string for the type of building. This must appear
            under the BUILDING_TYPES contant of this module.
    """
    program_id = '{} Building'.format(building_type)
    try:
        return _program_types[program_id]
    except KeyError:
        try:  # search the extension data
            bld_mix_dict = _building_programs_dict[building_type]
            progs, ratios = [], []
            for key, val in bld_mix_dict.items():
                progs.append(program_type_by_identifier(key))
                ratios.append(val)
            bld_program = ProgramType.average(program_id, progs, ratios)
            bld_program.lock()
            _program_types[
                program_id] = bld_program  # cache the object for next time
            return bld_program
        except KeyError:  # construction is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the building types.\nChoose from:\n{}'.
                format(building_type, '\n'.join(BUILDING_TYPES)))
Example #6
0
    def from_dict(cls, data, host):
        """Create Room2DEnergyProperties from a dictionary.

        Note that the dictionary must be a non-abridged version for this
        classmethod to work.

        Args:
            data: A dictionary representation of Room2DEnergyProperties.
            host: A Room2D object that hosts these properties.
        """
        assert data['type'] == 'Room2DEnergyProperties', \
            'Expected Room2DEnergyProperties. Got {}.'.format(data['type'])

        new_prop = cls(host)
        if 'construction_set' in data and data['construction_set'] is not None:
            new_prop.construction_set = \
                ConstructionSet.from_dict(data['construction_set'])
        if 'program_type' in data and data['program_type'] is not None:
            new_prop.program_type = ProgramType.from_dict(data['program_type'])
        if 'hvac' in data and data['hvac'] is not None:
            hvac_class = HVAC_TYPES_DICT[data['hvac']['type']]
            new_prop.hvac = hvac_class.from_dict(data['hvac'])
        cls._deserialize_window_vent(new_prop, data)

        return new_prop
Example #7
0
def test_program_type_diversify():
    """Test the diversify methods."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.00015, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.0025, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting,
                                 equipment, None, None, infiltration,
                                 ventilation, setpoint)

    div_programs = office_program.diversify(10)
    assert len(div_programs) == 10
    for prog in div_programs:
        assert isinstance(prog, ProgramType)
        assert prog.people.people_per_area != people.people_per_area
        assert prog.lighting.watts_per_area != lighting.watts_per_area
        assert prog.electric_equipment.watts_per_area != equipment.watts_per_area
        assert prog.infiltration.flow_per_exterior_area != \
            infiltration.flow_per_exterior_area

    div_programs = office_program.diversify(10, schedule_offset=0)
    for prog in div_programs:
        assert prog.people.occupancy_schedule == people.occupancy_schedule
Example #8
0
def test_program_type_equality():
    """Test the equality of ProgramType objects."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    led_lighting = Lighting('LED Office Lighting', 5, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.00015, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.0025, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting,
                                 equipment, None, None, infiltration,
                                 ventilation, setpoint)
    office_program_dup = office_program.duplicate()
    office_program_alt = ProgramType('Open Office Program', people,
                                     led_lighting, equipment, None, None,
                                     infiltration, ventilation, setpoint)

    assert office_program is office_program
    assert office_program is not office_program_dup
    assert office_program == office_program_dup
    office_program_dup.people.people_per_area = 0.1
    assert office_program != office_program_dup
    assert office_program != office_program_alt
Example #9
0
def test_program_type_init():
    """Test the initialization of ProgramType and basic properties."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.00015, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.0025, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting,
                                 equipment, None, None, infiltration,
                                 ventilation, setpoint)

    str(office_program)  # test the string representation

    assert office_program.identifier == 'Open Office Program'
    assert isinstance(office_program.people, People)
    assert office_program.people == people
    assert isinstance(office_program.lighting, Lighting)
    assert office_program.lighting == lighting
    assert isinstance(office_program.electric_equipment, ElectricEquipment)
    assert office_program.electric_equipment == equipment
    assert office_program.gas_equipment is None
    assert isinstance(office_program.infiltration, Infiltration)
    assert office_program.infiltration == infiltration
    assert isinstance(office_program.ventilation, Ventilation)
    assert office_program.ventilation == ventilation
    assert isinstance(office_program.setpoint, Setpoint)
    assert office_program.setpoint == setpoint
    assert len(office_program.schedules) == 7
    assert len(office_program.schedules_unique) == 6
Example #10
0
def test_program_type_lockability():
    """Test the lockability of ProgramType objects."""
    simple_office = ScheduleDay('Simple Weekday Occupancy', [0, 1, 0],
                                [Time(0, 0), Time(9, 0), Time(17, 0)])
    light_schedule = ScheduleRuleset('Office Lighting-Equip Schedule', simple_office,
                                     None, schedule_types.fractional)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    led_lighting = Lighting('LED Office Lighting', 5, light_schedule)
    office_program = ProgramType('Open Office Program', lighting=lighting)

    office_program.lighting.watts_per_area = 6
    office_program.lock()
    with pytest.raises(AttributeError):
        office_program.lighting.watts_per_area = 8
    with pytest.raises(AttributeError):
        office_program.lighting = led_lighting
    office_program.unlock()
    office_program.lighting.watts_per_area = 8
    office_program.lighting = led_lighting
Example #11
0
def program_type_by_identifier(program_type_identifier):
    """Get a program_type from the library given its identifier.

    Args:
        program_type_identifier: A text string for the identifier of the ProgramType.
    """
    try:
        return _program_types[program_type_identifier]
    except KeyError:
        try:  # search the extension data
            p_type_dict = _program_types_standards_dict[
                program_type_identifier]
            scheds = _scheds_from_ptype_dict(p_type_dict)
            return ProgramType.from_dict_abridged(p_type_dict, scheds)
        except KeyError:  # construction is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the program type library.'.format(
                    program_type_identifier))
Example #12
0
def test_schedule_from_lib():
    """Test the existence of schedule objects in the library."""
    runner = CliRunner()

    result = runner.invoke(schedule_type_limit_by_id, ['Fractional'])
    assert result.exit_code == 0
    sch_dict = json.loads(result.output)
    assert isinstance(ScheduleTypeLimit.from_dict(sch_dict), ScheduleTypeLimit)

    result = runner.invoke(schedule_by_id, ['Generic Office Occupancy'])
    assert result.exit_code == 0
    sch_dict = json.loads(result.output)
    assert isinstance(ScheduleRuleset.from_dict(sch_dict), ScheduleRuleset)

    result = runner.invoke(program_type_by_id, ['Generic Office Program'])
    assert result.exit_code == 0
    prog_dict = json.loads(result.output)
    assert isinstance(ProgramType.from_dict(prog_dict), ProgramType)
def program_type_by_name(program_type_name):
    """Get a program_type from the library given its name.

    Args:
        program_type_name: A text string for the name of the ProgramType.
    """
    try:  # see if the program type has already been loaded to a Python object
        return _program_types[program_type_name]
    except KeyError:  # program type likely needs to be loaded from standards data
        try:
            _prog_dict = _program_type_standards_dict[program_type_name]
        except KeyError:  # program type is nowhere to be found; raise an error
            raise ValueError('"{}" was not found in the program type library.'.format(
                program_type_name))

    # create the Python object from the standards gem dictionary
    _prog_obj = ProgramType.from_standards_dict(_prog_dict)
    _prog_obj.lock()
    _program_types[program_type_name] = _prog_obj  # load faster next time
    return _prog_obj
Example #14
0
def dict_to_object(honeybee_energy_dict, raise_exception=True):
    """Re-serialize a dictionary of almost any object within honeybee_energy.

    This includes any Material, Construction, ConstructionSet, Schedule, Load,
    ProgramType, or Simulation object.

    Args:
        honeybee_energy_dict: A dictionary of any Honeybee energy object. Note
            that this should be a non-abridged dictionary to be valid.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a part of honeybee_energy.
            Default: True.

    Returns:
        A Python object derived from the input honeybee_energy_dict.
    """
    try:  # get the type key from the dictionary
        obj_type = honeybee_energy_dict['type']
    except KeyError:
        raise ValueError(
            'Honeybee_energy dictionary lacks required "type" key.')

    if obj_type == 'ProgramType':
        return ProgramType.from_dict(honeybee_energy_dict)
    elif obj_type == 'ConstructionSet':
        return ConstructionSet.from_dict(honeybee_energy_dict)
    elif obj_type in SCHEDULE_TYPES:
        return dict_to_schedule(honeybee_energy_dict)
    elif obj_type in CONSTRUCTION_TYPES:
        return dict_to_construction(honeybee_energy_dict)
    elif obj_type in MATERIAL_TYPES:
        return dict_to_material(honeybee_energy_dict)
    elif obj_type in LOAD_TYPES:
        return dict_to_load(honeybee_energy_dict)
    elif obj_type in SIMULATION_TYPES:
        return dict_to_simulation(honeybee_energy_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized honeybee energy object'.format(obj_type))
Example #15
0
def test_averaged_program_type():
    """Test the averaged_program_type method."""
    pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3))
    pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3))
    room2d_1 = Room2D('Office1', Face3D(pts_1), 3)
    room2d_2 = Room2D('Office2', Face3D(pts_2), 3)

    simple_office = ScheduleDay('Simple Weekday Occupancy', [0, 1, 0],
                                [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.0002, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.005, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting, equipment,
                                 None, None, infiltration, ventilation, setpoint)
    plenum_program = ProgramType('Plenum Program')

    room2d_1.properties.energy.program_type = office_program
    room2d_2.properties.energy.program_type = plenum_program

    story = Story('OfficeFloor', [room2d_1, room2d_2])
    story.solve_room_2d_adjacency(0.01)
    story.set_outdoor_window_parameters(SimpleWindowRatio(0.4))
    story.multiplier = 4
    building = Building('OfficeBuilding', [story])

    office_avg = building.properties.energy.averaged_program_type('Office Avg Program')

    assert office_avg.people.people_per_area == pytest.approx(0.025, rel=1e-3)
    assert office_avg.people.occupancy_schedule.default_day_schedule.values == \
        office_program.people.occupancy_schedule.default_day_schedule.values
    assert office_avg.people.latent_fraction == \
        office_program.people.latent_fraction
    assert office_avg.people.radiant_fraction == \
        office_program.people.radiant_fraction

    assert office_avg.lighting.watts_per_area == pytest.approx(5, rel=1e-3)
    assert office_avg.lighting.schedule.default_day_schedule.values == \
        office_program.lighting.schedule.default_day_schedule.values
    assert office_avg.lighting.return_air_fraction == \
        office_program.lighting.return_air_fraction
    assert office_avg.lighting.radiant_fraction == \
        office_program.lighting.radiant_fraction
    assert office_avg.lighting.visible_fraction == \
        office_program.lighting.visible_fraction

    assert office_avg.electric_equipment.watts_per_area == pytest.approx(5, rel=1e-3)
    assert office_avg.electric_equipment.schedule.default_day_schedule.values == \
        office_program.electric_equipment.schedule.default_day_schedule.values
    assert office_avg.electric_equipment.radiant_fraction == \
        office_program.electric_equipment.radiant_fraction
    assert office_avg.electric_equipment.latent_fraction == \
        office_program.electric_equipment.latent_fraction
    assert office_avg.electric_equipment.lost_fraction == \
        office_program.electric_equipment.lost_fraction

    assert office_avg.gas_equipment is None

    assert office_avg.infiltration.flow_per_exterior_area == \
        pytest.approx(0.0001, rel=1e-3)
    assert office_avg.infiltration.schedule.default_day_schedule.values == \
        office_program.infiltration.schedule.default_day_schedule.values
    assert office_avg.infiltration.constant_coefficient == \
        office_program.infiltration.constant_coefficient
    assert office_avg.infiltration.temperature_coefficient == \
        office_program.infiltration.temperature_coefficient
    assert office_avg.infiltration.velocity_coefficient == \
        office_program.infiltration.velocity_coefficient

    assert office_avg.ventilation.flow_per_person == pytest.approx(0.0025, rel=1e-3)
    assert office_avg.ventilation.flow_per_area == pytest.approx(0.00015, rel=1e-3)
    assert office_avg.ventilation.flow_per_zone == pytest.approx(0, rel=1e-3)
    assert office_avg.ventilation.air_changes_per_hour == pytest.approx(0, rel=1e-3)
    assert office_avg.ventilation.schedule is None

    assert office_avg.setpoint.heating_setpoint == pytest.approx(21, rel=1e-3)
    assert office_avg.setpoint.cooling_setpoint == pytest.approx(24, rel=1e-3)
try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_ep_string, clean_ep_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:
    from honeybee_energy.programtype import ProgramType
    from honeybee_energy.lib.programtypes import program_type_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try:
    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):
    # set default ratios to None
    _ratios_ = _ratios_ if len(_ratios_) != 0 else None
    name = clean_and_id_ep_string('ProgramType') if _name_ is None else \
        clean_ep_string(_name_)

    # get programs from library if a name is input
    for i, prog in enumerate(_programs):
        if isinstance(prog, str):
            _programs[i] = program_type_by_identifier(prog)

    # create blended program
    program = ProgramType.average(name, _programs, _ratios_)
    if _name_ is not None:
        program.display_name = _name_
Example #17
0
try:
    from honeybee_energy.programtype import ProgramType
    from honeybee_energy.lib.programtypes import program_type_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try:
    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):
    # get the base program type
    if base_program_ is None:
        program = ProgramType(clean_and_id_ep_string(_name))
        program.display_name = _name
    else:
        if isinstance(base_program_, str):
            base_program_ = program_type_by_identifier(base_program_)
        program = base_program_.duplicate()
        program.identifier = clean_and_id_ep_string(_name)
        program.display_name = _name
    
    # go through each input load and assign it to the set
    if _people_ is not None:
        program.people = _people_
    if _lighting_ is not None:
        program.lighting = _lighting_
    if _electric_equip_ is not None:
        program.electric_equipment = _electric_equip_
Example #18
0
def test_program_type_setability():
    """Test the setting of properties of ProgramType."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.00015, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.0025, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program')

    assert office_program.identifier == 'Open Office Program'
    office_program.identifier = 'Office Program'
    assert office_program.identifier == 'Office Program'
    assert office_program.people is None
    office_program.people = people
    assert office_program.people == people
    assert office_program.lighting is None
    office_program.lighting = lighting
    assert office_program.lighting == lighting
    assert office_program.electric_equipment is None
    office_program.electric_equipment = equipment
    assert office_program.electric_equipment == equipment
    assert office_program.infiltration is None
    office_program.infiltration = infiltration
    assert office_program.infiltration == infiltration
    assert office_program.ventilation is None
    office_program.ventilation = ventilation
    assert office_program.ventilation == ventilation
    assert office_program.setpoint is None
    office_program.setpoint = setpoint
    assert office_program.setpoint == setpoint

    with pytest.raises(AssertionError):
        office_program.people = lighting
    with pytest.raises(AssertionError):
        office_program.lighting = equipment
    with pytest.raises(AssertionError):
        office_program.electric_equipment = people
    with pytest.raises(AssertionError):
        office_program.infiltration = people
    with pytest.raises(AssertionError):
        office_program.ventilation = setpoint
    with pytest.raises(AssertionError):
        office_program.setpoint = ventilation
Example #19
0
def test_program_type_average():
    """Test the ProgramType.average method."""
    simple_office = ScheduleDay(
        'Simple Weekday Occupancy', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    occ_schedule = ScheduleRuleset('Office Occupancy Schedule', simple_office,
                                   None, schedule_types.fractional)
    light_schedule = occ_schedule.duplicate()
    light_schedule.identifier = 'Office Lighting-Equip Schedule'
    light_schedule.default_day_schedule.values = [0.25, 1, 0.25]
    equip_schedule = light_schedule.duplicate()
    inf_schedule = ScheduleRuleset.from_constant_value(
        'Infiltration Schedule', 1, schedule_types.fractional)
    heat_setpt = ScheduleRuleset.from_constant_value(
        'Office Heating Schedule', 21, schedule_types.temperature)
    cool_setpt = ScheduleRuleset.from_constant_value(
        'Office Cooling Schedule', 24, schedule_types.temperature)

    people = People('Open Office People', 0.05, occ_schedule)
    lighting = Lighting('Open Office Lighting', 10, light_schedule)
    equipment = ElectricEquipment('Open Office Equipment', 10, equip_schedule)
    infiltration = Infiltration('Office Infiltration', 0.0002, inf_schedule)
    ventilation = Ventilation('Office Ventilation', 0.005, 0.0003)
    setpoint = Setpoint('Office Setpoints', heat_setpt, cool_setpt)
    office_program = ProgramType('Open Office Program', people, lighting,
                                 equipment, None, None, infiltration,
                                 ventilation, setpoint)
    plenum_program = ProgramType('Plenum Program')

    office_avg = ProgramType.average('Office Average Program',
                                     [office_program, plenum_program])

    assert office_avg.people.people_per_area == pytest.approx(0.025, rel=1e-3)
    assert office_avg.people.occupancy_schedule.default_day_schedule.values == \
        office_program.people.occupancy_schedule.default_day_schedule.values
    assert office_avg.people.latent_fraction == \
        office_program.people.latent_fraction
    assert office_avg.people.radiant_fraction == \
        office_program.people.radiant_fraction

    assert office_avg.lighting.watts_per_area == pytest.approx(5, rel=1e-3)
    assert office_avg.lighting.schedule.default_day_schedule.values == \
        office_program.lighting.schedule.default_day_schedule.values
    assert office_avg.lighting.return_air_fraction == \
        office_program.lighting.return_air_fraction
    assert office_avg.lighting.radiant_fraction == \
        office_program.lighting.radiant_fraction
    assert office_avg.lighting.visible_fraction == \
        office_program.lighting.visible_fraction

    assert office_avg.electric_equipment.watts_per_area == pytest.approx(
        5, rel=1e-3)
    assert office_avg.electric_equipment.schedule.default_day_schedule.values == \
        office_program.electric_equipment.schedule.default_day_schedule.values
    assert office_avg.electric_equipment.radiant_fraction == \
        office_program.electric_equipment.radiant_fraction
    assert office_avg.electric_equipment.latent_fraction == \
        office_program.electric_equipment.latent_fraction
    assert office_avg.electric_equipment.lost_fraction == \
        office_program.electric_equipment.lost_fraction

    assert office_avg.gas_equipment is None

    assert office_avg.infiltration.flow_per_exterior_area == \
        pytest.approx(0.0001, rel=1e-3)
    assert office_avg.infiltration.schedule.default_day_schedule.values == \
        office_program.infiltration.schedule.default_day_schedule.values
    assert office_avg.infiltration.constant_coefficient == \
        office_program.infiltration.constant_coefficient
    assert office_avg.infiltration.temperature_coefficient == \
        office_program.infiltration.temperature_coefficient
    assert office_avg.infiltration.velocity_coefficient == \
        office_program.infiltration.velocity_coefficient

    assert office_avg.ventilation.flow_per_person == pytest.approx(0.0025,
                                                                   rel=1e-3)
    assert office_avg.ventilation.flow_per_area == pytest.approx(0.00015,
                                                                 rel=1e-3)
    assert office_avg.ventilation.flow_per_zone == pytest.approx(0, rel=1e-3)
    assert office_avg.ventilation.air_changes_per_hour == pytest.approx(
        0, rel=1e-3)
    assert office_avg.ventilation.schedule is None

    assert office_avg.setpoint.heating_setpoint == pytest.approx(21, rel=1e-3)
    assert office_avg.setpoint.cooling_setpoint == pytest.approx(24, rel=1e-3)
Example #20
0
def test_dict_to_object_program_type():
    """Test the dict_to_object method with ProgramType objects."""
    program_type_obj = ProgramType('Test Program')
    program_type_dict = program_type_obj.to_dict()
    new_prog_type = dict_to_object(program_type_dict)
    assert isinstance(new_prog_type, ProgramType)
Example #21
0
ghenv.Component.AdditionalHelpFromDocStrings = "2"

try:  # import the core honeybee dependencies
    from honeybee.typing import clean_and_id_ep_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:
    from honeybee_energy.programtype import ProgramType
    from honeybee_energy.lib.programtypes import program_type_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try:
    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):
    # set default ratios to None
    _ratios_ = _ratios_ if len(_ratios_) != 0 else None

    # get programs from library if a name is input
    for i, prog in enumerate(_programs):
        if isinstance(prog, str):
            _programs[i] = program_type_by_identifier(prog)

    # create blended program
    program = ProgramType.average(clean_and_id_ep_string(_name), _programs,
                                  _ratios_)
    program.display_name = _name
Example #22
0
from honeybee_energy.load.people import People
from honeybee_energy.load.lighting import Lighting
from honeybee_energy.load.equipment import ElectricEquipment
from honeybee_energy.load.infiltration import Infiltration
from honeybee_energy.load.ventilation import Ventilation
from honeybee_energy.load.setpoint import Setpoint

from ._loadprogramtypes import _json_program_types
import honeybee_energy.lib.schedules as _s

# establish variables for the default schedules used across the library
# and auto-generate schedules if they were not loaded from default.idf
try:
    plenum_program = _json_program_types['Plenum']
except KeyError:
    plenum_program = ProgramType('Plenum')
    plenum_program.lock()
    _json_program_types['Plenum'] = plenum_program

try:
    office_program = _json_program_types['Generic Office Program']
except KeyError:
    if _s.generic_office_occupancy is not None:
        people = People('Generic Office People', 0.0565,
                        _s.generic_office_occupancy,
                        _s.generic_office_activity)
        lighting = Lighting('Generic Office Lighting', 10.55,
                            _s.generic_office_lighting, 0.0, 0.7, 0.2)
        equipment = ElectricEquipment('Generic Office Equipment', 10.33,
                                      _s.generic_office_equipment, 0.5)
        infiltration = Infiltration('Generic Office Infiltration', 0.0002266,
Example #23
0
def test_program_type_from_standards_dict():
    """Test the from_standards_dict methods."""
    program_dict = {
        "template": "90.1-2013",
        "building_type": "Office",
        "space_type": "MediumOffice - OpenOffice",
        "lighting_standard": "ASHRAE 90.1-2013",
        "lighting_per_area": 0.98,
        "lighting_per_person": None,
        "additional_lighting_per_area": None,
        "lighting_fraction_to_return_air": 0.0,
        "lighting_fraction_radiant": 0.7,
        "lighting_fraction_visible": 0.2,
        "lighting_schedule": "OfficeMedium BLDG_LIGHT_SCH_2013",
        "ventilation_standard": "ASHRAE 62.1-2007",
        "ventilation_primary_space_type": "Office Buildings",
        "ventilation_secondary_space_type": "Office space",
        "ventilation_per_area": 0.06,
        "ventilation_per_person": 5.0,
        "ventilation_air_changes": None,
        "minimum_total_air_changes": None,
        "occupancy_per_area": 5.25,
        "occupancy_schedule": "OfficeMedium BLDG_OCC_SCH",
        "occupancy_activity_schedule": "OfficeMedium ACTIVITY_SCH",
        "infiltration_per_exterior_area": 0.0446,
        "infiltration_schedule": "OfficeMedium INFIL_SCH_PNNL",
        "gas_equipment_per_area": None,
        "gas_equipment_fraction_latent": None,
        "gas_equipment_fraction_radiant": None,
        "gas_equipment_fraction_lost": None,
        "gas_equipment_schedule": None,
        "electric_equipment_per_area": 0.96,
        "electric_equipment_fraction_latent": 0.0,
        "electric_equipment_fraction_radiant": 0.5,
        "electric_equipment_fraction_lost": 0.0,
        "electric_equipment_schedule": "OfficeMedium BLDG_EQUIP_SCH_2013",
        "heating_setpoint_schedule": "OfficeMedium HTGSETP_SCH_YES_OPTIMUM",
        "cooling_setpoint_schedule": "OfficeMedium CLGSETP_SCH_YES_OPTIMUM"
    }
    office_program = ProgramType.from_standards_dict(program_dict)

    assert office_program.name == 'MediumOffice - OpenOffice'
    assert office_program.people.people_per_area == pytest.approx(0.05651, rel=1e-3)
    assert office_program.people.occupancy_schedule.name == 'OfficeMedium BLDG_OCC_SCH'
    assert office_program.people.activity_schedule.name == 'OfficeMedium ACTIVITY_SCH'
    assert office_program.lighting.watts_per_area == pytest.approx(10.548, rel=1e-3)
    assert office_program.lighting.schedule.name == 'OfficeMedium BLDG_LIGHT_SCH_2013'
    assert office_program.lighting.return_air_fraction == pytest.approx(0.0, rel=1e-3)
    assert office_program.lighting.radiant_fraction == pytest.approx(0.7, rel=1e-3)
    assert office_program.lighting.visible_fraction == pytest.approx(0.2, rel=1e-3)
    assert office_program.electric_equipment.watts_per_area == pytest.approx(10.3333, rel=1e-3)
    assert office_program.electric_equipment.schedule.name == 'OfficeMedium BLDG_EQUIP_SCH_2013'
    assert office_program.electric_equipment.latent_fraction == pytest.approx(0.0, rel=1e-3)
    assert office_program.electric_equipment.radiant_fraction == pytest.approx(0.5, rel=1e-3)
    assert office_program.electric_equipment.lost_fraction == pytest.approx(0.0, rel=1e-3)
    assert office_program.gas_equipment is None
    assert office_program.infiltration.flow_per_exterior_area == pytest.approx(0.000226568, rel=1e-3)
    assert office_program.infiltration.schedule.name == 'OfficeMedium INFIL_SCH_PNNL'
    assert office_program.ventilation.flow_per_person == pytest.approx(0.0023597, rel=1e-3)
    assert office_program.ventilation.flow_per_area == pytest.approx(0.0003048, rel=1e-3)
    assert office_program.ventilation.flow_per_zone == pytest.approx(0.0, rel=1e-3)
    assert office_program.ventilation.air_changes_per_hour == pytest.approx(0.0, rel=1e-3)
    assert office_program.setpoint.heating_schedule.name == 'OfficeMedium HTGSETP_SCH_YES_OPTIMUM'
    assert office_program.setpoint.heating_setpoint == pytest.approx(21.0, rel=1e-3)
    assert office_program.setpoint.heating_setback == pytest.approx(15.6, rel=1e-3)
    assert office_program.setpoint.cooling_schedule.name == 'OfficeMedium CLGSETP_SCH_YES_OPTIMUM'
    assert office_program.setpoint.cooling_setpoint == pytest.approx(24.0, rel=1e-3)
    assert office_program.setpoint.cooling_setback == pytest.approx(26.7, rel=1e-3)
Example #24
0
"""Load all program types from the JSON libraries."""
from honeybee_energy.programtype import ProgramType

from ._loadschedules import _idf_schedules

import os
import json


# empty dictionaries to hold json-loaded program types
_json_program_types = {}


# load program types from the default and user-supplied files
cur_dir = os.path.dirname(__file__)
program_lib = os.path.join(cur_dir, 'library', 'programtypes')
for f in os.listdir(program_lib):
    f_path = os.path.join(program_lib, f)
    if os.path.isfile(f_path) and f_path.endswith('.json'):
        with open(f_path, 'r') as json_file:
            file_contents = json_file.read()
        p_dict = json.loads(file_contents)
        for p_name in p_dict:
            try:
                program = ProgramType.from_dict_abridged(p_dict[p_name], _idf_schedules)
                program.lock()
                _json_program_types[program.name] = program
            except ValueError:
                pass  # failed to find the schedule in the schedule library
from honeybee_energy.config import folders
from honeybee_energy.programtype import ProgramType

from ._loadschedules import _schedules

import os
import json

# empty dictionary to hold loaded program types
_program_types = {}

# first load the honeybee defaults
with open(folders.defaults_file) as json_file:
    default_data = json.load(json_file)['program_types']
for pro_dict in default_data:
    program = ProgramType.from_dict_abridged(pro_dict, _schedules)
    program.lock()
    _program_types[pro_dict['identifier']] = program
_default_programs = set(list(_program_types.keys()))


# then load program types from the user-supplied files
def load_program_object(pro_dict):
    """Load a program object from a dictionary and add it to the _program_types dict."""
    try:
        if pro_dict['type'] == 'ProgramTypeAbridged':
            program = ProgramType.from_dict_abridged(pro_dict, _schedules)
        else:
            program = ProgramType.from_dict(pro_dict)
        program.lock()
        assert pro_dict['identifier'] not in _default_programs, 'Cannot overwrite ' \
    from honeybee_energy.programtype import ProgramType
    from honeybee_energy.lib.programtypes import program_type_by_identifier
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try:
    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):
    # get the base program type
    name = clean_and_id_ep_string('ProgramType') if _name_ is None else \
        clean_ep_string(_name_)
    if base_program_ is None:
        program = ProgramType(name)
    else:
        if isinstance(base_program_, str):
            base_program_ = program_type_by_identifier(base_program_)
        program = base_program_.duplicate()
        program.identifier = name
    if _name_ is not None:
        program.display_name = _name_

    # go through each input load and assign it to the set
    if _people_ is not None:
        program.people = _people_
    if _lighting_ is not None:
        program.lighting = _lighting_
    if _electric_equip_ is not None:
        program.electric_equipment = _electric_equip_