Commit 03b044e2 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] add crocus study considering the number of days with snow on the ground

parent c2e4b77d
No related merge requests found
Showing with 27 additions and 10 deletions
+27 -10
......@@ -134,6 +134,7 @@ class AbstractStudy(object):
def load_df_centroid(self) -> pd.DataFrame:
df_centroid = pd.read_csv(op.join(self.map_full_path, 'coordonnees_massifs_alpes.csv'))
df_centroid.set_index('NOM', inplace=True)
# Sort the column in the order of the SAFRAN dataset
df_centroid = df_centroid.loc[self.original_safran_massif_names]
return df_centroid
......
......@@ -23,7 +23,7 @@ class Crocus(AbstractStudy):
def annual_aggregation_function(self, *args, **kwargs):
return np.mean(*args, **kwargs)
def apply_annual_aggregation(self, time_serie):
def winter_annual_aggregation(self, time_serie):
# In the Durand paper, we only want the data from November to April
# 91 = 30 + 31 + 30 first days of the time serie correspond to the month of August + September + October
# 92 = 31 + 30 + 31 last days correspond to the month of May + June + JUly
......@@ -35,6 +35,9 @@ class CrocusSwe(Crocus):
def __init__(self, *args, **kwargs):
super().__init__(CrocusSweVariable, *args, **kwargs)
def apply_annual_aggregation(self, time_serie):
return self.winter_annual_aggregation(time_serie)
class ExtendedCrocusSwe(AbstractExtendedStudy, CrocusSwe):
pass
......@@ -45,11 +48,24 @@ class CrocusDepth(Crocus):
def __init__(self, *args, **kwargs):
super().__init__(CrocusDepthVariable, *args, **kwargs)
def apply_annual_aggregation(self, time_serie):
return self.winter_annual_aggregation(time_serie)
class ExtendedCrocusDepth(AbstractExtendedStudy, CrocusDepth):
pass
class CrocusDaysWithSnowOnGround(Crocus):
"""Having snow on the ground is equivalent to snow depth > 0"""
def __init__(self, *args, **kwargs):
super().__init__(CrocusDepthVariable, *args, **kwargs)
def annual_aggregation_function(self, *args, **kwargs):
return np.count_nonzero(*args, **kwargs)
if __name__ == '__main__':
for variable_clas in [CrocusSweVariable, CrocusDepthVariable]:
study = Crocus(variable_class=variable_clas, altitude=2400)
......
......@@ -41,3 +41,4 @@ class CrocusDepthVariable(CrocusVariable):
def __init__(self, dataset, altitude):
# Units are m
super().__init__(dataset, altitude, "SNOWDEPTH")
......@@ -19,6 +19,7 @@ class Safran(AbstractStudy):
class SafranFrequency(Safran):
def __init__(self, variable_class: type, nb_consecutive_days=1, *args, **kwargs):
assert nb_consecutive_days <= 7
super().__init__(variable_class, *args, **kwargs)
self.nb_consecutive_days = nb_consecutive_days
......
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from experiment.meteo_france_SCM_study.crocus.crocus import CrocusDepth, CrocusSwe, ExtendedCrocusDepth, \
ExtendedCrocusSwe
ExtendedCrocusSwe, CrocusDaysWithSnowOnGround
from experiment.meteo_france_SCM_study.safran.safran import SafranSnowfall, ExtendedSafranSnowfall, SafranRainfall, \
SafranTemperature, SafranTotalPrecip
......@@ -22,7 +22,7 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo
for alti in AbstractStudy.ALTITUDES[::1]:
if verbose:
print('alti: {}, nb_day: {}'.format(alti, nb_day))
study = study_class(altitude=alti, nb_consecutive_days=nb_day) if is_safran_study else study_class(alti)
study = study_class(altitude=alti, nb_consecutive_days=nb_day) if is_safran_study else study_class(altitude=alti)
yield study
if only_first_one and not both_altitude:
break
......@@ -50,12 +50,12 @@ def extended_visualization():
def annual_mean_vizu_compare_durand_study(safran=True, take_mean_value=True):
if safran:
for study_class in [SafranTotalPrecip, SafranRainfall, SafranSnowfall, SafranTemperature][:1]:
for study_class in [SafranTotalPrecip, SafranRainfall, SafranSnowfall, SafranTemperature][2:3]:
study = study_class(altitude=1800, year_min=1958, year_max=2002)
study_visualizer = StudyVisualizer(study)
study_visualizer.visualize_annual_mean_values(take_mean_value=True)
else:
for study_class in [CrocusSwe, CrocusDepth][1:]:
for study_class in [CrocusSwe, CrocusDepth, CrocusDaysWithSnowOnGround][-1:]:
study = study_class(altitude=1800, year_min=1958, year_max=2005)
study_visualizer = StudyVisualizer(study)
study_visualizer.visualize_annual_mean_values(take_mean_value=take_mean_value)
......@@ -65,7 +65,7 @@ def normal_visualization():
save_to_file = False
only_first_one = True
# for study_class in SCM_STUDIES[:1]:
for study_class in [SafranRainfall, SafranSnowfall, SafranTemperature][:1]:
for study_class in [SafranSnowfall, SafranRainfall, SafranTemperature][:1]:
for study in study_iterator(study_class, only_first_one=only_first_one):
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file)
# study_visualizer.visualize_independent_margin_fits(threshold=[None, 20, 40, 60][0])
......@@ -89,7 +89,7 @@ def complete_analysis(only_first_one=False):
if __name__ == '__main__':
annual_mean_vizu_compare_durand_study(safran=False, take_mean_value=True)
# normal_visualization()
# annual_mean_vizu_compare_durand_study(safran=True, take_mean_value=True)
normal_visualization()
# extended_visualization()
# complete_analysis()
......@@ -226,8 +226,6 @@ class StudyVisualizer(object):
margin_model = margin_class(coordinates=self.coordinates)
estimator = FullEstimatorInASingleStepWithSmoothMargin(self.dataset, margin_model, max_stable_model)
title = get_display_name_from_object_type(type(max_stable_model))
# if isinstance(max_stable_model, AbstractMaxStableModelWithCovarianceFunction):
# title += ' ' + str(default_covariance_function).split('.')[-1]
self.fit_and_visualize_estimator(estimator, axes[i], title=title)
# Add the label
self.show_or_save_to_file()
......
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