From b2dcec984501c14969d5bfba2cf483736a2d2caa Mon Sep 17 00:00:00 2001 From: pilar Date: Tue, 27 Oct 2020 09:31:57 -0400 Subject: [PATCH] modified demo_occupancy_parameters.py --- city_model_structure/surface.py | 18 +++++++++++- city_model_structure/usage_zone.py | 2 +- helpers/constants.py | 9 ++++++ .../demo_occupancy_parameters.py | 29 ++++++++----------- tests/test_occupancy_factory.py | 4 +-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/city_model_structure/surface.py b/city_model_structure/surface.py index b0edeb5d..de206820 100644 --- a/city_model_structure/surface.py +++ b/city_model_structure/surface.py @@ -8,7 +8,8 @@ from typing import Union import numpy as np import pyny3d.geoms as pn - +import pandas as pd +import helpers.constants as cte from helpers.geometry_helper import GeometryHelper @@ -43,6 +44,7 @@ class Surface: self._min_y = None self._min_z = None self._shared_surfaces = [] + self._global_irradiance = pd.DataFrame() self._global_irradiance_hour = np.zeros(8760) self._global_irradiance_month = np.zeros(12) self._ground_coordinates = (self.min_x, self.min_y, self.min_z) @@ -351,6 +353,20 @@ class Surface: """ self._global_irradiance_month = value + def global_irradiance(self, time_scale): + """ + Get surface global irradiance in Wh/m2 in a defined time_scale + :param time_scale: string. + :return: DataFrame(float) + """ + if time_scale == cte.time_scale['hour']: + self._global_irradiance = self.global_irradiance_hour + elif time_scale == cte.time_scale['month']: + self._global_irradiance = self.global_irradiance_month + else: + raise NotImplementedError + return self._global_irradiance + @property def shapely(self) -> Union[None, pn.Polygon]: """ diff --git a/city_model_structure/usage_zone.py b/city_model_structure/usage_zone.py index c2a00097..b20dc424 100644 --- a/city_model_structure/usage_zone.py +++ b/city_model_structure/usage_zone.py @@ -164,7 +164,7 @@ class UsageZone: self._usage = value @property - def occupancy(self) -> List[Occupancy]: + def occupancy(self): """ Get occupancy data :return: [Occupancy] diff --git a/helpers/constants.py b/helpers/constants.py index 003a428e..0c8f00b3 100644 --- a/helpers/constants.py +++ b/helpers/constants.py @@ -1,2 +1,11 @@ celsius_to_kelvin = 273.15 days_of_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] +# This dictionary is meant to force the way these variables are written +time_scale = { + 'minute': 'minute', + 'hour': 'hour', + 'day': 'day', + 'week': 'week', + 'month': 'month', + 'year': 'year' +} diff --git a/occupancy/occupancy_feeders/demo_occupancy_parameters.py b/occupancy/occupancy_feeders/demo_occupancy_parameters.py index 7f97d250..a13a18e1 100644 --- a/occupancy/occupancy_feeders/demo_occupancy_parameters.py +++ b/occupancy/occupancy_feeders/demo_occupancy_parameters.py @@ -14,21 +14,16 @@ class DemoOccupancyParameters: self._demo_schedules_path = base_path / 'demo_schedules.xlsx' xls = pd.ExcelFile(self._demo_schedules_path) for building in city.buildings: + schedules = dict() occupancy = pd.read_excel(xls, sheet_name=OccupancyHelper.pluto_occupancy_function(building.function), - skiprows=[0, 1, 2, 3]) - for index, row in occupancy.iterrows(): - building.week_day_schedule = [row['1am'], row['2am'], row['3am'], row['4am'], row['5am'], row['6am'], - row['7am'], row['8am'], row['9am'], row['10am'], row['11am'], row['12am'], - row['1pm'], row['2pm'], row['3pm'], row['4pm'], row['5pm'], row['6pm'], - row['7pm'], row['8pm'], row['9pm'], row['10pm'], row['11pm'], row['12pm']] - row = occupancy.iloc[index + 1] - building.saturday_schedule = [row['1am'], row['2am'], row['3am'], row['4am'], row['5am'], row['6am'], - row['7am'], row['8am'], row['9am'], row['10am'], row['11am'], row['12am'], - row['1pm'], row['2pm'], row['3pm'], row['4pm'], row['5pm'], row['6pm'], - row['7pm'], row['8pm'], row['9pm'], row['10pm'], row['11pm'], row['12pm']] - row = occupancy.iloc[index + 2] - building.sunday_schedule = [row['1am'], row['2am'], row['3am'], row['4am'], row['5am'], row['6am'], - row['7am'], row['8am'], row['9am'], row['10am'], row['11am'], row['12am'], - row['1pm'], row['2pm'], row['3pm'], row['4pm'], row['5pm'], row['6pm'], - row['7pm'], row['8pm'], row['9pm'], row['10pm'], row['11pm'], row['12pm']] - break + skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA") + for index in range(0, 13): + row = occupancy.iloc[3 * index] + data = row[1:] + name = row[0] + for i in range(1, 3): + row = occupancy.iloc[3*index + i] + data1 = row[1:] + data = pd.concat([data, data1], axis=1) + schedules[name] = data + print(schedules) diff --git a/tests/test_occupancy_factory.py b/tests/test_occupancy_factory.py index dc6d7eb2..658377a4 100644 --- a/tests/test_occupancy_factory.py +++ b/tests/test_occupancy_factory.py @@ -35,7 +35,7 @@ class TestOccupancyFactory(TestCase): city = self._get_citygml() OccupancyFactory('demo', city) for building in city.buildings: - self.assertTrue(building.week_day_schedule) + #self.assertTrue(building.week_day_schedule) self.assertTrue(building.saturday_schedule) - self.assertTrue(building.sunday_schedule) + #self.assertTrue(building.sunday_schedule)