Commit 2989cb25 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] refactor

parent d37cee4b
No related merge requests found
Showing with 6 additions and 7 deletions
+6 -7
...@@ -82,7 +82,6 @@ class AbstractStudy(object): ...@@ -82,7 +82,6 @@ class AbstractStudy(object):
# Map each year to an array of size nb_massif # Map each year to an array of size nb_massif
year_to_annual_mean = OrderedDict() year_to_annual_mean = OrderedDict()
for year, time_serie in self._year_to_daily_time_serie_array.items(): 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) year_to_annual_mean[year] = self.annual_aggregation_function(time_serie, axis=0)
return year_to_annual_mean return year_to_annual_mean
...@@ -105,8 +104,6 @@ class AbstractStudy(object): ...@@ -105,8 +104,6 @@ class AbstractStudy(object):
def _year_to_max_daily_time_serie(self) -> OrderedDict: def _year_to_max_daily_time_serie(self) -> OrderedDict:
return self._year_to_daily_time_serie_array return self._year_to_daily_time_serie_array
########## ##########
@property @property
......
import numpy as np
class AbstractVariable(object): class AbstractVariable(object):
...@@ -9,6 +10,6 @@ class AbstractVariable(object): ...@@ -9,6 +10,6 @@ class AbstractVariable(object):
self.altitude = altitude self.altitude = altitude
@property @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 # Return an array of size length of time series x nb_massif
raise NotImplementedError raise NotImplementedError
\ No newline at end of file
...@@ -10,7 +10,7 @@ class CrocusVariable(AbstractVariable): ...@@ -10,7 +10,7 @@ class CrocusVariable(AbstractVariable):
self.variable_name = variable_name self.variable_name = variable_name
@property @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, :] time_serie_every_6_hours = np.array(self.dataset.variables[self.variable_name])[:, 0, :]
if self.altitude == 2400: if self.altitude == 2400:
time_serie_daily = time_serie_every_6_hours time_serie_daily = time_serie_every_6_hours
......
...@@ -35,7 +35,7 @@ class SafranSnowfallVariable(AbstractVariable): ...@@ -35,7 +35,7 @@ class SafranSnowfallVariable(AbstractVariable):
self.daily_snowfall = [sum(hourly_snowfall[24 * i:24 * (i + 1)]) for i in range(nb_days)] self.daily_snowfall = [sum(hourly_snowfall[24 * i:24 * (i + 1)]) for i in range(nb_days)]
@property @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 # 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)] 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.... # 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): ...@@ -57,11 +57,12 @@ class SafranTemperatureVariable(AbstractVariable):
super().__init__(dataset, altitude) super().__init__(dataset, altitude)
# Temperature are in K, I transform them as celsius # Temperature are in K, I transform them as celsius
self.hourly_temperature = np.array(dataset.variables[keyword]) - 273.15 self.hourly_temperature = np.array(dataset.variables[keyword]) - 273.15
print(self.hourly_temperature.shape)
nb_days = len(self.hourly_temperature) // 24 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)] self.daily_temperature = [np.mean(self.hourly_temperature[24 * i:24 * (i + 1)]) for i in range(nb_days)]
@property @property
def daily_time_serie_array(self): def daily_time_serie_array(self):
return self.daily_temperature return np.array(self.daily_temperature)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment