Newer
Older
import datetime
import time
from typing import List
Le Roux Erwan
committed
import matplotlib
from extreme_trend.ensemble_fit.together_ensemble_fit.together_ensemble_fit import TogetherEnsembleFit
Le Roux Erwan
committed
matplotlib.use('Agg')
Le Roux Erwan
committed
import matplotlib as mpl
Le Roux Erwan
committed
mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']
Le Roux Erwan
committed
from extreme_trend.ensemble_fit.independent_ensemble_fit.independent_ensemble_fit import IndependentEnsembleFit
Le Roux Erwan
committed
from extreme_trend.ensemble_fit.visualizer_for_projection_ensemble import VisualizerForProjectionEnsemble
from extreme_trend.ensemble_fit.visualizer_for_sensitivity import VisualizerForSensivity
Le Roux Erwan
committed
from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \
Le Roux Erwan
committed
AnomalyTemperatureWithSplineTemporalCovariate
Le Roux Erwan
committed
Le Roux Erwan
committed
from extreme_fit.model.margin_model.polynomial_margin_model.utils import \
ALTITUDINAL_GEV_MODELS_BASED_ON_POINTWISE_ANALYSIS
Le Roux Erwan
committed
Le Roux Erwan
committed
from extreme_fit.model.utils import set_seed_for_test
Le Roux Erwan
committed
from extreme_data.meteo_france_data.adamont_data.adamont.adamont_safran import AdamontSnowfall
Le Roux Erwan
committed
from extreme_data.meteo_france_data.adamont_data.adamont_scenario import AdamontScenario, get_gcm_rcm_couples, \
rcp_scenarios
Le Roux Erwan
committed
from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_covariate_for_fit import \
TimeTemporalCovariate
from extreme_fit.model.result_from_model_fit.result_from_extremes.abstract_extract_eurocode_return_level import \
AbstractExtractEurocodeReturnLevel
Le Roux Erwan
committed
from extreme_trend.one_fold_fit.altitude_group import altitudes_for_groups
from extreme_data.meteo_france_data.scm_models_data.utils import Season
def main():
Le Roux Erwan
committed
start = time.time()
study_class = AdamontSnowfall
Le Roux Erwan
committed
ensemble_fit_classes = [IndependentEnsembleFit, TogetherEnsembleFit][1:]
Le Roux Erwan
committed
temporal_covariate_for_fit = [TimeTemporalCovariate,
AnomalyTemperatureWithSplineTemporalCovariate][1]
set_seed_for_test()
AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2
Le Roux Erwan
committed
fast = False
Le Roux Erwan
committed
scenarios = rcp_scenarios[::-1] if fast is False else [AdamontScenario.rcp85]
Le Roux Erwan
committed
for scenario in scenarios:
gcm_rcm_couples = get_gcm_rcm_couples(scenario)
if fast is None:
massif_names = None
Le Roux Erwan
committed
gcm_rcm_couples = gcm_rcm_couples
Le Roux Erwan
committed
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
altitudes_list = altitudes_for_groups[3:]
Le Roux Erwan
committed
elif fast:
massif_names = ['Vanoise', 'Haute-Maurienne']
Le Roux Erwan
committed
gcm_rcm_couples = gcm_rcm_couples[:]
Le Roux Erwan
committed
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
Le Roux Erwan
committed
altitudes_list = altitudes_for_groups[:1]
Le Roux Erwan
committed
else:
massif_names = ['Vanoise']
altitudes_list = altitudes_for_groups[3:]
Le Roux Erwan
committed
assert isinstance(gcm_rcm_couples, list)
Le Roux Erwan
committed
assert isinstance(altitudes_list, List)
assert isinstance(altitudes_list[0], List)
print('Scenario is', scenario)
print('Covariate is {}'.format(temporal_covariate_for_fit))
Le Roux Erwan
committed
model_classes = ALTITUDINAL_GEV_MODELS_BASED_ON_POINTWISE_ANALYSIS
assert scenario in rcp_scenarios
visualizer = VisualizerForProjectionEnsemble(
Le Roux Erwan
committed
altitudes_list, gcm_rcm_couples, study_class, Season.annual, scenario,
model_classes=model_classes,
ensemble_fit_classes=ensemble_fit_classes,
massif_names=massif_names,
temporal_covariate_for_fit=temporal_covariate_for_fit,
Le Roux Erwan
committed
remove_physically_implausible_models=True,
gcm_to_year_min_and_year_max=None,
Le Roux Erwan
committed
)
Le Roux Erwan
committed
visualizer.plot()
end = time.time()
duration = str(datetime.timedelta(seconds=end - start))
print('Total duration', duration)
Le Roux Erwan
committed
if __name__ == '__main__':
main()