From 384abbcd17af1cdc5b5724463b57dfd4c8bcd223 Mon Sep 17 00:00:00 2001
From: Le Roux Erwan <erwan.le-roux@irstea.fr>
Date: Mon, 26 Nov 2018 18:11:14 +0100
Subject: [PATCH] [MARGIN FUNCTION] add full visualization for 1D/2D margin
 functions

---
 .../regression_margin}/__init__.py            |  0
 .../regression_margin/regression_margin.py    | 42 +++++++++++++++++++
 .../visualization_margin_model.py             | 33 +++++++++++++++
 experiment/return_level_plot/__init__.py      |  0
 .../return_level_plot/spatial_2D_plot.py      |  0
 extreme_estimator/estimator/full_estimator.py |  8 ++--
 .../estimator/margin_estimator.py             |  2 +-
 .../margin_model/abstract_margin_model.py     | 34 ++++++++-------
 .../abstract_margin_function.py               | 41 +++++++++++++++++-
 .../independent_margin_function.py            |  3 +-
 .../margin_function/param_function.py         |  4 +-
 .../margin_model/smooth_margin_model.py       |  2 +-
 .../abstract_max_stable_model.py              |  2 +-
 .../coordinates_1D.py                         |  9 ++++
 .../dataset/simulation_dataset.py             |  7 ++--
 .../annual_maxima_observations.py             |  4 +-
 .../test_R_model/test_margin_function.py      | 21 ----------
 .../test_estimator/test_margin_estimators.py  |  3 +-
 .../test_gev/__init__.py                      |  0
 .../test_gev_mle_fit.py                       |  0
 20 files changed, 160 insertions(+), 55 deletions(-)
 rename {test/test_extreme_estimator/test_R_model => experiment/regression_margin}/__init__.py (100%)
 create mode 100644 experiment/regression_margin/regression_margin.py
 create mode 100644 experiment/regression_margin/visualization_margin_model.py
 create mode 100644 experiment/return_level_plot/__init__.py
 rename {extreme_estimator => experiment}/return_level_plot/spatial_2D_plot.py (100%)
 delete mode 100644 test/test_extreme_estimator/test_R_model/test_margin_function.py
 create mode 100644 test/test_extreme_estimator/test_gev/__init__.py
 rename test/test_extreme_estimator/{test_R_model => test_gev}/test_gev_mle_fit.py (100%)

