Commit 040bbffe authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting project] add split years to abstract_study.py. add some constant values as well.

parent 7aed624a
No related merge requests found
Showing with 17 additions and 3 deletions
+17 -3
......@@ -60,22 +60,30 @@ class AbstractStudy(object):
REANALYSIS_PYRENEES_FLAT_FOLDER = 'S2M_AERIS_AVRIL_2020/'
REANALYSIS_ALPS_ALLSLOPES_FOLDER = 'SAFRAN_montagne-CROCUS_2019/alp_allslopes/reanalysis'
YEAR_MIN = 1959
YEAR_MAX = 2019
# REANALYSIS_FOLDER = 'SAFRAN_montagne-CROCUS_2019/postes/reanalysis'
def __init__(self, variable_class: type, altitude: int = 1800, year_min=1959, year_max=2019,
def __init__(self, variable_class: type, altitude: int = 1800, year_min=YEAR_MIN, year_max=YEAR_MAX,
multiprocessing=True, orientation=None, slope=20.0,
season=SeasonForTheMaxima.annual,
french_region=FrenchRegion.alps):
french_region=FrenchRegion.alps,
split_years=None):
assert isinstance(altitude, int), type(altitude)
assert altitude in ALTITUDES, altitude
self.french_region = french_region
self.altitude = altitude
self.model_name = None
self.variable_class = variable_class
assert self.YEAR_MIN <= year_min <= year_max <= self.YEAR_MAX
self.year_min = year_min
self.year_max = year_max
self.multiprocessing = multiprocessing
self.season = season
if split_years is None:
split_years = list(range(year_min, year_max+1))
self.split_years = set(split_years)
# Add some attributes, for the "allslopes" reanalysis
assert orientation is None or orientation in ORIENTATIONS
assert slope in SLOPES
......@@ -358,7 +366,8 @@ class AbstractStudy(object):
nc_files = [(int(f.split('_')[-2][:4]) + 1, f) for f in os.listdir(self.study_full_path) if f.endswith('.nc')]
ordered_years, path_files = zip(*[(year, op.join(self.study_full_path, nc_file))
for year, nc_file in sorted(nc_files, key=lambda t: t[0])
if self.year_min <= year <= self.year_max])
if (self.year_min <= year <= self.year_max)
and (year in self.split_years)])
return path_files, ordered_years
""" Temporal properties """
......
......@@ -34,6 +34,11 @@ class TestSCMAllStudy(unittest.TestCase):
daily_time_series = study.year_to_daily_time_serie_array[year]
self.assertEqual(len(days), len(daily_time_series))
def test_study_for_split(self):
split_years = [1959 + 10 * i for i in range(7)]
study = SafranSnowfall(altitude=900, split_years=split_years)
self.assertEqual(split_years, list(study.ordered_years))
def test_instantiate_studies(self):
study_classes = SCM_STUDIES
nb_sample = 2
......
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