Commit c7416d72 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] add function to compare with durand paper

parent f8caea2c
No related merge requests found
Showing with 32 additions and 23 deletions
+32 -23
......@@ -20,11 +20,13 @@ from utils import get_full_path, cached_property
class AbstractStudy(object):
ALTITUDES = [1800, 2400]
def __init__(self, variable_class: type, altitude: int = 1800):
def __init__(self, variable_class: type, altitude: int = 1800, year_min=1000, year_max=3000):
assert altitude in self.ALTITUDES, altitude
self.altitude = altitude
self.model_name = None
self.variable_class = variable_class
self.year_min = year_min
self.year_max = year_max
def write_to_file(self, df: pd.DataFrame):
if not op.exists(self.result_full_path):
......@@ -59,7 +61,9 @@ class AbstractStudy(object):
year_to_dataset = OrderedDict()
nc_files = [(int(f.split('_')[-2][:4]), f) for f in os.listdir(self.safran_full_path) if f.endswith('.nc')]
for year, nc_file in sorted(nc_files, key=lambda t: t[0]):
year_to_dataset[year] = Dataset(op.join(self.safran_full_path, nc_file))
if self.year_min <= year < self.year_max:
year_to_dataset[year] = Dataset(op.join(self.safran_full_path, nc_file))
print(year_to_dataset.keys())
return year_to_dataset
@cached_property
......@@ -174,14 +178,13 @@ class AbstractStudy(object):
# ax.scatter(x, y)
# ax.text(x, y, massif_name)
# Display the center of the massif
# ax.scatter(self.massifs_coordinates.x_coordinates, self.massifs_coordinates.y_coordinates, s=1)
# # Display the name of the massif
# for _, row in self.massifs_coordinates.df_all_coordinates.iterrows():
# x, y = list(row)
# massif_name = row.name
# ax.text(x, y, massif_name)
# print(self.massifs_coordinates.df_all_coordinates.head())
ax.scatter(self.massifs_coordinates.x_coordinates, self.massifs_coordinates.y_coordinates, s=1)
# Display the name of the massif
for _, row in self.massifs_coordinates.df_all_coordinates.iterrows():
x, y = list(row)
massif_name = row.name
value = massif_name_to_value[massif_name]
ax.text(x, y, str(round(value, 1)))
if show:
plt.show()
......
......@@ -9,18 +9,17 @@ from experiment.meteo_france_SCM_study.safran.safran_variable import SafranSnowf
class Safran(AbstractStudy):
def __init__(self, variable_class: type, altitude: int = 1800):
super().__init__(variable_class, altitude)
def __init__(self, variable_class: type, *args, **kwargs):
super().__init__(variable_class, *args, **kwargs)
self.model_name = 'Safran'
class SafranFrequency(Safran):
def __init__(self, variable_class: type, nb_days_of_snowfall=1, altitude: int = 1800, ):
super().__init__(variable_class, altitude)
def __init__(self, variable_class: type, nb_days_of_snowfall=1, *args, **kwargs):
super().__init__(variable_class, *args, **kwargs)
self.nb_days_of_snowfall = nb_days_of_snowfall
def instantiate_variable_object(self, dataset) -> AbstractVariable:
return self.variable_class(dataset, self.nb_days_of_snowfall)
......@@ -34,8 +33,8 @@ class SafranFrequency(Safran):
class SafranSnowfall(SafranFrequency):
def __init__(self, altitude: int = 1800, nb_days_of_snowfall=1):
super().__init__(SafranSnowfallVariable, nb_days_of_snowfall, altitude)
def __init__(self, *args, **kwargs):
super().__init__(SafranSnowfallVariable, *args, **kwargs)
class ExtendedSafranSnowfall(AbstractExtendedStudy, SafranSnowfall):
......@@ -44,14 +43,14 @@ class ExtendedSafranSnowfall(AbstractExtendedStudy, SafranSnowfall):
class SafranPrecipitation(SafranFrequency):
def __init__(self, altitude: int = 1800, nb_days_of_snowfall=1):
super().__init__(SafranPrecipitationVariable, nb_days_of_snowfall, altitude)
def __init__(self, *args, **kwargs):
super().__init__(SafranPrecipitationVariable, *args, **kwargs)
class SafranTemperature(Safran):
def __init__(self, altitude: int = 1800):
super().__init__(SafranTemperatureVariable, altitude)
def __init__(self, *args, **kwargs):
super().__init__(SafranTemperatureVariable, *args, **kwargs)
def annual_aggregation_function(self, *args, **kwargs):
return np.mean(*args, **kwargs)
......
......@@ -47,11 +47,17 @@ def extended_visualization():
# study_visualizer.visualize_all_experimental_law()
def annual_mean_vizu_compare_durand_study():
for study_class in [SafranPrecipitation, SafranSnowfall, SafranTemperature][1:]:
study = study_class(altitude=1800, year_min=1958, year_max=2002)
study_visualizer = StudyVisualizer(study)
study_visualizer.visualize_annual_mean_values()
def normal_visualization():
save_to_file = False
only_first_one = True
# for study_class in SCM_STUDIES[:1]:
for study_class in [SafranPrecipitation, SafranSnowfall, SafranTemperature][-1:]:
for study_class in [SafranPrecipitation, SafranSnowfall, 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])
......@@ -75,6 +81,7 @@ def complete_analysis(only_first_one=False):
if __name__ == '__main__':
normal_visualization()
annual_mean_vizu_compare_durand_study()
# normal_visualization()
# extended_visualization()
# complete_analysis()
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