From a2bb733b05ef8b8fdc8e662c8ce223d8070d01da Mon Sep 17 00:00:00 2001 From: jdevine Date: Wed, 7 Jul 2021 18:31:09 +0200 Subject: [PATCH] local weather function added --- cara/apps/calculator/model_generator.py | 4 +++- cara/data.py | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cara/apps/calculator/model_generator.py b/cara/apps/calculator/model_generator.py index 9305dd71..0b3f5135 100644 --- a/cara/apps/calculator/model_generator.py +++ b/cara/apps/calculator/model_generator.py @@ -20,6 +20,8 @@ LOG = logging.getLogger(__name__) minutes_since_midnight = typing.NewType('minutes_since_midnight', int) + + # Used to declare when an attribute of a class must have a value provided, and # there should be no default value used. _NO_DEFAULT = object() @@ -263,7 +265,7 @@ class FormData: month = datetime_object.month inside_temp = models.PiecewiseConstant((0, 24), (293,)) - outside_temp = data.GenevaTemperatures[month] + outside_temp = data.Temperatures[str(month)] ventilation: models.Ventilation if self.window_type == 'window_sliding': diff --git a/cara/data.py b/cara/data.py index 79b34454..523d608e 100644 --- a/cara/data.py +++ b/cara/data.py @@ -1,8 +1,15 @@ import numpy as np from cara import models +import json -def location_celcius_per_hour (lat, long): - pass +weather_station = "067000-99999" #this is the Cointrin station for Geneva + +def location_celcius_per_hour(w_station): + with open("/Users/jdevine/cara_rep/cara/cara/global_weather_set.json", "r") as json_file: + weather_dict = json.load(json_file) + Location_hourly_temperatures_celsius_per_hour = weather_dict[w_station] + print(Location_hourly_temperatures_celsius_per_hour) + return Location_hourly_temperatures_celsius_per_hour # average temperature of each month, hour per hour (from midnight to 11 pm) @@ -37,14 +44,14 @@ Geneva_hourly_temperatures_celsius_per_hour = { # Geneva hourly temperatures as piecewise constant function (in Kelvin) -GenevaTemperatures_hourly = { +Temperatures_hourly = { month: models.PiecewiseConstant(tuple(np.arange(25.)), tuple(273.15+np.array(temperatures))) - for month,temperatures in Geneva_hourly_temperatures_celsius_per_hour.items() + for month,temperatures in location_celcius_per_hour(weather_station).items() } # same temperatures on a finer temperature mesh -GenevaTemperatures = { - month: GenevaTemperatures_hourly[month].refine(refine_factor=4) - for month,temperatures in Geneva_hourly_temperatures_celsius_per_hour.items() +Temperatures = { + month: Temperatures_hourly[month].refine(refine_factor=4) + for month,temperatures in location_celcius_per_hour(weather_station).items() }