diff --git a/test/test_extreme_estimator/test_R_model/__init__.py b/experiment/regression_margin/__init__.py
similarity index 100%
rename from test/test_extreme_estimator/test_R_model/__init__.py
rename to experiment/regression_margin/__init__.py
diff --git a/experiment/regression_margin/regression_margin.py b/experiment/regression_margin/regression_margin.py
new file mode 100644
index 00000000..e7089fee
--- /dev/null
+++ b/experiment/regression_margin/regression_margin.py
@@ -0,0 +1,42 @@
+import numpy as np
+
+from extreme_estimator.estimator.full_estimator import FullEstimatorInASingleStepWithSmoothMargin
+from extreme_estimator.extreme_models.margin_model.smooth_margin_model import LinearShapeAxis0MarginModel, \
+    LinearAllParametersAllAxisMarginModel
+from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith
+from extreme_estimator.gev_params import GevParams
+from spatio_temporal_dataset.coordinates.unidimensional_coordinates.coordinates_1D import LinSpaceCoordinates
+import matplotlib.pyplot as plt
+
+from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset
+
+nb_points = 50
+nb_obs = 100
+
+coordinates = LinSpaceCoordinates.from_nb_points(nb_points=nb_points)
+
+
+########## GENERATING THE DATA #####################
+
+# MarginModel Linear with respect to the shape (from 0.01 to 0.02)
+margin_model = LinearShapeAxis0MarginModel(coordinates=coordinates, params_sample={GevParams.GEV_SHAPE: 0.02})
+max_stable_model = Smith()
+dataset = FullSimulatedDataset.from_double_sampling(nb_obs=nb_obs, margin_model=margin_model,
+                                                    coordinates=coordinates,
+                                                    max_stable_model=max_stable_model)
+# Visualize the sampling margin
+dataset.margin_model.margin_function_sample.visualize_all()
+# Plot a realization from the maxima gev (i.e the maxima obtained just by simulating the marginal law)
+for maxima_gev in np.transpose(dataset.maxima_gev):
+    plt.plot(coordinates.coordinates_values, maxima_gev)
+plt.show()
+
+######### FITTING A MODEL #################
+
+margin_model = LinearAllParametersAllAxisMarginModel(coordinates)
+full_estimator = FullEstimatorInASingleStepWithSmoothMargin(dataset, margin_model, max_stable_model)
+full_estimator.fit()
+print(full_estimator.full_params_fitted)
+
+# Plot the margin functions
+# margin_model.margin_function_sample.visualize_2D()
diff --git a/experiment/regression_margin/visualization_margin_model.py b/experiment/regression_margin/visualization_margin_model.py
new file mode 100644
index 00000000..1f405c9d
--- /dev/null
+++ b/experiment/regression_margin/visualization_margin_model.py
@@ -0,0 +1,33 @@
+import unittest
+
+from extreme_estimator.gev_params import GevParams
+from extreme_estimator.extreme_models.margin_model.smooth_margin_model import LinearShapeAxis0MarginModel, \
+    LinearAllParametersAllAxisMarginModel
+from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
+from spatio_temporal_dataset.coordinates.unidimensional_coordinates.coordinates_1D import LinSpaceCoordinates
+
+
+class VisualizationMarginModel(unittest.TestCase):
+    DISPLAY = True
+    nb_points = 50
+    margin_model = [LinearShapeAxis0MarginModel, LinearAllParametersAllAxisMarginModel][-1]
+
+    @classmethod
+    def example_visualization_2D(cls):
+        spatial_coordinates = CircleCoordinates.from_nb_points(nb_points=cls.nb_points)
+        margin_model = cls.margin_model(coordinates=spatial_coordinates)
+        if cls.DISPLAY:
+            margin_model.margin_function_sample.visualize_all()
+
+    @classmethod
+    def example_visualization_1D(cls):
+        coordinates = LinSpaceCoordinates.from_nb_points(nb_points=cls.nb_points)
+        # MarginModel Linear with respect to the shape (from 0.01 to 0.02)
+        margin_model = cls.margin_model(coordinates=coordinates, params_sample={GevParams.GEV_SHAPE: 0.02})
+        if cls.DISPLAY:
+            margin_model.margin_function_sample.visualize_all()
+
+
+if __name__ == '__main__':
+    VisualizationMarginModel.example_visualization_1D()
+    VisualizationMarginModel.example_visualization_2D()
diff --git a/experiment/return_level_plot/__init__.py b/experiment/return_level_plot/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/extreme_estimator/return_level_plot/spatial_2D_plot.py b/experiment/return_level_plot/spatial_2D_plot.py
similarity index 100%
rename from extreme_estimator/return_level_plot/spatial_2D_plot.py
rename to experiment/return_level_plot/spatial_2D_plot.py
diff --git a/extreme_estimator/estimator/full_estimator.py b/extreme_estimator/estimator/full_estimator.py
index 04fe3ad9..33b3e5da 100644
--- a/extreme_estimator/estimator/full_estimator.py
+++ b/extreme_estimator/estimator/full_estimator.py
@@ -25,7 +25,7 @@ class SmoothMarginalsThenUnitaryMsp(AbstractFullEstimator):
         self.margin_estimator.fit()
         # Compute the maxima_frech
         maxima_frech = AbstractMarginModel.gev2frech(maxima_gev=self.dataset.maxima_gev,
-                                                     coordinates=self.dataset.coordinates_values,
+                                                     coordinates_values=self.dataset.coordinates_values,
                                                      margin_function=self.margin_estimator.margin_function_fitted)
         # Update maxima frech field through the dataset object
         self.dataset.maxima_frech = maxima_frech
@@ -47,15 +47,15 @@ class FullEstimatorInASingleStepWithSmoothMargin(AbstractFullEstimator):
         self.smooth_margin_function_to_fit = margin_model.margin_function_start_fit
 
     def _fit(self):
