def get_aligned_prevailing(self, collection): """"Get a Prevailing Temperature Collection aligned with input collection.""" if isinstance(collection, HourlyContinuousCollection): new_coll = self.hourly_prevailing_temperature_timestep( collection.header.analysis_period.timestep) if not collection.header.analysis_period.is_annual: new_coll = new_coll.filter_by_analysis_period( collection.header.analysis_period) return new_coll new_coll = collection.get_aligned_collection( data_type=PrevailingOutdoorTemperature(), unit='C') if isinstance(collection, HourlyDiscontinuousCollection): prevail_val_dict = self.hourly_prevailing_temperature_timestep( collection.header.analysis_period.timestep).moys_dict for i, datetime in enumerate(new_coll.datetimes): new_coll[i] = prevail_val_dict[datetime.moy] elif isinstance(collection, DailyCollection): daily_temps = self.daily_prevailing_temperature for i, datetime in enumerate(new_coll.datetimes): new_coll[i] = daily_temps[datetime - 1] elif isinstance(collection, MonthlyCollection): monthly_temps = self.monthly_prevailing_temperature for i, datetime in enumerate(new_coll.datetimes): new_coll[i] = monthly_temps[datetime - 1] elif isinstance(collection, MonthlyPerHourCollection): mon_per_hr = self.monthly_per_hour_prevailing_temperature monthly_per_hour_dict = {} for val, dt in zip(mon_per_hr.values, mon_per_hr.datetimes): monthly_per_hour_dict[dt] = val for i, datetime in enumerate(new_coll.datetimes): new_coll[i] = monthly_per_hour_dict[datetime] return new_coll
def test_adaptive_collection_immutability(): """Test that the Adaptive collection is immutable.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length) adapt_obj = Adaptive(prevail_temp, op_temp) # check that editing the original collection does not mutate the object op_temp[0] = 28 assert adapt_obj.operative_temperature[0] == 26 # check that editing collection properties does not mutate the object with pytest.raises(Exception): adapt_obj.operative_temperature[0] = 28 with pytest.raises(Exception): adapt_obj.operative_temperature.values = [28] * calc_length with pytest.raises(Exception): adapt_obj.degrees_from_neutral[0] = 0.5 with pytest.raises(Exception): adapt_obj.degrees_from_neutral.values = [0.5] * calc_length # check that properties cannot be edited directly with pytest.raises(Exception): adapt_obj.operative_temperature = op_temp with pytest.raises(Exception): adapt_obj.degrees_from_neutral = op_temp with pytest.raises(Exception): adapt_obj.comfort_parameter = AdaptiveParameter(False)
def test_init_adaptive_collection_mrt(): """Test the initialization of the Adaptive collection with MRT.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) air_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) air_temp = HourlyContinuousCollection(air_temp_header, [24] * calc_length) adapt_obj = Adaptive.from_air_and_rad_temp(prevail_temp, air_temp, 28) assert adapt_obj.comfort_model == 'Adaptive' assert adapt_obj.calc_length == calc_length str(adapt_obj) # test that the string representation is ok assert isinstance(adapt_obj.prevailing_outdoor_temperature, HourlyContinuousCollection) assert len(adapt_obj.prevailing_outdoor_temperature.values) == calc_length assert adapt_obj.prevailing_outdoor_temperature[0] == 22 assert isinstance(adapt_obj.operative_temperature, HourlyContinuousCollection) assert len(adapt_obj.operative_temperature.values) == calc_length assert adapt_obj.operative_temperature[0] == 26 assert isinstance(adapt_obj.neutral_temperature, HourlyContinuousCollection) assert len(adapt_obj.neutral_temperature.values) == calc_length assert adapt_obj.neutral_temperature[0] == pytest.approx(24.62, rel=1e-3) assert isinstance(adapt_obj.degrees_from_neutral, HourlyContinuousCollection) assert len(adapt_obj.degrees_from_neutral.values) == calc_length assert adapt_obj.degrees_from_neutral[0] == pytest.approx(1.3799, rel=1e-3)
def test_adaptive_collection_cooling_effect_output(): """Test the cooling effect output of the Adaptive collection.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length) adapt_obj = Adaptive(prevail_temp, op_temp, air_speed=0.7) assert isinstance(adapt_obj.cooling_effect, HourlyContinuousCollection) assert len(adapt_obj.cooling_effect.values) == calc_length assert adapt_obj.cooling_effect[0] == 1.2
def test_init_adaptive_collection_full_collection_input(): """Test initialization of the Adaptive collection with inputs as collections.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length) air_speed_header = Header(AirSpeed(), 'm/s', AnalysisPeriod(end_month=1, end_day=1)) air_speed = HourlyContinuousCollection(air_speed_header, [0.7] * calc_length) adapt_obj = Adaptive(prevail_temp, op_temp, air_speed) assert adapt_obj.operative_temperature[0] == 26 assert adapt_obj.air_speed[0] == 0.7
def test_init_adaptive_collection_full_input(): """Test the initialization of the Adaptive collection will all inputs.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length) custom_par = AdaptiveParameter(True, 2, False, False, 15, 0.25) adapt_obj = Adaptive(prevail_temp, op_temp, 0.7, custom_par) assert adapt_obj.operative_temperature[0] == 26 assert adapt_obj.air_speed[0] == 0.7 assert adapt_obj.comfort_parameter.ashrae55_or_en15251 is True assert adapt_obj.comfort_parameter.neutral_offset == 2 assert adapt_obj.comfort_parameter.avg_month_or_running_mean is False assert adapt_obj.comfort_parameter.discrete_or_continuous_air_speed is False assert adapt_obj.comfort_parameter.cold_prevail_temp_limit == 15 assert adapt_obj.comfort_parameter.conditioning == 0.25
def test_adaptive_collection_comfort_outputs(): """Test the is_comfortable and thermal_condition outputs of the collection.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, range(20, 20 + calc_length)) adapt_obj = Adaptive(prevail_temp, op_temp) assert isinstance(adapt_obj.is_comfortable, HourlyContinuousCollection) assert len(adapt_obj.is_comfortable.values) == calc_length assert adapt_obj.is_comfortable[0] == 0 assert adapt_obj.is_comfortable[5] == 1 assert adapt_obj.is_comfortable[10] == 0 assert isinstance(adapt_obj.thermal_condition, HourlyContinuousCollection) assert len(adapt_obj.thermal_condition.values) == calc_length assert adapt_obj.thermal_condition[0] == -1 assert adapt_obj.thermal_condition[5] == 0 assert adapt_obj.thermal_condition[10] == 1
def test_adaptive_collection_defaults(): """Test the default inputs assigned to the Adaptive collection.""" calc_length = 24 prevail_header = Header(PrevailingOutdoorTemperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) prevail_temp = HourlyContinuousCollection(prevail_header, [22] * calc_length) op_temp_header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) op_temp = HourlyContinuousCollection(op_temp_header, [26] * calc_length) adapt_obj = Adaptive(prevail_temp, op_temp) assert isinstance(adapt_obj.air_speed, HourlyContinuousCollection) assert len(adapt_obj.air_speed.values) == calc_length assert adapt_obj.air_speed[0] == 0.1 assert isinstance(adapt_obj.comfort_parameter, AdaptiveParameter) default_par = AdaptiveParameter() assert adapt_obj.comfort_parameter.ashrae55_or_en15251 == default_par.ashrae55_or_en15251 assert adapt_obj.comfort_parameter.neutral_offset == default_par.neutral_offset assert adapt_obj.comfort_parameter.avg_month_or_running_mean == default_par.avg_month_or_running_mean assert adapt_obj.comfort_parameter.discrete_or_continuous_air_speed == default_par.discrete_or_continuous_air_speed assert adapt_obj.comfort_parameter.cold_prevail_temp_limit == default_par.cold_prevail_temp_limit assert adapt_obj.comfort_parameter.conditioning == default_par.conditioning
def _get_header(self): new_header = self._head.duplicate() new_header._data_type = PrevailingOutdoorTemperature() return new_header