From 2989cb25cd0ecb96dacef303a3ed3b744c1957e8 Mon Sep 17 00:00:00 2001 From: Le Roux Erwan <erwan.le-roux@irstea.fr> Date: Thu, 7 Mar 2019 17:44:46 +0100 Subject: [PATCH] [SCM] refactor --- experiment/meteo_france_SCM_study/abstract_study.py | 3 --- experiment/meteo_france_SCM_study/abstract_variable.py | 3 ++- experiment/meteo_france_SCM_study/crocus/crocus_variables.py | 2 +- experiment/meteo_france_SCM_study/safran/safran_variable.py | 5 +++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/experiment/meteo_france_SCM_study/abstract_study.py b/experiment/meteo_france_SCM_study/abstract_study.py index 31e8db9e..901970a8 100644 --- a/experiment/meteo_france_SCM_study/abstract_study.py +++ b/experiment/meteo_france_SCM_study/abstract_study.py @@ -82,7 +82,6 @@ class AbstractStudy(object): # Map each year to an array of size nb_massif year_to_annual_mean = OrderedDict() for year, time_serie in self._year_to_daily_time_serie_array.items(): - print(time_serie.shape) year_to_annual_mean[year] = self.annual_aggregation_function(time_serie, axis=0) return year_to_annual_mean @@ -105,8 +104,6 @@ class AbstractStudy(object): def _year_to_max_daily_time_serie(self) -> OrderedDict: return self._year_to_daily_time_serie_array - - ########## @property diff --git a/experiment/meteo_france_SCM_study/abstract_variable.py b/experiment/meteo_france_SCM_study/abstract_variable.py index 00b0a98a..7a59e49d 100644 --- a/experiment/meteo_france_SCM_study/abstract_variable.py +++ b/experiment/meteo_france_SCM_study/abstract_variable.py @@ -1,3 +1,4 @@ +import numpy as np class AbstractVariable(object): @@ -9,6 +10,6 @@ class AbstractVariable(object): self.altitude = altitude @property - def daily_time_serie_array(self): + def daily_time_serie_array(self) -> np.ndarray: # Return an array of size length of time series x nb_massif raise NotImplementedError \ No newline at end of file diff --git a/experiment/meteo_france_SCM_study/crocus/crocus_variables.py b/experiment/meteo_france_SCM_study/crocus/crocus_variables.py index 947cece7..10186699 100644 --- a/experiment/meteo_france_SCM_study/crocus/crocus_variables.py +++ b/experiment/meteo_france_SCM_study/crocus/crocus_variables.py @@ -10,7 +10,7 @@ class CrocusVariable(AbstractVariable): self.variable_name = variable_name @property - def daily_time_serie_array(self): + def daily_time_serie_array(self) -> np.ndarray: time_serie_every_6_hours = np.array(self.dataset.variables[self.variable_name])[:, 0, :] if self.altitude == 2400: time_serie_daily = time_serie_every_6_hours diff --git a/experiment/meteo_france_SCM_study/safran/safran_variable.py b/experiment/meteo_france_SCM_study/safran/safran_variable.py index c07cfb7c..41a24eb3 100644 --- a/experiment/meteo_france_SCM_study/safran/safran_variable.py +++ b/experiment/meteo_france_SCM_study/safran/safran_variable.py @@ -35,7 +35,7 @@ class SafranSnowfallVariable(AbstractVariable): self.daily_snowfall = [sum(hourly_snowfall[24 * i:24 * (i + 1)]) for i in range(nb_days)] @property - def daily_time_serie_array(self): + def daily_time_serie_array(self) -> np.ndarray: # Aggregate the daily snowfall by the number of consecutive days shifted_list = [self.daily_snowfall[i:] for i in range(self.nb_consecutive_days_of_snowfall)] # First element of shifted_list is of length n, Second element of length n-1, Third element n-2.... @@ -57,11 +57,12 @@ class SafranTemperatureVariable(AbstractVariable): super().__init__(dataset, altitude) # Temperature are in K, I transform them as celsius self.hourly_temperature = np.array(dataset.variables[keyword]) - 273.15 + print(self.hourly_temperature.shape) nb_days = len(self.hourly_temperature) // 24 self.daily_temperature = [np.mean(self.hourly_temperature[24 * i:24 * (i + 1)]) for i in range(nb_days)] @property def daily_time_serie_array(self): - return self.daily_temperature + return np.array(self.daily_temperature) -- GitLab