forked from antoinedoury/RCM-Emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
128 lines (109 loc) · 5.62 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 14 15:28:58 2024
@author: dourya
"""
import sys
import numpy as np
import xarray as xr
sys.path.append('/cnrm/mosca/USERS/dourya/scripts/python/NN/GITHUB')
from emu_funs import Predictors,Pred,Target,wrapModel,Domain
from emu_funs import launch_gpu
from collections import UserDict
from datetime import date
# ----------------- Namelist ------------------------
# Please modify the following namelist with the values corresponding to
# your emulator.
launch_gpu(0)
dir_cm6='/cnrm/mosca/USERS/dourya/NO_SAVE/DATA/CNRM-CM6/'
var0_nosfc1 = ['zg850','zg700','zg500',
'ta850','ta700','ta500',
'hus850','hus700','hus500',
'ua850','ua700','ua500',
'va850','va700','va500']
filename='tas_ALPX-12_CNRM-CM6_historical_r15i1p1f2_CNRM_CNRM-ALADIN63-emul-CNRM-UNET11-tP1_v1-r1_day_19500101-20141231.nc'
namelist_out = UserDict({
'target_var':'tas',
'domain':'FRA',
'domain_size':(20,16),
'filepath_in':'path to file containing inputs to downscale',
'filepath_ref':'same ref file as the one used for training',
'var_list' : var0_nosfc1,
'opt_ghg' : 'ONE',
'filepath_forc' : 'path to correspong external forcings',
'filepath_grid' : 'path to output domain grid',
'filepath_model' : 'pathto emulator trained' ,
'filepath_aero':'path to corresponding aerosols file',
'aero_ext':True,'aero_stdz':True,'aero_var':'od550aer',
'filepath_out':'path to save the output file'+filename,
})
### example of CMIP lookalike attributes
attributes={
"Conventions" : 'CF-1.10',
"activity_id": 'emulation',
"contact": '[email protected]',
"domain_id": 'ALPX-12',
"domain": 'EUR-11 CORDEX domain cropped to a domain centered on Alps.',
"driving_experiment":'Historical run with GCM forcing',
"driving_experiment_id":'historical',
"driving_institution_id":'CNRM-CERFACS',
"driving_source_id":'CNRM-CM6',
"driving_variant_label":'r15i1p1f',
"emulator": 'CNRM_UNET11, introduced in Doury et al, 2022, is based fully'\
'convolutional neural network shaped from the UNeT base (Ronnenberg et al, 2015).'\
'The network is minimizing the mean squared error (mse) loss function.',
"emulator_id":'CNRM-UNET11',
"frequency": 'day',
"further_info_url":'',
"institution":'Centre National de Recherches Meteorologiques,CNRM, Toulouse, France',
"institution_id":"CNRM",
'mip_era':"CMIP6",
"native_resolution" : "0.11°",
"product":"emulator_output",
"project_id":"I4C",
"realm":"",
"source": "CNRM-UNET11 is trained here for the near surface temperature of CNRM-ALADIN63 RCM ",
"source_id":'ALADIN63-emul-CNRM-UNET11',
"source_type":'RCM_emulator',
"version_realization":'v1-r1',
"target_institution_id":'CNRM',
"target_source_id":'CNRM-ALADIN63',
"target_version_realization":'v1',
"tracking_id":'',
"training":'Trained using PP predictors from the CNRM ALADIN63 RCM nested into (CMI5) CNRM-CM5 for the period 1950-2100'\
'combining the historical and rcp85 simulations. The emulator is trained in perfect model framework, implying'\
'that predictors and predictands come from the same RCM simulation, predictors are coarsened to the GCM resolution'\
'(150km) and a spatial smoothing is applied, following the protocol described in Doury et al, 2022. The preditors'\
'include the geopotential altitude, the temperature, the specific humidity and the eastern and northern wind components'\
'at 3 pressure levels (500, 700, 850 hpa). External forcings such as the GHG concentration, and the solar and ozone values'\
'are also inputs.The predictor list and pre-processing is identical from the one described in Doury et al 2022,'\
'except that we remove here the uas,vas and psl variables from predictors list.',
"training_id": 'tP1',
"variable_id":'tas',
"version_realization_info":'this is the 1st realization of the emulator CNRM-ALADIN63-emul-CNRM-UNET11-TP1 over ALPX-12 domain.',
"license":'',
"reference":"""Doury, A., Somot, S., Gadat, S. et al. Regional climate model emulator based on deep learning:
concept and first evaluation of a novel hybrid downscaling approach. Clim Dyn 60, 1751–1779 (2023).
https://doi.org/10.1007/s00382-022-06343-9""",
"creation_date":date.today().strftime("%d/%m/%Y")
}
for key in namelist_out:
setattr(namelist_out,key,namelist_out[key])
listin_pred = []
aninput_pred = Predictors(namelist_out.domain,namelist_out.domain_size,
filepath=namelist_out.filepath_in,
filepath_ref=namelist_out.filepath_ref,
var_list=namelist_out.var_list,
filepath_forc=namelist_out.filepath_forc,
filepath_aero=namelist_out.filepath_aero,
opt_ghg=namelist_out.opt_ghg,
aero_ext=namelist_out.aero_ext,aero_var=namelist_out.aero_var,aero_stdz=namelist_out.aero_stdz)
listin_pred.append(aninput_pred)
apred = Pred(namelist_out.domain, namelist_out.domain_size,
inputIn = listin_pred,
filepath_grid =namelist_out.filepath_grid,
filepath_out=namelist_out.filepath_out,
filepath_model=namelist_out.filepath_model,
attributes=attributes)
print(f"apred is {apred.ds}")