Commit 83a8fc6e authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

update examples. remove png image

parent 74e75149
No related merge requests found
Showing with 8 additions and 26 deletions
+8 -26
import pandas as pd import pandas as pd
import numpy as np import numpy as np
from s2m.safran import SafranSnowfall1Day from s2m.safran.safran import SafranSnowfall1Day
from s2m import \ from s2m.study_utils import SCM_STUDY_CLASS_TO_ABBREVIATION
SCM_STUDY_CLASS_TO_ABBREVIATION
from s2m.altitudes_studies import AltitudesStudies
def generate_excel_with_annual_maxima(fast=True, maxima_dates=False): def generate_excel_with_annual_maxima(fast=True, maxima_dates=False):
...@@ -17,8 +15,8 @@ def generate_excel_with_annual_maxima(fast=True, maxima_dates=False): ...@@ -17,8 +15,8 @@ def generate_excel_with_annual_maxima(fast=True, maxima_dates=False):
if maxima_dates: if maxima_dates:
study_name += ' - number of days since 1st August, e.g. 1 represents the 2nd of August' study_name += ' - number of days since 1st August, e.g. 1 represents the 2nd of August'
writer = pd.ExcelWriter('{}.xlsx'.format(study_name), engine='xlsxwriter') writer = pd.ExcelWriter('{}.xlsx'.format(study_name), engine='xlsxwriter')
altitude_studies = AltitudesStudies(study_class, altitudes) for altitude in altitudes:
for altitude, study in altitude_studies.altitude_to_study.items(): study = study_class(altitude=altitude)
write_df_with_annual_maxima_v2(altitude, writer, study, maxima_dates) write_df_with_annual_maxima_v2(altitude, writer, study, maxima_dates)
writer.save() writer.save()
...@@ -38,26 +36,6 @@ def write_df_with_annual_maxima_v2(altitude, writer, study, maxima_dates=False) ...@@ -38,26 +36,6 @@ def write_df_with_annual_maxima_v2(altitude, writer, study, maxima_dates=False)
print(df.head()) print(df.head())
df.to_excel(writer, sheet_name='altitude = {} m'.format(altitude)) df.to_excel(writer, sheet_name='altitude = {} m'.format(altitude))
def write_df_with_annual_maxima(massif_name, writer, altitude_studies, maxima_dates=False) -> pd.DataFrame:
columns = []
altitudes = []
for altitude, study in altitude_studies.altitude_to_study.items():
df_maxima = study.observations_annual_maxima.df_maxima_gev
if massif_name in study.study_massif_names:
altitudes.append(altitude)
s = df_maxima.loc[massif_name]
if maxima_dates:
values = study.massif_name_to_annual_maxima_index[massif_name]
s = pd.Series(index=s.index, data=values)
# s.values = np.array(values)
# Fit the data and add the parameters as the first columns
columns.append(s)
df = pd.concat(columns, axis=1)
altitude_str = [str(a) + ' m' for a in altitudes]
df.columns = altitude_str
df.to_excel(writer, sheet_name=massif_name)
return df
if __name__ == '__main__': if __name__ == '__main__':
generate_excel_with_annual_maxima(fast=False, maxima_dates=True) generate_excel_with_annual_maxima(fast=False, maxima_dates=True)
examples/example1.png

84.1 KB

...@@ -4,6 +4,8 @@ from s2m.visualization.visualizer import Visualizer ...@@ -4,6 +4,8 @@ from s2m.visualization.visualizer import Visualizer
altitude = 2100 altitude = 2100
study = SafranTemperature(altitude=altitude, year_min=2020, year_max=2020) study = SafranTemperature(altitude=altitude, year_min=2020, year_max=2020)
annual_maxima = study.massif_name_to_annual_maxima["Chartreuse"]
visualizer = Visualizer(study) visualizer = Visualizer(study)
massif_name_to_value = { massif_name_to_value = {
m: v[0] for m, v in study.massif_name_to_annual_maxima.items() m: v[0] for m, v in study.massif_name_to_annual_maxima.items()
...@@ -20,3 +22,5 @@ visualizer.visualize_study(massif_name_to_value=massif_name_to_value, cmap=plt.c ...@@ -20,3 +22,5 @@ visualizer.visualize_study(massif_name_to_value=massif_name_to_value, cmap=plt.c
' between the 1st August 2019\n and' ' between the 1st August 2019\n and'
' the 31st of July 2020 ($^o$C)'.format(altitude)) ' the 31st of July 2020 ($^o$C)'.format(altitude))
if __name__ == '__main__':
co
\ No newline at end of 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