Commit 34f8410f authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] add units. add graph_one_row mode

parent ef988378
No related merge requests found
Showing with 42 additions and 18 deletions
+42 -18
...@@ -37,7 +37,7 @@ class ExtendedCrocusDepth(AbstractExtendedStudy, CrocusDepth): ...@@ -37,7 +37,7 @@ class ExtendedCrocusDepth(AbstractExtendedStudy, CrocusDepth):
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)
# d = study.year_to_dataset_ordered_dict[1960] d = study.year_to_dataset_ordered_dict[1960]
# print(d) # print(d)
a = study.year_to_daily_time_serie[1960] a = study.year_to_daily_time_serie[1960]
print(a.shape) print(a.shape)
...@@ -19,6 +19,7 @@ class CrocusSweVariable(CrocusVariable): ...@@ -19,6 +19,7 @@ class CrocusSweVariable(CrocusVariable):
NAME = 'Snow Water Equivalent' NAME = 'Snow Water Equivalent'
def __init__(self, dataset): def __init__(self, dataset):
# Units are kg m-2
super().__init__(dataset, 'SNOWSWE') super().__init__(dataset, 'SNOWSWE')
...@@ -26,4 +27,5 @@ class CrocusDepthVariable(CrocusVariable): ...@@ -26,4 +27,5 @@ class CrocusDepthVariable(CrocusVariable):
NAME = 'Snow Depth' NAME = 'Snow Depth'
def __init__(self, dataset): def __init__(self, dataset):
# Units are m
super().__init__(dataset, "SNOWDEPTH") super().__init__(dataset, "SNOWDEPTH")
...@@ -33,11 +33,16 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo ...@@ -33,11 +33,16 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo
def extended_visualization(): def extended_visualization():
for study_class in SCM_EXTENDED_STUDIES[:]: for study_class in SCM_EXTENDED_STUDIES[:1]:
for study in study_iterator(study_class, only_first_one=False): for study in study_iterator(study_class, only_first_one=True):
study_visualizer = StudyVisualizer(study, single_massif_graph=True, save_to_file=True) study_visualizer = StudyVisualizer(study, only_first_row=True, save_to_file=False)
# study_visualizer.visualize_all_kde_graphs() # study_visualizer.visualize_all_kde_graphs()
study_visualizer.visualize_all_experimental_law() study_visualizer.visualize_all_experimental_law()
# for study_class in SCM_EXTENDED_STUDIES[:]:
# for study in study_iterator(study_class, only_first_one=False):
# study_visualizer = StudyVisualizer(study, single_massif_graph=True, save_to_file=True)
# # study_visualizer.visualize_all_kde_graphs()
# study_visualizer.visualize_all_experimental_law()
def normal_visualization(): def normal_visualization():
......
...@@ -28,13 +28,19 @@ from utils import get_display_name_from_object_type, VERSION_TIME, float_to_str_ ...@@ -28,13 +28,19 @@ from utils import get_display_name_from_object_type, VERSION_TIME, float_to_str_
class StudyVisualizer(object): class StudyVisualizer(object):
def __init__(self, study: AbstractStudy, show=True, save_to_file=False, single_massif_graph=False): def __init__(self, study: AbstractStudy, show=True, save_to_file=False, only_one_graph=False, only_first_row=False):
self.single_massif_graph = single_massif_graph self.only_first_row = only_first_row
self.only_one_graph = only_one_graph
self.save_to_file = save_to_file self.save_to_file = save_to_file
self.study = study self.study = study
self.show = False if self.save_to_file else show self.show = False if self.save_to_file else show
self.window_size_for_smoothing = 21 self.window_size_for_smoothing = 21
self.figsize = (16.0, 10.0) if self.only_one_graph:
self.figsize = (6.0, 4.0)
elif self.only_first_row:
self.figsize = (16.0, 6.0)
else:
self.figsize = (16.0, 10.0)
@property @property
def observations(self): def observations(self):
...@@ -51,18 +57,23 @@ class StudyVisualizer(object): ...@@ -51,18 +57,23 @@ class StudyVisualizer(object):
# Graph for each massif / or groups of massifs # Graph for each massif / or groups of massifs
def visualize_massif_graphs(self, visualize_function): def visualize_massif_graphs(self, visualize_function):
if self.single_massif_graph: if self.only_one_graph:
fig, ax = plt.subplots(1, 1, figsize=self.figsize) fig, ax = plt.subplots(1, 1, figsize=self.figsize)
visualize_function(ax, 0) visualize_function(ax, 0)
else: else:
nb_columns = 5 nb_columns = 5
nb_rows = math.ceil(len(self.study.safran_massif_names) / nb_columns) nb_rows = 1 if self.only_first_row else math.ceil(len(self.study.safran_massif_names) / nb_columns)
fig, axes = plt.subplots(nb_rows, nb_columns, figsize=self.figsize) fig, axes = plt.subplots(nb_rows, nb_columns, figsize=self.figsize)
fig.subplots_adjust(hspace=1.0, wspace=1.0) fig.subplots_adjust(hspace=1.0, wspace=1.0)
for massif_id, massif_name in enumerate(self.study.safran_massif_names): if self.only_first_row:
row_id, column_id = massif_id // nb_columns, massif_id % nb_columns for massif_id, massif_name in enumerate(self.study.safran_massif_names[:nb_columns]):
ax = axes[row_id, column_id] ax = axes[massif_id]
visualize_function(ax, massif_id) visualize_function(ax, massif_id)
else:
for massif_id, massif_name in enumerate(self.study.safran_massif_names):
row_id, column_id = massif_id // nb_columns, massif_id % nb_columns
ax = axes[row_id, column_id]
visualize_function(ax, massif_id)
def visualize_all_experimental_law(self): def visualize_all_experimental_law(self):
self.visualize_massif_graphs(self.visualize_experimental_law) self.visualize_massif_graphs(self.visualize_experimental_law)
...@@ -93,13 +104,15 @@ class StudyVisualizer(object): ...@@ -93,13 +104,15 @@ class StudyVisualizer(object):
ax.scatter([xi], [yi], color=color, marker="o", label=name) ax.scatter([xi], [yi], color=color, marker="o", label=name)
ax.set_ylabel('Probability Density function f(x)', color=color_kde) ax.set_ylabel('Probability Density function f(x)', color=color_kde)
ax.set_xlabel('x = {}'.format(self.study.title)) xlabel = 'x = {}'.format(self.study.title) if self.only_one_graph else 'x'
ax.set_xlabel(xlabel)
extraticks = [float(float_to_str_with_only_some_significant_digits(x, nb_digits=2)) extraticks = [float(float_to_str_with_only_some_significant_digits(x, nb_digits=2))
for x in sorted(list(x_level_to_color.keys()))] for x in sorted(list(x_level_to_color.keys()))]
if not self.single_massif_graph: if not self.only_one_graph:
extraticks = [extraticks[0], extraticks[-1]] extraticks = [extraticks[0], extraticks[-1]]
ax.set_xticks(extraticks) ax.set_xticks(extraticks)
ax.set_title(self.study.safran_massif_names[massif_id]) if not self.only_one_graph:
ax.set_title(self.study.safran_massif_names[massif_id])
ax.legend() ax.legend()
def visualize_all_mean_and_max_graphs(self): def visualize_all_mean_and_max_graphs(self):
...@@ -160,11 +173,15 @@ class StudyVisualizer(object): ...@@ -160,11 +173,15 @@ class StudyVisualizer(object):
def show_or_save_to_file(self, plot_name): def show_or_save_to_file(self, plot_name):
title = self.study.title title = self.study.title
title += '\n' + plot_name title += '\n' + plot_name
plt.suptitle(title) if not self.only_one_graph:
plt.suptitle(title)
if self.show: if self.show:
plt.show() plt.show()
if self.save_to_file: if self.save_to_file:
filename = "{}/{}/{}".format(VERSION_TIME, '_'.join(self.study.title.split()), '_'.join(plot_name.split())) filename = "{}/{}".format(VERSION_TIME, '_'.join(self.study.title.split()))
if not self.only_one_graph:
filename += "/{}".format('_'.join(plot_name.split()))
filepath = op.join(self.study.result_full_path, filename + '.png') filepath = op.join(self.study.result_full_path, filename + '.png')
dir = op.dirname(filepath) dir = op.dirname(filepath)
if not op.exists(dir): if not op.exists(dir):
......
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