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

[refactor] fix issue. the temporal covariate is the the anomaly of temperature...

[refactor] fix issue. the temporal covariate is the the anomaly of temperature smoothed with a spline
parent 07d47261
No related merge requests found
Showing with 21 additions and 22 deletions
+21 -22
...@@ -26,7 +26,7 @@ def get_scenario_name(scenario): ...@@ -26,7 +26,7 @@ def get_scenario_name(scenario):
return str(scenario).split('.')[-1] return str(scenario).split('.')[-1]
def year_to_global_mean_temp(gcm, scenario, year_min=None, year_max=None, spline=False, anomaly=False): def year_to_global_mean_temp(gcm, scenario, year_min=None, year_max=None, spline=True, anomaly=True):
d = OrderedDict() d = OrderedDict()
years, global_mean_temps = years_and_global_mean_temps(gcm, scenario, year_min, year_max, spline=spline, years, global_mean_temps = years_and_global_mean_temps(gcm, scenario, year_min, year_max, spline=spline,
anomaly=anomaly) anomaly=anomaly)
...@@ -43,7 +43,7 @@ def get_column_name(anomaly, spline): ...@@ -43,7 +43,7 @@ def get_column_name(anomaly, spline):
return basic_column_name return basic_column_name
def years_and_global_mean_temps(gcm, scenario, year_min=None, year_max=None, anomaly=False, spline=True): def years_and_global_mean_temps(gcm, scenario, year_min=None, year_max=None, anomaly=True, spline=True):
# Compute everything # Compute everything
ensemble_member = 'r{}i1p1'.format(gcm_to_rnumber[gcm]) ensemble_member = 'r{}i1p1'.format(gcm_to_rnumber[gcm])
scenario_name = get_scenario_name(scenario) scenario_name = get_scenario_name(scenario)
...@@ -75,7 +75,7 @@ def years_and_global_mean_temps(gcm, scenario, year_min=None, year_max=None, ano ...@@ -75,7 +75,7 @@ def years_and_global_mean_temps(gcm, scenario, year_min=None, year_max=None, ano
return years, global_mean_temp return years, global_mean_temp
def dat_to_csv(csv_filepath, txt_filepath, spline): def dat_to_csv(csv_filepath, txt_filepath):
d = OrderedDict() d = OrderedDict()
with open(txt_filepath, 'r') as f: with open(txt_filepath, 'r') as f:
for i, l in enumerate(f): for i, l in enumerate(f):
......
...@@ -13,7 +13,7 @@ from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualiz ...@@ -13,7 +13,7 @@ from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualiz
from root_utils import VERSION_TIME from root_utils import VERSION_TIME
def main_plot_temperature_all(anomaly=False, spline=False): def main_plot_temperature_all(anomaly=True, spline=True):
ax = plt.gca() ax = plt.gca()
for gcm in get_gcm_list(adamont_version=2)[:]: for gcm in get_gcm_list(adamont_version=2)[:]:
for scenario in rcp_scenarios[:]: for scenario in rcp_scenarios[:]:
...@@ -23,7 +23,7 @@ def main_plot_temperature_all(anomaly=False, spline=False): ...@@ -23,7 +23,7 @@ def main_plot_temperature_all(anomaly=False, spline=False):
end_plot(anomaly, ax, spline) end_plot(anomaly, ax, spline)
def main_plot_temperature_with_spline_on_top(anomaly=False): def main_plot_temperature_with_spline_on_top(anomaly=True):
spline = None spline = None
for gcm in get_gcm_list(adamont_version=2)[:]: for gcm in get_gcm_list(adamont_version=2)[:]:
ax = plt.gca() ax = plt.gca()
...@@ -67,7 +67,7 @@ def end_plot(anomaly, ax, spline, title=None): ...@@ -67,7 +67,7 @@ def end_plot(anomaly, ax, spline, title=None):
def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyle=None, def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyle=None,
label=None, spline: Union[None, bool] = False, anomaly=False): label=None, spline: Union[None, bool] = True, anomaly=True):
splines = [spline] if spline is not None else [True, False] splines = [spline] if spline is not None else [True, False]
for spline in splines: for spline in splines:
years, global_mean_temp = years_and_global_mean_temps(gcm, scenario, year_min=year_min, year_max=year_max, spline=spline, anomaly=anomaly) years, global_mean_temp = years_and_global_mean_temps(gcm, scenario, year_min=year_min, year_max=year_max, spline=spline, anomaly=anomaly)
...@@ -87,5 +87,5 @@ def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyl ...@@ -87,5 +87,5 @@ def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyl
if __name__ == '__main__': if __name__ == '__main__':
main_plot_temperature_with_spline_on_top(anomaly=True) # main_plot_temperature_with_spline_on_top(anomaly=True)
# main_plot_temperature_all(anomaly=True, spline=False) main_plot_temperature_all(anomaly=True, spline=True)
...@@ -26,7 +26,7 @@ from extreme_trend.one_fold_fit.one_fold_fit import \ ...@@ -26,7 +26,7 @@ from extreme_trend.one_fold_fit.one_fold_fit import \
OneFoldFit OneFoldFit
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \ from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \
AnomalyTemperatureTemporalCovariate AnomalyTemperatureWithSplineTemporalCovariate
class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
...@@ -182,7 +182,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -182,7 +182,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
moment = ' '.join(method_name.split('_')) moment = ' '.join(method_name.split('_'))
d_temperature = {'C': '{C}'} d_temperature = {'C': '{C}'}
str_for_last_year = ' at +${}^o\mathrm{C}$' \ str_for_last_year = ' at +${}^o\mathrm{C}$' \
if self.temporal_covariate_for_fit is AnomalyTemperatureTemporalCovariate else ' in {}' if self.temporal_covariate_for_fit is AnomalyTemperatureWithSplineTemporalCovariate else ' in {}'
str_for_last_year = str_for_last_year.format(self.first_one_fold_fit.covariate_after, **d_temperature) str_for_last_year = str_for_last_year.format(self.first_one_fold_fit.covariate_after, **d_temperature)
moment = moment.replace('moment', '{}{}'.format(OneFoldFit.get_moment_str(order=order), str_for_last_year)) moment = moment.replace('moment', '{}{}'.format(OneFoldFit.get_moment_str(order=order), str_for_last_year))
plot_name = '{} '.format(moment) plot_name = '{} '.format(moment)
......
...@@ -31,7 +31,7 @@ from extreme_trend.one_fold_fit.altitude_group import DefaultAltitudeGroup, alti ...@@ -31,7 +31,7 @@ from extreme_trend.one_fold_fit.altitude_group import DefaultAltitudeGroup, alti
from root_utils import NB_CORES, batch from root_utils import NB_CORES, batch
from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_covariate_for_fit import TimeTemporalCovariate from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_covariate_for_fit import TimeTemporalCovariate
from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \ from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \
AnomalyTemperatureTemporalCovariate AnomalyTemperatureWithSplineTemporalCovariate
from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset
from spatio_temporal_dataset.slicer.split import Split from spatio_temporal_dataset.slicer.split import Split
from spatio_temporal_dataset.spatio_temporal_observations.annual_maxima_observations import AnnualMaxima from spatio_temporal_dataset.spatio_temporal_observations.annual_maxima_observations import AnnualMaxima
...@@ -133,7 +133,7 @@ class OneFoldFit(object): ...@@ -133,7 +133,7 @@ class OneFoldFit(object):
def _covariate_before_and_after(self): def _covariate_before_and_after(self):
if self.temporal_covariate_for_fit in [None, TimeTemporalCovariate]: if self.temporal_covariate_for_fit in [None, TimeTemporalCovariate]:
return self.last_year - self.nb_years, self.last_year return self.last_year - self.nb_years, self.last_year
elif self.temporal_covariate_for_fit is AnomalyTemperatureTemporalCovariate: elif self.temporal_covariate_for_fit is AnomalyTemperatureWithSplineTemporalCovariate:
# In 2020, we are roughly at 1 degree. Thus it natural to see the augmentation from 1 to 2 degree. # In 2020, we are roughly at 1 degree. Thus it natural to see the augmentation from 1 to 2 degree.
return 1, self.last_anomaly return 1, self.last_anomaly
else: else:
...@@ -142,7 +142,7 @@ class OneFoldFit(object): ...@@ -142,7 +142,7 @@ class OneFoldFit(object):
@property @property
def between_covariate_str(self): def between_covariate_str(self):
d_temperature = {'C': '{C}'} d_temperature = {'C': '{C}'}
s = ' between +${}^o\mathrm{C}$ and +${}^o\mathrm{C}$' if self.temporal_covariate_for_fit is AnomalyTemperatureTemporalCovariate \ s = ' between +${}^o\mathrm{C}$ and +${}^o\mathrm{C}$' if self.temporal_covariate_for_fit is AnomalyTemperatureWithSplineTemporalCovariate \
else ' between {} and {}' else ' between {} and {}'
s = s.format(self.covariate_before, self.covariate_after, s = s.format(self.covariate_before, self.covariate_after,
**d_temperature) **d_temperature)
......
...@@ -8,16 +8,15 @@ from extreme_trend.elevation_temporal_model_for_projections.visualizer_for_sensi ...@@ -8,16 +8,15 @@ from extreme_trend.elevation_temporal_model_for_projections.visualizer_for_sensi
VisualizerForSensivity VisualizerForSensivity
from extreme_trend.ensemble_fit.independent_ensemble_fit.independent_ensemble_fit import IndependentEnsembleFit from extreme_trend.ensemble_fit.independent_ensemble_fit.independent_ensemble_fit import IndependentEnsembleFit
from extreme_trend.ensemble_fit.visualizer_for_projection_ensemble import VisualizerForProjectionEnsemble
from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \ from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \
AnomalyTemperatureTemporalCovariate AnomalyTemperatureWithSplineTemporalCovariate
mpl.rcParams['text.usetex'] = True mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}'] mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']
from extreme_fit.model.margin_model.polynomial_margin_model.utils import \ from extreme_fit.model.margin_model.polynomial_margin_model.utils import \
ALTITUDINAL_GEV_MODELS_BASED_ON_POINTWISE_ANALYSIS ALTITUDINAL_GEV_MODELS_BASED_ON_POINTWISE_ANALYSIS
from extreme_trend.elevation_temporal_model_for_projections.visualizer_for_projection_ensemble import \
VisualizerForProjectionEnsemble
import matplotlib import matplotlib
from extreme_fit.model.utils import set_seed_for_test from extreme_fit.model.utils import set_seed_for_test
...@@ -40,7 +39,7 @@ def main(): ...@@ -40,7 +39,7 @@ def main():
start = time.time() start = time.time()
study_class = AdamontSnowfall study_class = AdamontSnowfall
ensemble_fit_class = [IndependentEnsembleFit] ensemble_fit_class = [IndependentEnsembleFit]
temporal_covariate_for_fit = [TimeTemporalCovariate, AnomalyTemperatureTemporalCovariate][1] temporal_covariate_for_fit = [TimeTemporalCovariate, AnomalyTemperatureWithSplineTemporalCovariate][1]
set_seed_for_test() set_seed_for_test()
AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2 AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2
......
...@@ -44,7 +44,7 @@ class MeanAlpsTemperatureCovariate(AbstractTemperatureCovariate): ...@@ -44,7 +44,7 @@ class MeanAlpsTemperatureCovariate(AbstractTemperatureCovariate):
def load_year_to_temperature_covariate(cls): def load_year_to_temperature_covariate(cls):
return load_year_to_mean_alps_temperatures() return load_year_to_mean_alps_temperatures()
class AnomalyTemperatureTemporalCovariate(AbstractTemporalCovariateForFit): class AnomalyTemperatureWithSplineTemporalCovariate(AbstractTemporalCovariateForFit):
gcm_and_scenario_to_d = {} gcm_and_scenario_to_d = {}
@classmethod @classmethod
...@@ -54,7 +54,7 @@ class AnomalyTemperatureTemporalCovariate(AbstractTemporalCovariateForFit): ...@@ -54,7 +54,7 @@ class AnomalyTemperatureTemporalCovariate(AbstractTemporalCovariateForFit):
scenario_str = row[AbstractCoordinates.COORDINATE_RCP] scenario_str = row[AbstractCoordinates.COORDINATE_RCP]
scenario = str_to_scenario(scenario_str) scenario = str_to_scenario(scenario_str)
if (gcm, scenario) not in cls.gcm_and_scenario_to_d: if (gcm, scenario) not in cls.gcm_and_scenario_to_d:
d = year_to_global_mean_temp(gcm, scenario, anomaly=True) d = year_to_global_mean_temp(gcm, scenario, anomaly=True, spline=True)
cls.gcm_and_scenario_to_d[(gcm, scenario)] = d cls.gcm_and_scenario_to_d[(gcm, scenario)] = d
d = cls.gcm_and_scenario_to_d[(gcm, scenario)] d = cls.gcm_and_scenario_to_d[(gcm, scenario)]
global_mean_temp = d[year] global_mean_temp = d[year]
......
...@@ -16,7 +16,7 @@ from extreme_trend.one_fold_fit.one_fold_fit import OneFoldFit ...@@ -16,7 +16,7 @@ from extreme_trend.one_fold_fit.one_fold_fit import OneFoldFit
from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_covariate_for_fit import \ from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_covariate_for_fit import \
TimeTemporalCovariate TimeTemporalCovariate
from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \ from spatio_temporal_dataset.coordinates.temporal_coordinates.temperature_covariate import \
AnomalyTemperatureTemporalCovariate AnomalyTemperatureWithSplineTemporalCovariate
class TestOneFoldFit(unittest.TestCase): class TestOneFoldFit(unittest.TestCase):
...@@ -60,7 +60,7 @@ class TestOneFoldFit(unittest.TestCase): ...@@ -60,7 +60,7 @@ class TestOneFoldFit(unittest.TestCase):
dataset = self.load_dataset(study_class, scenario=AdamontScenario.rcp85) dataset = self.load_dataset(study_class, scenario=AdamontScenario.rcp85)
one_fold_fit = OneFoldFit(self.massif_name, dataset, one_fold_fit = OneFoldFit(self.massif_name, dataset,
models_classes=self.model_classes, models_classes=self.model_classes,
temporal_covariate_for_fit=AnomalyTemperatureTemporalCovariate, temporal_covariate_for_fit=AnomalyTemperatureWithSplineTemporalCovariate,
only_models_that_pass_goodness_of_fit_test=False) only_models_that_pass_goodness_of_fit_test=False)
_ = one_fold_fit.best_estimator.margin_model _ = one_fold_fit.best_estimator.margin_model
self.assertTrue(True) self.assertTrue(True)
...@@ -91,7 +91,7 @@ class TestOneFoldFit(unittest.TestCase): ...@@ -91,7 +91,7 @@ class TestOneFoldFit(unittest.TestCase):
year_min=year_min, year_max=year_max) year_min=year_min, year_max=year_max)
one_fold_fit = OneFoldFit(self.massif_name, dataset, one_fold_fit = OneFoldFit(self.massif_name, dataset,
models_classes=self.model_classes, models_classes=self.model_classes,
temporal_covariate_for_fit=AnomalyTemperatureTemporalCovariate, temporal_covariate_for_fit=AnomalyTemperatureWithSplineTemporalCovariate,
altitude_class=VeyHighAltitudeGroup, altitude_class=VeyHighAltitudeGroup,
only_models_that_pass_goodness_of_fit_test=False, only_models_that_pass_goodness_of_fit_test=False,
remove_physically_implausible_models=True) remove_physically_implausible_models=True)
......
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