created epw_weather_parameters.py
This commit is contained in:
parent
a0613201e3
commit
146162165f
|
@ -225,3 +225,43 @@ class City:
|
||||||
:return: real
|
:return: real
|
||||||
"""
|
"""
|
||||||
return self._latitude
|
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
|
||||||
|
|
|
@ -108,7 +108,7 @@ class CityObject:
|
||||||
@property
|
@property
|
||||||
def centroid(self):
|
def centroid(self):
|
||||||
"""
|
"""
|
||||||
City object location
|
City object centroid
|
||||||
:return: [x,y,z]
|
:return: [x,y,z]
|
||||||
"""
|
"""
|
||||||
if self._centroid is None:
|
if self._centroid is None:
|
||||||
|
|
|
@ -69,7 +69,7 @@ class ExportsFactory:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _sra(self):
|
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):
|
def export(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,6 +6,7 @@ Copyright © 2020 Project Author Guillermo.GutierrezMorote@concordia.ca
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
|
|
||||||
class SimplifiedRadiosityAlgorithm:
|
class SimplifiedRadiosityAlgorithm:
|
||||||
|
|
||||||
def __init__(self, city, file_name, begin_month=1, begin_day=1, end_month=12, end_day=31):
|
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]
|
return [x, y, z]
|
||||||
|
|
||||||
def _export(self):
|
def _export(self):
|
||||||
print('export')
|
|
||||||
buildings = []
|
buildings = []
|
||||||
for building_index, building in enumerate(self._city.buildings):
|
for building_index, building in enumerate(self._city.buildings):
|
||||||
building_dict = {
|
building_dict = {
|
||||||
|
|
|
@ -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
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
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.xls_weather_parameters import XlsWeatherParameters
|
||||||
from imports.weather_feeders.epw_weather_parameters import EpwWeatherParameters
|
from imports.weather_feeders.epw_weather_parameters import EpwWeatherParameters
|
||||||
|
|
||||||
|
@ -20,9 +19,6 @@ class WeatherFactory:
|
||||||
self._base_path = base_path
|
self._base_path = base_path
|
||||||
self._file_name = file_name
|
self._file_name = file_name
|
||||||
|
|
||||||
def _dat(self):
|
|
||||||
DatWeatherParameters(self._city, self._base_path)
|
|
||||||
|
|
||||||
def _tmy3(self):
|
def _tmy3(self):
|
||||||
raise Exception('Not implemented')
|
raise Exception('Not implemented')
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ class DatWeatherParameters:
|
||||||
def __init__(self, city, path):
|
def __init__(self, city, path):
|
||||||
self._weather_values = None
|
self._weather_values = None
|
||||||
self._city = city
|
self._city = city
|
||||||
# todo: change it to reference_weather_city_name
|
self._city_name = city.climate_reference_city
|
||||||
self._city_name = city.name
|
|
||||||
file_name = 'inseldb_' + self._city_name + '.dat'
|
file_name = 'inseldb_' + self._city_name + '.dat'
|
||||||
self._path = Path(path / file_name)
|
self._path = Path(path / file_name)
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ class EpwWeatherParameters:
|
||||||
try:
|
try:
|
||||||
file = open(self._path, 'r')
|
file = open(self._path, 'r')
|
||||||
line = file.readline().split(',')
|
line = file.readline().split(',')
|
||||||
city_name = line[1]
|
city.climate_reference_city = line[1]
|
||||||
latitude = line[6]
|
city.latitude = line[6]
|
||||||
longitude = line[7]
|
city.longitude = line[7]
|
||||||
time_zone = line[8]
|
city.time_zone = line[8]
|
||||||
for i in range(0, 2):
|
for i in range(0, 2):
|
||||||
line = file.readline().split(',')
|
line = file.readline().split(',')
|
||||||
line = file.readline().split(',')
|
line = file.readline().split(',')
|
||||||
|
@ -45,7 +45,7 @@ class EpwWeatherParameters:
|
||||||
|
|
||||||
if self._weather_values is None:
|
if self._weather_values is None:
|
||||||
try:
|
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',
|
names=['year', 'month', 'day', 'hour', 'minute',
|
||||||
'data_source_and_uncertainty_flags',
|
'data_source_and_uncertainty_flags',
|
||||||
'dry_bulb_temperature_c', 'dew_point_temperature_c',
|
'dry_bulb_temperature_c', 'dew_point_temperature_c',
|
||||||
|
@ -73,7 +73,7 @@ class EpwWeatherParameters:
|
||||||
|
|
||||||
for building in self._city.buildings:
|
for building in self._city.buildings:
|
||||||
new_value = pd.DataFrame(self._weather_values[['dry_bulb_temperature_c']].to_numpy(), columns=['epw'])
|
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:
|
if number_invalid_records > 0:
|
||||||
sys.stderr.write(f'Warning: {self._path} invalid records (value of 99.9) in dry bulb temperature\n')
|
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:
|
if 'hour' not in building.external_temperature:
|
||||||
|
@ -82,7 +82,7 @@ class EpwWeatherParameters:
|
||||||
pd.concat([building.external_temperature['hour'], new_value], axis=1)
|
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'])
|
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:
|
if number_invalid_records > 0:
|
||||||
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in global horizontal radiation\n')
|
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in global horizontal radiation\n')
|
||||||
if 'hour' not in building.global_horizontal:
|
if 'hour' not in building.global_horizontal:
|
||||||
|
@ -91,7 +91,7 @@ class EpwWeatherParameters:
|
||||||
pd.concat([building.global_horizontal['hour'], new_value], axis=1)
|
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'])
|
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:
|
if number_invalid_records > 0:
|
||||||
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in diffuse horizontal radiation\n')
|
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in diffuse horizontal radiation\n')
|
||||||
if 'hour' not in building.diffuse:
|
if 'hour' not in building.diffuse:
|
||||||
|
@ -100,7 +100,7 @@ class EpwWeatherParameters:
|
||||||
pd.concat([building.diffuse['hour'], new_value], axis=1)
|
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'])
|
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:
|
if number_invalid_records > 0:
|
||||||
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in direct horizontal radiation\n')
|
sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in direct horizontal radiation\n')
|
||||||
if 'hour' not in building.beam:
|
if 'hour' not in building.beam:
|
||||||
|
|
|
@ -59,4 +59,4 @@ class TestExports(TestCase):
|
||||||
self._export('energy_ade')
|
self._export('energy_ade')
|
||||||
|
|
||||||
def test_sra_export(self):
|
def test_sra_export(self):
|
||||||
self._export('sra')
|
self._export('sra')
|
||||||
|
|
|
@ -29,19 +29,13 @@ class TestWeatherFactory(TestCase):
|
||||||
self.assertIsNotNone(self._city_gml, 'city is none')
|
self.assertIsNotNone(self._city_gml, 'city is none')
|
||||||
return self._city_gml
|
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):
|
def test_city_with_weather(self):
|
||||||
"""
|
"""
|
||||||
Enrich the city with the weather information and verify it
|
Enrich the city with the weather information and verify it
|
||||||
:return: None
|
: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:
|
for building in city.buildings:
|
||||||
values = building.external_temperature['hour'][['inseldb']]
|
values = building.external_temperature['hour'][['inseldb']]
|
||||||
self.assertFalse(values.empty, 'wrong value external_temperature')
|
self.assertFalse(values.empty, 'wrong value external_temperature')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user