def test_get_standard_effective_temperature(): """Test the get_standard_effective_temperature method.""" calc_length = 8760 set_obj = PMV.from_epw(epw, False, False, met_rate=2.4, clo_value=1.0) assert isinstance(set_obj, PMV) assert isinstance(set_obj.air_temperature, HourlyContinuousCollection) assert len(set_obj.air_temperature.values) == calc_length assert set_obj.air_temperature[0] == -6.1 assert isinstance(set_obj.rel_humidity, HourlyContinuousCollection) assert len(set_obj.rel_humidity.values) == calc_length assert set_obj.rel_humidity[0] == 81 assert isinstance(set_obj.standard_effective_temperature, HourlyContinuousCollection) assert len(set_obj.standard_effective_temperature.values) == calc_length assert set_obj.standard_effective_temperature[0] == pytest.approx(12.76, rel=1e-2) assert isinstance(set_obj.thermal_condition, HourlyContinuousCollection) assert len(set_obj.thermal_condition.values) == calc_length assert set_obj.thermal_condition[0] == -1 assert set_obj.percent_neutral == pytest.approx(18.961187, rel=1e-3) assert set_obj.percent_hot == pytest.approx(38.6415525, rel=1e-3) assert set_obj.percent_cold == pytest.approx(42.39726, rel=1e-3)
def test_get_standard_effective_temperature_with_wind(): """Test the get_standard_effective_temperature method with wind.""" set_obj = PMV.from_epw(epw, True, False, met_rate=2.4, clo_value=1.0) assert set_obj.percent_neutral == pytest.approx(19.82, rel=1e-2) assert set_obj.percent_hot == pytest.approx(15.56, rel=1e-2) assert set_obj.percent_cold == pytest.approx(64.61, rel=1e-2)
def test_get_standard_effective_temperature_with_sun(): """Test the get_standard_effective_temperature method with sun.""" set_obj = PMV.from_epw(epw, False, True, met_rate=2.4, clo_value=1.0) assert set_obj.percent_neutral == pytest.approx(17.043378, rel=1e-3) assert set_obj.percent_hot == pytest.approx(44.56621, rel=1e-3) assert set_obj.percent_cold == pytest.approx(38.39041, rel=1e-3)
def test_get_standard_effective_temperature_with_sun_and_wind(): """Test the get_standard_effective_temperature method with sun and wind.""" set_obj = PMV.from_epw(epw, True, True, met_rate=2.4, clo_value=1.0) assert set_obj.percent_neutral == pytest.approx(17.95, rel=1e-2) assert set_obj.percent_hot == pytest.approx(18.82, rel=1e-2) assert set_obj.percent_cold == pytest.approx(63.23, rel=1e-2)
def test_pmv_collection_defaults(): """Test the default inputs assigned to the PMV collection.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) pmv_obj = PMV(air_temp, 50) assert isinstance(pmv_obj.rad_temperature, HourlyContinuousCollection) assert len(pmv_obj.rad_temperature.values) == calc_length assert pmv_obj.rad_temperature[0] == pmv_obj.air_temperature[0] assert isinstance(pmv_obj.air_speed, HourlyContinuousCollection) assert len(pmv_obj.air_speed.values) == calc_length assert pmv_obj.air_speed[0] == 0.1 assert isinstance(pmv_obj.met_rate, HourlyContinuousCollection) assert len(pmv_obj.met_rate.values) == calc_length assert pmv_obj.met_rate[0] == 1.1 assert isinstance(pmv_obj.clo_value, HourlyContinuousCollection) assert len(pmv_obj.clo_value.values) == calc_length assert pmv_obj.clo_value[0] == 0.7 assert isinstance(pmv_obj.external_work, HourlyContinuousCollection) assert len(pmv_obj.external_work.values) == calc_length assert pmv_obj.external_work[0] == 0 assert isinstance(pmv_obj.comfort_parameter, PMVParameter) default_par = PMVParameter() assert pmv_obj.comfort_parameter.ppd_comfort_thresh == default_par.ppd_comfort_thresh assert pmv_obj.comfort_parameter.humid_ratio_upper == default_par.humid_ratio_upper assert pmv_obj.comfort_parameter.humid_ratio_lower == default_par.humid_ratio_lower assert pmv_obj.comfort_parameter.still_air_threshold == default_par.still_air_threshold
def test_init_pmv_collection_full_collection_input(): """Test initialization of the PMV collection will all inputs as collections.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) rel_humid_header = Header(RelativeHumidity(), '%', AnalysisPeriod(end_month=1, end_day=1)) rel_humid = HourlyContinuousCollection(rel_humid_header, [50] * calc_length) rad_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) rad_temp = HourlyContinuousCollection(rad_temp_header, [22] * calc_length) air_speed_header = Header(AirSpeed(), 'm/s', AnalysisPeriod(end_month=1, end_day=1)) air_speed = HourlyContinuousCollection(air_speed_header, [0.5] * calc_length) met_header = Header(MetabolicRate(), 'met', AnalysisPeriod(end_month=1, end_day=1)) met_rate = HourlyContinuousCollection(met_header, [1.2] * calc_length) clo_header = Header(ClothingInsulation(), 'clo', AnalysisPeriod(end_month=1, end_day=1)) clo_level = HourlyContinuousCollection(clo_header, [0.85] * calc_length) work_header = Header(MetabolicRate(), 'met', AnalysisPeriod(end_month=1, end_day=1)) ext_work = HourlyContinuousCollection(work_header, [0.1] * calc_length) pmv_obj = PMV(air_temp, rel_humid, rad_temp, air_speed, met_rate, clo_level, ext_work) assert pmv_obj.air_temperature[0] == 24 assert pmv_obj.rel_humidity[0] == 50 assert pmv_obj.rad_temperature[0] == 22 assert pmv_obj.air_speed[0] == 0.5 assert pmv_obj.met_rate[0] == 1.2 assert pmv_obj.clo_value[0] == 0.85 assert pmv_obj.external_work[0] == 0.1
def test_init_pmv_collection(): """Test the initialization of the PMV collection and basic outputs.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) pmv_obj = PMV(air_temp, 50) assert pmv_obj.comfort_model == 'Predicted Mean Vote' assert pmv_obj.calc_length == calc_length assert pmv_obj._hr_calculated is False assert pmv_obj._hr_comfort_required is False str(pmv_obj) # test that the string representaiton is ok assert isinstance(pmv_obj.air_temperature, HourlyContinuousCollection) assert len(pmv_obj.air_temperature.values) == calc_length assert pmv_obj.air_temperature[0] == 24 assert isinstance(pmv_obj.rel_humidity, HourlyContinuousCollection) assert len(pmv_obj.rel_humidity.values) == calc_length assert pmv_obj.rel_humidity[0] == 50 assert isinstance(pmv_obj.predicted_mean_vote, HourlyContinuousCollection) assert len(pmv_obj.predicted_mean_vote.values) == calc_length assert pmv_obj.predicted_mean_vote[0] == pytest.approx(-0.0535, rel=1e-2) assert isinstance(pmv_obj.percentage_people_dissatisfied, HourlyContinuousCollection) assert len(pmv_obj.percentage_people_dissatisfied.values) == calc_length assert pmv_obj.percentage_people_dissatisfied[0] == pytest.approx(5.0594, rel=1e-2) assert isinstance(pmv_obj.standard_effective_temperature, HourlyContinuousCollection) assert len(pmv_obj.standard_effective_temperature.values) == calc_length assert pmv_obj.standard_effective_temperature[0] == pytest.approx(25.0694, rel=1e-2)
def test_pmv_collection_comfort_outputs(): """Test the is_comfortable and thermal_condition outputs of the PMV collection.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, range(20, 20 + calc_length)) pmv_obj = PMV(air_temp, 50) assert isinstance(pmv_obj.is_comfortable, HourlyContinuousCollection) assert len(pmv_obj.is_comfortable.values) == calc_length assert pmv_obj.is_comfortable[0] == 0 assert pmv_obj.is_comfortable[5] == 1 assert pmv_obj.is_comfortable[10] == 0 assert isinstance(pmv_obj.thermal_condition, HourlyContinuousCollection) assert len(pmv_obj.thermal_condition.values) == calc_length assert pmv_obj.thermal_condition[0] == -1 assert pmv_obj.thermal_condition[5] == 0 assert pmv_obj.thermal_condition[10] == 1 assert isinstance(pmv_obj.discomfort_reason, HourlyContinuousCollection) assert len(pmv_obj.discomfort_reason.values) == calc_length assert pmv_obj.discomfort_reason[0] == -1 assert pmv_obj.discomfort_reason[5] == 0 assert pmv_obj.discomfort_reason[10] == 1
def test_pmv_collection_immutability(): """Test that the PMV collection is immutable.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) pmv_obj = PMV(air_temp, 50) # check that editing the original collection does not mutate the object air_temp[0] = 26 assert pmv_obj.air_temperature[0] == 24 # check that editing collection properties does not mutate the object with pytest.raises(Exception): pmv_obj.air_temperature[0] = 26 with pytest.raises(Exception): pmv_obj.air_temperature.values = [26] * calc_length with pytest.raises(Exception): pmv_obj.predicted_mean_vote[0] = 0.5 with pytest.raises(Exception): pmv_obj.predicted_mean_vote.values = [0.5] * calc_length pmv_obj.comfort_parameter.ppd_comfort_thresh = 15 assert pmv_obj.comfort_parameter.ppd_comfort_thresh == 10 # check that properties cannot be edited directly with pytest.raises(Exception): pmv_obj.air_temperature = air_temp with pytest.raises(Exception): pmv_obj.predicted_mean_vote = air_temp with pytest.raises(Exception): pmv_obj.comfort_parameter = PMVParameter()
def test_pmv_collection_humidity_ratio_outputs(): """Test the humudity ratio outputs of the PMV collection.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) pmv_obj = PMV(air_temp, 90) assert isinstance(pmv_obj.humidity_ratio, HourlyContinuousCollection) assert len(pmv_obj.humidity_ratio.values) == calc_length assert pmv_obj.humidity_ratio[0] == pytest.approx(0.016939, rel=1e-3) hr_par = PMVParameter(humid_ratio_upper=0.012) pmv_obj = PMV(air_temp, 90, comfort_parameter=hr_par) assert pmv_obj._hr_calculated is True assert pmv_obj._hr_comfort_required is True assert pmv_obj.humidity_ratio[0] == pytest.approx(0.016939, rel=1e-3) assert pmv_obj.is_comfortable[0] == 0 assert pmv_obj.thermal_condition[0] == 0 assert pmv_obj.discomfort_reason[0] == 2
def test_pmv_collection_comfort_percent_outputs(): """Test the percent outputs of the PMV collection.""" relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) pmv_obj = PMV(epw.dry_bulb_temperature, epw.relative_humidity, met_rate=2.4, clo_value=1) assert pmv_obj.percent_comfortable == pytest.approx(18.961187, rel=1e-3) assert pmv_obj.percent_uncomfortable == pytest.approx(81.0388127, rel=1e-3) assert pmv_obj.percent_neutral == pytest.approx(18.961187, rel=1e-3) assert pmv_obj.percent_hot == pytest.approx(38.6415525, rel=1e-3) assert pmv_obj.percent_cold == pytest.approx(42.39726027, rel=1e-3) assert pmv_obj.percent_dry == 0.0 assert pmv_obj.percent_humid == 0.0
def test_pmv_collection_heat_loss_outputs(): """Test the heat loss outputs of the PMV collection.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) pmv_obj = PMV(air_temp, 50, air_speed=0.5) assert isinstance(pmv_obj.adjusted_air_temperature, HourlyContinuousCollection) assert len(pmv_obj.adjusted_air_temperature.values) == calc_length assert pmv_obj.adjusted_air_temperature[0] == pytest.approx(21.79, rel=1e-2) assert isinstance(pmv_obj.cooling_effect, HourlyContinuousCollection) assert len(pmv_obj.cooling_effect.values) == calc_length assert pmv_obj.cooling_effect[0] == pytest.approx(2.215, rel=1e-2) assert isinstance(pmv_obj.heat_loss_conduction, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_conduction.values) == calc_length assert pmv_obj.heat_loss_conduction[0] == pytest.approx(12.14, rel=1e-2) assert isinstance(pmv_obj.heat_loss_sweating, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_sweating.values) == calc_length assert pmv_obj.heat_loss_sweating[0] == pytest.approx(2.44, rel=1e-2) assert isinstance(pmv_obj.heat_loss_latent_respiration, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_latent_respiration.values) == calc_length assert pmv_obj.heat_loss_latent_respiration[0] == pytest.approx(4.95, rel=1e-2) assert isinstance(pmv_obj.heat_loss_dry_respiration, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_dry_respiration.values) == calc_length assert pmv_obj.heat_loss_dry_respiration[0] == pytest.approx(1.093, rel=1e-2) assert isinstance(pmv_obj.heat_loss_radiation, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_radiation.values) == calc_length assert pmv_obj.heat_loss_radiation[0] == pytest.approx(28.78, rel=1e-2) assert isinstance(pmv_obj.heat_loss_convection, HourlyContinuousCollection) assert len(pmv_obj.heat_loss_convection.values) == calc_length assert pmv_obj.heat_loss_convection[0] == pytest.approx(26.296, rel=1e-2)
def test_init_pmv_collection_epw(): """Test the initialization of the PMV collection with EPW input.""" calc_length = 8760 relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) pmv_obj = PMV(epw.dry_bulb_temperature, epw.relative_humidity) assert len(pmv_obj.air_temperature.values) == calc_length assert pmv_obj.air_temperature[0] == -6.1 assert len(pmv_obj.rel_humidity.values) == calc_length assert pmv_obj.rel_humidity[0] == 81 assert len(pmv_obj.predicted_mean_vote.values) == calc_length assert pmv_obj.predicted_mean_vote[0] == pytest.approx(-8.70793209, rel=1e-3) assert len(pmv_obj.percentage_people_dissatisfied.values) == calc_length assert pmv_obj.percentage_people_dissatisfied[0] == pytest.approx(100.0, rel=1e-1) assert len(pmv_obj.standard_effective_temperature.values) == calc_length assert pmv_obj.standard_effective_temperature[0] == pytest.approx(-3.65, rel=1e-2)
def test_init_pmv_collection_full_input(): """Test the initialization of the PMV collection will all inputs.""" calc_length = 24 air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) custom_par = PMVParameter(15, 0.012, 0.004, 0.2) pmv_obj = PMV(air_temp, 50, 22, 0.5, 1.2, 0.85, 0.1, custom_par) assert pmv_obj.air_temperature[0] == 24 assert pmv_obj.rel_humidity[0] == 50 assert pmv_obj.rad_temperature[0] == 22 assert pmv_obj.air_speed[0] == 0.5 assert pmv_obj.met_rate[0] == 1.2 assert pmv_obj.clo_value[0] == 0.85 assert pmv_obj.external_work[0] == 0.1 assert pmv_obj.comfort_parameter.ppd_comfort_thresh == 15 assert pmv_obj.comfort_parameter.humid_ratio_upper == 0.012 assert pmv_obj.comfort_parameter.humid_ratio_lower == 0.004 assert pmv_obj.comfort_parameter.still_air_threshold == 0.2
def set_(epw_file, include_wind, include_sun, met_rate, clo_value, csv, output_file): """Get a data collection for Standard Effective Temperature from an EPW weather file. \b Args: epw_file: Path to an .epw file. """ try: epw_obj = EPW(epw_file) pmv_obj = PMV.from_epw(epw_obj, include_wind, include_sun, met_rate, clo_value) set_data = pmv_obj.standard_effective_temperature if csv: output_file.write('\n'.join([str(v) for v in set_data.values])) else: output_file.write(json.dumps(set_data.to_dict())) except Exception as e: _logger.exception('Failed to get SET from EPW file.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
pmv = pmv_result['pmv'] ppd = pmv_result['ppd'] set = pmv_result['set'] hr = humid_ratio_from_db_rh(input[0], input[3]) comfort = pmv_par.is_comfortable(pmv_result['ppd'], hr) condition = pmv_par.discomfort_reason(pmv_result['pmv'], pmv_result['ppd']) heat_loss = [ pmv_result['heat_loss']['cond'], pmv_result['heat_loss']['sweat'], pmv_result['heat_loss']['res_l'], pmv_result['heat_loss']['res_s'], pmv_result['heat_loss']['rad'], pmv_result['heat_loss']['conv'] ] else: # The inputs include Data Collections. if not isinstance(_air_temp, BaseCollection): _air_temp = data_colls[0].get_aligned_collection( float(_air_temp), Temperature(), 'C') comf_obj = PMV(_air_temp, _rel_humid, _mrt_, _air_speed_, _met_rate_, _clothing_, 0, pmv_par) pmv = comf_obj.predicted_mean_vote ppd = comf_obj.percentage_people_dissatisfied set = comf_obj.standard_effective_temperature comfort = comf_obj.is_comfortable condition = comf_obj.discomfort_reason heat_loss = [ comf_obj.heat_loss_conduction, comf_obj.heat_loss_sweating, comf_obj.heat_loss_latent_respiration, comf_obj.heat_loss_dry_respiration, comf_obj.heat_loss_radiation, comf_obj.heat_loss_convection ]
def pmv_by_room(result_sql, air_speed, met_rate, clo_value, comfort_par, result_type, output_file): """Get data collections for PMV in each room from an EnergyPlus sql. \b Args: result_sql: Path to an SQLite file that was generated by EnergyPlus. This file must contain hourly or sub-hourly results for zone comfort variables. """ try: # load the energyplus results related to thermal comfort sql_obj = SQLiteResult(result_sql) air_temps = sql_obj.data_collections_by_output_name( 'Zone Mean Air Temperature') rad_temps = sql_obj.data_collections_by_output_name( 'Zone Mean Radiant Temperature') huimidities = sql_obj.data_collections_by_output_name( 'Zone Air Relative Humidity') # load any of the other data collections if specified assert len(air_temps) != 0, \ 'Input result-sql does not contain thermal comfort outputs.' base_data = air_temps[0] air_speed = _load_data(air_speed, base_data, AirSpeed, 'm/s') met_rate = _load_data(met_rate, base_data, MetabolicRate, 'met') clo_value = _load_data(clo_value, base_data, ClothingInsulation, 'clo') # get aligned data for each room align_dict = { a_dat.header.metadata['Zone']: [a_dat] for a_dat in air_temps } for h_dat in huimidities: align_dict[h_dat.header.metadata['System']].append(h_dat) for r_dat in rad_temps: align_dict[r_dat.header.metadata['Zone']].append(r_dat) # run the collections through the PMV model and output results param = _load_pmv_par_str(comfort_par) pmv_colls = [] for res in align_dict.values(): pmv_obj = PMV(res[0], res[1], res[2], air_speed, met_rate, clo_value, comfort_parameter=param) if result_type == 'PMV': pmv_colls.append(pmv_obj.predicted_mean_vote) elif result_type == 'PPD': pmv_colls.append(pmv_obj.percentage_people_dissatisfied) elif result_type == 'SET': pmv_colls.append(pmv_obj.standard_effective_temperature) elif result_type == 'Comfort': pmv_colls.append(pmv_obj.is_comfortable) else: pmv_colls.append(pmv_obj.thermal_condition) output_file.write(json.dumps([col.to_dict() for col in pmv_colls])) except Exception as e: _logger.exception( 'Failed to run PMV model from sql file.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)