From 678a41803cfda6f7524188ee07e5453246975853 Mon Sep 17 00:00:00 2001 From: Le Roux Erwan <erwan.le-roux@irstea.fr> Date: Wed, 15 Apr 2020 14:57:21 +0200 Subject: [PATCH] [contrasting project] move and rename TemporalMarginFitMethod --- .../estimator/margin_estimator/utils.py | 5 ++- .../quantile_estimator_from_margin.py | 6 ++-- .../abstract_temporal_linear_margin_model.py | 33 +++++++------------ .../temporal_linear_margin_models.py | 5 +-- .../margin_model/parametric_margin_model.py | 6 ++-- extreme_fit/model/margin_model/utils.py | 12 +++++++ .../eurocode_return_level_uncertainties.py | 8 ++--- extreme_trend/abstract_gev_trend_test.py | 6 ++-- ...bstract_comparison_non_stationary_model.py | 8 ++--- .../gev_trend_test_one_parameter.py | 12 +++---- .../gumbel_trend_test_one_parameter.py | 12 +++---- .../gev_trend_test_three_parameters.py | 6 ++-- .../gev_trend_test_two_parameters.py | 10 +++--- .../gumbel_test_two_parameters.py | 6 ++-- ...dy_visualizer_for_non_stationary_trends.py | 6 ++-- extreme_trend/visualizers/utils.py | 6 ++-- .../gelman_convergence_test.py | 6 ++-- .../main_bayesian_mcmc.py | 6 ++-- .../figure1_mean_ratio_return_level_ratio.py | 6 ++-- ...dy_visualizer_for_double_stationary_fit.py | 6 ++-- .../checks/qqplot/plot_qqplot.py | 6 ++-- .../daily_exp_simulation.py | 8 ++--- .../gev_simulation.py | 10 +++--- .../test_gev_temporal_extremes_bayesian.py | 6 ++-- .../test_gev_temporal_extremes_gumbel.py | 6 ++-- .../test_gev_temporal_extremes_l_moments.py | 6 ++-- .../test_gev_temporal_extremes_mle.py | 6 ++-- .../test_gev/test_gev_temporal_is_mev.py | 6 ++-- .../test_gev/test_stationary_gev_fit.py | 10 +++--- .../test_model/test_confidence_interval.py | 14 ++++---- 30 files changed, 126 insertions(+), 123 deletions(-) create mode 100644 extreme_fit/model/margin_model/utils.py diff --git a/extreme_fit/estimator/margin_estimator/utils.py b/extreme_fit/estimator/margin_estimator/utils.py index 6617a91f..145174be 100644 --- a/extreme_fit/estimator/margin_estimator/utils.py +++ b/extreme_fit/estimator/margin_estimator/utils.py @@ -4,8 +4,7 @@ import pandas as pd from extreme_fit.distribution.gev.gev_params import GevParams from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel from spatio_temporal_dataset.coordinates.temporal_coordinates.generated_temporal_coordinates import \ ConsecutiveTemporalCoordinates @@ -24,7 +23,7 @@ def fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_y return estimator -def fitted_stationary_gev(x_gev, fit_method=TemporalMarginFitMethod.is_mev_gev_fit, model_class=StationaryTemporalModel, starting_year=None, +def fitted_stationary_gev(x_gev, fit_method=MarginFitMethod.is_mev_gev_fit, model_class=StationaryTemporalModel, starting_year=None, transformation_class=CenteredScaledNormalization) -> GevParams: coordinates = ConsecutiveTemporalCoordinates.from_nb_temporal_steps(nb_temporal_steps=len(x_gev), transformation_class=CenteredScaledNormalization) diff --git a/extreme_fit/estimator/quantile_estimator/quantile_estimator_from_margin.py b/extreme_fit/estimator/quantile_estimator/quantile_estimator_from_margin.py index 7a672a42..68e8518c 100644 --- a/extreme_fit/estimator/quantile_estimator/quantile_estimator_from_margin.py +++ b/extreme_fit/estimator/quantile_estimator/quantile_estimator_from_margin.py @@ -5,15 +5,15 @@ from extreme_fit.estimator.quantile_estimator.abstract_quantile_estimator import from extreme_fit.function.abstract_quantile_function import AbstractQuantileFunction, \ QuantileFunctionFromMarginFunction from extreme_fit.function.margin_function.abstract_margin_function import AbstractMarginFunction -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset class QuantileEstimatorFromMargin(LinearMarginEstimator, AbstractQuantileEstimator): def __init__(self, dataset: AbstractDataset, quantile, margin_model_class: type): - margin_model = margin_model_class(dataset.coordinates, fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + margin_model = margin_model_class(dataset.coordinates, fit_method=MarginFitMethod.extremes_fevd_mle) super().__init__(dataset=dataset, quantile=quantile, margin_model=margin_model) @cached_property diff --git a/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py index f097aad5..36a7ab01 100644 --- a/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py +++ b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py @@ -6,6 +6,7 @@ import pandas as pd from extreme_fit.distribution.exp_params import ExpParams from extreme_fit.distribution.gev.gev_params import GevParams from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel +from extreme_fit.model.margin_model.utils import MarginFitMethod, fitmethod_to_str from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit from extreme_fit.model.result_from_model_fit.result_from_extremes.result_from_bayesian_extremes import \ AbstractResultFromExtremes, ResultFromBayesianExtremes @@ -16,16 +17,6 @@ from extreme_fit.model.utils import safe_run_r_estimator from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates -class TemporalMarginFitMethod(Enum): - is_mev_gev_fit = 0 - extremes_fevd_bayesian = 1 - extremes_fevd_mle = 2 - extremes_fevd_gmle = 3 - extremes_fevd_l_moments = 4 - - -def fitmethod_to_str(fit_method): - return str(fit_method).split('.')[-1] class AbstractTemporalLinearMarginModel(LinearMarginModel): @@ -33,7 +24,7 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): def __init__(self, coordinates: AbstractCoordinates, use_start_value=False, params_start_fit=None, params_sample=None, starting_point=None, - fit_method=TemporalMarginFitMethod.is_mev_gev_fit, + fit_method=MarginFitMethod.is_mev_gev_fit, nb_iterations_for_bayesian_fit=5000, params_start_fit_bayesian=None, type_for_MLE="GEV", @@ -43,7 +34,7 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): self.type_for_mle = type_for_MLE self.params_start_fit_bayesian = params_start_fit_bayesian self.nb_iterations_for_bayesian_fit = nb_iterations_for_bayesian_fit - assert isinstance(fit_method, TemporalMarginFitMethod), fit_method + assert isinstance(fit_method, MarginFitMethod), fit_method self.fit_method = fit_method def fitmargin_from_maxima_gev(self, data: np.ndarray, df_coordinates_spat: pd.DataFrame, @@ -54,13 +45,13 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): df_coordinates_temp.values)) x = ro.FloatVector(data) if self.params_class is GevParams: - if self.fit_method == TemporalMarginFitMethod.is_mev_gev_fit: + if self.fit_method == MarginFitMethod.is_mev_gev_fit: return self.ismev_gev_fit(x, df_coordinates_temp) - elif self.fit_method == TemporalMarginFitMethod.extremes_fevd_bayesian: + elif self.fit_method == MarginFitMethod.extremes_fevd_bayesian: return self.extremes_fevd_bayesian_fit(x, df_coordinates_temp) - elif self.fit_method in [TemporalMarginFitMethod.extremes_fevd_mle, - TemporalMarginFitMethod.extremes_fevd_gmle, - TemporalMarginFitMethod.extremes_fevd_l_moments, + elif self.fit_method in [MarginFitMethod.extremes_fevd_mle, + MarginFitMethod.extremes_fevd_gmle, + MarginFitMethod.extremes_fevd_l_moments, ]: return self.extremes_fevd_mle_related_fit(x, df_coordinates_temp) else: @@ -82,11 +73,11 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): # Gev fit with extRemes package def extremes_fevd_mle_related_fit(self, x, df_coordinates_temp) -> AbstractResultFromExtremes: - if self.fit_method == TemporalMarginFitMethod.extremes_fevd_mle: + if self.fit_method == MarginFitMethod.extremes_fevd_mle: method = "MLE" - elif self.fit_method == TemporalMarginFitMethod.extremes_fevd_gmle: + elif self.fit_method == MarginFitMethod.extremes_fevd_gmle: method = "GMLE" - elif self.fit_method == TemporalMarginFitMethod.extremes_fevd_l_moments: + elif self.fit_method == MarginFitMethod.extremes_fevd_l_moments: method = "Lmoments" assert self.margin_function_start_fit.is_a_stationary_model else: @@ -156,4 +147,4 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): if __name__ == '__main__': - print(fitmethod_to_str(TemporalMarginFitMethod.extremes_fevd_l_moments)) + print(fitmethod_to_str(MarginFitMethod.extremes_fevd_l_moments)) diff --git a/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py b/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py index 5e69a015..4746520c 100644 --- a/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py +++ b/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py @@ -1,6 +1,7 @@ from extreme_fit.distribution.exp_params import ExpParams from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - AbstractTemporalLinearMarginModel, TemporalMarginFitMethod + AbstractTemporalLinearMarginModel +from extreme_fit.model.margin_model.utils import MarginFitMethod from extreme_fit.model.utils import r from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates @@ -70,7 +71,7 @@ class NonStationaryLocationAndScaleTemporalModel(AbstractTemporalLinearMarginMod class GumbelTemporalModel(StationaryTemporalModel): def __init__(self, coordinates: AbstractCoordinates, use_start_value=False, params_start_fit=None, - params_sample=None, starting_point=None, fit_method=TemporalMarginFitMethod.is_mev_gev_fit, + params_sample=None, starting_point=None, fit_method=MarginFitMethod.is_mev_gev_fit, nb_iterations_for_bayesian_fit=5000, params_start_fit_bayesian=None): super().__init__(coordinates, use_start_value, params_start_fit, params_sample, starting_point, fit_method, nb_iterations_for_bayesian_fit, params_start_fit_bayesian, type_for_MLE="Gumbel") diff --git a/extreme_fit/model/margin_model/parametric_margin_model.py b/extreme_fit/model/margin_model/parametric_margin_model.py index 49f1995c..8e83405d 100644 --- a/extreme_fit/model/margin_model/parametric_margin_model.py +++ b/extreme_fit/model/margin_model/parametric_margin_model.py @@ -30,17 +30,17 @@ class ParametricMarginModel(AbstractMarginModel, ABC): df_coordinates_temp: pd.DataFrame) -> ResultFromSpatialExtreme: assert data.shape[1] == len(df_coordinates_spat) + return self.fit_from_statial_extremes(data, df_coordinates_spat, df_coordinates_temp) + + def fit_from_statial_extremes(self, data, df_coordinates_spat, df_coordinates_temp): # Margin formula for fitspatgev fit_params = get_margin_formula_spatial_extreme(self.margin_function_start_fit.form_dict) - # Covariables covariables = get_coord(df_coordinates=df_coordinates_spat) fit_params['temp.cov'] = get_coord(df_coordinates=df_coordinates_temp) - # Start parameters coef_dict = self.margin_function_start_fit.coef_dict fit_params['start'] = r.list(**coef_dict) - res = safe_run_r_estimator(function=r.fitspatgev, use_start=self.use_start_value, data=data, covariables=covariables, **fit_params) return ResultFromSpatialExtreme(res) diff --git a/extreme_fit/model/margin_model/utils.py b/extreme_fit/model/margin_model/utils.py new file mode 100644 index 00000000..d511d1ec --- /dev/null +++ b/extreme_fit/model/margin_model/utils.py @@ -0,0 +1,12 @@ +from enum import Enum + + +class MarginFitMethod(Enum): + is_mev_gev_fit = 0 + extremes_fevd_bayesian = 1 + extremes_fevd_mle = 2 + extremes_fevd_gmle = 3 + extremes_fevd_l_moments = 4 + +def fitmethod_to_str(fit_method): + return str(fit_method).split('.')[-1] diff --git a/extreme_fit/model/result_from_model_fit/result_from_extremes/eurocode_return_level_uncertainties.py b/extreme_fit/model/result_from_model_fit/result_from_extremes/eurocode_return_level_uncertainties.py index 4f11e495..68e6fc82 100644 --- a/extreme_fit/model/result_from_model_fit/result_from_extremes/eurocode_return_level_uncertainties.py +++ b/extreme_fit/model/result_from_model_fit/result_from_extremes/eurocode_return_level_uncertainties.py @@ -4,8 +4,8 @@ from extreme_fit.model.result_from_model_fit.result_from_extremes.abstract_extra ExtractEurocodeReturnLevelFromMyBayesianExtremes, ExtractEurocodeReturnLevelFromCiMethod from spatio_temporal_dataset.utils import load_temporal_coordinates_and_dataset from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.result_from_model_fit.result_from_extremes.confidence_interval_method import \ ConfidenceIntervalMethodFromExtremes @@ -46,9 +46,9 @@ class EurocodeConfidenceIntervalFromExtremes(object): # Select fit method depending on the ci_method if ci_method in [ConfidenceIntervalMethodFromExtremes.ci_bayes, ConfidenceIntervalMethodFromExtremes.my_bayes]: - fit_method = TemporalMarginFitMethod.extremes_fevd_bayesian + fit_method = MarginFitMethod.extremes_fevd_bayesian else: - fit_method = TemporalMarginFitMethod.extremes_fevd_mle + fit_method = MarginFitMethod.extremes_fevd_mle # Fitted estimator fitted_estimator = fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_year=None, fit_method=fit_method, nb_iterations_for_bayesian_fit=20000) diff --git a/extreme_trend/abstract_gev_trend_test.py b/extreme_trend/abstract_gev_trend_test.py index 48173331..b31820f3 100644 --- a/extreme_trend/abstract_gev_trend_test.py +++ b/extreme_trend/abstract_gev_trend_test.py @@ -9,8 +9,8 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE, YEAR_OF_INTEREST from extreme_data.meteo_france_data.scm_models_data.crocus.crocus_variables import AbstractSnowLoadVariable from extreme_fit.estimator.margin_estimator.utils import fitted_linear_margin_estimator from extreme_fit.distribution.gev.gev_params import GevParams -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ StationaryTemporalModel from extreme_fit.model.utils import SafeRunException @@ -27,7 +27,7 @@ class AbstractGevTrendTest(object): def __init__(self, years, maxima, starting_year, unconstrained_model_class, constrained_model_class=StationaryTemporalModel, quantile_level=EUROCODE_QUANTILE, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): self.years = years self.maxima = maxima self.starting_year = starting_year diff --git a/extreme_trend/trend_test_one_parameter/abstract_comparison_non_stationary_model.py b/extreme_trend/trend_test_one_parameter/abstract_comparison_non_stationary_model.py index 97e5e53a..56a6c6ce 100644 --- a/extreme_trend/trend_test_one_parameter/abstract_comparison_non_stationary_model.py +++ b/extreme_trend/trend_test_one_parameter/abstract_comparison_non_stationary_model.py @@ -2,8 +2,8 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_trend.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_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +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 @@ -20,13 +20,13 @@ class AbstractComparisonNonStationaryModelOneParameter(GevTrendTestOneParameter) class ComparisonAgainstMu(AbstractComparisonNonStationaryModelOneParameter, GevLocationAndScaleTrendTest): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, constrained_model_class=NonStationaryLocationTemporalModel, quantile_level=quantile_level, fit_method=fit_method) class ComparisonAgainstSigma(AbstractComparisonNonStationaryModelOneParameter, GevLocationAndScaleTrendTest): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, constrained_model_class=NonStationaryScaleTemporalModel, quantile_level=quantile_level, fit_method=fit_method) diff --git a/extreme_trend/trend_test_one_parameter/gev_trend_test_one_parameter.py b/extreme_trend/trend_test_one_parameter/gev_trend_test_one_parameter.py index fa1a4c3c..c2371186 100644 --- a/extreme_trend/trend_test_one_parameter/gev_trend_test_one_parameter.py +++ b/extreme_trend/trend_test_one_parameter/gev_trend_test_one_parameter.py @@ -1,7 +1,7 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +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, NonStationaryShapeTemporalModel, \ StationaryTemporalModel @@ -20,7 +20,7 @@ class GevTrendTestOneParameterAgainstStationary(GevTrendTestOneParameter): def __init__(self, years, maxima, starting_year, unconstrained_model_class, gev_param_name, quantile_level=EUROCODE_QUANTILE, constrained_model_class=StationaryTemporalModel, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=unconstrained_model_class, quantile_level=quantile_level, @@ -36,7 +36,7 @@ class GevTrendTestOneParameterAgainstStationary(GevTrendTestOneParameter): class GevLocationTrendTest(GevTrendTestOneParameterAgainstStationary): def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, constrained_model_class=StationaryTemporalModel, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryLocationTemporalModel, constrained_model_class=constrained_model_class, @@ -61,7 +61,7 @@ class GevLocationTrendTest(GevTrendTestOneParameterAgainstStationary): class GevScaleTrendTest(GevTrendTestOneParameterAgainstStationary): def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, constrained_model_class=StationaryTemporalModel, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryScaleTemporalModel, constrained_model_class=constrained_model_class, @@ -88,7 +88,7 @@ class GevScaleTrendTest(GevTrendTestOneParameterAgainstStationary): class GevShapeTrendTest(GevTrendTestOneParameterAgainstStationary): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryShapeTemporalModel, gev_param_name=GevParams.SHAPE, diff --git a/extreme_trend/trend_test_one_parameter/gumbel_trend_test_one_parameter.py b/extreme_trend/trend_test_one_parameter/gumbel_trend_test_one_parameter.py index 0c7c0008..e3028a00 100644 --- a/extreme_trend/trend_test_one_parameter/gumbel_trend_test_one_parameter.py +++ b/extreme_trend/trend_test_one_parameter/gumbel_trend_test_one_parameter.py @@ -3,8 +3,8 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_trend.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.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ GumbelTemporalModel, NonStationaryLocationGumbelModel, NonStationaryScaleGumbelModel from root_utils import classproperty @@ -12,7 +12,7 @@ from root_utils import classproperty class GumbelVersusGumbel(GevTrendTestOneParameter): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=GumbelTemporalModel, constrained_model_class=GumbelTemporalModel, @@ -42,7 +42,7 @@ class GumbelVersusGumbel(GevTrendTestOneParameter): class GevStationaryVersusGumbel(GevTrendTestOneParameter): def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=StationaryTemporalModel, constrained_model_class=GumbelTemporalModel, @@ -67,7 +67,7 @@ class GevStationaryVersusGumbel(GevTrendTestOneParameter): class GumbelLocationTrendTest(GevTrendTestOneParameterAgainstStationary): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryLocationGumbelModel, gev_param_name=GevParams.LOC, @@ -94,7 +94,7 @@ class GumbelLocationTrendTest(GevTrendTestOneParameterAgainstStationary): class GumbelScaleTrendTest(GevTrendTestOneParameterAgainstStationary): def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryScaleGumbelModel, gev_param_name=GevParams.SCALE, diff --git a/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py b/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py index baa69e62..793c7ea3 100644 --- a/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py +++ b/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py @@ -1,5 +1,5 @@ -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +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_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ @@ -17,7 +17,7 @@ class GevTrendTestThreeParameters(AbstractGevTrendTest): class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryLocationAndScaleTemporalModel, constrained_model_class=GumbelTemporalModel, diff --git a/extreme_trend/trend_test_two_parameters/gev_trend_test_two_parameters.py b/extreme_trend/trend_test_two_parameters/gev_trend_test_two_parameters.py index eb4acd0c..21d596e8 100644 --- a/extreme_trend/trend_test_two_parameters/gev_trend_test_two_parameters.py +++ b/extreme_trend/trend_test_two_parameters/gev_trend_test_two_parameters.py @@ -2,8 +2,8 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \ GevLocationTrendTest, GevScaleTrendTest -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ NonStationaryLocationAndScaleTemporalModel, StationaryTemporalModel, GumbelTemporalModel from extreme_fit.distribution.gev.gev_params import GevParams @@ -20,7 +20,7 @@ class GevTrendTestTwoParameters(AbstractGevTrendTest): class GevLocationAndScaleTrendTest(GevTrendTestTwoParameters): def __init__(self, years, maxima, starting_year, constrained_model_class=StationaryTemporalModel, - quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryLocationAndScaleTemporalModel, constrained_model_class=constrained_model_class, @@ -53,7 +53,7 @@ class GevLocationAndScaleTrendTest(GevTrendTestTwoParameters): class GevLocationAgainstGumbel(GevTrendTestTwoParameters, GevLocationTrendTest): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, quantile_level, GumbelTemporalModel, fit_method=fit_method) @classproperty @@ -71,7 +71,7 @@ class GevLocationAgainstGumbel(GevTrendTestTwoParameters, GevLocationTrendTest): class GevScaleAgainstGumbel(GevTrendTestTwoParameters, GevScaleTrendTest): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, quantile_level, GumbelTemporalModel, fit_method=fit_method) @classproperty diff --git a/extreme_trend/trend_test_two_parameters/gumbel_test_two_parameters.py b/extreme_trend/trend_test_two_parameters/gumbel_test_two_parameters.py index 8d9f2d57..812f259f 100644 --- a/extreme_trend/trend_test_two_parameters/gumbel_test_two_parameters.py +++ b/extreme_trend/trend_test_two_parameters/gumbel_test_two_parameters.py @@ -2,8 +2,8 @@ from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE 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.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +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 root_utils import classproperty @@ -11,7 +11,7 @@ from root_utils import classproperty class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters): - def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, unconstrained_model_class=NonStationaryLocationAndScaleGumbelModel, constrained_model_class=GumbelTemporalModel, diff --git a/extreme_trend/visualizers/study_visualizer_for_non_stationary_trends.py b/extreme_trend/visualizers/study_visualizer_for_non_stationary_trends.py index e55b047c..75188fd5 100644 --- a/extreme_trend/visualizers/study_visualizer_for_non_stationary_trends.py +++ b/extreme_trend/visualizers/study_visualizer_for_non_stationary_trends.py @@ -23,8 +23,8 @@ from extreme_trend.trend_test_one_parameter.gumbel_trend_test_one_parameter impo GumbelLocationTrendTest, GevStationaryVersusGumbel, GumbelScaleTrendTest, GumbelVersusGumbel from extreme_trend.trend_test_two_parameters.gumbel_test_two_parameters import \ GumbelLocationAndScaleTrendTest -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +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.result_from_model_fit.result_from_extremes.confidence_interval_method import \ @@ -54,7 +54,7 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer): effective_temporal_covariate=YEAR_OF_INTEREST_FOR_RETURN_LEVEL, relative_change_trend_plot=True, non_stationary_trend_test_to_marker=None, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle, + fit_method=MarginFitMethod.extremes_fevd_mle, select_only_acceptable_shape_parameter=True, fit_gev_only_on_non_null_maxima=False, fit_only_time_series_with_ninety_percent_of_non_null_values=True, diff --git a/extreme_trend/visualizers/utils.py b/extreme_trend/visualizers/utils.py index 78a4f4ad..ab8b1b17 100644 --- a/extreme_trend/visualizers/utils.py +++ b/extreme_trend/visualizers/utils.py @@ -1,8 +1,8 @@ from collections import OrderedDict from extreme_data.meteo_france_data.scm_models_data.utils import SeasonForTheMaxima -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_trend.visualizers.study_visualizer_for_non_stationary_trends import \ StudyVisualizerForNonStationaryTrends @@ -13,7 +13,7 @@ def load_altitude_to_visualizer(altitudes, massif_names, model_subsets_for_uncer save_to_file=True, multiprocessing=True, season=SeasonForTheMaxima.annual): - fit_method = TemporalMarginFitMethod.extremes_fevd_mle + fit_method = MarginFitMethod.extremes_fevd_mle altitude_to_visualizer = OrderedDict() for altitude in altitudes: study = study_class(altitude=altitude, multiprocessing=multiprocessing, season=season) diff --git a/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/gelman_convergence_test.py b/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/gelman_convergence_test.py index 0495452c..5d8b829d 100644 --- a/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/gelman_convergence_test.py +++ b/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/gelman_convergence_test.py @@ -1,8 +1,8 @@ import numpy as np import pandas as pd from extreme_fit.estimator.margin_estimator.utils import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.result_from_model_fit.result_from_extremes.result_from_bayesian_extremes import \ ResultFromBayesianExtremes from extreme_fit.model.utils import r @@ -57,7 +57,7 @@ def compute_mean_and_variance(mcmc_iterations, model_class, non_null_years_and_m maxima, years = non_null_years_and_maxima coordinates, dataset = load_temporal_coordinates_and_dataset(maxima, years) fitted_estimator = fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_year=None, - fit_method=TemporalMarginFitMethod.extremes_fevd_bayesian, + fit_method=MarginFitMethod.extremes_fevd_bayesian, nb_iterations_for_bayesian_fit=mcmc_iterations, params_start_fit_bayesian=params_start_fit) res = fitted_estimator.result_from_model_fit # type: ResultFromBayesianExtremes diff --git a/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/main_bayesian_mcmc.py b/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/main_bayesian_mcmc.py index 0de59453..969b8bae 100644 --- a/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/main_bayesian_mcmc.py +++ b/projects/contrasting_trends_in_snow_loads/check_mcmc_convergence_for_return_levels/main_bayesian_mcmc.py @@ -8,8 +8,8 @@ from extreme_data.exceeding_snow_loads.check_mcmc_convergence_for_return_levels. compute_gelman_score from extreme_fit.estimator.margin_estimator.utils import fitted_linear_margin_estimator from extreme_fit.distribution.gev.gev_params import GevParams -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel from extreme_fit.model.result_from_model_fit.result_from_extremes.abstract_extract_eurocode_return_level import \ ExtractEurocodeReturnLevelFromMyBayesianExtremes @@ -103,7 +103,7 @@ def get_return_level_bayesian_example(nb_iterations_for_bayesian_fit): model_class = StationaryTemporalModel coordinates, dataset = load_temporal_coordinates_and_dataset(maxima, years) fitted_estimator = fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_year=1959, - fit_method=TemporalMarginFitMethod.extremes_fevd_bayesian, + fit_method=MarginFitMethod.extremes_fevd_bayesian, nb_iterations_for_bayesian_fit=nb_iterations_for_bayesian_fit) return_level_bayesian = ExtractEurocodeReturnLevelFromMyBayesianExtremes(estimator=fitted_estimator, ci_method=ConfidenceIntervalMethodFromExtremes.my_bayes, diff --git a/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/figure1_mean_ratio_return_level_ratio.py b/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/figure1_mean_ratio_return_level_ratio.py index af9cbc34..7bfecbeb 100644 --- a/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/figure1_mean_ratio_return_level_ratio.py +++ b/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/figure1_mean_ratio_return_level_ratio.py @@ -5,8 +5,8 @@ from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusS from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day, SafranSnowfall3Days, \ SafranSnowfall7Days, SafranSnowfall5Days from extreme_data.meteo_france_data.scm_models_data.visualization.main_study_visualizer import ALL_ALTITUDES_WITHOUT_NAN -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from projects.contrasting_trends_in_snow_loads.gorman_figures.figure1.comparative_curve_wrt_altitude import \ ComparativeCurveWrtAltitude @@ -23,7 +23,7 @@ def load_altitude_to_study_visualizer(study_class, save_to_file=True) -> Ordered altitude=altitude, return_period=return_period, save_to_file=save_to_file, - fit_method=TemporalMarginFitMethod.extremes_fevd_l_moments) + fit_method=MarginFitMethod.extremes_fevd_l_moments) altitude_to_study_visualizer[altitude] = study_visualizer return altitude_to_study_visualizer diff --git a/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/study_visualizer_for_double_stationary_fit.py b/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/study_visualizer_for_double_stationary_fit.py index 144a3502..71ecc857 100644 --- a/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/study_visualizer_for_double_stationary_fit.py +++ b/projects/contrasting_trends_in_snow_loads/gorman_figures/figure1/study_visualizer_for_double_stationary_fit.py @@ -8,8 +8,8 @@ from extreme_data.meteo_france_data.scm_models_data.visualization.create_shifted get_colors, ticks_values_and_labels_for_percentages from extreme_data.meteo_france_data.scm_models_data.visualization.main_study_visualizer import ALL_ALTITUDES_WITHOUT_NAN from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualizer import StudyVisualizer -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod, fitmethod_to_str +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod, fitmethod_to_str import matplotlib.pyplot as plt @@ -21,7 +21,7 @@ class StudyVisualizerForReturnLevelChange(StudyVisualizer): def __init__(self, study_class, altitude, return_period=30, year_min=1959, year_middle=1989, year_max=2019, save_to_file=False, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle): + fit_method=MarginFitMethod.extremes_fevd_mle): self.return_period = return_period self.fit_method = fit_method diff --git a/projects/exceeding_snow_loads/checks/qqplot/plot_qqplot.py b/projects/exceeding_snow_loads/checks/qqplot/plot_qqplot.py index f392813a..b0e9901f 100644 --- a/projects/exceeding_snow_loads/checks/qqplot/plot_qqplot.py +++ b/projects/exceeding_snow_loads/checks/qqplot/plot_qqplot.py @@ -7,8 +7,8 @@ import pandas as pd from matplotlib.ticker import PercentFormatter from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusSnowLoadTotal -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.result_from_model_fit.result_from_extremes.abstract_extract_eurocode_return_level import \ AbstractExtractEurocodeReturnLevel from projects.exceeding_snow_loads.data.main_example_swe_total_plot import tuples_for_examples_paper1 @@ -188,7 +188,7 @@ if __name__ == '__main__': # altitudes = [900, 1800, 2700] altitude_to_visualizer = {altitude: StudyVisualizerForNonStationaryTrends(CrocusSnowLoadTotal(altitude=altitude), select_only_acceptable_shape_parameter=True, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle, + fit_method=MarginFitMethod.extremes_fevd_mle, multiprocessing=True, fit_gev_only_on_non_null_maxima=True, fit_only_time_series_with_ninety_percent_of_non_null_values=True, diff --git a/projects/quantile_regression_vs_evt/annual_maxima_simulation/daily_exp_simulation.py b/projects/quantile_regression_vs_evt/annual_maxima_simulation/daily_exp_simulation.py index f33e4f62..3f02d4fe 100644 --- a/projects/quantile_regression_vs_evt/annual_maxima_simulation/daily_exp_simulation.py +++ b/projects/quantile_regression_vs_evt/annual_maxima_simulation/daily_exp_simulation.py @@ -3,8 +3,8 @@ from abc import ABC from extreme_fit.distribution.abstract_params import AbstractParams from extreme_fit.distribution.exp_params import ExpParams from extreme_fit.model.daily_data_model import AbstractModelOnDailyData -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_exp_models import \ NonStationaryRateTemporalModel from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel @@ -45,7 +45,7 @@ class StationaryExpSimulation(AbstractDailyExpSimulation): AbstractParams.RATE: [10], } return StationaryTemporalModel.from_coef_list(coordinates, gev_param_name_to_coef_list, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle, + fit_method=MarginFitMethod.extremes_fevd_mle, params_class=ExpParams) @@ -56,5 +56,5 @@ class NonStationaryExpSimulation(AbstractDailyExpSimulation): AbstractParams.RATE: [0.1, 0.01], } return NonStationaryRateTemporalModel.from_coef_list(coordinates, gev_param_name_to_coef_list, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle, + fit_method=MarginFitMethod.extremes_fevd_mle, params_class=ExpParams) diff --git a/projects/quantile_regression_vs_evt/annual_maxima_simulation/gev_simulation.py b/projects/quantile_regression_vs_evt/annual_maxima_simulation/gev_simulation.py index decc4818..07a79aa9 100644 --- a/projects/quantile_regression_vs_evt/annual_maxima_simulation/gev_simulation.py +++ b/projects/quantile_regression_vs_evt/annual_maxima_simulation/gev_simulation.py @@ -7,8 +7,8 @@ from cached_property import cached_property from extreme_fit.distribution.gev.gev_params import GevParams from extreme_fit.estimator.quantile_estimator.abstract_quantile_estimator import AbstractQuantileEstimator from extreme_fit.model.margin_model.abstract_margin_model import AbstractMarginModel -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel from projects.quantile_regression_vs_evt.AbstractSimulation import AbstractSimulation @@ -36,7 +36,7 @@ class StationarySimulation(GevSimulation): GevParams.SCALE: [1], } return StationaryTemporalModel.from_coef_list(coordinates, gev_param_name_to_coef_list, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + fit_method=MarginFitMethod.extremes_fevd_mle) class NonStationaryLocationGumbelSimulation(GevSimulation): @@ -48,7 +48,7 @@ class NonStationaryLocationGumbelSimulation(GevSimulation): GevParams.SCALE: [1], } return NonStationaryLocationTemporalModel.from_coef_list(coordinates, gev_param_name_to_coef_list, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + fit_method=MarginFitMethod.extremes_fevd_mle) class NonStationaryLocationGevSimulation(GevSimulation): @@ -60,4 +60,4 @@ class NonStationaryLocationGevSimulation(GevSimulation): GevParams.SCALE: [1], } return NonStationaryLocationTemporalModel.from_coef_list(coordinates, gev_param_name_to_coef_list, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + fit_method=MarginFitMethod.extremes_fevd_mle) diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_bayesian.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_bayesian.py index fd3c4e6e..c5a2c265 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_bayesian.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_bayesian.py @@ -4,8 +4,8 @@ import numpy as np import pandas as pd from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel, NonStationaryLocationAndScaleTemporalModel from extreme_fit.model.utils import r, set_seed_r @@ -34,7 +34,7 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase): df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) - self.fit_method = TemporalMarginFitMethod.extremes_fevd_bayesian + self.fit_method = MarginFitMethod.extremes_fevd_bayesian def test_gev_temporal_margin_fit_stationary(self): # Create estimator diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_gumbel.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_gumbel.py index 63113950..9fb0bd03 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_gumbel.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_gumbel.py @@ -4,8 +4,8 @@ import numpy as np import pandas as pd from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import GumbelTemporalModel from extreme_fit.model.utils import r, set_seed_r from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates @@ -39,7 +39,7 @@ class TestGevTemporalExtremesGumbel(unittest.TestCase): estimator = fitted_linear_margin_estimator(GumbelTemporalModel, self.coordinates, self.dataset, starting_year=0, - fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + fit_method=MarginFitMethod.extremes_fevd_mle) ref = {'loc': -0.0862185692806497, 'scale': 1.0818465357627252, 'shape': 0} for year in range(1, 3): mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_l_moments.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_l_moments.py index c94c33ad..6fda38eb 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_l_moments.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_l_moments.py @@ -4,8 +4,8 @@ import numpy as np import pandas as pd from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel, NonStationaryLocationAndScaleTemporalModel from extreme_fit.model.utils import r, set_seed_r @@ -34,7 +34,7 @@ class TestGevTemporalExtremesLMoments(unittest.TestCase): df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) - self.fit_method = TemporalMarginFitMethod.extremes_fevd_l_moments + self.fit_method = MarginFitMethod.extremes_fevd_l_moments ref = {'loc': 0.0813843045950251, 'scale': 1.1791830110181365, 'shape': 0.6610403806908737} diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_mle.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_mle.py index a91b6ffb..e237f091 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_mle.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_extremes_mle.py @@ -4,8 +4,8 @@ import numpy as np import pandas as pd from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel, NonStationaryLocationAndScaleTemporalModel from extreme_fit.model.utils import r, set_seed_r @@ -34,7 +34,7 @@ class TestGevTemporalExtremesMle(unittest.TestCase): df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) - self.fit_method = TemporalMarginFitMethod.extremes_fevd_mle + self.fit_method = MarginFitMethod.extremes_fevd_mle def test_gev_temporal_margin_fit_stationary(self): # Create estimator diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_is_mev.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_is_mev.py index 69196d43..bab1dca6 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_is_mev.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_temporal_is_mev.py @@ -5,8 +5,8 @@ import pandas as pd from extreme_fit.estimator.margin_estimator.utils import fitted_linear_margin_estimator from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel from extreme_fit.model.utils import r, set_seed_r @@ -36,7 +36,7 @@ class TestGevTemporal(unittest.TestCase): df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) - self.fit_method = TemporalMarginFitMethod.is_mev_gev_fit + self.fit_method = MarginFitMethod.is_mev_gev_fit def test_gev_temporal_margin_fit_stationary(self): # Create estimator diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_stationary_gev_fit.py b/test/test_extreme_fit/test_distribution/test_gev/test_stationary_gev_fit.py index 737bab80..e8a6e3a6 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_stationary_gev_fit.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_stationary_gev_fit.py @@ -3,8 +3,8 @@ import unittest import numpy as np from extreme_fit.estimator.margin_estimator.utils import fitted_stationary_gev -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.utils import r, set_seed_r from extreme_fit.distribution.gev.gev_params import GevParams @@ -22,19 +22,19 @@ class TestStationaryGevFit(unittest.TestCase): def test_stationary_gev_fit_with_ismev(self): params_estimated = fitted_stationary_gev(x_gev=np.array(r['x_gev']), - fit_method=TemporalMarginFitMethod.is_mev_gev_fit) + fit_method=MarginFitMethod.is_mev_gev_fit) ref = {'loc': 0.0219, 'scale': 1.0347, 'shape': 0.8295} self.fit_estimator(params_estimated, ref) def test_stationary_gev_fit_with_mle(self): params_estimated = fitted_stationary_gev(x_gev=np.array(r['x_gev']), - fit_method=TemporalMarginFitMethod.extremes_fevd_mle) + fit_method=MarginFitMethod.extremes_fevd_mle) ref = {'loc': 0.02191974259369493, 'scale': 1.0347946062900268, 'shape': 0.829052520147379} self.fit_estimator(params_estimated, ref) def test_stationary_gev_fit_with_l_moments(self): params_estimated = fitted_stationary_gev(x_gev=np.array(r['x_gev']), - fit_method=TemporalMarginFitMethod.extremes_fevd_l_moments) + fit_method=MarginFitMethod.extremes_fevd_l_moments) ref = {'loc': 0.0813843045950251, 'scale': 1.1791830110181365, 'shape': 0.6610403806908737} self.fit_estimator(params_estimated, ref) diff --git a/test/test_extreme_fit/test_model/test_confidence_interval.py b/test/test_extreme_fit/test_model/test_confidence_interval.py index 00f2475d..40abf8d7 100644 --- a/test/test_extreme_fit/test_model/test_confidence_interval.py +++ b/test/test_extreme_fit/test_model/test_confidence_interval.py @@ -4,8 +4,8 @@ import numpy as np import pandas as pd from extreme_fit.estimator.margin_estimator.utils import fitted_linear_margin_estimator -from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ - TemporalMarginFitMethod +from extreme_fit.model.margin_model.utils import \ + MarginFitMethod from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryTemporalModel, \ NonStationaryLocationTemporalModel, NonStationaryLocationAndScaleTemporalModel, \ NonStationaryLocationAndScaleGumbelModel, NonStationaryLocationGumbelModel @@ -65,17 +65,17 @@ class TestConfidenceInterval(unittest.TestCase): } def test_my_bayes(self): - self.fit_method = TemporalMarginFitMethod.extremes_fevd_bayesian + self.fit_method = MarginFitMethod.extremes_fevd_bayesian self.ci_method = ConfidenceIntervalMethodFromExtremes.my_bayes self.model_class_to_triplet = self.bayesian_ci def test_ci_bayes(self): - self.fit_method = TemporalMarginFitMethod.extremes_fevd_bayesian + self.fit_method = MarginFitMethod.extremes_fevd_bayesian self.ci_method = ConfidenceIntervalMethodFromExtremes.ci_bayes self.model_class_to_triplet = self.bayesian_ci def test_ci_normal_mle(self): - self.fit_method = TemporalMarginFitMethod.extremes_fevd_mle + self.fit_method = MarginFitMethod.extremes_fevd_mle self.ci_method = ConfidenceIntervalMethodFromExtremes.ci_mle self.model_class_to_triplet = { StationaryTemporalModel: (-4.703945484843988, 30.482318639674023, 65.66858276419204), @@ -86,7 +86,7 @@ class TestConfidenceInterval(unittest.TestCase): } def test_ci_normal_gmle(self): - self.fit_method = TemporalMarginFitMethod.extremes_fevd_gmle + self.fit_method = MarginFitMethod.extremes_fevd_gmle self.ci_method = ConfidenceIntervalMethodFromExtremes.ci_mle self.model_class_to_triplet = { # Test only for the GEV cases (for the Gumbel cases results are just the same, since there is no shape parameter) @@ -97,7 +97,7 @@ class TestConfidenceInterval(unittest.TestCase): def test_ci_boot(self): - self.fit_method = TemporalMarginFitMethod.extremes_fevd_mle + self.fit_method = MarginFitMethod.extremes_fevd_mle self.ci_method = ConfidenceIntervalMethodFromExtremes.ci_boot self.model_class_to_triplet= { # I think the boostrapping works only in the stationary context -- GitLab