-        # todo: specify the shape of the margin
-        # Estimate the margin
-        self.max_stable_params_fitted = self.max_stable_model.fitmaxstab(
+        # Estimate both the margin and the max-stable structure
+        self.full_params_fitted = self.max_stable_model.fitmaxstab(
             maxima_frech=self.dataset.maxima_frech,
             df_coordinates=self.dataset.df_coordinates,
             fit_marge=True,
             fit_marge_form_dict=self.smooth_margin_function_to_fit.fit_marge_form_dict,
             margin_start_dict=self.smooth_margin_function_to_fit.margin_start_dict
         )
+        # Initialize
 
 
 class PointwiseAndThenUnitaryMsp(AbstractFullEstimator):
diff --git a/extreme_estimator/estimator/margin_estimator.py b/extreme_estimator/estimator/margin_estimator.py
index ce4d9a3e..4453d868 100644
--- a/extreme_estimator/estimator/margin_estimator.py
+++ b/extreme_estimator/estimator/margin_estimator.py
@@ -33,4 +33,4 @@ class SmoothMarginEstimator(AbstractMarginEstimator):
 
     def _fit(self):
         self._margin_function_fitted = self.margin_model.fitmargin_from_maxima_gev(maxima_gev=self.dataset.maxima_gev,
-                                                                                   coordinates=self.dataset.coordinates_values)
+                                                                                   coordinates_values=self.dataset.coordinates_values)
diff --git a/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py b/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py
index f6cff25c..7365f4e6 100644
--- a/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py
+++ b/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py
@@ -1,7 +1,8 @@
 import numpy as np
 
 from extreme_estimator.extreme_models.abstract_model import AbstractModel
-from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import AbstractMarginFunction
+from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function \
+    import AbstractMarginFunction
 from extreme_estimator.gev_params import GevParams
 from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
 
@@ -27,34 +28,36 @@ class AbstractMarginModel(AbstractModel):
     # Conversion class methods
 
     @classmethod
-    def convert_maxima(cls, convertion_r_function, maxima: np.ndarray, coordinates: np.ndarray,
-                       margin_function: AbstractMarginFunction):
-        assert isinstance(coordinates, np.ndarray)
-        assert len(maxima) == len(coordinates)
+    def convert_maxima(cls, convertion_r_function, maxima: np.ndarray, coordinates_values: np.ndarray,
+                       margin_function: AbstractMarginFunction) -> np.ndarray:
+        assert isinstance(coordinates_values, np.ndarray)
+        assert len(maxima) == len(coordinates_values)
         converted_maxima = []
-        for x, coordinate in zip(maxima, coordinates):
+        for x, coordinate in zip(maxima, coordinates_values):
             gev_params = margin_function.get_gev_params(coordinate)
             x_gev = convertion_r_function(x, **gev_params.to_dict())
             converted_maxima.append(x_gev)
         return np.array(converted_maxima)
 
     @classmethod
-    def gev2frech(cls, maxima_gev: np.ndarray, coordinates: np.ndarray, margin_function: AbstractMarginFunction):
-        return cls.convert_maxima(cls.r.gev2frech, maxima_gev, coordinates, margin_function)
+    def gev2frech(cls, maxima_gev: np.ndarray, coordinates_values: np.ndarray,
+                  margin_function: AbstractMarginFunction) -> np.ndarray:
+        return cls.convert_maxima(cls.r.gev2frech, maxima_gev, coordinates_values, margin_function)
 
     @classmethod
-    def frech2gev(cls, maxima_frech: np.ndarray, coordinates: np.ndarray, margin_function: AbstractMarginFunction):
-        return cls.convert_maxima(cls.r.frech2gev, maxima_frech, coordinates, margin_function)
+    def frech2gev(cls, maxima_frech: np.ndarray, coordinates_values: np.ndarray,
+                  margin_function: AbstractMarginFunction) -> np.ndarray:
+        return cls.convert_maxima(cls.r.frech2gev, maxima_frech, coordinates_values, margin_function)
 
     # Sampling methods
 
-    def rmargin_from_maxima_frech(self, maxima_frech: np.ndarray, coordinates: np.ndarray):
-        maxima_gev = self.frech2gev(maxima_frech, coordinates, self.margin_function_sample)
+    def rmargin_from_maxima_frech(self, maxima_frech: np.ndarray, coordinates_values: np.ndarray) -> np.ndarray:
+        maxima_gev = self.frech2gev(maxima_frech, coordinates_values, self.margin_function_sample)
         return maxima_gev
 
-    def rmargin_from_nb_obs(self, nb_obs, coordinates):
+    def rmargin_from_nb_obs(self, nb_obs: int, coordinates_values: np.ndarray) -> np.ndarray:
         maxima_gev = []
-        for coordinate in coordinates:
+        for coordinate in coordinates_values:
             gev_params = self.margin_function_sample.get_gev_params(coordinate)
             x_gev = self.r.rgev(nb_obs, **gev_params.to_dict())
             maxima_gev.append(x_gev)
