From 146162165f991240c21ecffd4b948a9e92300aed Mon Sep 17 00:00:00 2001 From: Pilar Date: Tue, 13 Apr 2021 19:00:28 -0400 Subject: [PATCH] created epw_weather_parameters.py --- city_model_structure/city.py | 40 +++++++++++++++++++ city_model_structure/city_object.py | 2 +- exports/exports_factory.py | 2 +- .../formats/simplified_radiosity_algorithm.py | 2 +- imports/weather_factory.py | 4 -- .../weather_feeders/dat_weather_parameters.py | 3 +- .../weather_feeders/epw_weather_parameters.py | 18 ++++----- tests/test_exports.py | 2 +- tests/test_weather_factory.py | 10 +---- 9 files changed, 56 insertions(+), 27 deletions(-) diff --git a/city_model_structure/city.py b/city_model_structure/city.py index 9085e28f..2fc54467 100644 --- a/city_model_structure/city.py +++ b/city_model_structure/city.py @@ -225,3 +225,43 @@ class City: :return: real """ return self._latitude + + @latitude.setter + def latitude(self, value): + """ + city latitude in degrees + :parameter value: real + """ + self._latitude = value + + @property + def longitude(self): + """ + city longitude in degrees + :return: real + """ + return self._longitude + + @longitude.setter + def longitude(self, value): + """ + city longitude in degrees + :parameter value: real + """ + self._longitude = value + + @property + def time_zone(self): + """ + city time_zone + :return: real + """ + return self._time_zone + + @time_zone.setter + def time_zone(self, value): + """ + city time_zone + :parameter value: real + """ + self._time_zone = value diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index ed5855d8..10d5181e 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -108,7 +108,7 @@ class CityObject: @property def centroid(self): """ - City object location + City object centroid :return: [x,y,z] """ if self._centroid is None: diff --git a/exports/exports_factory.py b/exports/exports_factory.py index 583f7a88..fe0fd578 100644 --- a/exports/exports_factory.py +++ b/exports/exports_factory.py @@ -69,7 +69,7 @@ class ExportsFactory: @property def _sra(self): - return SimplifiedRadiosityAlgorithm(self._city, (self._path/ f'{self._city.name}_sra.xml')) + return SimplifiedRadiosityAlgorithm(self._city, (self._path / f'{self._city.name}_sra.xml')) def export(self): """ diff --git a/exports/formats/simplified_radiosity_algorithm.py b/exports/formats/simplified_radiosity_algorithm.py index a6134494..4d38ad07 100644 --- a/exports/formats/simplified_radiosity_algorithm.py +++ b/exports/formats/simplified_radiosity_algorithm.py @@ -6,6 +6,7 @@ Copyright © 2020 Project Author Guillermo.GutierrezMorote@concordia.ca from pathlib import Path import xmltodict + class SimplifiedRadiosityAlgorithm: def __init__(self, city, file_name, begin_month=1, begin_day=1, end_month=12, end_day=31): @@ -25,7 +26,6 @@ class SimplifiedRadiosityAlgorithm: return [x, y, z] def _export(self): - print('export') buildings = [] for building_index, building in enumerate(self._city.buildings): building_dict = { diff --git a/imports/weather_factory.py b/imports/weather_factory.py index dd0a6558..5f101676 100644 --- a/imports/weather_factory.py +++ b/imports/weather_factory.py @@ -4,7 +4,6 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from pathlib import Path -from imports.weather_feeders.dat_weather_parameters import DatWeatherParameters from imports.weather_feeders.xls_weather_parameters import XlsWeatherParameters from imports.weather_feeders.epw_weather_parameters import EpwWeatherParameters @@ -20,9 +19,6 @@ class WeatherFactory: self._base_path = base_path self._file_name = file_name - def _dat(self): - DatWeatherParameters(self._city, self._base_path) - def _tmy3(self): raise Exception('Not implemented') diff --git a/imports/weather_feeders/dat_weather_parameters.py b/imports/weather_feeders/dat_weather_parameters.py index 25a0cd21..cac3b90e 100644 --- a/imports/weather_feeders/dat_weather_parameters.py +++ b/imports/weather_feeders/dat_weather_parameters.py @@ -16,8 +16,7 @@ class DatWeatherParameters: def __init__(self, city, path): self._weather_values = None self._city = city - # todo: change it to reference_weather_city_name - self._city_name = city.name + self._city_name = city.climate_reference_city file_name = 'inseldb_' + self._city_name + '.dat' self._path = Path(path / file_name) diff --git a/imports/weather_feeders/epw_weather_parameters.py b/imports/weather_feeders/epw_weather_parameters.py index 5f0f7167..5268dafd 100644 --- a/imports/weather_feeders/epw_weather_parameters.py +++ b/imports/weather_feeders/epw_weather_parameters.py @@ -21,10 +21,10 @@ class EpwWeatherParameters: try: file = open(self._path, 'r') line = file.readline().split(',') - city_name = line[1] - latitude = line[6] - longitude = line[7] - time_zone = line[8] + city.climate_reference_city = line[1] + city.latitude = line[6] + city.longitude = line[7] + city.time_zone = line[8] for i in range(0, 2): line = file.readline().split(',') line = file.readline().split(',') @@ -45,7 +45,7 @@ class EpwWeatherParameters: if self._weather_values is None: try: - self._weather_values = pd.read_csv(self._path, header=0, skiprows=8, + self._weather_values = pd.read_csv(self._path, header=0, skiprows=7, names=['year', 'month', 'day', 'hour', 'minute', 'data_source_and_uncertainty_flags', 'dry_bulb_temperature_c', 'dew_point_temperature_c', @@ -73,7 +73,7 @@ class EpwWeatherParameters: for building in self._city.buildings: new_value = pd.DataFrame(self._weather_values[['dry_bulb_temperature_c']].to_numpy(), columns=['epw']) - number_invalid_records = new_value[new_value.epw == 99.9].count()['epw'] + number_invalid_records = new_value[new_value.epw == 99.9].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 99.9) in dry bulb temperature\n') if 'hour' not in building.external_temperature: @@ -82,7 +82,7 @@ class EpwWeatherParameters: pd.concat([building.external_temperature['hour'], new_value], axis=1) new_value = pd.DataFrame(self._weather_values[['global_horizontal_radiation_wh_m2']].to_numpy(), columns=['epw']) - number_invalid_records = new_value[new_value.epw == 9999].count()['epw'] + number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in global horizontal radiation\n') if 'hour' not in building.global_horizontal: @@ -91,7 +91,7 @@ class EpwWeatherParameters: pd.concat([building.global_horizontal['hour'], new_value], axis=1) new_value = pd.DataFrame(self._weather_values[['diffuse_horizontal_radiation_wh_m2']].to_numpy(), columns=['epw']) - number_invalid_records = new_value[new_value.epw == 9999].count()['epw'] + number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in diffuse horizontal radiation\n') if 'hour' not in building.diffuse: @@ -100,7 +100,7 @@ class EpwWeatherParameters: pd.concat([building.diffuse['hour'], new_value], axis=1) new_value = pd.DataFrame(self._weather_values[['direct_normal_radiation_wh_m2']].to_numpy(), columns=['epw']) - number_invalid_records = new_value[new_value.epw == 9999].count()['epw'] + number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in direct horizontal radiation\n') if 'hour' not in building.beam: diff --git a/tests/test_exports.py b/tests/test_exports.py index bad8ba7e..3052befb 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -59,4 +59,4 @@ class TestExports(TestCase): self._export('energy_ade') def test_sra_export(self): - self._export('sra') \ No newline at end of file + self._export('sra') diff --git a/tests/test_weather_factory.py b/tests/test_weather_factory.py index 48528c94..91d69cce 100644 --- a/tests/test_weather_factory.py +++ b/tests/test_weather_factory.py @@ -29,19 +29,13 @@ class TestWeatherFactory(TestCase): self.assertIsNotNone(self._city_gml, 'city is none') return self._city_gml - def _get_city_with_weather(self): - if self._city_with_weather is None: - file_path = (Path(__file__).parent / 'tests_data' / '20buildings.gml').resolve() - self._city_with_weather = self._get_citygml(file_path) - WeatherFactory('dat', self._city_with_weather, base_path=self._example_path).enrich() - return self._city_with_weather - def test_city_with_weather(self): """ Enrich the city with the weather information and verify it :return: None """ - city = self._get_city_with_weather() + file_path = (Path(__file__).parent / 'tests_data' / '20buildings.gml').resolve() + city = self._get_citygml(file_path) for building in city.buildings: values = building.external_temperature['hour'][['inseldb']] self.assertFalse(values.empty, 'wrong value external_temperature')