Ejemplo n.º 1
0
def dict_to_load(load_dict, raise_exception=True):
    """Get a Python object of any Load from a dictionary.

    Args:
        load_dict: A dictionary of any Honeybee energy load. 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 load. Default: True.

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

    if load_type == 'People':
        return People.from_dict(load_dict)
    elif load_type == 'Lighting':
        return Lighting.from_dict(load_dict)
    elif load_type == 'ElectricEquipment':
        return ElectricEquipment.from_dict(load_dict)
    elif load_type == 'GasEquipment':
        return GasEquipment.from_dict(load_dict)
    elif load_type == 'Infiltration':
        return Infiltration.from_dict(load_dict)
    elif load_type == 'Ventilation':
        return Ventilation.from_dict(load_dict)
    elif load_type == 'Setpoint':
        return Setpoint.from_dict(load_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Load type'.format(load_type))
Ejemplo n.º 2
0
def single_family_home(directory):
    poly_file = './scripts/geometry/single_family_geo.json'
    with open(poly_file, 'r') as fp:
        geo_dict = json.load(fp)

    # create the basic Room objects
    program = prog_type_lib.program_type_by_identifier('2013::MidriseApartment::Apartment')
    c_set = constr_set_lib.construction_set_by_identifier('2013::ClimateZone5::SteelFramed')
    rooms = []
    for i, room_geo_dict in enumerate(geo_dict['rooms']):
        room_geo = Polyface3D.from_dict(room_geo_dict)
        room_geo.merge_overlapping_edges(0.01, math.radians(1))
        room = Room.from_polyface3d('House_Room_{}'.format(i), room_geo)
        room.properties.energy.program_type = program
        room.properties.energy.construction_set = c_set
        room.properties.energy.add_default_ideal_air()
        rooms.append(room)

    # make some of the rooms different to make it interesting
    program2 = prog_type_lib.program_type_by_identifier('2013::MidriseApartment::Corridor')
    rooms[6].properties.energy.program_type = program2
    cook_vals = [0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0]
    cook_meals = ScheduleRuleset.from_daily_values('Cooking_Meals', cook_vals)
    kitchen_equip = GasEquipment('Kitchen Stove', 20, cook_meals)
    rooms[0].properties.energy.gas_equipment = kitchen_equip

    # add the apertures to the rooms
    apertures = []
    for i, ap_geo in enumerate(geo_dict['apertures']):
        ap_face = Face3D.from_dict(ap_geo)
        hb_ap = Aperture('House_Aperture_{}'.format(i), ap_face)
        hb_ap.extruded_border(0.3)
        apertures.append(hb_ap)

    # assign apertures and solve adjacency
    for room in rooms:
        for face in room.faces:
            for sf in apertures:
                if face.geometry.is_sub_face(sf.geometry, 0.5, 1.0):
                    face.add_aperture(sf)
    Room.solve_adjacency(rooms, 0.01)

    # load up the context shades
    shades = []
    for i, shd_geo in enumerate(geo_dict['shades']):
        shd_face = Face3D.from_dict(shd_geo)
        shades.append(Shade('Context_Shade_{}'.format(i), shd_face))

    # put it all together in a Model and write out the JSON
    model = Model('Single_Family_Home', rooms=rooms, orphaned_shades=shades,
                  units='Meters', tolerance=0.01, angle_tolerance=1.0)
    dest_file = os.path.join(directory, 'single_family_home.hbjson')
    with open(dest_file, 'w') as fp:
        json.dump(model.to_dict(), fp, indent=4)
Ejemplo n.º 3
0
def test_gas_equipment_init():
    """Test the initialization of GasEquipment and basic properties."""
    simple_office = ScheduleDay(
        'Simple Weekday', [0, 1, 0],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    schedule = ScheduleRuleset('Kitchen Equip', simple_office, None,
                               schedule_types.fractional)
    equipment = GasEquipment('Kitchen Stove Equip', 8, schedule)
    str(equipment)  # test the string representation

    assert equipment.name == 'Kitchen Stove Equip'
    assert equipment.watts_per_area == 8
    assert equipment.schedule.name == 'Kitchen Equip'
    assert equipment.schedule.schedule_type_limit == schedule_types.fractional
    assert equipment.schedule == schedule
    assert equipment.radiant_fraction == 0
    assert equipment.latent_fraction == 0
    assert equipment.lost_fraction == 0
    assert equipment.convected_fraction == 1
Ejemplo n.º 4
0
def from_standards_dict(cls, data):
    """Create a ProgramType from an OpenStudio standards gem dictionary.

    Args:
        data: An OpenStudio standards dictionary of a space type in the
            format below.

    .. code-block:: python

        {
        "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"
        }
    """
    pr_type_identifier = data['space_type']
    people = None
    lighting = None
    electric_equipment = None
    gas_equipment = None
    hot_water = None
    infiltration = None
    ventilation = None
    setpoint = None

    if 'occupancy_schedule' in data and data['occupancy_schedule'] is not None and \
            'occupancy_per_area' in data and data['occupancy_per_area'] != 0:
        occ_sched = sch_lib.schedule_by_identifier(data['occupancy_schedule'])
        act_sched = sch_lib.schedule_by_identifier(
            data['occupancy_activity_schedule'])
        occ_density = data['occupancy_per_area'] / 92.903
        people = People('{}_People'.format(pr_type_identifier), occ_density,
                        occ_sched, act_sched)

    if 'lighting_schedule' in data and data['lighting_schedule'] is not None:
        light_sched = sch_lib.schedule_by_identifier(data['lighting_schedule'])
        try:
            lpd = data['lighting_per_area'] * 10.7639
        except (TypeError, KeyError):
            lpd = 0  # there's a schedule but no actual load object
        try:
            raf = data['lighting_fraction_to_return_air']
        except KeyError:
            raf = 0
        try:
            lfr = data['lighting_fraction_radiant']
        except KeyError:
            lfr = 0.32
        try:
            lfv = data['lighting_fraction_visible']
        except KeyError:
            lfv = 0.25
        lighting = Lighting('{}_Lighting'.format(pr_type_identifier), lpd,
                            light_sched, raf, lfr, lfv)
        lighting.baseline_watts_per_area = lpd

    if 'electric_equipment_schedule' in data and \
            data['electric_equipment_schedule'] is not None:
        eequip_sched = sch_lib.schedule_by_identifier(
            data['electric_equipment_schedule'])
        try:
            eepd = data['electric_equipment_per_area'] * 10.7639
        except KeyError:
            eepd = 0  # there's a schedule but no actual load object
        electric_equipment = ElectricEquipment(
            '{}_Electric'.format(pr_type_identifier), eepd, eequip_sched,
            data['electric_equipment_fraction_radiant'],
            data['electric_equipment_fraction_latent'],
            data['electric_equipment_fraction_lost'])

    if 'gas_equipment_schedule' in data and \
            data['gas_equipment_schedule'] is not None:
        gequip_sched = sch_lib.schedule_by_identifier(
            data['gas_equipment_schedule'])
        try:
            gepd = data['gas_equipment_per_area'] * 3.15459
        except (TypeError, KeyError):
            gepd = 0  # there's a schedule but no actual load object
        gas_equipment = GasEquipment('{}_Gas'.format(pr_type_identifier), gepd,
                                     gequip_sched,
                                     data['gas_equipment_fraction_radiant'],
                                     data['gas_equipment_fraction_latent'],
                                     data['gas_equipment_fraction_lost'])

    if 'service_water_heating_schedule' in data and \
            data['service_water_heating_schedule'] is not None:
        shw_sch = sch_lib.schedule_by_identifier(
            data['service_water_heating_schedule'])
        try:
            shw_load = data[
                'service_water_heating_peak_flow_per_area'] * 40.7458
        except (TypeError, KeyError):
            shw_load = 0  # there's a schedule but no actual load object
        try:
            shw_temp = round(
                (data['service_water_heating_target_temperature'] - 32.) * 5. /
                9.)
        except (TypeError, KeyError):
            shw_temp = 60
        try:
            fs = data['service_water_heating_fraction_sensible']
        except (TypeError, KeyError):
            fs = 0.2
        try:
            fl = data['service_water_heating_fraction_latent']
        except (TypeError, KeyError):
            fl = 0.05
        hot_water = ServiceHotWater('{}_SHW'.format(pr_type_identifier),
                                    shw_load, shw_sch, shw_temp, fs, fl)

    if 'infiltration_schedule' in data and \
            data['infiltration_schedule'] is not None:
        inf_sched = sch_lib.schedule_by_identifier(
            data['infiltration_schedule'])
        try:
            inf = data['infiltration_per_exterior_area'] * 0.00508
        except KeyError:  # might be using infiltration_per_exterior_wall_area
            try:
                inf = data['infiltration_per_exterior_wall_area'] * 0.00508
            except KeyError:
                inf = 0  # there's a schedule but no actual load object
        infiltration = Infiltration(
            '{}_Infiltration'.format(pr_type_identifier), inf, inf_sched)

    if 'ventilation_standard' in data and \
            data['ventilation_standard'] is not None:
        person = data['ventilation_per_person'] * 0.000471947 if \
            'ventilation_per_person' in data and \
            data['ventilation_per_person'] is not None else 0
        area = data['ventilation_per_area'] * 0.00508 if \
            'ventilation_per_area' in data and \
            data['ventilation_per_area'] is not None else 0
        ach = data['ventilation_air_changes'] if \
            'ventilation_air_changes' in data and \
            data['ventilation_air_changes'] is not None else 0
        ventilation = Ventilation('{}_Ventilation'.format(pr_type_identifier),
                                  person, area, 0, ach)

    if 'heating_setpoint_schedule' in data and \
            data['heating_setpoint_schedule'] is not None:
        heat_sched = sch_lib.schedule_by_identifier(
            data['heating_setpoint_schedule'])
        cool_sched = sch_lib.schedule_by_identifier(
            data['cooling_setpoint_schedule'])
        setpoint = Setpoint('{}_Setpoint'.format(pr_type_identifier),
                            heat_sched, cool_sched)

    return cls(data['space_type'], people, lighting, electric_equipment,
               gas_equipment, hot_water, infiltration, ventilation, setpoint)
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):
    # make a default Equipment name if none is provided
    if _name_ is None:
        name = "Equipment_{}".format(uuid.uuid4())
    else:
        name = clean_and_id_ep_string(_name_)

    # get the schedule
    if isinstance(_schedule, str):
        _schedule = schedule_by_identifier(_schedule)

    # get default radiant, latent, and lost fractions
    radiant_fract_ = radiant_fract_ if radiant_fract_ is not None else 0.0
    latent_fract_ = latent_fract_ if latent_fract_ is not None else 0.0
    lost_fract_ = lost_fract_ if lost_fract_ is not None else 0.0

    # create the Equipment object
    if gas_:
        equip = GasEquipment(name, _watts_per_area, _schedule, radiant_fract_,
                             latent_fract_, lost_fract_)
    else:
        equip = ElectricEquipment(name, _watts_per_area, _schedule,
                                  radiant_fract_, latent_fract_, lost_fract_)
    if _name_ is not None:
        equip.display_name = _name_