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

[contrasting project] modify year_to_days to match with the definition.

parent 59518cca
No related merge requests found
Showing with 31 additions and 7 deletions
+31 -7
......@@ -18,6 +18,7 @@ from PIL import ImageDraw
from matplotlib.colors import Normalize
from netCDF4 import Dataset
from extreme_data.edf_data.weather_types import load_df_weather_types
from extreme_data.meteo_france_data.scm_models_data.abstract_variable import AbstractVariable
from extreme_data.meteo_france_data.scm_models_data.utils import ALTITUDES, ZS_INT_23, ZS_INT_MASK, LONGITUDES, \
LATITUDES, ORIENTATIONS, SLOPES, ORDERED_ALLSLOPES_ALTITUDES, ORDERED_ALLSLOPES_ORIENTATIONS, \
......@@ -81,7 +82,7 @@ class AbstractStudy(object):
# Map each year to the 'days since year-08-01 06:00:00'
year_to_days = OrderedDict()
for year in self.ordered_years:
date = datetime.datetime(year=year, month=8, day=1, hour=6, minute=0, second=0)
date = datetime.datetime(year=year-1, month=8, day=1, hour=6, minute=0, second=0)
days = []
for i in range(366):
days.append(date_to_str(date))
......@@ -95,7 +96,14 @@ class AbstractStudy(object):
def year_to_wps(self):
assert 1954 <= self.year_min and self.year_max <= WP_PATTERN_MAX_YEAR, \
'Weather patterns are not available between {} and {}'.format(self.year_min, self.year_max)
pass
year_to_wps = {}
for year, days in self.year_to_days.items():
year_to_wps[year] = self.df_weather_types.loc[days].iloc[:, 0].values
return year_to_wps
@cached_property
def df_weather_types(self):
return load_df_weather_types()
@property
def all_days(self):
......@@ -144,7 +152,6 @@ class AbstractStudy(object):
year_to_annual_maxima = OrderedDict()
for year, time_serie in self._year_to_max_daily_time_serie.items():
annual_maxima = np.concatenate((time_serie[:91], time_serie[-61:]), axis=0).max(axis=0)
print(annual_maxima)
year_to_annual_maxima[year] = annual_maxima
return year_to_annual_maxima
......
import unittest
import numpy as np
from datetime import datetime
import pandas as pd
from extreme_data.edf_data.weather_types import load_df_weather_types
from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusSwe3Days
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranTemperature
from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranTemperature, SafranPrecipitation1Day
from extreme_data.meteo_france_data.scm_models_data.utils import date_to_str
......@@ -45,9 +46,18 @@ class TestWeatherTypes(unittest.TestCase):
# wp_to_found_percentages = wp_to_found_percentages.astype(int)
self.assertEqual(wp_to_expected_percentages, wp_to_found_percentages)
def test_anticyclonique_weather_pattern(self):
study = CrocusSwe3Days(altitude=900, year_min=1954, year_max=2008)
pass
# def test_anticyclonique_weather_pattern(self):
# study = SafranPrecipitation1Day(altitude=900, year_min=1954, year_max=2008)
# p = []
# for year, wps in study.year_to_wps.items():
# daily_time_serie_array = study.year_to_daily_time_serie_array[year]
# self.assertEqual(len(daily_time_serie_array), len(wps))
# precipitation_on_anticlonic_days = np.max(daily_time_serie_array[np.array(wps) == 8, :], axis=1)
# print('NB anticlonic days', len(precipitation_on_anticlonic_days))
# p.extend(precipitation_on_anticlonic_days)
# p = sorted(p)[::-1]
# print(p[:5])
# self.assertLess(p[0], 10)
......
......@@ -14,6 +14,13 @@ from root_utils import get_display_name_from_object_type
class TestSCMAllStudy(unittest.TestCase):
def test_year_to_date(self):
year = 2019
study = SafranSnowfall(altitude=900, year_min=year, year_max=year)
first_day, *_, last_day = study.year_to_days[year]
self.assertIn(str(year-1), first_day)
self.assertIn(str(year), last_day)
def test_instantiate_studies(self):
nb_sample = 2
for nb_days in sample(set(NB_DAYS), k=nb_sample):
......
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