@@ -62,5 +65,6 @@ class AbstractMarginModel(AbstractModel):
 
     # Fitting methods needs to be defined in child classes
 
-    def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, coordinates: np.ndarray) -> AbstractMarginFunction:
+    def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, coordinates_values: np.ndarray) \
+            -> AbstractMarginFunction:
         pass
diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py b/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py
index 8b768b35..32bf0301 100644
--- a/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py
+++ b/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py
@@ -14,12 +14,40 @@ class AbstractMarginFunction(object):
         self.default_params = default_params.to_dict()
 
     def get_gev_params(self, coordinate: np.ndarray) -> GevParams:
-        """Main function that maps each coordinate to its GEV parameters"""
+        """Main method that maps each coordinate to its GEV parameters"""
         pass
 
     # Visualization function
 
-    def visualize_2D(self, gev_param_name=GevParams.GEV_LOC, ax=None, show=False):
+    def visualize_all(self):
+        fig, axes = plt.subplots(3, 1, sharex='col', sharey='row')
+        fig.subplots_adjust(hspace=0.4, wspace=0.4, )
+        for i, gev_param_name in enumerate(GevParams.GEV_PARAM_NAMES):
+            ax = axes[i]
+            self.visualize(gev_param_name, ax, show=False)
+            title_str = gev_param_name
+            ax.set_title(title_str)
+        plt.show()
+
+    def visualize(self, gev_param_name=GevParams.GEV_LOC, ax=None, show=True):
+        if self.coordinates.nb_columns == 1:
+            self.visualize_1D(gev_param_name, ax, show)
+        elif self.coordinates.nb_columns == 2:
+            self.visualize_2D(gev_param_name, ax, show)
+        else:
+            raise NotImplementedError('3D Margin visualization not yet implemented')
+
+    def visualize_1D(self, gev_param_name=GevParams.GEV_LOC, ax=None, show=True):
+        x = self.coordinates.x_coordinates
+        grid, linspace = self.get_grid_1D(x)
+        gev_param_idx = GevParams.GEV_PARAM_NAMES.index(gev_param_name)
+        if ax is None:
+            ax = plt.gca()
+        ax.plot(linspace, grid[:, gev_param_idx])
+        if show:
+            plt.show()
+
+    def visualize_2D(self, gev_param_name=GevParams.GEV_LOC, ax=None, show=True):
         x = self.coordinates.x_coordinates
         y = self.coordinates.y_coordinates
         grid = self.get_grid_2D(x, y)
@@ -32,6 +60,15 @@ class AbstractMarginFunction(object):
         if show:
             plt.show()
 
+    def get_grid_1D(self, x):
+        # TODO: to avoid getting the value several times, I could cache the results
+        resolution = 100
+        grid = np.zeros([resolution, 3])
+        linspace = np.linspace(x.min(), x.max(), resolution)
+        for i, xi in enumerate(linspace):
+            grid[i] = self.get_gev_params(np.array([xi])).to_array()
+        return grid, linspace
+
     def get_grid_2D(self, x, y):
         resolution = 100
         grid = np.zeros([resolution, resolution, 3])
diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py b/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py
index 24780e79..25de6fe2 100644
--- a/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py
+++ b/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py
@@ -65,7 +65,8 @@ class LinearMarginFunction(IndependentMarginFunction):
                                                      start=self.default_params[gev_param_name])
                 # Some check on the Linear param function
                 if gev_param_name == GevParams.GEV_SCALE:
-                    assert param_function.end > param_function.start, 'Impossible linear rate for Scale parameter'
+                    assert param_function.end > 0 and param_function.start > 0, \
+                        'Impossible start/end value for Scale parameter'
 
             # Add the param_function to the dictionary
             self.gev_param_name_to_param_function[gev_param_name] = param_function
diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/param_function.py b/extreme_estimator/extreme_models/margin_model/margin_function/param_function.py
index 5503da2c..24a81791 100644
--- a/extreme_estimator/extreme_models/margin_model/margin_function/param_function.py
+++ b/extreme_estimator/extreme_models/margin_model/margin_function/param_function.py
@@ -20,7 +20,7 @@ class ConstantParamFunction(ParamFunction):
 
 class LinearOneAxisParamFunction(ParamFunction):
 
