Commit 07b7c7d1 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] add abstract_extended_study which enable to extend any study by multiple inheritance

parent 5ed09100
No related merge requests found
Showing with 22 additions and 16 deletions
+22 -16
import numpy as np import numpy as np
from collections import OrderedDict from collections import OrderedDict
from experiment.meteo_france_SCM_study.safran.safran import Safran from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from utils import cached_property
class ExtendedSafran(Safran): class AbstractExtendedStudy(AbstractStudy):
@property @property
def region_names(self): def region_names(self):
...@@ -33,15 +32,14 @@ class ExtendedSafran(Safran): ...@@ -33,15 +32,14 @@ class ExtendedSafran(Safran):
for massif_name, region_name in self.massif_name_to_region_name.items() for massif_name, region_name in self.massif_name_to_region_name.items()
if region_name_loop in region_name] if region_name_loop in region_name]
massif_ids_belong_to_the_group = [massif_id massif_ids_belong_to_the_group = [massif_id
for massif_id, massif_name in self.original_safran_massif_id_to_massif_name.items() for massif_id, massif_name in
self.original_safran_massif_id_to_massif_name.items()
if massif_name in massif_names_belong_to_the_group] if massif_name in massif_names_belong_to_the_group]
region_name_to_massifs_ids[region_name_loop] = massif_ids_belong_to_the_group region_name_to_massifs_ids[region_name_loop] = massif_ids_belong_to_the_group
return region_name_to_massifs_ids return region_name_to_massifs_ids
""" Properties """ """ Properties """
@property @property
def _year_to_daily_time_serie(self) -> OrderedDict: def _year_to_daily_time_serie(self) -> OrderedDict:
return self._year_to_extended_time_serie(aggregation_function=np.mean) return self._year_to_extended_time_serie(aggregation_function=np.mean)
...@@ -62,8 +60,3 @@ class ExtendedSafran(Safran): ...@@ -62,8 +60,3 @@ class ExtendedSafran(Safran):
year_to_extended_time_serie[year] = new_time_serie year_to_extended_time_serie[year] = new_time_serie
return year_to_extended_time_serie return year_to_extended_time_serie
from experiment.meteo_france_SCM_study.abstract_extended_study import AbstractExtendedStudy
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from experiment.meteo_france_SCM_study.crocus.crocus_variables import CrocusSweVariable, CrocusDepthVariable from experiment.meteo_france_SCM_study.crocus.crocus_variables import CrocusSweVariable, CrocusDepthVariable
...@@ -19,12 +20,20 @@ class CrocusSwe(Crocus): ...@@ -19,12 +20,20 @@ class CrocusSwe(Crocus):
super().__init__(CrocusSweVariable, altitude) super().__init__(CrocusSweVariable, altitude)
class ExtendedCrocusSwe(AbstractExtendedStudy, CrocusSwe):
pass
class CrocusDepth(Crocus): class CrocusDepth(Crocus):
def __init__(self, altitude=1800): def __init__(self, altitude=1800):
super().__init__(CrocusDepthVariable, altitude) super().__init__(CrocusDepthVariable, altitude)
class ExtendedCrocusDepth(AbstractExtendedStudy, CrocusDepth):
pass
if __name__ == '__main__': if __name__ == '__main__':
for variable_class in [CrocusSweVariable, CrocusDepthVariable]: for variable_class in [CrocusSweVariable, CrocusDepthVariable]:
study = Crocus(variable_class=variable_class) study = Crocus(variable_class=variable_class)
......
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from experiment.meteo_france_SCM_study.crocus.crocus import CrocusDepth, CrocusSwe from experiment.meteo_france_SCM_study.crocus.crocus import CrocusDepth, CrocusSwe, ExtendedCrocusDepth, \
from experiment.meteo_france_SCM_study.safran.safran import Safran ExtendedCrocusSwe
from experiment.meteo_france_SCM_study.safran.safran import Safran, ExtendedSafran
from itertools import product from itertools import product
from experiment.meteo_france_SCM_study.safran.safran_extended import ExtendedSafran
from experiment.meteo_france_SCM_study.safran.safran_visualizer import StudyVisualizer from experiment.meteo_france_SCM_study.safran.safran_visualizer import StudyVisualizer
...@@ -21,7 +21,7 @@ def load_all_studies(study_class, only_first_one=False): ...@@ -21,7 +21,7 @@ def load_all_studies(study_class, only_first_one=False):
if __name__ == '__main__': if __name__ == '__main__':
for study_class in [ExtendedSafran, Safran, CrocusSwe, CrocusDepth][:1]: for study_class in [ExtendedSafran, ExtendedCrocusSwe, ExtendedCrocusDepth][:]:
for study in load_all_studies(study_class, only_first_one=True): for study in load_all_studies(study_class, only_first_one=True):
study_visualizer = StudyVisualizer(study) study_visualizer = StudyVisualizer(study)
# study_visualizer.visualize_independent_margin_fits(threshold=[None, 20, 40, 60][0]) # study_visualizer.visualize_independent_margin_fits(threshold=[None, 20, 40, 60][0])
......
import pandas as pd import pandas as pd
from experiment.meteo_france_SCM_study.safran.safran_extended import ExtendedSafran from experiment.meteo_france_SCM_study.safran.safran import ExtendedSafran
from utils import VERSION from utils import VERSION
......
from experiment.meteo_france_SCM_study.abstract_extended_study import AbstractExtendedStudy
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from experiment.meteo_france_SCM_study.abstract_variable import AbstractVariable from experiment.meteo_france_SCM_study.abstract_variable import AbstractVariable
from experiment.meteo_france_SCM_study.safran.safran_snowfall_variable import SafranSnowfallVariable from experiment.meteo_france_SCM_study.safran.safran_snowfall_variable import SafranSnowfallVariable
...@@ -17,3 +18,6 @@ class Safran(AbstractStudy): ...@@ -17,3 +18,6 @@ class Safran(AbstractStudy):
def variable_name(self): def variable_name(self):
return super().variable_name + ' cumulated over {} days'.format(self.nb_days_of_snowfall) return super().variable_name + ' cumulated over {} days'.format(self.nb_days_of_snowfall)
class ExtendedSafran(AbstractExtendedStudy, Safran):
pass
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