Commit 58bff8c7 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[GEV TREND TEST] add gev trend test two parameters (for Location and scale...

[GEV TREND TEST] add gev trend test two parameters (for Location and scale parameters). IMPORTANT: Now the definition of test sign correspond to the sign of the strength (i.e. the increase with respect to some quantile)
parent cdcbd7e6
No related merge requests found
Showing with 61 additions and 22 deletions
+61 -22
......@@ -4,6 +4,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visual
Altitude_Hypercube_Year_Visualizer
from experiment.trend_analysis.univariate_test.gev_trend_test_one_parameter import GevScaleTrendTest, \
GevLocationTrendTest
from experiment.trend_analysis.univariate_test.gev_trend_test_two_parameters import GevLocationAndScaleTrendTest
"""
Visualize the 0.99 quantile initial value and its evolution
......@@ -15,14 +16,14 @@ def main_fast_spatial_risk_evolution():
for altitude in FULL_ALTITUDES[-1:]:
vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude,
exact_starting_year=1958, reduce_strength_array=True,
trend_test_class=GevScaleTrendTest)
# vizualiser.save_to_file = False
trend_test_class=GevLocationAndScaleTrendTest)
vizualiser.save_to_file = False
vizualiser.visualize_massif_trend_test_one_altitude()
def main_full_spatial_risk_evolution():
for altitude in FULL_ALTITUDES[:]:
for trend_test_class in [GevLocationTrendTest, GevScaleTrendTest][:]:
for trend_test_class in [GevLocationTrendTest, GevScaleTrendTest, GevLocationAndScaleTrendTest][-1:]:
vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude,
exact_starting_year=1958, reduce_strength_array=True,
trend_test_class=trend_test_class)
......
import time
from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusRecentSwe
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.altitude_year_hypercube_visualizer import \
Altitude_Hypercube_Year_Visualizer
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.main_files.main_full_hypercube import \
get_full_parameters
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.utils_hypercube import \
load_altitude_visualizer
from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import GevScaleChangePointTest, \
GevLocationChangePointTest
from experiment.trend_analysis.univariate_test.gev_trend_test_one_parameter import GevLocationTrendTest
FULL_ALTITUDES = [900, 1200, 1500, 1800, 2100, 2400, 2700, 3000]
def get_full_altitude_visualizer(altitude_hypercube_class, exact_starting_year=None, altitude=900,
reduce_strength_array=False,
trend_test_class = GevLocationChangePointTest):
trend_test_class = GevLocationTrendTest):
altitudes, first_starting_year, last_starting_year, nb_data_reduced_for_speed, only_first_one, save_to_file, _ = get_full_parameters(
altitude=altitude)
if exact_starting_year is not None:
......
......@@ -25,9 +25,8 @@ class AbstractGevTrendTest(AbstractUnivariateTest):
quantile_for_strength = 0.98
nb_years_for_quantile_evolution = 10
def __init__(self, years, maxima, starting_year, non_stationary_model_class, gev_param_name):
def __init__(self, years, maxima, starting_year, non_stationary_model_class):
super().__init__(years, maxima, starting_year)
self.gev_param_name = gev_param_name
df = pd.DataFrame({AbstractCoordinates.COORDINATE_T: years})
df_maxima_gev = pd.DataFrame(maxima, index=df.index)
observations = AbstractSpatioTemporalObservations(df_maxima_gev=df_maxima_gev)
......@@ -104,6 +103,14 @@ class AbstractGevTrendTest(AbstractUnivariateTest):
# Evolution of the GEV parameters and corresponding quantiles
@property
def test_sign(self) -> int:
return np.sign(self.test_trend_slope_strength)
def get_non_stationary_linear_coef(self, gev_param_name):
return self.non_stationary_estimator.margin_function_fitted.get_coef(gev_param_name,
AbstractCoordinates.COORDINATE_T)
@property
def non_stationary_constant_gev_params(self) -> GevParams:
return self.non_stationary_estimator.result_from_fit.constant_gev_params
......
from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_estimator.extreme_models.margin_model.temporal_linear_margin_model import StationaryStationModel, \
from extreme_estimator.extreme_models.margin_model.temporal_linear_margin_model import \
NonStationaryLocationStationModel, NonStationaryScaleStationModel, NonStationaryShapeStationModel
from extreme_estimator.margin_fits.gev.gev_params import GevParams
import numpy as np
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
class GevTrendTestOneParameter(AbstractGevTrendTest):
def __init__(self, years, maxima, starting_year, non_stationary_model_class, gev_param_name):
super().__init__(years, maxima, starting_year, non_stationary_model_class)
self.gev_param_name = gev_param_name
@property
def degree_freedom_chi2(self) -> int:
return 1
@property
def test_sign(self) -> int:
return np.sign(self.non_stationary_linear_coef)
@property
def non_stationary_linear_coef(self):
return self.non_stationary_estimator.margin_function_fitted.get_coef(self.gev_param_name,
AbstractCoordinates.COORDINATE_T)
return self.get_non_stationary_linear_coef(gev_param_name=self.gev_param_name)
class GevLocationTrendTest(GevTrendTestOneParameter):
......
from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_estimator.extreme_models.margin_model.temporal_linear_margin_model import \
NonStationaryLocationAndScaleModel
from extreme_estimator.margin_fits.gev.gev_params import GevParams
class GevTrendTestTwoParameters(AbstractGevTrendTest):
@property
def degree_freedom_chi2(self) -> int:
return 2
class GevLocationAndScaleTrendTest(GevTrendTestTwoParameters):
def __init__(self, years, maxima, starting_year):
super().__init__(years, maxima, starting_year,
NonStationaryLocationAndScaleModel)
def _slope_strength(self):
mu1 = self.get_non_stationary_linear_coef(gev_param_name=GevParams.LOC)
sigma1 = self.get_non_stationary_linear_coef(gev_param_name=GevParams.SCALE)
return self.non_stationary_constant_gev_params.quantile_strength_evolution_ratio(p=self.quantile_for_strength,
mu1=mu1,
sigma1=sigma1)
......@@ -72,3 +72,18 @@ class NonStationaryShapeStationModel(TemporalLinearMarginModel):
@property
def shl(self):
return 1
class NonStationaryLocationAndScaleModel(TemporalLinearMarginModel):
def load_margin_functions(self, gev_param_name_to_dims=None):
super().load_margin_functions({GevParams.LOC: [self.coordinates.idx_temporal_coordinates],
GevParams.SCALE: [self.coordinates.idx_temporal_coordinates]})
@property
def mul(self):
return 1
@property
def sigl(self):
return 1
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