-    def __init__(self, linear_axis: int, coordinates_axis: np.ndarray, start: float, end: float = 2.0):
+    def __init__(self, linear_axis: int, coordinates_axis: np.ndarray, start: float, end: float = 0.01):
         self.linear_axis = linear_axis
         self.t_min = coordinates_axis.min()
         self.t_max = coordinates_axis.max()
@@ -36,7 +36,7 @@ class LinearOneAxisParamFunction(ParamFunction):
 
 class LinearParamFunction(ParamFunction):
 
-    def __init__(self, linear_axes: List[int], coordinates: np.ndarray, start: float, end: float = 2.0):
+    def __init__(self, linear_axes: List[int], coordinates: np.ndarray, start: float, end: float = 0.01):
         self.linear_one_axis_param_functions = []  # type: List[LinearOneAxisParamFunction]
         self.start = start
         self.end = end
diff --git a/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py b/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py
index 8d22b109..88951e44 100644
--- a/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py
+++ b/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py
@@ -20,7 +20,7 @@ class LinearMarginModel(AbstractMarginModel):
                                                               default_params=GevParams.from_dict(self.params_start_fit),
                                                               gev_param_name_to_linear_axes=gev_param_name_to_linear_axis)
 
-    def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, coordinates: np.ndarray) -> AbstractMarginFunction:
+    def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, coordinates_values: np.ndarray) -> AbstractMarginFunction:
         return self.margin_function_start_fit
 
 
diff --git a/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py b/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py
index 5ad1c115..d8051e86 100644
--- a/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py
+++ b/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py
@@ -21,7 +21,7 @@ class AbstractMaxStableModel(AbstractModel):
         return {'cov.mod': self.cov_mod}
 
     def fitmaxstab(self, maxima_frech: np.ndarray, df_coordinates: pd.DataFrame, fit_marge=False,
-                   fit_marge_form_dict=None, margin_start_dict=None):
+                   fit_marge_form_dict=None, margin_start_dict=None) -> dict:
         assert isinstance(maxima_frech, np.ndarray)
         assert isinstance(df_coordinates, pd.DataFrame)
         if fit_marge:
diff --git a/spatio_temporal_dataset/coordinates/unidimensional_coordinates/coordinates_1D.py b/spatio_temporal_dataset/coordinates/unidimensional_coordinates/coordinates_1D.py
index 53730282..49df99a0 100644
--- a/spatio_temporal_dataset/coordinates/unidimensional_coordinates/coordinates_1D.py
+++ b/spatio_temporal_dataset/coordinates/unidimensional_coordinates/coordinates_1D.py
@@ -10,6 +10,15 @@ class AbstractUniDimensionalCoordinates(AbstractCoordinates):
     pass
 
 
+class LinSpaceCoordinates(AbstractUniDimensionalCoordinates):
+
+    @classmethod
+    def from_nb_points(cls, nb_points, start=-1.0, end=1.0):
+        axis_coordinates = np.linspace(start, end, nb_points)
+        df = pd.DataFrame.from_dict({cls.COORDINATE_X: axis_coordinates})
+        return cls.from_df(df)
+
+
 class UniformCoordinates(AbstractUniDimensionalCoordinates):
 
     @classmethod
diff --git a/spatio_temporal_dataset/dataset/simulation_dataset.py b/spatio_temporal_dataset/dataset/simulation_dataset.py
index 4738c8c8..a635baa7 100644
--- a/spatio_temporal_dataset/dataset/simulation_dataset.py
+++ b/spatio_temporal_dataset/dataset/simulation_dataset.py
@@ -19,8 +19,8 @@ class SimulatedDataset(AbstractDataset):
                  margin_model: AbstractMarginModel = None):
         super().__init__(temporal_observations, coordinates)
         assert margin_model is not None or max_stable_model is not None
-        self.margin_model = margin_model
-        self.max_stable_model = max_stable_model
+        self.margin_model = margin_model  # type: AbstractMarginModel
+        self.max_stable_model = max_stable_model  #  type: AbstractMaxStableModel
 
 
 class MaxStableDataset(SimulatedDataset):
@@ -47,4 +47,5 @@ class FullSimulatedDataset(SimulatedDataset):
                              margin_model: AbstractMarginModel):
         temporal_obs = FullAnnualMaxima.from_double_sampling(nb_obs, max_stable_model,
                                                              coordinates, margin_model)
