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): ...@@ -88,8 +88,8 @@ class AbstractGevTrendTest(AbstractUnivariateTest):
def degree_freedom_chi2(self) -> int: def degree_freedom_chi2(self) -> int:
raise NotImplementedError raise NotImplementedError
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
raise NotImplementedError raise NotImplementedError
@property @property
......
...@@ -23,8 +23,8 @@ class GumbelVersusGumbel(GevTrendTestOneParameter): ...@@ -23,8 +23,8 @@ class GumbelVersusGumbel(GevTrendTestOneParameter):
def is_significant(self) -> bool: def is_significant(self) -> bool:
return False return False
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 2 return 2
@classproperty @classproperty
...@@ -49,8 +49,8 @@ class GevStationaryVersusGumbel(GevTrendTestOneParameter): ...@@ -49,8 +49,8 @@ class GevStationaryVersusGumbel(GevTrendTestOneParameter):
quantile_level=quantile_level, quantile_level=quantile_level,
fit_method=fit_method) fit_method=fit_method)
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3 return 3
def _slope_strength(self): def _slope_strength(self):
...@@ -74,8 +74,8 @@ class GumbelLocationTrendTest(GevTrendTestOneParameterAgainstStationary): ...@@ -74,8 +74,8 @@ class GumbelLocationTrendTest(GevTrendTestOneParameterAgainstStationary):
quantile_level=quantile_level, quantile_level=quantile_level,
constrained_model_class=GumbelTemporalModel, fit_method=fit_method) constrained_model_class=GumbelTemporalModel, fit_method=fit_method)
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3 return 3
def _slope_strength(self): def _slope_strength(self):
...@@ -107,8 +107,8 @@ class GumbelScaleTrendTest(GevTrendTestOneParameterAgainstStationary): ...@@ -107,8 +107,8 @@ class GumbelScaleTrendTest(GevTrendTestOneParameterAgainstStationary):
p=self.quantile_level, p=self.quantile_level,
sigma1=self.non_stationary_linear_coef) sigma1=self.non_stationary_linear_coef)
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 3 return 3
@classproperty @classproperty
......
...@@ -50,6 +50,6 @@ class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters): ...@@ -50,6 +50,6 @@ class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters):
def marker(self): def marker(self):
return 'D' return 'D'
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 5 return 5
\ No newline at end of file
...@@ -65,8 +65,8 @@ class GevLocationAgainstGumbel(GevTrendTestTwoParameters, GevLocationTrendTest): ...@@ -65,8 +65,8 @@ class GevLocationAgainstGumbel(GevTrendTestTwoParameters, GevLocationTrendTest):
def marker(self): def marker(self):
return 'o' return 'o'
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4 return 4
...@@ -83,6 +83,6 @@ class GevScaleAgainstGumbel(GevTrendTestTwoParameters, GevScaleTrendTest): ...@@ -83,6 +83,6 @@ class GevScaleAgainstGumbel(GevTrendTestTwoParameters, GevScaleTrendTest):
def marker(self): def marker(self):
return '^' return '^'
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4 return 4
...@@ -18,8 +18,8 @@ class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters): ...@@ -18,8 +18,8 @@ class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters):
quantile_level=quantile_level, quantile_level=quantile_level,
fit_method=fit_method) fit_method=fit_method)
@property @classproperty
def total_number_of_parameters_for_unconstrained_model(self) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4 return 4
@property @property
......
...@@ -2,6 +2,7 @@ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusSno ...@@ -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 \ from papers.exceeding_snow_loads.check_mle_convergence_for_trends.shape.study_visualizer_for_shape_repartition import \
StudyVisualizerForShape StudyVisualizerForShape
from papers.exceeding_snow_loads.paper_main_utils import load_altitude_to_visualizer 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, def main_shape_repartition(altitudes, massif_names=None,
...@@ -28,6 +29,6 @@ if __name__ == '__main__': ...@@ -28,6 +29,6 @@ if __name__ == '__main__':
# main_shape_repartition([900], save_to_file=False) # main_shape_repartition([900], save_to_file=False)
# main_shape_repartition([900, 1800, 2700]) # main_shape_repartition([900, 1800, 2700])
# main_shape_repartition([300, 600, 900, 1200, 1500, 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], # 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) # study_visualizer_class=StudyVisualizerForShape, save_to_file=True)
...@@ -3,7 +3,7 @@ from cached_property import cached_property ...@@ -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.plot.create_shifted_cmap import get_shifted_map
from experiment.meteo_france_data.scm_models_data.abstract_study import AbstractStudy 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 StudyVisualizerForNonStationaryTrends
from experiment.trend_analysis.abstract_score import MeanScore from experiment.trend_analysis.abstract_score import MeanScore
......
...@@ -4,18 +4,31 @@ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusSno ...@@ -4,18 +4,31 @@ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusSno
CrocusSnowLoad3Days CrocusSnowLoad3Days
from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \ from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \
ALL_ALTITUDES_WITHOUT_NAN 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 from root_utils import get_display_name_from_object_type
paper_altitudes = ALL_ALTITUDES_WITHOUT_NAN paper_altitudes = ALL_ALTITUDES_WITHOUT_NAN
paper_study_classes = [CrocusSnowLoadTotal, CrocusSnowLoadEurocode, CrocusSnowLoad3Days][:2] paper_study_classes = [CrocusSnowLoadTotal, CrocusSnowLoadEurocode, CrocusSnowLoad3Days][:2]
# dpi_paper1_figure = 700 # dpi_paper1_figure = 700
dpi_paper1_figure = None dpi_paper1_figure = None
NON_STATIONARY_TREND_TEST_PAPER = [GumbelVersusGumbel,
GumbelLocationTrendTest, GumbelScaleTrendTest,
GumbelLocationAndScaleTrendTest,
GevStationaryVersusGumbel,
GevLocationAgainstGumbel, GevScaleAgainstGumbel,
GevLocationAndScaleTrendTestAgainstGumbel]
class ModelSubsetForUncertainty(Enum): class ModelSubsetForUncertainty(Enum):
stationary_gumbel = 0 stationary_gumbel = 0
stationary_gumbel_and_gev = 1 stationary_gumbel_and_gev = 1
non_stationary_gumbel = 2 non_stationary_gumbel = 2
non_stationary_gumbel_and_gev = 3 non_stationary_gumbel_and_gev = 3
...@@ -16,7 +16,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat ...@@ -16,7 +16,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat
StudyVisualizer StudyVisualizer
from papers.exceeding_snow_loads.check_mcmc_convergence_for_return_levels.gelman_convergence_test import \ from papers.exceeding_snow_loads.check_mcmc_convergence_for_return_levels.gelman_convergence_test import \
compute_gelman_convergence_value 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.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.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 \ 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): ...@@ -76,12 +76,7 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer):
self.uncertainty_massif_names = self.study.study_massif_names self.uncertainty_massif_names = self.study.study_massif_names
if self.non_stationary_trend_test_to_marker is None: if self.non_stationary_trend_test_to_marker is None:
# Assign default argument for the non stationary trends # Assign default argument for the non stationary trends
self.non_stationary_trend_test = [GumbelVersusGumbel, self.non_stationary_trend_test = NON_STATIONARY_TREND_TEST_PAPER
GumbelLocationTrendTest, GumbelScaleTrendTest,
GumbelLocationAndScaleTrendTest,
GevStationaryVersusGumbel,
GevLocationAgainstGumbel, GevScaleAgainstGumbel,
GevLocationAndScaleTrendTestAgainstGumbel]
self.non_stationary_trend_test_to_marker = {t: t.marker for t in self.non_stationary_trend_test} self.non_stationary_trend_test_to_marker = {t: t.marker for t in self.non_stationary_trend_test}
else: else:
self.non_stationary_trend_test = list(self.non_stationary_trend_test_to_marker.keys()) self.non_stationary_trend_test = list(self.non_stationary_trend_test_to_marker.keys())
...@@ -284,7 +279,8 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer): ...@@ -284,7 +279,8 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer):
@cached_property @cached_property
def selected_and_significative_trend_test_class_counter(self): 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 @cached_property
def massif_name_to_marker_style(self): 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