Commit 28c9d300 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[refactor] move altitudes_studies.py. create trend test folder inside extreme_trend.

parent 08ca4b88
No related merge requests found
Showing with 17 additions and 224 deletions
+17 -224
import numpy as np
from extreme_data.meteo_france_data.adamont_data.abstract_adamont_study import AbstractAdamontStudy
from extreme_data.meteo_france_data.adamont_data.adamont_scenario import AdamontScenario
from extreme_data.meteo_france_data.adamont_data.adamont.adamont_variables import \
SafranSnowfallSimulationVariable
from extreme_data.meteo_france_data.scm_models_data.abstract_study import YEAR_MIN, YEAR_MAX
from extreme_data.meteo_france_data.scm_models_data.abstract_variable import AbstractVariable
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day
from extreme_data.meteo_france_data.scm_models_data.safran.safran_variable import SafranSnowfallVariable
from extreme_data.meteo_france_data.adamont_data.adamont_scenario import AdamontScenario
from extreme_data.meteo_france_data.scm_models_data.utils import Season, FrenchRegion
......
import os
from typing import List
import os.path as op
import numpy as np
from cached_property import cached_property
from extreme_data.meteo_france_data.adamont_data.deprecated.single_simulation import SingleSimulation
ADAMONT_PATH = r"/home/erwan/Documents/projects/spatiotemporalextremes/local/spatio_temporal_datasets/ADAMONT"
class EnsembleSimulation(object):
def __init__(self, scenario='HISTO', parameter='SNOWSWE',
first_winter_required_for_histo=1958, last_winter_for_histo=2004):
assert False, 'RE-read the code to take into the new dates'
self.scenario = scenario
self.parameter = parameter
self.first_winter_required_for_histo = first_winter_required_for_histo
self.last_year_for_histo = last_winter_for_histo
# Assert value for the parameter
assert scenario in ['HISTO', 'RCP45']
assert parameter in ['SNOWSWE']
assert first_winter_required_for_histo >= 1950
assert first_winter_required_for_histo <= 2004
# Load simulations
# todo: so far i am using one ensemble member
print('single ensemble member', self.nc_files[0])
self.simulations = [SingleSimulation(nc_path, self.parameter,
self.first_winter_required_for_histo,
self.last_year_for_histo) for nc_path in self.nc_paths][:1]
@cached_property
def simulations_path(self):
return op.join(ADAMONT_PATH, self.parameter, self.scenario)
@cached_property
def nc_paths(self):
return [op.join(ADAMONT_PATH, self.parameter, self.scenario, nc_file) for nc_file in self.nc_files]
@cached_property
def nc_files(self) -> List[str]:
nc_files = []
for file in os.listdir(self.simulations_path):
first_year = int(file.split('_')[-3][:4])
if first_year <= self.first_winter_required_for_histo:
# Also remove the historical simulations that contain "CNRM-CM5"
# Problem reported in "limitations" on their website
# Ce problème affecte toutes lessimulations HISTORIQUE CORDEX
# réalisées en utilisant le forçage CNRM-CM5: CCLM4-8-17: ALADIN53 et RCA4
if self.scenario == 'HISTO' and 'CNRM-CM5' in file:
print('here', file)
continue
nc_files.append(file)
assert len(nc_files) > 0
return nc_files
@cached_property
def simulations_names(self):
return [' + '.join(file.split('_')[2:-5]) for file in self.nc_files]
def massif_name_and_altitude_to_mean_return_level(self):
return {}
@property
def first_simulation(self):
return self.simulations[0]
@property
def massif_name_and_altitude(self):
pass
@cached_property
def massif_name_and_altitude_to_mean_average_annual_maxima(self):
d = {}
for m, a in self.first_simulation.massif_name_and_altitude_to_average_maxima.keys():
d[(m, a)] = np.mean([s.massif_name_and_altitude_to_average_maxima[(m, a)] for s in self.simulations])
return d
if __name__ == '__main__':
# np.array(d.variables['SNOWSWE'])
ensemble = EnsembleSimulation(first_winter_required_for_histo=1958)
print(len(ensemble.simulations))
print(ensemble.simulations_names)
s = ensemble.first_simulation
d = s.dataset
# print(s.massif_name_and_altitude_to_annual_maxima_time_series)
# print(s.massif_name_and_altitude_to_average_maxima)
print(ensemble.massif_name_and_altitude_to_mean_average_annual_maxima)
print(s.years)
# print(d)
from datetime import datetime
import numpy as np
import os.path as op
from cached_property import cached_property
from netCDF4._netCDF4 import Dataset
from datetime import timedelta
from extreme_data.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
class SingleSimulation(object):
def __init__(self, nc_path, parameter, fist_year, last_year):
self.fist_year = fist_year
self.last_year = last_year
self.parameter = parameter
self.nc_path = nc_path
@cached_property
def dataset(self):
return Dataset(self.nc_path)
@cached_property
def winter_year(self):
start = datetime(year=1900, month=1, day=1, hour=0, minute=0, second=0)
seconds_after_start = np.array(self.dataset.variables['TIME'])
dates = [start + timedelta(seconds=s) for s in seconds_after_start]
winter_year = [date.year - 1 if date.month < 8 else date.year for date in dates]
return np.array(winter_year)
@cached_property
def years(self):
return sorted([year for year in set(self.winter_year) if self.fist_year <= year <= self.last_year])
def massif_name_and_altitude_to_return_level(self):
return {}
@property
def massif_number_to_massif_name(self):
# from adamont_data metadata
s = """1 Chablais
2 Aravis
3 Mont-Blanc
4 Bauges
5 Beaufortain
6 Haute-Tarentaise
7 Chartreuse
8 Belledonne
9 Maurienne
10 Vanoise
11 Haute-Maurienne
12 Grandes-Rousses
13 Thabor
14 Vercors
15 Oisans
16 Pelvoux
17 Queyras
18 Devoluy
19 Champsaur
20 Parpaillon
21 Ubaye
22 Haut_Var-Haut_Verdon
23 Mercantour"""
l = s.split('\n')
return dict([e.split() for e in l])
@cached_property
def massif_name_and_altitude_to_annual_maxima_time_series(self):
all_values = np.array(self.dataset.variables[self.parameter])
zs_list = [int(e) for e in np.array(self.dataset.variables['ZS'])]
massif_number_list = np.array(self.dataset.variables['MASSIF_NUMBER'])
massif_name_list = [self.massif_number_to_massif_name[str(n)] for n in massif_number_list]
d = {}
for year in self.years:
indexes = np.where(self.winter_year == year)[0]
winter_values = all_values[indexes, 0, :]
assert len(winter_values) in [365, 366]
for time_serie, zs, massif_name in zip(winter_values.transpose(), zs_list, massif_name_list):
# print(zs, massif_name, len(time_serie))
d[(massif_name, zs)] = time_serie
return d
@cached_property
def massif_name_and_altitude_to_average_maxima(self):
return {t: np.mean(s) for t, s in self.massif_name_and_altitude_to_annual_maxima_time_series.items()}
import pandas as pd
import numpy as np
import xlsxwriter
from extreme_data.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusDepth, CrocusSwe3Days
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day, SafranSnowfall3Days
from extreme_data.meteo_france_data.scm_models_data.utils import FrenchRegion
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day
from extreme_data.meteo_france_data.scm_models_data.visualization.main_study_visualizer import \
SCM_STUDY_CLASS_TO_ABBREVIATION
from extreme_fit.estimator.margin_estimator.utils import fitted_stationary_gev
from projects.altitude_spatial_model.altitudes_fit.altitudes_studies import AltitudesStudies
from extreme_data.meteo_france_data.scm_models_data.altitudes_studies import AltitudesStudies
def generate_excel_with_annual_maxima(fast=True, maxima_dates=False):
......
import pandas as pd
import numpy as np
import xlsxwriter
from extreme_data.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusDepth, CrocusSwe3Days
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day, SafranSnowfall3Days
from extreme_data.meteo_france_data.scm_models_data.utils import FrenchRegion
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day
from extreme_data.meteo_france_data.scm_models_data.visualization.main_study_visualizer import \
SCM_STUDY_CLASS_TO_ABBREVIATION
from extreme_fit.estimator.margin_estimator.utils import fitted_stationary_gev
from projects.altitude_spatial_model.altitudes_fit.altitudes_studies import AltitudesStudies
from extreme_data.meteo_france_data.scm_models_data.altitudes_studies import AltitudesStudies
def generate_excel_with_annual_maxima(fast=True, maxima_dates=False):
......
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \
from extreme_trend.trend_test.trend_test_one_parameter.gev_trend_test_one_parameter import \
GevTrendTestOneParameter
from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import GevLocationAndScaleTrendTest
from extreme_trend.trend_test.trend_test_two_parameters import GevLocationAndScaleTrendTest
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \
NonStationaryLocationTemporalModel, NonStationaryScaleTemporalModel
import numpy as np
class AbstractComparisonNonStationaryModelOneParameter(GevTrendTestOneParameter):
......
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \
......
# Comparison with the Gumbel model
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \
from extreme_trend.trend_test.trend_test_one_parameter.gev_trend_test_one_parameter import \
GevTrendTestOneParameter, GevTrendTestOneParameterAgainstStationary
from extreme_fit.distribution.gev.gev_params import GevParams
from extreme_fit.model.margin_model.utils import \
......
......@@ -3,7 +3,7 @@ from extreme_fit.model.margin_model.polynomial_margin_model.polynomial_margin_mo
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \
NonStationaryLocationAndScaleTemporalModel, GumbelTemporalModel, StationaryTemporalModel, \
NonStationaryLocationAndScaleAndShapeTemporalModel
......
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_fit.model.margin_model.polynomial_margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel, \
NonStationaryQuadraticScaleModel
from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \
from extreme_trend.trend_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test.trend_test_one_parameter.gev_trend_test_one_parameter import \
GevLocationTrendTest, GevScaleTrendTest
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
......
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_fit.model.margin_model.polynomial_margin_model.polynomial_margin_model import \
NonStationaryQuadraticLocationGumbelModel, NonStationaryQuadraticScaleGumbelModel
from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import \
GevTrendTestTwoParameters
from extreme_fit.distribution.gev.gev_params import GevParams
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \
NonStationaryLocationAndScaleGumbelModel, GumbelTemporalModel
from extreme_trend.trend_test.trend_test_two_parameters.gev_trend_test_two_parameters import GevTrendTestTwoParameters
from root_utils import classproperty
......
from collections import OrderedDict, Counter
from enum import Enum
from multiprocessing.pool import Pool
from typing import Dict, List, Tuple
from typing import Dict, List
import matplotlib.pyplot as plt
import numpy as np
......@@ -18,15 +18,10 @@ from extreme_data.meteo_france_data.scm_models_data.abstract_study import Abstra
from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualizer import \
StudyVisualizer
from projects.exceeding_snow_loads.utils import NON_STATIONARY_TREND_TEST_PAPER_1, ALTITUDE_TO_GREY_MASSIF
from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test_one_parameter.gumbel_trend_test_one_parameter import \
GumbelLocationTrendTest, GevStationaryVersusGumbel, GumbelScaleTrendTest, GumbelVersusGumbel
from extreme_trend.trend_test_two_parameters.gumbel_test_two_parameters import \
GumbelLocationAndScaleTrendTest
from extreme_trend.trend_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_fit.model.margin_model.utils import \
MarginFitMethod
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import GumbelTemporalModel, \
StationaryTemporalModel
from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import GumbelTemporalModel
from extreme_fit.model.result_from_model_fit.result_from_extremes.confidence_interval_method import \
ConfidenceIntervalMethodFromExtremes
from extreme_fit.model.result_from_model_fit.result_from_extremes.eurocode_return_level_uncertainties import \
......
......@@ -3,7 +3,7 @@ from cached_property import cached_property
from extreme_data.meteo_france_data.scm_models_data.visualization.create_shifted_cmap import get_shifted_map
from extreme_data.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
from extreme_trend.visualizers.study_visualizer_for_non_stationary_trends import \
from extreme_trend.trend_test.visualizers import \
StudyVisualizerForNonStationaryTrends
......
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