Commit ff92a0cb authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM][NON STATIONARY TREND] modify some display parameter. add pre loaded...

[SCM][NON STATIONARY TREND] modify some display parameter. add pre loaded LATITUDE & LONGITUDE to scm_constants file. remove massif file.
parent d4a2ae88
No related merge requests found
Showing with 79 additions and 111 deletions
+79 -111
......@@ -13,7 +13,7 @@ from PIL import ImageDraw
from netCDF4 import Dataset
from experiment.meteo_france_SCM_study.abstract_variable import AbstractVariable
from experiment.meteo_france_SCM_study.altitude import ALTITUDES, ZS_INT_23, ZS_INT_MASK
from experiment.meteo_france_SCM_study.scm_constants import ALTITUDES, ZS_INT_23, ZS_INT_MASK, LONGITUDES, LATITUDES
from experiment.meteo_france_SCM_study.visualization.utils import get_km_formatter
from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \
AbstractMarginFunction
......@@ -173,12 +173,14 @@ class AbstractStudy(object):
@property
def df_massifs_longitude_and_latitude(self) -> pd.DataFrame:
# DataFrame object that represents the massif coordinates in degrees extracted from the SCM data
any_ordered_dict = list(self.year_to_dataset_ordered_dict.values())[0]
longitude = np.array(any_ordered_dict.variables['longitude'])[self.altitude_mask]
latitude = np.array(any_ordered_dict.variables['latitude'])[self.altitude_mask]
# any_ordered_dict = list(self.year_to_dataset_ordered_dict.values())[0]
# longitude = np.array(any_ordered_dict.variables['longitude'])
# latitude = np.array(any_ordered_dict.variables['latitude'])
longitude = np.array(LONGITUDES)
latitude = np.array(LATITUDES)
index = self.altitude_to_massif_names[self.altitude]
columns = [AbstractSpatialCoordinates.COORDINATE_X, AbstractSpatialCoordinates.COORDINATE_Y]
data = dict(zip(columns, [longitude, latitude]))
data = dict(zip(columns, [longitude[self.altitude_mask], latitude[self.altitude_mask]]))
return pd.DataFrame(data=data, index=index, columns=columns)
def load_df_centroid(self) -> pd.DataFrame:
......
"""
ZS was extracted from a netcdf file
"""
import numpy as np
ZS = """[ 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 300.
600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 300. 600. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 4500.
4800. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 300. 600.
900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 600. 900. 1200. 1500.
1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 0. 300. 600. 900.
1200. 1500. 1800. 2100. 0. 300. 600. 900. 1200. 1500. 1800. 2100.
2400. 2700. 3000. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400.
2700. 3000. 3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700.
3000. 3300. 3600. 3900. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 3900. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 0.
300. 600. 900. 1200. 1500. 1800. 2100. 2400. 0. 300. 600. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 300. 600. 900. 1200.
1500. 1800. 2100. 2400. 2700. 3000. 600. 900. 1200. 1500. 1800. 2100.
2400. 2700. 3000. 3300. 3600. 600. 900. 1200. 1500. 1800. 2100. 2400.
2700. 3000. 3300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700.
3000. 3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.]"""
ZS_INT = [int(float(e)) for e in ZS[1:-1].split()]
ALTITUDES = sorted(set(ZS_INT))
# Create a ZS_INT with only the 23 first massifs
ZS_INT_23 = ZS_INT[:-10].copy()
# Create a ZS_INT with np.nan all altitudes corresponding to the 24th massif
ZS_INT_MASK = np.array(ZS_INT)
ZS_INT_MASK[-10:] = np.nan
from utils import first
MASSIF_NAMES_1800 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Bauges', 'Beaufortain',
'Haute-Tarentaise', 'Chartreuse', 'Belledonne', 'Maurienne', 'Vanoise',
'Haute-Maurienne', 'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans',
'Pelvoux', 'Queyras', 'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye',
'Alpes-Azur', 'Mercantour']
# Some massif like Chartreuse do not have massif whose altitude is higher or equal to 2400
MASSIF_NAMES_2400 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Beaufortain', 'Haute-Tarentaise',
'Belledonne', 'Maurienne', 'Vanoise', 'Haute-Maurienne',
'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans', 'Pelvoux', 'Queyras',
'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye', 'Alpes-Azur',
'Mercantour']
class Massif(object):
def __init__(self, name: str, id: int, lat: float, lon: float) -> None:
self.lon = lon
self.lat = lat
self.id = id
self.name = name
@classmethod
def from_str(cls, s: str):
name, id, lat, lon = s.split(',')
return cls(name.strip(), int(id), float(lat), float(lon))
def safran_massif_names_from_datasets(datasets, altitude):
# Massifs names are extracted from SAFRAN dataset
reference_massif_list = MASSIF_NAMES_1800 if altitude == 1800 else MASSIF_NAMES_2400
if hasattr(datasets[0], 'massifsList'):
# Assert the all the datasets have the same indexing for the massif
assert len(set([dataset.massifsList for dataset in datasets])) == 1
# List of the name of the massif used by all the SAFRAN datasets
massifs = [Massif.from_str(massif_str) for massif_str in first(datasets).massifsList.split('/')]
# IMPORTANT: Sort the massif names
massifs = sorted(massifs, key=lambda massif: massif.id)
safran_names = [massif.name for massif in massifs]
assert reference_massif_list == safran_names, '{} \n{}'.format(reference_massif_list, safran_names)
return reference_massif_list
"""
ZS was extracted from a netcdf file
"""
import numpy as np
ZS = """[ 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 300.
600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 300. 600. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 4500.
4800. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 300. 600.
900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 600. 900. 1200. 1500.
1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 0. 300. 600. 900.
1200. 1500. 1800. 2100. 0. 300. 600. 900. 1200. 1500. 1800. 2100.
2400. 2700. 3000. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400.
2700. 3000. 3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700.
3000. 3300. 3600. 3900. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 3900. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 0.
300. 600. 900. 1200. 1500. 1800. 2100. 2400. 0. 300. 600. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 3600. 3900. 4200. 900.
1200. 1500. 1800. 2100. 2400. 2700. 3000. 3300. 300. 600. 900. 1200.
1500. 1800. 2100. 2400. 2700. 3000. 600. 900. 1200. 1500. 1800. 2100.
2400. 2700. 3000. 3300. 3600. 600. 900. 1200. 1500. 1800. 2100. 2400.
2700. 3000. 3300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 3600. 0. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700.
3000. 3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.
3300. 300. 600. 900. 1200. 1500. 1800. 2100. 2400. 2700. 3000.]"""
ZS_INT = [int(float(e)) for e in ZS[1:-1].split()]
ALTITUDES = sorted(set(ZS_INT))
# Create a ZS_INT with only the 23 first massifs
ZS_INT_23 = ZS_INT[:-10].copy()
# Create a ZS_INT with np.nan all altitudes corresponding to the 24th massif
ZS_INT_MASK = np.array(ZS_INT)
ZS_INT_MASK[-10:] = np.nan
# Longitudes and Latitudes in degrees
LONGITUDES = [6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.64493, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.39738, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.82392, 6.10178, 6.10178, 6.10178, 6.10178, 6.10178, 6.10178, 6.10178, 6.10178, 6.10178, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.57668, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 6.90053, 5.80795, 5.80795, 5.80795, 5.80795, 5.80795, 5.80795, 5.80795, 5.80795, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.00201, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.35451, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.61786, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.91492, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.21836, 6.59154, 6.59154, 6.59154, 6.59154, 6.59154, 6.59154, 6.59154, 6.59154, 6.59154, 5.4932, 5.4932, 5.4932, 5.4932, 5.4932, 5.4932, 5.4932, 5.4932, 5.4932, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 5.99951, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.45769, 6.79352, 6.79352, 6.79352, 6.79352, 6.79352, 6.79352, 6.79352, 6.79352, 6.79352, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 5.8499, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.23469, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.50065, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.67076, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 6.79647, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.31586, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025, 7.3025]
LATITUDES = [46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 46.17685, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89494, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.89794, 45.65578, 45.65578, 45.65578, 45.65578, 45.65578, 45.65578, 45.65578, 45.65578, 45.65578, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.65756, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.54313, 45.37753, 45.37753, 45.37753, 45.37753, 45.37753, 45.37753, 45.37753, 45.37753, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.27395, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.32783, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.411, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.26072, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.11517, 45.01923, 45.01923, 45.01923, 45.01923, 45.01923, 45.01923, 45.01923, 45.01923, 45.01923, 45.00409, 45.00409, 45.00409, 45.00409, 45.00409, 45.00409, 45.00409, 45.00409, 45.00409, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.94609, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.83699, 44.77139, 44.77139, 44.77139, 44.77139, 44.77139, 44.77139, 44.77139, 44.77139, 44.77139, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.69552, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.70565, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.57217, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.44757, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12458, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 44.12649, 46.39, 46.39, 46.39, 46.39, 46.39, 46.39, 46.39, 46.39, 46.39, 46.39]
......@@ -2,7 +2,7 @@ from collections import OrderedDict
from typing import Dict
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
from experiment.meteo_france_SCM_study.altitude import ALTITUDES
from experiment.meteo_france_SCM_study.scm_constants import ALTITUDES
class Studies(object):
......
import time
from typing import Generator, List
from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
......@@ -37,7 +38,7 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo
for alti in altis:
if verbose:
print('alti: {}, nb_day: {}'.format(alti, nb_day), end='')
print('alti: {}, nb_day: {} '.format(alti, nb_day), end='')
study = study_class(altitude=alti, nb_consecutive_days=nb_day) if is_safran_study \
else study_class(altitude=alti)
massifs = study.altitude_to_massif_names[alti]
......@@ -119,20 +120,29 @@ def trend_analysis():
save_to_file = True
only_first_one = False
short_altitudes = [300, 1200, 2100, 3000][:1]
full_altitude_with_at_least_2_stations = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200][-5:]
altitudes = full_altitude_with_at_least_2_stations
full_altitude_with_at_least_2_stations = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200][:]
durand_altitude = [1800]
altitudes = durand_altitude
normalization_class = [None, BetweenMinusOneAndOneNormalization, BetweenZeroAndOneNormalization][-1]
study_classes = [CrocusSwe, CrocusDepth, SafranSnowfall, SafranRainfall, SafranTemperature][:1]
study_classes = [CrocusSwe, CrocusDepth, SafranSnowfall, SafranRainfall, SafranTemperature][2:3]
for study in study_iterator_global(study_classes, only_first_one=only_first_one, altitudes=altitudes):
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file,
transformation_class=normalization_class)
study_visualizer.visualize_temporal_trend_relevance(complete_analysis=False, multiprocessing=True)
if __name__ == '__main__':
def main_run():
# annual_mean_vizu_compare_durand_study(safran=True, take_mean_value=True, altitude=2100)
# normal_visualization(temporal_non_stationarity=True)
trend_analysis()
# max_stable_process_vizu_compare_gaume_study(altitude=1800, nb_days=1)
# extended_visualization()
# complete_analysis()
if __name__ == '__main__':
start = time.time()
main_run()
duration = time.time() - start
print('Full run took {}s'.format(round(duration, 1)))
......@@ -134,14 +134,7 @@ class StudyVisualizer(object):
self._observations.convert_to_spatio_temporal_index(self.coordinates)
if self.normalization_under_one_observations:
self._observations.normalize()
# Write a summary of observations
df = self._observations.df_maxima_gev
print('Observations summary:', ' ', end='')
print('Mean value:', df.mean().mean(), ' ', end='')
print('Min value:', df.min().min(), ' ', end='')
print('Max value:', df.max().max(), ' ', end='')
print('# of zero values:', df.size - np.count_nonzero(df.values), '\n')
self._observations.print_summary()
return self._observations
# Graph for each massif / or groups of massifs
......@@ -177,11 +170,11 @@ class StudyVisualizer(object):
trend_tests = [ConditionalIndedendenceLocationTrendTest(dataset=self.dataset, verbose=verbose,
multiprocessing=multiprocessing)]
# max_stable_models = load_test_max_stable_models(default_covariance_function=self.default_covariance_function)
# for max_stable_model in [max_stable_models[1], max_stable_models[-2]]:
# trend_tests.append(MaxStableLocationTrendTest(dataset=self.dataset,
# max_stable_model=max_stable_model, verbose=verbose,
# multiprocessing=multiprocessing))
max_stable_models = load_test_max_stable_models(default_covariance_function=self.default_covariance_function)
for max_stable_model in [max_stable_models[1], max_stable_models[-2]]:
trend_tests.append(MaxStableLocationTrendTest(dataset=self.dataset,
max_stable_model=max_stable_model, verbose=verbose,
multiprocessing=multiprocessing))
nb_trend_tests = len(trend_tests)
fig, axes = plt.subplots(1, nb_trend_tests, figsize=self.figsize)
......
......@@ -112,7 +112,8 @@ class AbstractSpatioTemporalObservations(object):
print('Mean value:', df.mean().mean(), ' ', end='')
print('Min value:', df.min().min(), ' ', end='')
print('Max value:', df.max().max(), ' ', end='')
print('# of zero values:', df.size - np.count_nonzero(df.values), '\n')
percentage = round(100 * (df.size - np.count_nonzero(df.values)) / df.size, 1)
print('Percentage of zero values {} out of {} observations'.format(percentage, df.size), '\n')
@_df_maxima.setter
def _df_maxima(self, value):
......
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