Commit 4b3349ca authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[paper 1] add trend_test_analysis. modify a property into a classproperty

parent 08f4c04c
No related merge requests found
Showing with 57 additions and 31 deletions
+57 -31
......@@ -88,8 +88,8 @@ class AbstractGevTrendTest(AbstractUnivariateTest):
def degree_freedom_chi2(self) -> int:
raise NotImplementedError
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
raise NotImplementedError
@property
......
......@@ -23,8 +23,8 @@ class GumbelVersusGumbel(GevTrendTestOneParameter):
def is_significant(self) -> bool:
return False
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 2
@classproperty
......@@ -49,8 +49,8 @@ class GevStationaryVersusGumbel(GevTrendTestOneParameter):
quantile_level=quantile_level,
fit_method=fit_method)
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3
def _slope_strength(self):
......@@ -74,8 +74,8 @@ class GumbelLocationTrendTest(GevTrendTestOneParameterAgainstStationary):
quantile_level=quantile_level,
constrained_model_class=GumbelTemporalModel, fit_method=fit_method)
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3
def _slope_strength(self):
......@@ -107,8 +107,8 @@ class GumbelScaleTrendTest(GevTrendTestOneParameterAgainstStationary):
p=self.quantile_level,
sigma1=self.non_stationary_linear_coef)
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3
@classproperty
......
......@@ -50,6 +50,6 @@ class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters):
def marker(self):
return 'D'
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 5
\ No newline at end of file
......@@ -65,8 +65,8 @@ class GevLocationAgainstGumbel(GevTrendTestTwoParameters, GevLocationTrendTest):
def marker(self):
return 'o'
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4
......@@ -83,6 +83,6 @@ class GevScaleAgainstGumbel(GevTrendTestTwoParameters, GevScaleTrendTest):
def marker(self):
return '^'
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4
......@@ -18,8 +18,8 @@ class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters):
quantile_level=quantile_level,
fit_method=fit_method)
@property
def total_number_of_parameters_for_unconstrained_model(self) -> int:
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4
@property
......
......@@ -2,6 +2,7 @@ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusSno
from papers.exceeding_snow_loads.check_mle_convergence_for_trends.shape.study_visualizer_for_shape_repartition import \
StudyVisualizerForShape
from papers.exceeding_snow_loads.paper_main_utils import load_altitude_to_visualizer
from papers.exceeding_snow_loads.paper_utils import paper_altitudes
def main_shape_repartition(altitudes, massif_names=None,
......@@ -28,6 +29,6 @@ if __name__ == '__main__':
# main_shape_repartition([900], save_to_file=False)
# main_shape_repartition([900, 1800, 2700])
# main_shape_repartition([300, 600, 900, 1200, 1500, 1800, 2700])
main_shape_repartition([900, 1800, 2700], study_visualizer_class=StudyVisualizerForShape, save_to_file=True)
main_shape_repartition(paper_altitudes, study_visualizer_class=StudyVisualizerForShape, save_to_file=True)
# main_shape_repartition([300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200],
# study_visualizer_class=StudyVisualizerForShape, save_to_file=True)
......@@ -3,7 +3,7 @@ from cached_property import cached_property
from experiment.meteo_france_data.plot.create_shifted_cmap import get_shifted_map
from experiment.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
from experiment.exceeding_snow_loads.study_visualizer_for_non_stationary_trends import \
from papers.exceeding_snow_loads.study_visualizer_for_non_stationary_trends import \
StudyVisualizerForNonStationaryTrends
from experiment.trend_analysis.abstract_score import MeanScore
......
......@@ -4,18 +4,31 @@ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusSno
CrocusSnowLoad3Days
from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \
ALL_ALTITUDES_WITHOUT_NAN
from experiment.trend_analysis.univariate_test.extreme_trend_test.trend_test_one_parameter.gumbel_trend_test_one_parameter import \
GumbelVersusGumbel, GumbelLocationTrendTest, GumbelScaleTrendTest, GevStationaryVersusGumbel
from experiment.trend_analysis.univariate_test.extreme_trend_test.trend_test_three_parameters.gev_trend_test_three_parameters import \
GevLocationAndScaleTrendTestAgainstGumbel
from experiment.trend_analysis.univariate_test.extreme_trend_test.trend_test_two_parameters.gev_trend_test_two_parameters import \
GevLocationAgainstGumbel, GevScaleAgainstGumbel
from experiment.trend_analysis.univariate_test.extreme_trend_test.trend_test_two_parameters.gumbel_test_two_parameters import \
GumbelLocationAndScaleTrendTest
from root_utils import get_display_name_from_object_type
paper_altitudes = ALL_ALTITUDES_WITHOUT_NAN
paper_study_classes = [CrocusSnowLoadTotal, CrocusSnowLoadEurocode, CrocusSnowLoad3Days][:2]
# dpi_paper1_figure = 700
dpi_paper1_figure = None
NON_STATIONARY_TREND_TEST_PAPER = [GumbelVersusGumbel,
GumbelLocationTrendTest, GumbelScaleTrendTest,
GumbelLocationAndScaleTrendTest,
GevStationaryVersusGumbel,
GevLocationAgainstGumbel, GevScaleAgainstGumbel,
GevLocationAndScaleTrendTestAgainstGumbel]
class ModelSubsetForUncertainty(Enum):
stationary_gumbel = 0
stationary_gumbel_and_gev = 1
non_stationary_gumbel = 2
non_stationary_gumbel_and_gev = 3
......@@ -16,7 +16,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat
StudyVisualizer
from papers.exceeding_snow_loads.check_mcmc_convergence_for_return_levels.gelman_convergence_test import \
compute_gelman_convergence_value
from papers.exceeding_snow_loads.paper_utils import ModelSubsetForUncertainty
from papers.exceeding_snow_loads.paper_utils import ModelSubsetForUncertainty, NON_STATIONARY_TREND_TEST_PAPER
from experiment.trend_analysis.abstract_score import MeanScore
from experiment.trend_analysis.univariate_test.extreme_trend_test.abstract_gev_trend_test import AbstractGevTrendTest
from experiment.trend_analysis.univariate_test.extreme_trend_test.trend_test_one_parameter.gumbel_trend_test_one_parameter import \
......@@ -76,12 +76,7 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer):
self.uncertainty_massif_names = self.study.study_massif_names
if self.non_stationary_trend_test_to_marker is None:
# Assign default argument for the non stationary trends
self.non_stationary_trend_test = [GumbelVersusGumbel,
GumbelLocationTrendTest, GumbelScaleTrendTest,
GumbelLocationAndScaleTrendTest,
GevStationaryVersusGumbel,
GevLocationAgainstGumbel, GevScaleAgainstGumbel,
GevLocationAndScaleTrendTestAgainstGumbel]
self.non_stationary_trend_test = NON_STATIONARY_TREND_TEST_PAPER
self.non_stationary_trend_test_to_marker = {t: t.marker for t in self.non_stationary_trend_test}
else:
self.non_stationary_trend_test = list(self.non_stationary_trend_test_to_marker.keys())
......@@ -284,7 +279,8 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer):
@cached_property
def selected_and_significative_trend_test_class_counter(self):
return Counter([type(t) for t in self.massif_name_to_trend_test_that_minimized_aic.values() if t.is_significant])
return Counter(
[type(t) for t in self.massif_name_to_trend_test_that_minimized_aic.values() if t.is_significant])
@cached_property
def massif_name_to_marker_style(self):
......
import unittest
from papers.exceeding_snow_loads.paper_utils import NON_STATIONARY_TREND_TEST_PAPER
class TestTrendAnalysis(unittest.TestCase):
def test_nb_parameters(self):
trend_test_classes = NON_STATIONARY_TREND_TEST_PAPER
nb_expected = [2, 3, 3, 4, 3, 4, 4, 5]
for trend_test_class, nb in zip(trend_test_classes, nb_expected):
self.assertEqual(trend_test_class.total_number_of_parameters_for_unconstrained_model, nb)
if __name__ == '__main__':
unittest.main()
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