def test_utci_parameters_to_from_dict(): """Test UTCI Parameters to/from dict methods.""" cold_thresh = 8 heat_thresh = 27 extreme_cold_thresh = -41 very_strong_cold_thresh = -28 strong_cold_thresh = -14 moderate_cold_thresh = -1 moderate_heat_thresh = 29 strong_heat_thresh = 33 very_strong_heat_thresh = 39 extreme_heat_thresh = 47 utci_comf = UTCIParameter( cold_thresh, heat_thresh, extreme_cold_thresh, very_strong_cold_thresh, strong_cold_thresh, moderate_cold_thresh, moderate_heat_thresh, strong_heat_thresh, very_strong_heat_thresh, extreme_heat_thresh) utci_comf_dict = utci_comf.to_dict() new_utci_comf = UTCIParameter.from_dict(utci_comf_dict) assert new_utci_comf.cold_thresh == cold_thresh assert new_utci_comf.heat_thresh == heat_thresh assert new_utci_comf.extreme_cold_thresh == extreme_cold_thresh assert new_utci_comf.very_strong_cold_thresh == very_strong_cold_thresh assert new_utci_comf.strong_cold_thresh == strong_cold_thresh assert new_utci_comf.moderate_cold_thresh == moderate_cold_thresh assert new_utci_comf.moderate_heat_thresh == moderate_heat_thresh assert new_utci_comf.strong_heat_thresh == strong_heat_thresh assert new_utci_comf.very_strong_heat_thresh == very_strong_heat_thresh assert new_utci_comf.extreme_heat_thresh == extreme_heat_thresh
def test_comfort_check(): """Test comfort check on UTCI Parameters.""" utci_comf = UTCIParameter() comf_test = utci_comf.is_comfortable(5) assert comf_test == 0 comf_test = utci_comf.is_comfortable(22) assert comf_test == 1
def test_thermal_condition_check(): """Test the thermal condition check on UTCI Parameters.""" utci_comf = UTCIParameter() condition_test = utci_comf.thermal_condition(5) assert condition_test == -1 condition_test = utci_comf.thermal_condition(22) assert condition_test == 0 condition_test = utci_comf.thermal_condition(32) assert condition_test == 1
def test_utci_parameters_invalid(): """Test UTCI Parameters for invalid inputs.""" cold_thresh = 30 heat_thresh = 8 with pytest.raises(AssertionError): UTCIParameter(cold_thresh=cold_thresh) with pytest.raises(AssertionError): UTCIParameter(heat_thresh=heat_thresh)
def test_utci_parameters(): """Test UTCI Parameters.""" cold_thresh = 8 heat_thresh = 27 extreme_cold_thresh = -41 very_strong_cold_thresh = -28 strong_cold_thresh = -14 moderate_cold_thresh = -1 moderate_heat_thresh = 29 strong_heat_thresh = 33 very_strong_heat_thresh = 39 extreme_heat_thresh = 47 utci_comf = UTCIParameter(cold_thresh, heat_thresh, extreme_cold_thresh, very_strong_cold_thresh, strong_cold_thresh, moderate_cold_thresh, moderate_heat_thresh, strong_heat_thresh, very_strong_heat_thresh, extreme_heat_thresh) assert utci_comf.cold_thresh == cold_thresh assert utci_comf.heat_thresh == heat_thresh assert utci_comf.extreme_cold_thresh == extreme_cold_thresh assert utci_comf.very_strong_cold_thresh == very_strong_cold_thresh assert utci_comf.strong_cold_thresh == strong_cold_thresh assert utci_comf.moderate_cold_thresh == moderate_cold_thresh assert utci_comf.moderate_heat_thresh == moderate_heat_thresh assert utci_comf.strong_heat_thresh == strong_heat_thresh assert utci_comf.very_strong_heat_thresh == very_strong_heat_thresh assert utci_comf.extreme_heat_thresh == extreme_heat_thresh
def test_utci_collection_immutability(): """Test that the UTCI 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) utci_obj = UTCI(air_temp, 50) # check that editing the original collection does not mutate the object air_temp[0] = 26 assert utci_obj.air_temperature[0] == 24 # check that editing collection properties does not mutate the object with pytest.raises(Exception): utci_obj.air_temperature[0] = 26 with pytest.raises(Exception): utci_obj.air_temperature.values = [26] * calc_length with pytest.raises(Exception): utci_obj.air_temperature = air_temp with pytest.raises(Exception): utci_obj.universal_thermal_climate_index[0] = 20 with pytest.raises(Exception): utci_obj.universal_thermal_climate_index.values = [20] * calc_length # check that properties cannot be edited directly with pytest.raises(Exception): utci_obj.universal_thermal_climate_index = air_temp with pytest.raises(Exception): utci_obj.comfort_parameter = UTCIParameter()
def test_utci_collection_defaults(): """Test the default inputs assigned to the UTCI 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) utci_obj = UTCI(air_temp, 50) assert isinstance(utci_obj.rad_temperature, HourlyContinuousCollection) assert len(utci_obj.rad_temperature.values) == calc_length assert utci_obj.rad_temperature[0] == utci_obj.air_temperature[0] assert isinstance(utci_obj.wind_speed, HourlyContinuousCollection) assert len(utci_obj.wind_speed.values) == calc_length assert utci_obj.wind_speed[0] == 0.1 assert isinstance(utci_obj.comfort_parameter, UTCIParameter) default_par = UTCIParameter() assert utci_obj.comfort_parameter.cold_thresh == default_par.cold_thresh assert utci_obj.comfort_parameter.heat_thresh == default_par.heat_thresh assert utci_obj.comfort_parameter.extreme_cold_thresh == default_par.extreme_cold_thresh assert utci_obj.comfort_parameter.very_strong_cold_thresh == default_par.very_strong_cold_thresh assert utci_obj.comfort_parameter.strong_cold_thresh == default_par.strong_cold_thresh assert utci_obj.comfort_parameter.moderate_cold_thresh == default_par.moderate_cold_thresh assert utci_obj.comfort_parameter.moderate_heat_thresh == default_par.moderate_heat_thresh assert utci_obj.comfort_parameter.strong_heat_thresh == default_par.strong_heat_thresh assert utci_obj.comfort_parameter.very_strong_heat_thresh == default_par.very_strong_heat_thresh assert utci_obj.comfort_parameter.extreme_heat_thresh == default_par.extreme_heat_thresh
def _load_utci_par_str(comfort_par_str): """Load a UTCIParameter from a string. Args: comfort_par_str: A string of a UTCIParameter to be loaded. """ if comfort_par_str is not None and comfort_par_str != '' \ and comfort_par_str != 'None': return UTCIParameter.from_string(comfort_par_str)
def test_thermal_condition_seven_point_check(): """Test the thermal condition check on UTCI Parameters.""" utci_comf = UTCIParameter() condition_test = utci_comf.thermal_condition_seven_point(-30) assert condition_test == -3 condition_test = utci_comf.thermal_condition_seven_point(-15) assert condition_test == -2 condition_test = utci_comf.thermal_condition_seven_point(5) assert condition_test == -1 condition_test = utci_comf.thermal_condition_seven_point(22) assert condition_test == 0 condition_test = utci_comf.thermal_condition_seven_point(30) assert condition_test == 1 condition_test = utci_comf.thermal_condition_seven_point(36) assert condition_test == 2 condition_test = utci_comf.thermal_condition_seven_point(40) assert condition_test == 3
def test_init_utci_collection_full_input(): """Test the initialization of the UTCI 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 = UTCIParameter(8, 25, -41, -28, -14, -1, 27, 31, 37, 45) utci_obj = UTCI(air_temp, 50, 22, 0.5, custom_par) assert utci_obj.air_temperature[0] == 24 assert utci_obj.rel_humidity[0] == 50 assert utci_obj.rad_temperature[0] == 22 assert utci_obj.wind_speed[0] == 0.5 assert utci_obj.comfort_parameter.cold_thresh == 8 assert utci_obj.comfort_parameter.heat_thresh == 25 assert utci_obj.comfort_parameter.extreme_cold_thresh == -41 assert utci_obj.comfort_parameter.very_strong_cold_thresh == -28 assert utci_obj.comfort_parameter.strong_cold_thresh == -14 assert utci_obj.comfort_parameter.moderate_cold_thresh == -1 assert utci_obj.comfort_parameter.moderate_heat_thresh == 27 assert utci_obj.comfort_parameter.strong_heat_thresh == 31 assert utci_obj.comfort_parameter.very_strong_heat_thresh == 37 assert utci_obj.comfort_parameter.extreme_heat_thresh == 45
def test_original_utci_category(): """Test the thermal condition check on UTCI Parameters.""" utci_comf = UTCIParameter() condition_test = utci_comf.original_utci_category(-50) assert condition_test == 0 condition_test = utci_comf.original_utci_category(-30) assert condition_test == 1 condition_test = utci_comf.original_utci_category(-18) assert condition_test == 2 condition_test = utci_comf.original_utci_category(-8) assert condition_test == 3 condition_test = utci_comf.original_utci_category(5) assert condition_test == 4 condition_test = utci_comf.original_utci_category(22) assert condition_test == 5 condition_test = utci_comf.original_utci_category(30) assert condition_test == 6 condition_test = utci_comf.original_utci_category(36) assert condition_test == 7 condition_test = utci_comf.original_utci_category(40) assert condition_test == 8 condition_test = utci_comf.original_utci_category(50) assert condition_test == 9
except ValueError as e: raise TypeError('input {} is not valid. Expected float or ' 'DataCollection. Got {}'.format( input, type(input))) return input_list, data_colls if all_required_inputs(ghenv.Component) and _run is True: # Process inputs and assign defaults. input_list = [_air_temp, _mrt_, _wind_vel_, _rel_humid] input, data_colls = extract_collections(input_list) if data_colls == []: # The inputs are all individual values. utci = universal_thermal_climate_index(input[0], float(input[1]), input[2], input[3]) utci_par = UTCIParameter() comfort = utci_par.is_comfortable(utci) condition = utci_par.thermal_condition(utci) category = utci_par.thermal_condition_eleven_point(utci) 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 = UTCI(_air_temp, _rel_humid, _mrt_, _wind_vel_) utci = comf_obj.universal_thermal_climate_index comfort = comf_obj.is_comfortable condition = comf_obj.thermal_condition category = comf_obj.thermal_condition_eleven_point