def test_equipment_equality(): """Test the equality of ElectricEquipment objects.""" weekday_office = ScheduleDay( 'Weekday Office Equip', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Equip', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Equip', weekday_office, [weekend_rule], schedule_types.fractional) equipment = ElectricEquipment('Open Office Zone Equip', 10, schedule) equipment_dup = equipment.duplicate() equipment_alt = ElectricEquipment( 'Open Office Zone Equip', 10, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert equipment is equipment assert equipment is not equipment_dup assert equipment == equipment_dup equipment_dup.watts_per_area = 6 assert equipment != equipment_dup assert equipment != equipment_alt
def test_lighting_setability(): """Test the setting of properties of Lighting.""" simple_office = ScheduleDay( 'Simple Weekday Light', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) schedule = ScheduleRuleset('Office Lighting', simple_office, None, schedule_types.fractional) constant = ScheduleRuleset.from_constant_value('Constant Light', 1, schedule_types.fractional) lighting = Lighting('Open Office Zone Lighting', 10, schedule) lighting.identifier = 'Office Zone Lighting' assert lighting.identifier == 'Office Zone Lighting' lighting.watts_per_area = 6 assert lighting.watts_per_area == 6 lighting.schedule = constant assert lighting.schedule == constant assert lighting.schedule.values() == [1] * 8760 lighting.return_air_fraction = 0.1 assert lighting.return_air_fraction == 0.1 lighting.radiant_fraction = 0.4 assert lighting.radiant_fraction == 0.4 lighting.visible_fraction = 0.2 assert lighting.visible_fraction == 0.2 lighting.baseline_watts_per_area = 5.0 assert lighting.baseline_watts_per_area == 5.0
def test_people_equality(): """Test the equality of People objects.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True occ_schedule = ScheduleRuleset('Office Occupancy', weekday_office, [weekend_rule], schedule_types.fractional) people = People('Open Office Zone People', 0.05, occ_schedule) people_dup = people.duplicate() people_alt = People( 'Open Office Zone People', 0.05, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert people is people assert people is not people_dup assert people == people_dup people_dup.people_per_area = 0.06 assert people != people_dup assert people != people_alt
def test_people_setability(): """Test the setting of properties of People.""" simple_office = ScheduleDay( 'Simple Weekday Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) occ_schedule = ScheduleRuleset('Office Occupancy', simple_office, None, schedule_types.fractional) constant_ppl = ScheduleRuleset.from_constant_value( 'Constant Occ', 1, schedule_types.fractional) sleeping_act = ScheduleRuleset.from_constant_value( 'Sleeping Activity', 95, schedule_types.activity_level) people = People('Open Office Zone People', 0.05, occ_schedule) people.identifier = 'Office Zone People' assert people.identifier == 'Office Zone People' people.people_per_area = 0.1 assert people.people_per_area == 0.1 assert people.area_per_person == 10 people.area_per_person = 20 assert people.area_per_person == 20 assert people.people_per_area == 0.05 people.occupancy_schedule = constant_ppl assert people.occupancy_schedule == constant_ppl people.activity_schedule = sleeping_act assert people.activity_schedule.schedule_type_limit == schedule_types.activity_level assert people.activity_schedule.values() == [95] * 8760 people.radiant_fraction = 0.4 assert people.radiant_fraction == 0.4 people.latent_fraction = 0.2 assert people.latent_fraction == 0.2
def test_check_duplicate_schedule_identifiers(): """Test the check_duplicate_schedule_identifiers method.""" room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.program_type = office_program room.properties.energy.add_default_ideal_air() south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5)) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.6, schedule_types.fractional) half_occ = ScheduleRuleset.from_constant_value( 'Half Occupied', 0.5, schedule_types.fractional) south_face.apertures[0].outdoor_shades[0].properties.energy.transmittance_schedule = \ fritted_glass_trans room.properties.energy.people = People('Office Occ', 0.05, half_occ) model = Model('TinyHouse', [room]) assert model.properties.energy.check_duplicate_schedule_identifiers(False) half_occ.unlock() half_occ.identifier = 'Fritted Glass' half_occ.lock() assert not model.properties.energy.check_duplicate_schedule_identifiers(False) with pytest.raises(ValueError): model.properties.energy.check_duplicate_schedule_identifiers(True)
def test_service_hot_water_init_from_idf(): """Test the initialization of Lighting from_idf.""" weekday_office = ScheduleDay('Weekday Office Water Use', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay('Saturday Office Water Use', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Water Use', weekday_office, [weekend_rule], schedule_types.fractional) shw = ServiceHotWater('Open Office Zone Hot Water', 0.1, schedule) sched_dict = {schedule.identifier: schedule} room = Room.from_box('Test_Zone', 10, 10, 3) idf_str, sch_strs = shw.to_idf(room) for sch in sch_strs: sch_obj = ScheduleRuleset.from_idf_constant(sch) sched_dict[sch_obj.identifier] = sch_obj rebuilt_shw, room_id, flow = ServiceHotWater.from_idf( idf_str, room.floor_area, sched_dict) if (sys.version_info >= (3, 0)): assert shw == rebuilt_shw assert room_id == room.identifier assert flow == shw.flow_per_area * room.floor_area
def test_schedule_ruleset_equality(): """Test the equality of ScheduleRuleset objects.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Occupancy', weekday_office, [weekend_rule], schedule_types.fractional) schedule_dup = schedule.duplicate() residential_schedule = ScheduleRuleset.from_daily_values( 'Residence Occupancy', [ 1, 1, 1, 1, 1, 1, 1, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.5, 0.5, 0.5, 0.5, 1, 1, 1 ]) assert schedule is schedule assert schedule is not schedule_dup assert schedule == schedule_dup schedule_dup.schedule_rules[0].apply_friday = True assert schedule != schedule_dup assert schedule != residential_schedule
def test_check_duplicate_schedule_type_limit_names(): """Test the check_duplicate_schedule_type_limit_names method.""" room = Room.from_box('Tiny House Zone', 5, 10, 3) room.properties.energy.program_type = office_program room.properties.energy.hvac = IdealAirSystem() south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].overhang(0.5, indoor=False) south_face.apertures[0].overhang(0.5, indoor=True) south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5)) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.6, schedule_types.fractional) on_off = ScheduleTypeLimit('On-off', 0, 1, 'Discrete') full_occ = ScheduleRuleset.from_constant_value('Occupied', 1, on_off) south_face.apertures[0].outdoor_shades[0].properties.energy.transmittance_schedule = \ fritted_glass_trans room.properties.energy.people = People('Office Occ', 0.05, full_occ) model = Model('Tiny House', [room]) assert model.properties.energy.check_duplicate_schedule_type_limit_names( False) full_occ.unlock() new_sch_type = ScheduleTypeLimit('Fractional', 0, 1, 'Discrete') full_occ.schedule_type_limit = new_sch_type full_occ.lock() assert not model.properties.energy.check_duplicate_schedule_type_limit_names( False) with pytest.raises(ValueError): model.properties.energy.check_duplicate_schedule_type_limit_names(True)
def test_set_loads(): """Test the setting of a load objects on a Room.""" lab_equip_day = ScheduleDay('Daily Lab Equipment', [0.25, 0.5, 0.25], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_equipment = ScheduleRuleset('Lab Equipment', lab_equip_day, None, schedule_types.fractional) lab_vent_day = ScheduleDay('Daily Lab Ventilation', [0.5, 1, 0.5], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_ventilation = ScheduleRuleset('Lab Ventilation', lab_vent_day, None, schedule_types.fractional) room = Room.from_box('BioLaboratoryZone', 5, 10, 3) room.properties.energy.program_type = office_program lab_equip = ElectricEquipment('Lab Equipment', 50, lab_equipment) lav_vent = Ventilation('Lab Ventilation', 0, 0, 0, 6, lab_ventilation) lab_setpt = room.properties.energy.setpoint.duplicate() lab_setpt.heating_setpoint = 22 lab_setpt.cooling_setpoint = 24 room.properties.energy.electric_equipment = lab_equip room.properties.energy.ventilation = lav_vent room.properties.energy.setpoint = lab_setpt assert room.properties.energy.program_type == office_program assert room.properties.energy.electric_equipment.watts_per_area == 50 assert room.properties.energy.electric_equipment.schedule == lab_equipment assert room.properties.energy.ventilation.flow_per_person == 0 assert room.properties.energy.ventilation.flow_per_area == 0 assert room.properties.energy.ventilation.air_changes_per_hour == 6 assert room.properties.energy.ventilation.schedule == lab_ventilation assert room.properties.energy.setpoint.heating_setpoint == 22 assert room.properties.energy.setpoint.heating_setback == 22 assert room.properties.energy.setpoint.cooling_setpoint == 24 assert room.properties.energy.setpoint.cooling_setback == 24
def schedule_primary_school_occupancy(directory): weekday_school = ScheduleDay('Weekday School Year', [0, 1, 0.5, 0], [Time(0, 0), Time(8, 0), Time(15, 0), Time(18, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0]) weekday_summer = ScheduleDay('Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) summer_weekday_rule = ScheduleRule( weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule( weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True summer_design = ScheduleDay('School Summer Design', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(18, 0)]) winter_design = ScheduleDay('School Winter Design', [0]) schedule = ScheduleRuleset('School Occupancy', weekday_school, [summer_weekday_rule, summer_weekend_rule, school_weekend_rule], schedule_types.fractional, weekend_summer, summer_design, winter_design) dest_file = os.path.join(directory, 'schedule_primary_school_occupancy.json') with open(dest_file, 'w') as fp: json.dump(schedule.to_dict(True), fp, indent=4)
def test_service_hot_water_average(): """Test the ServiceHotWater.average method.""" weekday_office = ScheduleDay('Weekday Office Water Use', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay('Weekday Lobby Water Use', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Water Use', [0]) weekend_lobby = ScheduleDay('Weekend Office Water Use', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Water Use', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Water Use', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_shws = ServiceHotWater( 'Office Hot Water', 0.05, office_schedule, 60, 0.3, 0.05) br_shws = ServiceHotWater( 'Bathroom Hot Water', 0.1, lobby_schedule, 50, 0.4, 0.1) office_avg = ServiceHotWater.average( 'Office Average Hot Water', [office_shws, br_shws]) assert office_avg.flow_per_area == pytest.approx(0.075, rel=1e-3) assert office_avg.target_temperature == pytest.approx(55.0, rel=1e-3) assert office_avg.sensible_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.latent_fraction == pytest.approx(0.075, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
def model_energy_window_ventilation(directory): room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.add_default_ideal_air() south_face = room[3] north_face = room[1] south_face.apertures_by_ratio(0.4, 0.01) north_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].is_operable = True north_face.apertures[0].is_operable = True heat_setpt = ScheduleRuleset.from_constant_value( 'House Heating', 20, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'House Cooling', 28, schedule_types.temperature) setpoint = Setpoint('House Setpoint', heat_setpt, cool_setpt) room.properties.energy.setpoint = setpoint vent_control = VentilationControl(22, 27, 12, 30) room.properties.energy.window_vent_control = vent_control ventilation = VentilationOpening(wind_cross_vent=True) room.properties.energy.assign_ventilation_opening(ventilation) model = Model('TinyHouse', [room]) dest_file = os.path.join(directory, 'model_energy_window_ventilation.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(included_prop=['energy']), fp, indent=4)
def test_lighting_equality(): """Test the equality of Lighting objects.""" weekday_office = ScheduleDay( 'Weekday Office Lighting', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Lighting', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_rule = ScheduleRule(saturday_office) weekend_rule.apply_weekend = True schedule = ScheduleRuleset('Office Lighting', weekday_office, [weekend_rule], schedule_types.fractional) lighting = Lighting('Open Office Zone Lighting', 10, schedule) lighting_dup = lighting.duplicate() lighting_alt = Lighting( 'Open Office Zone Lighting', 10, ScheduleRuleset.from_constant_value('Constant', 1, schedule_types.fractional)) assert lighting is lighting assert lighting is not lighting_dup assert lighting == lighting_dup lighting_dup.watts_per_area = 6 assert lighting != lighting_dup assert lighting != lighting_alt
def test_lighting_average(): """Test the Lighting.average method.""" weekday_office = ScheduleDay('Weekday Office Lighting', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay('Weekday Lobby Lighting', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Lighting', [0]) weekend_lobby = ScheduleDay('Weekend Office Lighting', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Lighting', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Lighting', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_lights = Lighting('Office Lighting', 10, office_schedule, 0, 0.3, 0.3) lobby_lights = Lighting('Lobby Lighting', 6, lobby_schedule, 0.1, 0.4, 0.2) office_avg = Lighting.average('Office Average Lighting', [office_lights, lobby_lights]) assert office_avg.watts_per_area == pytest.approx(8, rel=1e-3) assert office_avg.return_air_fraction == pytest.approx(0.05, rel=1e-3) assert office_avg.radiant_fraction == pytest.approx(0.35, rel=1e-3) assert office_avg.visible_fraction == pytest.approx(0.25, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
def test_setpoint_init_from_idf_humidity(): """Test the initialization of Setpoint from_idf with humidity setpoints.""" simple_heat = ScheduleDay( 'Simple Weekday HtgSetp', [18, 21, 18], [Time(0, 0), Time(9, 0), Time(17, 0)]) simple_cool = ScheduleDay( 'Simple Weekday ClgSetp', [28, 24, 28], [Time(0, 0), Time(9, 0), Time(17, 0)]) heat_setpt = ScheduleRuleset('Office Heating', simple_heat, None, schedule_types.temperature) cool_setpt = ScheduleRuleset('Office Cooling', simple_cool, None, schedule_types.temperature) humid_setpt = ScheduleRuleset.from_constant_value('Office Humid', 30, schedule_types.humidity) dehumid_setpt = ScheduleRuleset.from_constant_value( 'Office Dehumid', 60, schedule_types.humidity) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt, humid_setpt, dehumid_setpt) sched_dict = { heat_setpt.identifier: heat_setpt, cool_setpt.identifier: cool_setpt, humid_setpt.identifier: humid_setpt, dehumid_setpt.identifier: dehumid_setpt } zone_id = 'Test Zone' idf_str = setpoint.to_idf(zone_id) humid_idf_str = setpoint.to_idf_humidistat(zone_id) rebuilt_setpoint = Setpoint.from_idf(idf_str, sched_dict) rebuilt_setpoint.add_humidity_from_idf(humid_idf_str, sched_dict) assert setpoint == rebuilt_setpoint
def test_schedule_ruleset_to_from_idf(): """Test the ScheduleRuleset to_idf and from_idf methods.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sunday_office = ScheduleDay('Sunday Office Occupancy', [0]) week_rule = ScheduleRule(weekday_office) week_rule.apply_weekday = True sat_rule = ScheduleRule(saturday_office, apply_saturday=True) summer_office = ScheduleDay( 'Summer Office Occupancy', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(22, 0)]) winter_office = ScheduleDay('Winter Office Occupancy', [0]) schedule = ScheduleRuleset('Office Occupancy', sunday_office, [week_rule, sat_rule], schedule_types.fractional, summer_office, winter_office) year_sched, week_scheds = schedule.to_idf() assert len(week_scheds) == 1 day_scheds = (weekday_office.to_idf(), saturday_office.to_idf(), sunday_office.to_idf(), summer_office.to_idf(), winter_office.to_idf()) sch_type = schedule_types.fractional.to_idf() rebuilt_schedule = ScheduleRuleset.from_idf(year_sched, week_scheds, day_scheds, sch_type) rebuilt_year_sched, rebuilt_week_scheds = rebuilt_schedule.to_idf() assert rebuilt_year_sched == year_sched assert rebuilt_week_scheds[0] == week_scheds[0]
def test_schedule_ruleset_average_schedules(): """Test the average_schedules method.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Occupancy', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Occupancy', [0]) weekend_lobby = ScheduleDay('Weekend Office Occupancy', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Occupancy', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Occupancy', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_avg = ScheduleRuleset.average_schedules( 'Office Average', [office_schedule, lobby_schedule]) week_vals = office_avg.values(end_date=Date(1, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals assert (len(office_avg.schedule_rules)) == 1
def test_setpoint_equality(): """Test the equality of Setpoint objects.""" simple_heat = ScheduleDay( 'Simple Weekday HtgSetp', [18, 21, 18], [Time(0, 0), Time(9, 0), Time(17, 0)]) simple_cool = ScheduleDay( 'Simple Weekday ClgSetp', [28, 24, 28], [Time(0, 0), Time(9, 0), Time(17, 0)]) heat_setpt = ScheduleRuleset('Office Heating', simple_heat, None, schedule_types.temperature) cool_setpt = ScheduleRuleset('Office Cooling', simple_cool, None, schedule_types.temperature) heat_setpt_2 = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt_2 = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) setpoint_dup = setpoint.duplicate() setpoint_alt = Setpoint('Office Setpoint', heat_setpt_2, cool_setpt_2) assert setpoint is setpoint assert setpoint is not setpoint_dup assert setpoint == setpoint_dup setpoint_dup.humidifying_setpoint = 30 assert setpoint != setpoint_dup assert setpoint != setpoint_alt
def test_ideal_air_init_from_idf(): """Test the initialization of IdealAirSystem from_idf.""" ideal_air = IdealAirSystem('Test_System') with pytest.raises(AssertionError): ideal_air.to_idf() zone_id = 'ShoeBox' room = Room.from_box(zone_id, 5, 10, 3, 90, Point3D(0, 0, 3)) room.properties.energy.add_default_ideal_air() ideal_air = room.properties.energy.hvac with pytest.raises(AssertionError): ideal_air.to_idf() heat_setpt = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) room.properties.energy.setpoint = setpoint idf_str = ideal_air.to_idf() schedule_dict = {} rebuilt_ideal_air, rebuilt_zone_id = IdealAirSystem.from_idf( idf_str, schedule_dict) assert ideal_air == rebuilt_ideal_air assert zone_id == rebuilt_zone_id
def test_set_program_type(): """Test the setting of a ProgramType on a Room.""" lab_equip_day = ScheduleDay('Daily Lab Equipment', [0.25, 0.5, 0.25], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_equipment = ScheduleRuleset('Lab Equipment', lab_equip_day, None, schedule_types.fractional) lab_vent_day = ScheduleDay('Daily Lab Ventilation', [0.5, 1, 0.5], [Time(0, 0), Time(9, 0), Time(20, 0)]) lab_ventilation = ScheduleRuleset('Lab Ventilation', lab_vent_day, None, schedule_types.fractional) lab_program = office_program.duplicate() lab_program.identifier = 'Bio Laboratory' lab_program.electric_equipment.watts_per_area = 50 lab_program.electric_equipment.schedule = lab_equipment lab_program.ventilation.flow_per_person = 0 lab_program.ventilation.flow_per_area = 0 lab_program.ventilation.air_changes_per_hour = 6 lab_program.ventilation.schedule = lab_ventilation room = Room.from_box('ShoeBox', 5, 10, 3) room.properties.energy.program_type = lab_program assert room.properties.energy.program_type.identifier == 'Bio Laboratory' assert room.properties.energy.program_type == lab_program assert room.properties.energy.electric_equipment.watts_per_area == 50 assert room.properties.energy.electric_equipment.schedule == lab_equipment assert room.properties.energy.ventilation.flow_per_person == 0 assert room.properties.energy.ventilation.flow_per_area == 0 assert room.properties.energy.ventilation.air_changes_per_hour == 6 assert room.properties.energy.ventilation.schedule == lab_ventilation
def test_schedule_ruleset_average_schedules_date_range(): """Test the ScheduleRuleset average_schedules method with schedules over a date range.""" weekday_school = ScheduleDay( 'Weekday School Year', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(17, 0)]) weekend_school = ScheduleDay('Weekend School Year', [0.1]) weekday_summer = ScheduleDay( 'Weekday Summer', [0, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) weekend_summer = ScheduleDay('Weekend Summer', [0]) summer_weekday_rule = ScheduleRule(weekday_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekday_rule.apply_weekday = True summer_weekend_rule = ScheduleRule(weekend_summer, start_date=Date(7, 1), end_date=Date(9, 1)) summer_weekend_rule.apply_weekend = True summer_weekend_rule.apply_holiday = True school_weekend_rule = ScheduleRule(weekend_school) school_weekend_rule.apply_weekend = True school_weekend_rule.apply_holiday = True summer_design = ScheduleDay( 'School Summer Design', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(18, 0)]) winter_design = ScheduleDay('School Winter Design', [0]) all_rules = [summer_weekday_rule, summer_weekend_rule, school_weekend_rule] school_schedule = ScheduleRuleset('School Occupancy', weekday_school, all_rules, schedule_types.fractional, summer_design, winter_design) lobby_schedule = ScheduleRuleset.from_constant_value( 'Lobby Occupancy', 0.1, schedule_types.fractional) school_avg = ScheduleRuleset.average_schedules( 'Office Average', [school_schedule, lobby_schedule]) week_vals = school_avg.values(end_date=Date(1, 7)) avg_vals = [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ] assert week_vals[:24] == [0.1] * 24 assert week_vals[24:48] == avg_vals week_vals = school_avg.values(start_date=Date(7, 1), end_date=Date(7, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals
def test_dict_to_object_load(): """Test the dict_to_object method with Setpoint objects.""" heat_setpt = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) setpoint_dict = setpoint.to_dict() new_setpoint = dict_to_object(setpoint_dict) assert isinstance(new_setpoint, Setpoint)
def test_run_idf_window_ventilation(): """Test the Model.to.idf and run_idf method with a model possessing operable windows.""" room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.add_default_ideal_air() south_face = room[3] north_face = room[1] south_face.apertures_by_ratio(0.4, 0.01) north_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].is_operable = True north_face.apertures[0].is_operable = True heat_setpt = ScheduleRuleset.from_constant_value( 'House Heating', 20, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'House Cooling', 28, schedule_types.temperature) setpoint = Setpoint('House Setpoint', heat_setpt, cool_setpt) room.properties.energy.setpoint = setpoint vent_control = VentilationControl(22, 27, 12, 30) room.properties.energy.window_vent_control = vent_control ventilation = VentilationOpening(wind_cross_vent=True) op_aps = room.properties.energy.assign_ventilation_opening(ventilation) assert len(op_aps) == 2 model = Model('TinyHouse', [room]) # Get the input SimulationParameter sim_par = SimulationParameter() sim_par.output.add_zone_energy_use() ddy_file = './tests/ddy/chicago.ddy' sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file) sim_par.run_period.end_date = Date(6, 7) sim_par.run_period.start_date = Date(6, 1) # create the IDF string for simulation paramters and model idf_str = '\n\n'.join((sim_par.to_idf(), model.to.idf(model))) # write the final string into an IDF idf = os.path.join(folders.default_simulation_folder, 'test_file_window_vent', 'in.idf') write_to_file(idf, idf_str, True) # prepare the IDF for simulation epw_file = './tests/simulation/chicago.epw' prepare_idf_for_simulation(idf, epw_file) # run the IDF through EnergyPlus sql, zsz, rdd, html, err = run_idf(idf, epw_file) assert os.path.isfile(sql) assert os.path.isfile(err) err_obj = Err(err) assert 'EnergyPlus Completed Successfully' in err_obj.file_contents
def test_setpoint_lockability(): """Test the lockability of Setpoint objects.""" heat_setpt = ScheduleRuleset.from_constant_value( 'Office Heating', 21, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'Office Cooling', 24, schedule_types.temperature) setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt) setpoint.heating_setpoint = 20 setpoint.lock() with pytest.raises(AttributeError): setpoint.heating_setpoint = 22 setpoint.unlock() setpoint.heating_setpoint = 22
def test_schedule_ruleset_init(): """Test the ScheduleRuleset initialization and basic properties.""" weekday_office = ScheduleDay( 'Weekday Office Occupancy', [0, 1, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) saturday_office = ScheduleDay( 'Saturday Office Occupancy', [0, 0.25, 0], [Time(0, 0), Time(9, 0), Time(17, 0)]) sunday_office = ScheduleDay('Sunday Office Occupancy', [0]) sat_rule = ScheduleRule(saturday_office, apply_saturday=True) sun_rule = ScheduleRule(sunday_office, apply_sunday=True) summer_office = ScheduleDay( 'Summer Office Occupancy', [0, 1, 0.25], [Time(0, 0), Time(6, 0), Time(22, 0)]) winter_office = ScheduleDay('Winter Office Occupancy', [0]) schedule = ScheduleRuleset('Office Occupancy', weekday_office, [sat_rule, sun_rule], schedule_types.fractional, summer_office, winter_office) str(schedule) # test the string representation assert schedule.name == 'Office Occupancy' assert schedule.default_day_schedule == weekday_office assert schedule.summer_designday_schedule == summer_office assert schedule.winter_designday_schedule == winter_office assert schedule.schedule_type_limit == schedule_types.fractional assert len(schedule.schedule_rules) == 2 schedule.remove_rule(1) assert len(schedule.schedule_rules) == 1 schedule.add_rule(sun_rule) assert len(schedule.schedule_rules) == 2 with pytest.raises(ValueError): schedule = ScheduleRuleset('Office Occupancy', weekday_office)
def test_ventilation_average(): """Test the Ventilation.average method.""" weekday_office = ScheduleDay( 'Weekday Office Ventilation', [0, 1, 0.5, 0], [Time(0, 0), Time(9, 0), Time(17, 0), Time(19, 0)]) weekday_lobby = ScheduleDay( 'Weekday Lobby Ventilation', [0.1, 1, 0.1], [Time(0, 0), Time(8, 0), Time(20, 0)]) weekend_office = ScheduleDay('Weekend Office Ventilation', [0]) weekend_lobby = ScheduleDay('Weekend Office Ventilation', [0.1]) wknd_office_rule = ScheduleRule(weekend_office, apply_saturday=True, apply_sunday=True) wknd_lobby_rule = ScheduleRule(weekend_lobby, apply_saturday=True, apply_sunday=True) office_schedule = ScheduleRuleset('Office Ventilation', weekday_office, [wknd_office_rule], schedule_types.fractional) lobby_schedule = ScheduleRuleset('Lobby Ventilation', weekday_lobby, [wknd_lobby_rule], schedule_types.fractional) office_vent = Ventilation('Office Ventilation', 0.01, 0.0006, 0, 0, office_schedule) lobby_vent = Ventilation('Lobby Ventilation', 0, 0, 0, 1, lobby_schedule) office_avg = Ventilation.average('Average Ventilation', [office_vent, lobby_vent]) assert office_avg.flow_per_person == pytest.approx(0.005, rel=1e-3) assert office_avg.flow_per_area == pytest.approx(0.0003, rel=1e-3) assert office_avg.flow_per_zone == pytest.approx(0, rel=1e-3) assert office_avg.air_changes_per_hour == pytest.approx(0.5, rel=1e-3) week_vals = office_avg.schedule.values(end_date=Date(1, 7)) avg_vals = [ 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75, 0.75, 0.5, 0.05, 0.05, 0.05, 0.05 ] assert week_vals[:24] == [0.05] * 24 assert week_vals[24:48] == avg_vals office_vent.schedule = None lobby_vent.schedule = None office_avg = Ventilation.average('Average Ventilation', [office_vent, lobby_vent]) assert office_avg.schedule is None
def test_schedule_ruleset_from_week_day_schedules(): """Test the initialization of ScheduleRuleset from_week_day_schedules.""" weekday_vals = [ 0, 0, 0, 0, 0, 0, 0, 0.1, 0.25, 1, 1, 1, 0.5, 1, 1, 1, 1, 0.5, 0.5, 0.25, 0, 0, 0, 0 ] sat_vals = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0 ] sun_vals = [0 for i in range(24)] weekday = ScheduleDay.from_values_at_timestep('Weekday Office Occ', weekday_vals) sat = ScheduleDay.from_values_at_timestep('Saturday Office Occ', sat_vals) sun = ScheduleDay.from_values_at_timestep('Sunday Office Occ', sun_vals) schedule = ScheduleRuleset.from_week_day_schedules( 'Office Occ', sun, weekday, weekday, weekday, weekday, weekday, sat, sun, weekday, sun, schedule_types.fractional) assert schedule.identifier == 'Office Occ' assert len(schedule.schedule_rules) == 2 assert schedule.summer_designday_schedule.values_at_timestep( ) == weekday_vals assert schedule.winter_designday_schedule.values_at_timestep() == sun_vals sch_week_vals = schedule.values(end_date=Date(1, 7)) assert sch_week_vals == sun_vals + weekday_vals + weekday_vals + weekday_vals + \ weekday_vals + weekday_vals + sat_vals
def test_schedule_ruleset_from_week_daily_values(): """Test the initialization of ScheduleRuleset from_week_daily_values.""" weekday = [ 0, 0, 0, 0, 0, 0, 0, 0.1, 0.25, 1, 1, 1, 0.5, 1, 1, 1, 1, 0.5, 0.5, 0.25, 0, 0, 0, 0 ] sat = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0 ] sun = [0 for i in range(24)] schedule = ScheduleRuleset.from_week_daily_values( 'Office Occ', sun, weekday, weekday, weekday, weekday, weekday, sat, sun, schedule_type_limit=schedule_types.fractional) assert schedule.identifier == 'Office Occ' assert len(schedule.schedule_rules) == 2 assert schedule.summer_designday_schedule.values_at_timestep() == weekday assert schedule.winter_designday_schedule.values_at_timestep() == sun sch_week_vals = schedule.values(end_date=Date(1, 7)) assert sch_week_vals == sun + weekday + weekday + weekday + weekday + weekday + sat
def test_to_dict(): """Test the Shade to_dict method with energy properties.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) shade_dict = shade.to_dict() assert 'properties' in shade_dict assert shade_dict['properties']['type'] == 'ShadeProperties' assert 'energy' in shade_dict['properties'] assert shade_dict['properties']['energy'][ 'type'] == 'ShadeEnergyProperties' light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf shade_dict = shade.to_dict() assert 'construction' in shade_dict['properties']['energy'] assert shade_dict['properties']['energy']['construction'][ 'solar_reflectance'] == 0.5 assert shade_dict['properties']['energy']['construction'][ 'visible_reflectance'] == 0.5 assert shade_dict['properties']['energy']['construction']['is_specular'] fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans shade_dict = shade.to_dict() assert 'transmittance_schedule' in shade_dict['properties']['energy'] assert shade_dict['properties']['energy'][ 'transmittance_schedule'] is not None
def test_writer_to_idf(): """Test the Shade to_idf method.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade = Shade('overhang', Face3D(verts)) assert hasattr(shade.to, 'idf') idf_string = shade.to.idf(shade) assert 'overhang,' in idf_string assert 'Shading:Building:Detailed,' in idf_string assert 'ShadingProperty:Reflectance' not in idf_string shade = Shade('overhang', Face3D(verts)) light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) shade.properties.energy.construction = light_shelf fritted_glass_trans = ScheduleRuleset.from_constant_value( 'FrittedGlass', 0.5, schedule_types.fractional) shade.properties.energy.transmittance_schedule = fritted_glass_trans assert hasattr(shade.to, 'idf') idf_string = shade.to.idf(shade) assert 'overhang,' in idf_string assert 'Shading:Building:Detailed,' in idf_string assert 'ShadingProperty:Reflectance' in idf_string assert 'FrittedGlass' in idf_string