-        return cls(temporal_obs, coordinates, max_stable_model)
+        return cls(temporal_observations=temporal_obs, coordinates=coordinates, max_stable_model=max_stable_model,
+                   margin_model=margin_model)
diff --git a/spatio_temporal_dataset/temporal_observations/annual_maxima_observations.py b/spatio_temporal_dataset/temporal_observations/annual_maxima_observations.py
index 6eb582b7..b159bbba 100644
--- a/spatio_temporal_dataset/temporal_observations/annual_maxima_observations.py
+++ b/spatio_temporal_dataset/temporal_observations/annual_maxima_observations.py
@@ -19,7 +19,7 @@ class MarginAnnualMaxima(AnnualMaxima):
     @classmethod
     def from_sampling(cls, nb_obs: int, coordinates: AbstractCoordinates,
                       margin_model: AbstractMarginModel):
-        maxima_gev = margin_model.rmargin_from_nb_obs(nb_obs=nb_obs, coordinates=coordinates.coordinates_values)
+        maxima_gev = margin_model.rmargin_from_nb_obs(nb_obs=nb_obs, coordinates_values=coordinates.coordinates_values)
         df_maxima_gev = pd.DataFrame(data=maxima_gev, index=coordinates.index)
         return cls(df_maxima_gev=df_maxima_gev)
 
@@ -41,6 +41,6 @@ class FullAnnualMaxima(MaxStableAnnualMaxima):
         max_stable_annual_maxima = super().from_sampling(nb_obs, max_stable_model, coordinates)
         #  Compute df_maxima_gev from df_maxima_frech
         maxima_gev = margin_model.rmargin_from_maxima_frech(maxima_frech=max_stable_annual_maxima.maxima_frech,
-                                                            coordinates=coordinates.coordinates_values)
+                                                            coordinates_values=coordinates.coordinates_values)
         max_stable_annual_maxima.df_maxima_gev = pd.DataFrame(data=maxima_gev, index=coordinates.index)
         return max_stable_annual_maxima
diff --git a/test/test_extreme_estimator/test_R_model/test_margin_function.py b/test/test_extreme_estimator/test_R_model/test_margin_function.py
deleted file mode 100644
index f412d8d0..00000000
--- a/test/test_extreme_estimator/test_R_model/test_margin_function.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import unittest
-
-from extreme_estimator.gev_params import GevParams
-from extreme_estimator.extreme_models.margin_model.smooth_margin_model import LinearShapeAxis0MarginModel
-from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
-
-
-class TestLinearMarginModel(unittest.TestCase):
-    DISPLAY = False
-
-    def test_visualization_2D(self):
-        spatial_coordinates = CircleCoordinates.from_nb_points(nb_points=50)
-        margin_model = LinearShapeAxis0MarginModel(coordinates=spatial_coordinates)
-        for gev_param_name in GevParams.GEV_PARAM_NAMES:
-            margin_model.margin_function_sample.visualize_2D(gev_param_name=gev_param_name, show=self.DISPLAY)
-        # maxima_gev = margin_model.rmargin_from_nb_obs(nb_obs=10, coordinates=coordinates)
-        # fitted_margin_function = margin_model.fitmargin_from_maxima_gev(maxima_gev=maxima_gev, coordinates=coordinates)
-
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/test/test_extreme_estimator/test_estimator/test_margin_estimators.py b/test/test_extreme_estimator/test_estimator/test_margin_estimators.py
index 473b88fa..cd7b0a9e 100644
--- a/test/test_extreme_estimator/test_estimator/test_margin_estimators.py
+++ b/test/test_extreme_estimator/test_estimator/test_margin_estimators.py
@@ -1,8 +1,7 @@
 import unittest
 
 from extreme_estimator.estimator.margin_estimator import SmoothMarginEstimator
-from extreme_estimator.return_level_plot.spatial_2D_plot import Spatial2DPlot
-from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
+from experiment.return_level_plot.spatial_2D_plot import Spatial2DPlot
 from spatio_temporal_dataset.dataset.simulation_dataset import MarginDataset
 from test.test_utils import load_smooth_margin_models, load_test_1D_and_2D_coordinates
 
diff --git a/test/test_extreme_estimator/test_gev/__init__.py b/test/test_extreme_estimator/test_gev/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/test/test_extreme_estimator/test_R_model/test_gev_mle_fit.py b/test/test_extreme_estimator/test_gev/test_gev_mle_fit.py
similarity index 100%
rename from test/test_extreme_estimator/test_R_model/test_gev_mle_fit.py
rename to test/test_extreme_estimator/test_gev/test_gev_mle_fit.py
-- 
GitLab