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

[paper 3] add adamont downloader & simulation handler

parent 4a49cf1a
No related merge requests found
Showing with 106 additions and 0 deletions
+106 -0
import subprocess
requests = """https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/CNRM-CM5/ALADIN53/historical/day/snowswe/SNOWSWE_PRO_CNRM-ALADIN53_CNRM-CERFACS-CNRM-CM5_HISTO_alp_1950080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/IPSL-CM5A/WRF331F/historical/day/snowswe/SNOWSWE_PRO_IPSL-INERIS-WRF331F_IPSL-IPSL-CM5A-MR_HISTO_alp_1951080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/CNRM-CM5/RCA4/historical/day/snowswe/SNOWSWE_PRO_SMHI-RCA4_CNRM-CERFACS-CNRM-CM5_HISTO_alp_1970080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/EC-EARTH/RCA4/historical/day/snowswe/SNOWSWE_PRO_SMHI-RCA4_ICHEC-EC-EARTH_HISTO_alp_1970080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MOHC-HadGEM2/RCA4/historical/day/snowswe/SNOWSWE_PRO_SMHI-RCA4_MOHC-HadGEM2-ES_HISTO_alp_1981080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/IPSL-CM5A/RCA4/historical/day/snowswe/SNOWSWE_PRO_SMHI-RCA4_IPSL-IPSL-CM5A-MR_HISTO_alp_1970080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MPI-ESM-LR/RCA4/historical/day/snowswe/SNOWSWE_PRO_SMHI-RCA4_MPI-M-MPI-ESM-LR_HISTO_alp_1970080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MOHC-HadGEM2/RACMO22E/historical/day/snowswe/SNOWSWE_PRO_KNMI-RACMO22E_MOHC-HadGEM2-ES_HISTO_alp_1981080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/CNRM-CM5/CCLM4-8-17/historical/day/snowswe/SNOWSWE_PRO_CLMcom-CCLM4-8-17_CNRM-CERFACS-CNRM-CM5_HISTO_alp_1950080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/EC-EARTH/CCLM4-8-17/historical/day/snowswe/SNOWSWE_PRO_CLMcom-CCLM4-8-17_ICHEC-EC-EARTH_HISTO_alp_1950080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MOHC-HadGEM2/CCLM4-8-17/historical/day/snowswe/SNOWSWE_PRO_CLMcom-CCLM4-8-17_MOHC-HadGEM2-ES_HISTO_alp_1981080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MPI-ESM-LR/CCLM4-8-17/historical/day/snowswe/SNOWSWE_PRO_CLMcom-CCLM4-8-17_MPI-M-MPI-ESM-LR_HISTO_alp_1950080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/MPI-ESM-LR/REMO019/historical/day/snowswe/SNOWSWE_PRO_MPI-CSC-REMO2009_MPI-M-MPI-ESM-LR_HISTO_alp_1950080106_2005073106_6h.nc
https://climatedata.umr-cnrm.fr/public/dcsc/projects/DRIAS/ADAMONT2017/Alpes/NorESM1/HIRHAM5/historical/day/snowswe/SNOWSWE_PRO_DMI-HIRHAM5_NCC-NorESM1-M_HISTO_alp_1951080106_2005073106_6h.nc
"""
for request in requests.split('\n')[:]:
command_line = 'wget {}'.format(request)
print(command_line)
subprocess.run(command_line, shell=True)
\ No newline at end of file
import os
from typing import List
import os.path as op
from cached_property import cached_property
from adamont.single_simulation import SingleSimulation
ADAMONT_PATH = r"/home/erwan/Documents/projects/spatiotemporalextremes/local/spatio_temporal_datasets/ADAMONT"
class EnsembleSimulation(object):
def __init__(self, scenario='HISTO', parameter='SNOWSWE',
first_winter_required_for_histo=1958, last_winter_for_histo=2004):
self.scenario = scenario
self.parameter = parameter
self.first_winter_required_for_histo = first_winter_required_for_histo
self.last_year_for_histo = last_winter_for_histo
# Assert value for the parameter
assert scenario in ['HISTO', 'RCP45']
assert parameter in ['SNOWSWE']
assert first_winter_required_for_histo >= 1950
assert first_winter_required_for_histo <= 2004
# Load simulations
self.simulations = [SingleSimulation(op.join(ADAMONT_PATH, nc_file)) for nc_file in self.nc_files]
"""Ce problème affecte toutes lessimulations HISTORIQUE CORDEX réalisées en utilisant le forçage CNRM-CM5: CCLM4-8-17: ALADIN53 et RCA4"""
@cached_property
def simulations_path(self):
return op.join(ADAMONT_PATH, self.parameter, self.scenario)
@cached_property
def nc_files(self) -> List[str]:
nc_files = []
for file in os.listdir(self.simulations_path):
first_year = int(file.split('_')[-3][:4])
if first_year <= self.first_winter_required_for_histo:
# Also remove the historical simulations that contain "CNRM-CM5"
# Problem reported in "limitations" on their website
# Ce problème affecte toutes lessimulations HISTORIQUE CORDEX
# réalisées en utilisant le forçage CNRM-CM5: CCLM4-8-17: ALADIN53 et RCA4
if self.scenario == 'HISTO' and 'CNRM-CM5' in file:
print('here', file)
continue
nc_files.append(file)
assert len(nc_files) > 0
return nc_files
@cached_property
def simulations_names(self):
return [' + '.join(file.split('_')[2:-5]) for file in self.nc_files]
def massif_name_and_altitude_to_mean_return_level(self):
return {}
if __name__ == '__main__':
ensemble = EnsembleSimulation(first_winter_required_for_histo=1985)
print(len(ensemble.simulations))
print(ensemble.simulations_names)
from cached_property import cached_property
from netCDF4._netCDF4 import Dataset
class SingleSimulation(object):
def __init__(self, nc_path):
self.nc_path = nc_path
@cached_property
def dataset(self):
return Dataset(self.nc_path)
def massif_name_and_altitude_to_return_level(self):
return {}
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