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 data_collection_at_timestep(self, timestep=1, start_date=Date(1, 1), end_date=Date(12, 31)): """Get a ladybug DataCollection representing this schedule at a given timestep. Note that ladybug DataCollections always follow the "Ladybug Tools Interpretation" of date time values as noted in the ScheduleDay.values_at_timestep documentation. Args: timestep: An integer for the number of steps per hour at which to make the resulting DataCollection. start_date: An optional ladybug Date object for when to start the DataCollection. Default: 1 Jan on a non-leap year. end_date: An optional ladybug Date object for when to end the DataCollection. Default: 31 Dec on a non-leap year. """ a_period = AnalysisPeriod(start_date.month, start_date.day, 0, end_date.month, end_date.day, 23, timestep, self.is_leap_year) data_type, unit = self._get_lb_data_type_and_unit() header = Header(data_type, unit, a_period, metadata={'schedule': self.name}) values = self.values_at_timestep(timestep, start_date, end_date) return HourlyContinuousCollection(header, values)
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_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 rad_to_ill(data): """Change the data type of an input collection from irradiane to illuminance.""" head = data.header new_header = Header(Illuminance(), 'lux', head.analysis_period, head.metadata) return HourlyContinuousCollection(new_header, data.values) if \ isinstance(data, HourlyContinuousCollection) else \ data.__class__(new_header, data.values, data.datetimes)
def test_data_by_outputs(): """Test the data_by_output command.""" runner = CliRunner() sql_path = './tests/result/eplusout_hourly.sql' out_names1 = [ 'Zone Ideal Loads Supply Air Total Cooling Energy', 'Zone Ideal Loads Supply Air Total Heating Energy' ] result = runner.invoke(data_by_outputs, [sql_path] + out_names1) assert result.exit_code == 0 data_list = json.loads(result.output) assert len(data_list) == 2 assert len(data_list[0]) == 7 assert all( isinstance(HourlyContinuousCollection.from_dict(dc), HourlyContinuousCollection) for dc in data_list[0]) out_names2 = [ 'Zone Lights Total Heating Energy', 'Chiller Electric Energy' ] result = runner.invoke(data_by_outputs, [sql_path] + out_names2) assert result.exit_code == 0 data_list = json.loads(result.output) assert len(data_list) == 2 assert len(data_list[0]) == 0 input_args = [sql_path, json.dumps(out_names1), json.dumps(out_names2)] result = runner.invoke(data_by_outputs, input_args) assert result.exit_code == 0 data_list = json.loads(result.output) assert len(data_list) == 2 assert len(data_list[0]) == 14 assert len(data_list[1]) == 0
def fract_exposed_from_mtx(person_sun_int_matrix, day_pattern): """Get a Data Collection of fraction exposed values from an intersection matrix. Args: person_sun_int_matrix: An intersection matrix of 0s and 1s for the points of a single person. day_pattern: A list of 8760 booleans indicating whether the sun is up (True) or down (Fasle). Returns: A data collection for the fraction of body exposed. """ pt_count = len(person_sun_int_matrix) fract_per_sun = [ sum(pt_int_ar) / pt_count for pt_int_ar in zip(*person_sun_int_matrix) ] fract_exp_vals = [] per_sun_i = 0 for is_sun in day_pattern: if is_sun: fract_exp_vals.append(fract_per_sun[per_sun_i]) per_sun_i += 1 else: fract_exp_vals.append(0) meta_dat = {'type': 'Fraction of Body Exposed to Direct Sun'} fract_exp_head = Header(Fraction(), 'fraction', AnalysisPeriod(), meta_dat) return HourlyContinuousCollection(fract_exp_head, fract_exp_vals)
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_bounds(): """Test the bounds method.""" header1 = Header(Temperature(), 'C', AnalysisPeriod()) values = list(xrange(8760)) dc1 = HourlyContinuousCollection(header1, values) min, max = dc1.bounds assert min == 0 assert max == 8759
def test_monthlychart_init(): """Test the initialization of MonthlyChart and basic properties.""" header = Header(Temperature(), 'C', AnalysisPeriod()) values = [i / 365 for i in range(8760)] data_coll = HourlyContinuousCollection(header, values) month_chart = MonthlyChart([data_coll]) str(month_chart) # test the string representation assert isinstance(month_chart.data_collections, tuple) assert isinstance(month_chart.data_collections[0], HourlyContinuousCollectionImmutable) assert isinstance(month_chart.legend_parameters, LegendParameters) assert month_chart.base_point == Point2D(0, 0) assert month_chart.x_dim == 10 assert month_chart.y_dim == 40 assert not month_chart.stack assert month_chart.percentile == 34 meshes = month_chart.data_meshes assert isinstance(meshes[0], Mesh2D) assert len(meshes[0].faces) == 24 * 12 plines = month_chart.data_polylines assert isinstance(plines[0], Polyline2D) assert len(plines) == 3 * 12 border = month_chart.chart_border assert isinstance(border, Polyline2D) assert len(border.segments) == 4 y_txt = month_chart.y_axis_labels1 assert all(isinstance(txt, str) for txt in y_txt) y_lines = month_chart.y_axis_lines y_pts = month_chart.y_axis_label_points1 assert len(y_lines) == len(y_txt) == len(y_pts) == 11 assert all(isinstance(line, LineSegment2D) for line in y_lines) assert all(isinstance(pt, Point2D) for pt in y_pts) assert isinstance(month_chart.y_axis_title_text1, str) assert 'Temperature' in month_chart.y_axis_title_text1 assert isinstance(month_chart.y_axis_title_location1, Plane) assert month_chart.y_axis_labels2 is None assert month_chart.y_axis_label_points2 is None assert month_chart.y_axis_title_text2 is None assert month_chart.y_axis_title_location2 is None month_txt = month_chart.month_labels assert all(isinstance(txt, str) for txt in month_txt) month_lines = month_chart.month_lines month_pts = month_chart.month_label_points assert len(month_txt) == len(month_pts) == 12 assert len(month_lines) == 11 assert all(isinstance(line, LineSegment2D) for line in month_lines) assert all(isinstance(pt, Point2D) for pt in month_pts) assert isinstance(month_chart.legend, Legend) assert isinstance(month_chart.title_text, str) assert isinstance(month_chart.lower_title_location, Plane) assert isinstance(month_chart.upper_title_location, Plane)
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 model_occ_schedules(model_json, threshold, period, output_file): """Translate a Model's occupancy schedules into a JSON of 0/1 values. \b Args: model_json: Full path to a Model JSON file. """ try: # re-serialize the Model with open(model_json) as json_file: data = json.load(json_file) model = Model.from_dict(data) # loop through the rooms and collect all unique occupancy schedules scheds, room_occupancy = [], {} for room in model.rooms: people = room.properties.energy.people if people is not None: model.properties.energy._check_and_add_schedule( people.occupancy_schedule, scheds) room_occupancy[room.identifier] = people.occupancy_schedule.identifier else: room_occupancy[room.identifier] = None # process the run period if it is supplied if period is not None and period != '' and period != 'None': a_per = AnalysisPeriod.from_string(period) start = Date(a_per.st_month, a_per.st_day) end = Date(a_per.end_month, a_per.end_day) a_period = AnalysisPeriod(start.month, start.day, 0, end.month, end.day, 23) timestep = a_per.timestep else: a_per = a_period = AnalysisPeriod() start, end, timestep = Date(1, 1), Date(12, 31), 1 # convert occupancy schedules to lists of 0/1 values schedules = {} for sch in scheds: values = [] for val in sch.values(timestep, start, end): is_occ = 0 if val < threshold else 1 values.append(is_occ) header = Header(Fraction(), 'fraction', a_period) schedules[sch.identifier] = HourlyContinuousCollection(header, values) if a_per.st_hour != 0 or a_per.end_hour != 23: schedules = {key: data.filter_by_analysis_period(a_per) for key, data in schedules.items()} schedules = {key: data.values for key, data in schedules.items()} # write out the JSON file occ_dict = {'schedules': schedules, 'room_occupancy': room_occupancy} output_file.write(json.dumps(occ_dict)) except Exception as e: _logger.exception('Model translation failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
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_utci_collection_comfort_outputs(): """Test the is_comfortable and thermal_condition outputs of 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, range(5, 5 + calc_length)) utci_obj = UTCI(air_temp, 50) assert isinstance(utci_obj.is_comfortable, HourlyContinuousCollection) assert len(utci_obj.is_comfortable.values) == calc_length assert utci_obj.is_comfortable[0] == 0 assert utci_obj.is_comfortable[12] == 1 assert utci_obj.is_comfortable[23] == 0 assert isinstance(utci_obj.thermal_condition, HourlyContinuousCollection) assert len(utci_obj.thermal_condition.values) == calc_length assert utci_obj.thermal_condition[0] == -1 assert utci_obj.thermal_condition[12] == 0 assert utci_obj.thermal_condition[23] == 1 assert isinstance(utci_obj.thermal_condition_five_point, HourlyContinuousCollection) assert len(utci_obj.thermal_condition_five_point.values) == calc_length assert utci_obj.thermal_condition_five_point[0] == -1 assert utci_obj.thermal_condition_five_point[12] == 0 assert utci_obj.thermal_condition_five_point[23] == 1 assert isinstance(utci_obj.thermal_condition_seven_point, HourlyContinuousCollection) assert len(utci_obj.thermal_condition_seven_point.values) == calc_length assert utci_obj.thermal_condition_seven_point[0] == -1 assert utci_obj.thermal_condition_seven_point[12] == 0 assert utci_obj.thermal_condition_seven_point[23] == 1 assert isinstance(utci_obj.thermal_condition_nine_point, HourlyContinuousCollection) assert len(utci_obj.thermal_condition_nine_point.values) == calc_length assert utci_obj.thermal_condition_nine_point[0] == -1 assert utci_obj.thermal_condition_nine_point[12] == 0 assert utci_obj.thermal_condition_nine_point[22] == 1 assert utci_obj.thermal_condition_nine_point[23] == 2 assert isinstance(utci_obj.thermal_condition_eleven_point, HourlyContinuousCollection) assert len(utci_obj.thermal_condition_eleven_point.values) == calc_length assert utci_obj.thermal_condition_eleven_point[0] == -1 assert utci_obj.thermal_condition_eleven_point[12] == 0 assert utci_obj.thermal_condition_eleven_point[22] == 1 assert utci_obj.thermal_condition_eleven_point[23] == 2 assert isinstance(utci_obj.original_utci_category, HourlyContinuousCollection) assert len(utci_obj.original_utci_category.values) == calc_length assert utci_obj.original_utci_category[0] == 4 assert utci_obj.original_utci_category[12] == 5 assert utci_obj.original_utci_category[23] == 6
def test_average_median(): """Test the average and median methods.""" header1 = Header(Temperature(), 'C', AnalysisPeriod()) values = list(xrange(8760)) dc = HourlyContinuousCollection(header1, values) assert dc.average == dc.median == 4379.5 dc[0] = -10000 assert dc.average == pytest.approx(4378.35844, rel=1e-3) assert dc.median == 4379.5
def test_horizontal_solarcal_collection_full_input(): """Test the initialization of the HorizontalSolarCal collection will all inputs.""" calc_length = 24 irr_header = Header(Irradiance(), 'W/m2', AnalysisPeriod(end_month=1, end_day=1)) dir_norm = HourlyContinuousCollection(irr_header, [500] * calc_length) diff_horiz = HourlyContinuousCollection(irr_header, [200] * calc_length) custom_par = SolarCalParameter('seated', None, 45, 0.65, 0.97) solarcal_obj = HorizontalSolarCal(Location(), dir_norm, diff_horiz, 24, 0.6, 0.35, custom_par) assert solarcal_obj.fraction_body_exposed[12] == 0.6 assert solarcal_obj.floor_reflectance[0] == 0.35 assert solarcal_obj.solarcal_body_parameter.posture == 'seated' assert solarcal_obj.solarcal_body_parameter.sharp is None assert solarcal_obj.solarcal_body_parameter.body_azimuth == 45 assert solarcal_obj.solarcal_body_parameter.body_absorptivity == 0.65 assert solarcal_obj.solarcal_body_parameter.body_emissivity == 0.97
def test_init_utci_collection_full_collection_input(): """Test initialization of the UTCI 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) wind_speed_header = Header(AirSpeed(), 'm/s', AnalysisPeriod(end_month=1, end_day=1)) wind_speed = HourlyContinuousCollection(wind_speed_header, [0.5] * calc_length) utci_obj = UTCI(air_temp, rel_humid, rad_temp, wind_speed) 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
def _match_face_input(self, surface_flow_data, rooms): """Match a an array of input data collections to input rooms. Args: surface_flow_data: An array of input data collections for surface energy flow. rooms: An array of input honeybee Rooms. """ # match the data collections to the rooms if surface_flow_data is None or len(surface_flow_data) == 0: return None, None, None, None base_data = surface_flow_data[0] values = [0 for val in range(len(base_data))] # compute the total values of the load window_vals, wall_vals, roof_vals, floor_vals = (values[:] for i in range(4)) for room in rooms: mult = room.multiplier match_objs = match_faces_to_data(surface_flow_data, room.faces) for obj in match_objs: if not isinstance(obj[0].boundary_condition, (Surface, Adiabatic)): if isinstance(obj[0], (Aperture, Door)): for i, val in enumerate(obj[1].values): window_vals[i] += val * mult elif isinstance(obj[0].type, Wall): for i, val in enumerate(obj[1].values): wall_vals[i] += val * mult elif isinstance(obj[0].type, RoofCeiling): for i, val in enumerate(obj[1].values): roof_vals[i] += val * mult elif isinstance(obj[0].type, Floor): for i, val in enumerate(obj[1].values): floor_vals[i] += val * mult # create the new totalled data collection new_header = base_data.header.duplicate() if 'Surface' in new_header.metadata: del new_header.metadata['Surface'] window_head, wall_head, roof_head, floor_head = \ (new_header.duplicate() for i in range(4)) window_head.metadata['type'] = 'Window Energy Flow' wall_head.metadata['type'] = 'Wall Conduction' roof_head.metadata['type'] = 'Roof Conduction' floor_head.metadata['type'] = 'Floor Conduction' all_headers = [window_head, wall_head, roof_head, floor_head] all_values = [window_vals, wall_vals, roof_vals, floor_vals] all_data = [] for head, vals in zip(all_headers, all_values): if isinstance(base_data, HourlyContinuousCollection): all_data.append(HourlyContinuousCollection(head, vals)) else: # it's one of the data collections that needs datetimes all_data.append( base_data.__class__(head, vals, base_data.datetimes)) return all_data
def serialize_data(data_dicts): """Reserialize a list of collection dictionaries.""" if len(data_dicts) == 0: return [] elif data_dicts[0]['type'] == 'HourlyContinuousCollection': return [HourlyContinuousCollection.from_dict(data) for data in data_dicts] elif data_dicts[0]['type'] == 'MonthlyCollection': return [MonthlyCollection.from_dict(data) for data in data_dicts] elif data_dicts[0]['type'] == 'DailyCollection': return [DailyCollection.from_dict(data) for data in data_dicts]
def test_filter_collections_by_statement(): """Test the method to filter collections by conditional statement.""" header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) values1 = list(xrange(24)) values2 = [12] * 24 values3 = list(xrange(12, 36)) dc1 = HourlyContinuousCollection(header, values1) dc2 = HourlyContinuousCollection(header, values2) dc3 = HourlyContinuousCollection(header, values3) filt_coll = HourlyContinuousCollection.filter_collections_by_statement( [dc1, dc2, dc3], 'a >= 12 and c <= 30') assert len(filt_coll) == 3 assert len(filt_coll[0]) == len(filt_coll[1]) == len(filt_coll[2]) == 7 assert filt_coll[0].values == (12, 13, 14, 15, 16, 17, 18) assert filt_coll[1].values == (12, 12, 12, 12, 12, 12, 12) assert filt_coll[2].values == (24, 25, 26, 27, 28, 29, 30) assert isinstance(filt_coll[0], HourlyDiscontinuousCollection)
def data_collection(self): """DataCollection of schedule values at this schedule's start_date and timestep. """ end_dt = self.end_date_time a_period = AnalysisPeriod(self.start_date.month, self.start_date.day, 0, end_dt.month, end_dt.day, end_dt.hour, self.timestep, self.is_leap_year) data_type, unit = self._get_lb_data_type_and_unit() header = Header(data_type, unit, a_period, metadata={'schedule': self.identifier}) return HourlyContinuousCollection(header, self._values)
def test_set(): runner = CliRunner() input_epw = './tests/epw/chicago.epw' result = runner.invoke( set_, [input_epw, '--exclude-wind', '--exclude-sun', '--json']) assert result.exit_code == 0 data_dict = json.loads(result.output) set_data = HourlyContinuousCollection.from_dict(data_dict) assert len(set_data) == 8760
def test_heating_degree_time_collection(): """Test the heat_index function with Data Collections.""" calc_length = 8760 relative_path = './tests/epw/chicago.epw' epw = EPW(relative_path) hourly_hi = HourlyContinuousCollection.compute_function_aligned( heat_index, [epw.dry_bulb_temperature, epw.relative_humidity], Temperature(), 'C') assert isinstance(hourly_hi, HourlyContinuousCollection) assert len(hourly_hi.values) == calc_length assert hourly_hi[4000] == pytest.approx(30.89833, rel=1e-3) hourly_category = HourlyContinuousCollection.compute_function_aligned( heat_index_warning_category, [hourly_hi], ThermalCondition(), 'condition') assert isinstance(hourly_category, HourlyContinuousCollection) assert len(hourly_category.values) == calc_length assert hourly_category[4000] == 1
def test_init_horizontal_ref_solarcal_collection(): """Test the initialization of the HorizontalRefSolarCal collection.""" calc_length = 24 irr_header = Header(Irradiance(), 'W/m2', AnalysisPeriod(end_month=1, end_day=1)) dir_norm = HourlyContinuousCollection(irr_header, [300] * calc_length) diff_horiz = HourlyContinuousCollection(irr_header, [100] * calc_length) ref_horiz = HourlyContinuousCollection(irr_header, [100] * calc_length) solarcal_obj = HorizontalRefSolarCal(Location(), dir_norm, diff_horiz, ref_horiz, 24) assert solarcal_obj.comfort_model == 'Horizontal Reflected SolarCal' assert solarcal_obj.calc_length == calc_length str(solarcal_obj) # test that the string representation is ok assert isinstance(solarcal_obj.direct_horizontal_solar, HourlyContinuousCollection) assert len(solarcal_obj.direct_horizontal_solar.values) == calc_length assert solarcal_obj.direct_horizontal_solar[12] == 300 assert isinstance(solarcal_obj.diffuse_horizontal_solar, HourlyContinuousCollection) assert len(solarcal_obj.diffuse_horizontal_solar.values) == calc_length assert solarcal_obj.diffuse_horizontal_solar[12] == 100 assert isinstance(solarcal_obj.reflected_horizontal_solar, HourlyContinuousCollection) assert len(solarcal_obj.reflected_horizontal_solar.values) == calc_length assert solarcal_obj.reflected_horizontal_solar[12] == 100 assert isinstance(solarcal_obj.effective_radiant_field, HourlyContinuousCollection) assert len(solarcal_obj.effective_radiant_field.values) == calc_length assert solarcal_obj.effective_radiant_field[12] == pytest.approx(79.35027, rel=1e-3) assert isinstance(solarcal_obj.mrt_delta, HourlyContinuousCollection) assert len(solarcal_obj.mrt_delta.values) == calc_length assert solarcal_obj.mrt_delta[12] == pytest.approx(18.20503, rel=1e-3) assert isinstance(solarcal_obj.mean_radiant_temperature, HourlyContinuousCollection) assert len(solarcal_obj.mean_radiant_temperature.values) == calc_length assert solarcal_obj.mean_radiant_temperature[12] == pytest.approx(42.20503, rel=1e-3)
def test_pmv_by_room(): runner = CliRunner() input_sql = './tests/sql/eplusout.sql' result = runner.invoke(pmv_by_room, [input_sql]) assert result.exit_code == 0 data_dicts = json.loads(result.output) pmv_data = [ HourlyContinuousCollection.from_dict(dat) for dat in data_dicts ] assert len(pmv_data) == 2 assert len(pmv_data[0]) == 8760
def test_adaptive_by_room(): runner = CliRunner() input_sql = './tests/sql/eplusout.sql' input_epw = './tests/epw/chicago.epw' result = runner.invoke(adaptive_by_room, [input_sql, input_epw, '-v', '0.65']) assert result.exit_code == 0 data_dicts = json.loads(result.output) ad_data = [HourlyContinuousCollection.from_dict(dat) for dat in data_dicts] assert len(ad_data) == 2 assert len(ad_data[0]) == 8760
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 _values_to_data(values, base_period, data_type, data_units): """Load an array of values to a data collection. Args: values: An array of numbers. base_period: An AnalysisPeriod to be used for data collection. data_type: The class of the data type for the values. data_units: The units of the values. """ if isinstance(values, list): header = Header(data_type(), data_units, base_period) return HourlyContinuousCollection(header, values) return values
def test_get_aligned_collection_continuous(): """Test the method for getting an aligned continuous collection.""" header = Header(Temperature(), 'C', AnalysisPeriod(end_month=1, end_day=1)) values = list(xrange(24)) dc1 = HourlyContinuousCollection(header, values) dc2 = dc1.get_aligned_collection(50, RelativeHumidity(), '%') assert dc2.header.data_type.name == 'Relative Humidity' assert dc2.header.unit == '%' assert isinstance(dc2, HourlyContinuousCollection) assert dc2.is_mutable is True dc3 = dc1.get_aligned_collection(50, RelativeHumidity(), '%', mutable=False) assert dc3.header.data_type.name == 'Relative Humidity' assert dc3.header.unit == '%' assert isinstance(dc3, HourlyContinuousCollectionImmutable) assert dc3.is_mutable is False dc4 = dc1.get_aligned_collection(50, RelativeHumidity(), '%', mutable=True) assert dc4.header.data_type.name == 'Relative Humidity' assert dc4.header.unit == '%' assert isinstance(dc4, HourlyContinuousCollection) assert dc4.is_mutable is True
def test_init_continuous(): """Test the init methods for continuous collections""" # Setup temperature data collection header = Header(Temperature(), 'C', AnalysisPeriod()) values = list(xrange(8760)) dc1 = HourlyContinuousCollection(header, values) assert len(dc1.datetimes) == 8760 assert list(dc1.values) == list(xrange(8760)) assert dc1.average == 4379.5 assert dc1.is_continuous is True str(dc1) # Test the string representation of the collection str(dc1.header) # Test the string representation of the header