1 | #!/usr/bin/env python3 |
---|
2 | ### |
---|
3 | ### Script to check water conservation in the IPSL coupled model |
---|
4 | ### |
---|
5 | ## Warning, to install, configure, run, use any of included software or |
---|
6 | ## to read the associated documentation you'll need at least one (1) |
---|
7 | ## brain in a reasonably working order. Lack of this implement will |
---|
8 | ## void any warranties (either express or implied). Authors assumes |
---|
9 | ## no responsability for errors, omissions, data loss, or any other |
---|
10 | ## consequences caused directly or indirectly by the usage of his |
---|
11 | ## software by incorrectly or partially configured personal |
---|
12 | ## |
---|
13 | ## |
---|
14 | ## SVN information |
---|
15 | # $Author$ |
---|
16 | # $Date$ |
---|
17 | # $Revision$ |
---|
18 | # $Id$ |
---|
19 | # $HeadURL$ |
---|
20 | |
---|
21 | |
---|
22 | ### |
---|
23 | ## Import system modules |
---|
24 | import sys, os, shutil, subprocess |
---|
25 | import numpy as np |
---|
26 | import configparser, re |
---|
27 | |
---|
28 | ## Creates parser |
---|
29 | config = configparser.ConfigParser() |
---|
30 | config.optionxform = str # To keep capitals |
---|
31 | |
---|
32 | config['Files'] = {} |
---|
33 | config['System'] = {} |
---|
34 | |
---|
35 | ##-- Some physical constants |
---|
36 | #-- Earth Radius |
---|
37 | Ra = 6366197.7236758135 |
---|
38 | #-- Gravity |
---|
39 | grav = 9.81 |
---|
40 | #-- Ice volumic mass (kg/m3) in LIM3/SI3 |
---|
41 | ICE_rho_ice = 917.0 |
---|
42 | #-- Snow volumic mass (kg/m3) in LIM3/SI3 |
---|
43 | ICE_rho_sno = 330.0 |
---|
44 | #-- Water in ponds coluclic mass (kg/m3) in LIM3/SI3 |
---|
45 | ICE_rho_pnd = 1000. |
---|
46 | #-- Ocean water volumic mass (kg/m3) in NEMO |
---|
47 | OCE_rho_liq = 1026. |
---|
48 | #-- Water volumic mass in atmosphere |
---|
49 | ATM_rho = 1.0e3 |
---|
50 | #-- Water volumic mass in surface reservoirs |
---|
51 | SRF_rho = 1.0e3 |
---|
52 | #-- Water volumic mass of rivers |
---|
53 | RUN_rho = 1.0e3 |
---|
54 | |
---|
55 | ## Read experiment parameters |
---|
56 | ATM = None ; ORCA = None ; NEMO = None ; OCE_relax = False ; OCE_icb = False ; Coupled = False ; Routing = None |
---|
57 | |
---|
58 | # Arguments passed |
---|
59 | print ( "Name of Python script:", sys.argv[0] ) |
---|
60 | IniFile = sys.argv[1] |
---|
61 | print ("Input file : ", IniFile ) |
---|
62 | config.read (IniFile) |
---|
63 | |
---|
64 | def setBool (chars) : |
---|
65 | '''Convert specific char string in boolean if possible''' |
---|
66 | setBool = chars |
---|
67 | for key in configparser.ConfigParser.BOOLEAN_STATES.keys () : |
---|
68 | if chars.lower() == key : setBool = configparser.ConfigParser.BOOLEAN_STATES[key] |
---|
69 | return setBool |
---|
70 | |
---|
71 | def setNum (chars) : |
---|
72 | '''Convert specific char string in integer or real if possible''' |
---|
73 | if type (chars) == str : |
---|
74 | realnum = re.compile ("^[-+]?[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?$") |
---|
75 | isReal = realnum.match(chars.strip()) != None |
---|
76 | isInt = chars.strip().isdigit() |
---|
77 | if isReal : |
---|
78 | if isInt : setNum = int (chars) |
---|
79 | else : setNum = float (chars) |
---|
80 | else : setNum = chars |
---|
81 | else : setNum = chars |
---|
82 | return setNum |
---|
83 | |
---|
84 | print ('[Experiment]') |
---|
85 | for VarName in config['Experiment'].keys() : |
---|
86 | locals()[VarName] = config['Experiment'][VarName] |
---|
87 | locals()[VarName] = setBool (locals()[VarName]) |
---|
88 | locals()[VarName] = setNum (locals()[VarName]) |
---|
89 | print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) ) |
---|
90 | |
---|
91 | ### |
---|
92 | ICO = ( 'ICO' in ATM ) |
---|
93 | LMDZ = ( 'LMD' in ATM ) |
---|
94 | |
---|
95 | ### |
---|
96 | ## Import system modules |
---|
97 | import sys, os, shutil, subprocess |
---|
98 | |
---|
99 | # Where do we run ? |
---|
100 | SysName, NodeName, Release, Version, Machine = os.uname() |
---|
101 | TGCC = ( 'irene' in NodeName ) |
---|
102 | IDRIS = ( 'jeanzay' in NodeName ) |
---|
103 | |
---|
104 | ## Set site specific libIGCM directories, and other specific stuff |
---|
105 | if TGCC : |
---|
106 | CPU = subprocess.getoutput ( 'lscpu | grep "Model name"' ) |
---|
107 | if "Intel(R) Xeon(R) Platinum" in CPU : Machine = 'irene' |
---|
108 | if "AMD" in CPU : Machine = 'irene-amd' |
---|
109 | |
---|
110 | ARCHIVE = subprocess.getoutput ( f'ccc_home --cccstore -d {Project} -u {User}' ) |
---|
111 | STORAGE = subprocess.getoutput ( f'ccc_home --cccwork -d {Project} -u {User}' ) |
---|
112 | SCRATCHDIR = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' ) |
---|
113 | R_IN = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM') |
---|
114 | rebuild = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' ) |
---|
115 | |
---|
116 | ## Specific to run at TGCC. |
---|
117 | # Needed before importing a NetCDF library (netCDF4, xarray, cmds, etc ...) |
---|
118 | import mpi4py |
---|
119 | mpi4py.rc.initialize = False |
---|
120 | |
---|
121 | ## Creates output directory |
---|
122 | #TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
123 | TmpDir = os.path.join ( '/ccc/scratch/cont003/drf/p86mart', f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
124 | |
---|
125 | if IDRIS : |
---|
126 | raise Exception("Pour IDRIS : repertoires et chemins a definir") |
---|
127 | |
---|
128 | ## Import specific module |
---|
129 | import nemo, lmdz |
---|
130 | ## Now import needed scientific modules |
---|
131 | import xarray as xr |
---|
132 | |
---|
133 | # Output file |
---|
134 | FileOut = f'CPL_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out' |
---|
135 | f_out = open ( FileOut, mode = 'w' ) |
---|
136 | |
---|
137 | # Function to print to stdout *and* output file |
---|
138 | def echo (string, end='\n') : |
---|
139 | print ( string, end=end ) |
---|
140 | sys.stdout.flush () |
---|
141 | f_out.write ( string + end ) |
---|
142 | f_out.flush () |
---|
143 | return None |
---|
144 | |
---|
145 | ## Set libIGCM directories |
---|
146 | R_OUT = os.path.join ( ARCHIVE , 'IGCM_OUT') |
---|
147 | R_BUF = os.path.join ( SCRATCHDIR, 'IGCM_OUT') |
---|
148 | |
---|
149 | L_EXP = os.path.join (TagName, SpaceName, ExperimentName, JobName) |
---|
150 | R_SAVE = os.path.join ( R_OUT, L_EXP ) |
---|
151 | R_BUFR = os.path.join ( R_BUF, L_EXP ) |
---|
152 | POST_DIR = os.path.join ( R_BUF, L_EXP, 'Out' ) |
---|
153 | REBUILD_DIR = os.path.join ( R_BUF, L_EXP, 'REBUILD' ) |
---|
154 | R_BUF_KSH = os.path.join ( R_BUFR, 'Out' ) |
---|
155 | R_FIGR = os.path.join ( STORAGE, 'IGCM_OUT', L_EXP ) |
---|
156 | |
---|
157 | #if os.path.isdir (TmpDir) : shutil.rmtree ( TmpDir ) |
---|
158 | if not os.path.isdir (TmpDir) : os.mkdir (TmpDir) |
---|
159 | TmpDirOCE = os.path.join (TmpDir, 'OCE') |
---|
160 | TmpDirICE = os.path.join (TmpDir, 'ICE') |
---|
161 | if not os.path.exists (TmpDirOCE) : os.mkdir (TmpDirOCE ) |
---|
162 | if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE ) |
---|
163 | |
---|
164 | echo ( f'Working in TMPDIR : {TmpDir}' ) |
---|
165 | |
---|
166 | echo ( f'\nDealing with {L_EXP}' ) |
---|
167 | |
---|
168 | #-- Model output directories |
---|
169 | if Freq == "MO" : FreqDir = os.path.join ('Output' , 'MO' ) |
---|
170 | if Freq == "SE" : FreqDir = os.path.join ('Analyse', 'SE' ) |
---|
171 | dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir ) |
---|
172 | dir_OCE_his = os.path.join ( R_SAVE, "OCE", FreqDir ) |
---|
173 | dir_ICE_his = os.path.join ( R_SAVE, "ICE", FreqDir ) |
---|
174 | dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir ) |
---|
175 | |
---|
176 | echo ( f'The analysis relies on files from the following model output directories : ' ) |
---|
177 | echo ( f'{dir_ATM_his}' ) |
---|
178 | echo ( f'{dir_OCE_his}' ) |
---|
179 | echo ( f'{dir_ICE_his}' ) |
---|
180 | echo ( f'{dir_SRF_his}' ) |
---|
181 | |
---|
182 | #-- Files Names |
---|
183 | if Freq == 'MO' : FileCommon = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M' |
---|
184 | if Freq == 'SE' : FileCommon = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M' |
---|
185 | |
---|
186 | echo ('\nOpen history files' ) |
---|
187 | file_ATM_his = os.path.join ( dir_ATM_his, f'{FileCommon}_histmth.nc' ) |
---|
188 | file_OCE_his = os.path.join ( dir_OCE_his, f'{FileCommon}_grid_T.nc' ) |
---|
189 | file_OCE_sca = os.path.join ( dir_OCE_his, f'{FileCommon}_scalar.nc' ) |
---|
190 | file_ICE_his = os.path.join ( dir_ICE_his, f'{FileCommon}_icemod.nc' ) |
---|
191 | file_SRF_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) |
---|
192 | file_OCE_srf = os.path.join ( dir_OCE_his, f'{FileCommon}_grid_T.nc' ) |
---|
193 | |
---|
194 | d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
195 | d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
196 | d_OCE_sca = xr.open_dataset ( file_OCE_sca, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
197 | d_ICE_his = xr.open_dataset ( file_ICE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
198 | if NEMO == '3.6' :d_ICE_his = d_ICE_his.rename ( {'y_grid_T':'y', 'x_grid_T':'x'} ) |
---|
199 | d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
200 | d_OCE_srf = xr.open_dataset ( file_OCE_srf, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
201 | |
---|
202 | echo ( file_ATM_his ) |
---|
203 | echo ( file_OCE_his ) |
---|
204 | echo ( file_OCE_sca ) |
---|
205 | echo ( file_ICE_his ) |
---|
206 | echo ( file_SRF_his ) |
---|
207 | |
---|
208 | ## Compute run length |
---|
209 | dtime = ( d_ATM_his.time_counter_bounds.max() - d_ATM_his.time_counter_bounds.min() ) |
---|
210 | echo ('\nRun length : {:8.2f} days'.format ( (dtime/np.timedelta64(1, "D")).values ) ) |
---|
211 | dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds |
---|
212 | |
---|
213 | ## Compute length of each period |
---|
214 | dtime_per = (d_ATM_his.time_counter_bounds[:,-1] - d_ATM_his.time_counter_bounds[:,0] ) |
---|
215 | echo ('\nPeriods lengths (days) : {:} days'.format ( (dtime_per/np.timedelta64(1, "D")).values ) ) |
---|
216 | dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds |
---|
217 | dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] ) |
---|
218 | |
---|
219 | #-- Open restart files |
---|
220 | YearRes = YearBegin - 1 # Year of the restart of beginning of simulation |
---|
221 | YearPre = YearBegin - PackFrequency # Year to find the tarfile of the restart of beginning of simulation |
---|
222 | |
---|
223 | echo (f'Restart dates - Start : {YearRes}-12-31 / End : {YearEnd}-12-31 ') |
---|
224 | |
---|
225 | file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' ) |
---|
226 | file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' ) |
---|
227 | |
---|
228 | echo ( f'{file_restart_beg}' ) |
---|
229 | echo ( f'{file_restart_end}' ) |
---|
230 | |
---|
231 | file_OCE_beg = f'OCE_{JobName}_{YearRes}1231_restart.nc' |
---|
232 | file_OCE_end = f'OCE_{JobName}_{YearEnd}1231_restart.nc' |
---|
233 | file_ICE_beg = f'ICE_{JobName}_{YearRes}1231_restart_icemod.nc' |
---|
234 | file_ICE_end = f'ICE_{JobName}_{YearEnd}1231_restart_icemod.nc' |
---|
235 | |
---|
236 | echo ( f'{file_OCE_beg}' ) |
---|
237 | echo ( f'{file_OCE_end}' ) |
---|
238 | echo ( f'{file_ICE_beg}' ) |
---|
239 | echo ( f'{file_ICE_end}' ) |
---|
240 | |
---|
241 | file_ATM_beg = f'ATM_{JobName}_{YearRes}1231_restartphy.nc' |
---|
242 | file_ATM_end = f'ATM_{JobName}_{YearEnd}1231_restartphy.nc' |
---|
243 | if LMDZ : |
---|
244 | file_DYN_beg = f'ATM_{JobName}_{YearRes}1231_restart.nc' |
---|
245 | file_DYN_end = f'ATM_{JobName}_{YearEnd}1231_restart.nc' |
---|
246 | if ICO : |
---|
247 | file_DYN_beg = f'ICO_{JobName}_{YearRes}1231_restart.nc' |
---|
248 | file_DYN_end = f'ICO_{JobName}_{YearEnd}1231_restart.nc' |
---|
249 | file_SRF_beg = f'SRF_{JobName}_{YearRes}1231_sechiba_rest.nc' |
---|
250 | file_SRF_end = f'SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc' |
---|
251 | liste_beg = [file_ATM_beg, file_DYN_beg, file_SRF_beg, ] |
---|
252 | liste_end = [file_ATM_end, file_DYN_end, file_SRF_end, ] |
---|
253 | echo ( f'{file_ATM_beg}') |
---|
254 | echo ( f'{file_ATM_end}') |
---|
255 | echo ( f'{file_SRF_beg}') |
---|
256 | echo ( f'{file_SRF_end}') |
---|
257 | |
---|
258 | if Routing == 'SIMPLE' : |
---|
259 | file_RUN_beg = f'SRF_{JobName}_{YearRes}1231_routing_restart.nc' |
---|
260 | file_RUN_end = f'SRF_{JobName}_{YearEnd}1231_routing_restart.nc' |
---|
261 | liste_beg.append ( file_RUN_beg ) |
---|
262 | liste_end.append ( file_RUN_end ) |
---|
263 | echo ( f'{file_RUN_beg}') |
---|
264 | echo ( f'{file_RUN_end}') |
---|
265 | |
---|
266 | echo ('\nExtract restart files from tar : ATM, ICO and SRF') |
---|
267 | for resFile in liste_beg : |
---|
268 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
269 | command = f'cd {TmpDir} ; tar xf {file_restart_beg} {resFile}' |
---|
270 | echo ( command ) |
---|
271 | os.system ( command ) |
---|
272 | |
---|
273 | for resFile in liste_end : |
---|
274 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
275 | command = f'cd {TmpDir} ; tar xf {file_restart_end} {resFile}' |
---|
276 | echo ( command ) |
---|
277 | os.system ( command ) |
---|
278 | |
---|
279 | echo ('\nOpening ATM SRF and ICO restart files') |
---|
280 | d_ATM_beg = xr.open_dataset ( os.path.join (TmpDir, file_ATM_beg), decode_times=False, decode_cf=True).squeeze() |
---|
281 | d_ATM_end = xr.open_dataset ( os.path.join (TmpDir, file_ATM_end), decode_times=False, decode_cf=True).squeeze() |
---|
282 | d_SRF_beg = xr.open_dataset ( os.path.join (TmpDir, file_SRF_beg), decode_times=False, decode_cf=True).squeeze() |
---|
283 | d_SRF_end = xr.open_dataset ( os.path.join (TmpDir, file_SRF_end), decode_times=False, decode_cf=True).squeeze() |
---|
284 | d_DYN_beg = xr.open_dataset ( os.path.join (TmpDir, file_DYN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
285 | d_DYN_end = xr.open_dataset ( os.path.join (TmpDir, file_DYN_end), decode_times=False, decode_cf=True).squeeze() |
---|
286 | |
---|
287 | for var in d_SRF_beg.variables : |
---|
288 | d_SRF_beg[var] = d_SRF_beg[var].where ( d_SRF_beg[var]<1.e20, 0.) |
---|
289 | d_SRF_end[var] = d_SRF_end[var].where ( d_SRF_end[var]<1.e20, 0.) |
---|
290 | |
---|
291 | if ICO : |
---|
292 | d_RUN_beg = xr.open_dataset ( os.path.join (TmpDir, file_RUN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
293 | d_RUN_end = xr.open_dataset ( os.path.join (TmpDir, file_RUN_end), decode_times=False, decode_cf=True).squeeze() |
---|
294 | |
---|
295 | echo ('\nExtract and rebuild OCE and ICE restarts') |
---|
296 | def get_ndomain (zfile) : |
---|
297 | #d_zfile = xr.open_dataset (zfile, decode_times=False).squeeze() |
---|
298 | #ndomain_opa = d_zfile.attrs['DOMAIN_number_total'] |
---|
299 | #d_zfile.close () |
---|
300 | ndomain_opa = subprocess.getoutput ( f'ls {zfile}_*.nc | wc -l' ).format() |
---|
301 | return int (ndomain_opa) |
---|
302 | |
---|
303 | |
---|
304 | if not os.path.exists ( os.path.join (TmpDir, file_OCE_beg) ) : |
---|
305 | if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart_0000.nc') ): |
---|
306 | command = f'cd {TmpDirOCE} ; tar xf {file_restart_beg} OCE_{JobName}_{YearRes}1231_restart_*.nc' |
---|
307 | echo ( command ) |
---|
308 | os.system ( command ) |
---|
309 | ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart') ) |
---|
310 | command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearRes}1231_restart {ndomain_opa} ; mv {file_OCE_beg} {TmpDir}' |
---|
311 | echo ( command ) |
---|
312 | os.system ( command ) |
---|
313 | echo ( f'Rebuild done : {file_OCE_beg}') |
---|
314 | |
---|
315 | if not os.path.exists ( os.path.join (TmpDir, file_OCE_end) ) : |
---|
316 | if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart_0000.nc') ): |
---|
317 | command = f'cd {TmpDirOCE} ; tar xf {file_restart_end} OCE_{JobName}_{YearEnd}1231_restart_*.nc' |
---|
318 | echo ( command ) |
---|
319 | os.system ( command ) |
---|
320 | ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart') ) |
---|
321 | command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearEnd}1231_restart {ndomain_opa} ; mv {file_OCE_end} {TmpDir}' |
---|
322 | echo ( command ) |
---|
323 | os.system ( command ) |
---|
324 | echo ( f'Rebuild done : {file_OCE_end}') |
---|
325 | |
---|
326 | if not os.path.exists ( os.path.join (TmpDir, file_ICE_beg) ) : |
---|
327 | if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ): |
---|
328 | command = f'cd {TmpDirICE} ; tar xf {file_restart_beg} ICE_{JobName}_{YearRes}1231_restart_icemod_*.nc' |
---|
329 | echo ( command ) |
---|
330 | os.system ( command ) |
---|
331 | ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ) |
---|
332 | command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearRes}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_beg} {TmpDir} ' |
---|
333 | echo ( command ) |
---|
334 | os.system ( command ) |
---|
335 | echo ( f'Rebuild done : {file_OCE_beg}') |
---|
336 | |
---|
337 | if not os.path.exists ( os.path.join (TmpDir, file_ICE_end) ) : |
---|
338 | if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearEnd}1231_restart_icemod') ): |
---|
339 | command = f'cd {TmpDirICE} ; tar xf {file_restart_end} ICE_{JobName}_{YearEnd}1231_restart_icemod_*.nc' |
---|
340 | echo ( command ) |
---|
341 | os.system ( command ) |
---|
342 | ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ) |
---|
343 | command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearEnd}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_end} {TmpDir}' |
---|
344 | echo ( command ) |
---|
345 | os.system ( command ) |
---|
346 | echo ( f'Rebuild done : {file_ICE_end}') |
---|
347 | |
---|
348 | echo ('Opening OCE and ICE restart files') |
---|
349 | if NEMO == 3.6 : |
---|
350 | d_OCE_beg = xr.open_dataset ( os.path.join (TmpDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
351 | d_OCE_end = xr.open_dataset ( os.path.join (TmpDir, file_OCE_end), decode_times=False, decode_cf=True).squeeze() |
---|
352 | d_ICE_beg = xr.open_dataset ( os.path.join (TmpDir, file_ICE_beg), decode_times=False, decode_cf=True).squeeze() |
---|
353 | d_ICE_end = xr.open_dataset ( os.path.join (TmpDir, file_ICE_end), decode_times=False, decode_cf=True).squeeze() |
---|
354 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
355 | d_OCE_beg = xr.open_dataset ( os.path.join (TmpDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
356 | d_OCE_end = xr.open_dataset ( os.path.join (TmpDir, file_OCE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
357 | d_ICE_beg = xr.open_dataset ( os.path.join (TmpDir, file_ICE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
358 | d_ICE_end = xr.open_dataset ( os.path.join (TmpDir, file_ICE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
359 | |
---|
360 | echo ( file_ATM_beg ) |
---|
361 | echo ( file_ATM_end ) |
---|
362 | echo ( file_DYN_beg ) |
---|
363 | echo ( file_DYN_end ) |
---|
364 | echo ( file_SRF_beg ) |
---|
365 | echo ( file_SRF_end ) |
---|
366 | if Routing == 'SIMPLE' : |
---|
367 | echo ( file_RUN_beg ) |
---|
368 | echo ( file_RUN_end ) |
---|
369 | echo ( file_OCE_beg ) |
---|
370 | echo ( file_OCE_end ) |
---|
371 | echo ( file_ICE_beg ) |
---|
372 | echo ( file_ICE_end ) |
---|
373 | |
---|
374 | def ATM_stock_int (stock) : |
---|
375 | '''Integrate stock on atmosphere grid''' |
---|
376 | ATM_stock_int = np.sum ( np.sort ( (stock * DYN_aire).to_masked_array().ravel()) ) |
---|
377 | return ATM_stock_int |
---|
378 | |
---|
379 | def OCE_stock_int (stock) : |
---|
380 | '''Integrate stock on ocean grid''' |
---|
381 | OCE_stock_int = np.sum ( np.sort ( (stock * OCE_aire).to_masked_array().ravel()) ) |
---|
382 | return OCE_stock_int |
---|
383 | |
---|
384 | def ONE_stock_int (stock) : |
---|
385 | '''Sum stock for field already integrated by cell''' |
---|
386 | ONE_stock_int = np.sum ( np.sort ( (stock).to_masked_array().ravel()) ) |
---|
387 | return ONE_stock_int |
---|
388 | |
---|
389 | # ATM grid with cell surfaces |
---|
390 | # ATM grid with cell surfaces |
---|
391 | if ICO : |
---|
392 | jpja, jpia = d_ATM_his['aire'][0].shape |
---|
393 | file_ATM_aire = os.path.join ( R_IN, 'ATM', 'GRID', f'aire_{ATM}_to_{jpia}x{jpja}.nc' ) |
---|
394 | d_ATM_aire = xr.open_dataset ( file_ATM_aire, decode_times=False ).squeeze() |
---|
395 | ATM_aire = lmdz.geo2point ( d_ATM_aire ['aire'].squeeze(), cumulPoles=True ) |
---|
396 | ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] ) |
---|
397 | ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] + d_ATM_his ['fract_lic'][0] ) |
---|
398 | SRF_aire = lmdz.geo2point ( d_SRF_his ['Areas'] * d_SRF_his ['Contfrac'] ) |
---|
399 | |
---|
400 | if LMDZ : |
---|
401 | ATM_aire = lmdz.geo2point ( d_ATM_his ['aire'][0], cumulPoles=True ) |
---|
402 | ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] ) |
---|
403 | ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] ) |
---|
404 | SRF_aire = lmdz.geo2point ( d_SRF_his ['Areas'] * d_SRF_his ['Contfrac'] ) |
---|
405 | |
---|
406 | if ICO : |
---|
407 | # Area on icosahedron grid |
---|
408 | file_DYN_aire = os.path.join ( R_IN, 'ATM', 'GRID', ATM+'_grid.nc' ) |
---|
409 | d_DYN_aire = xr.open_dataset ( file_DYN_aire, decode_times=False).squeeze() |
---|
410 | d_DYN_aire = d_DYN_aire.rename ( {'cell':'cell_mesh'} ) |
---|
411 | DYN_aire = d_DYN_aire['aire'] |
---|
412 | |
---|
413 | DYN_fsea = d_DYN_aire ['fract_oce'] + d_DYN_aire ['fract_sic'] |
---|
414 | DYN_flnd = 1.0 - DYN_fsea |
---|
415 | |
---|
416 | if LMDZ : |
---|
417 | DYN_aire = ATM_aire |
---|
418 | DYN_fsea = ATM_fsea |
---|
419 | DYN_flnd = ATM_flnd |
---|
420 | |
---|
421 | #if LMDZ : |
---|
422 | # d_ATM_beg = d_ATM_beg.assign ( coords={'lon':d_ATM_beg.lon*180./np.pi} ) |
---|
423 | |
---|
424 | # Get mask and surfaces |
---|
425 | sos = d_OCE_his ['sos'][0].squeeze() |
---|
426 | OCE_msk = nemo.lbc_mask ( xr.where ( sos>0, 1., 0.0 ), cd_type = 'T' ) |
---|
427 | so = sos = d_OCE_his ['sos'][0].squeeze() |
---|
428 | OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0. ) |
---|
429 | |
---|
430 | # lbc_mask removes the duplicate points (periodicity and north fold) |
---|
431 | OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', sval = 0.0 ) |
---|
432 | ICE_aire = OCE_aire |
---|
433 | |
---|
434 | ATM_aire_tot = ONE_stock_int (ATM_aire) |
---|
435 | SRF_aire_tot = ONE_stock_int (SRF_aire) |
---|
436 | OCE_aire_tot = ONE_stock_int (OCE_aire) |
---|
437 | ICE_aire_tot = ONE_stock_int (ICE_aire) |
---|
438 | |
---|
439 | ATM_aire_sea = ATM_aire * ATM_fsea |
---|
440 | ATM_aire_sea_tot = ONE_stock_int ( ATM_aire_sea ) |
---|
441 | |
---|
442 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
443 | echo ( '-- NEMO change in stores (for the records)' ) |
---|
444 | #-- Note that the total number of days of the run should be diagnosed rather than assumed |
---|
445 | #-- Here the result is in Sv |
---|
446 | # |
---|
447 | #-- Change in ocean volume in freshwater equivalent |
---|
448 | |
---|
449 | OCE_ssh_beg = d_OCE_beg['sshn'] |
---|
450 | OCE_ssh_end = d_OCE_end['sshn'] |
---|
451 | OCE_sum_ssh_beg = OCE_stock_int ( OCE_ssh_beg ) |
---|
452 | OCE_sum_ssh_end = OCE_stock_int ( OCE_ssh_end ) |
---|
453 | |
---|
454 | OCE_mas_wat_beg = OCE_sum_ssh_beg * OCE_rho_liq |
---|
455 | OCE_mas_wat_end = OCE_sum_ssh_end * OCE_rho_liq |
---|
456 | |
---|
457 | echo ( 'OCE_sum_ssh_beg = {:12.6e} m^3 | OCE_sum_ssh_end = {:12.6e} m^3'.format (OCE_sum_ssh_beg, OCE_sum_ssh_end) ) |
---|
458 | dOCE_vol_liq = ( OCE_sum_ssh_end - OCE_sum_ssh_beg ) |
---|
459 | dOCE_mas_liq = dOCE_vol_liq * OCE_rho_liq |
---|
460 | dOCE_mas_wat = dOCE_mas_liq |
---|
461 | |
---|
462 | echo ( 'dOCE vol = {:12.3e} m^3'.format (dOCE_vol_liq) ) |
---|
463 | echo ( 'dOCE ssh = {:12.3e} m '.format (dOCE_vol_liq/OCE_aire_tot) ) |
---|
464 | echo ( 'dOCE mass = {:12.3e} kg '.format (dOCE_mas_liq) ) |
---|
465 | echo ( 'dOCE mass = {:12.3e} Sv '.format (dOCE_mas_liq/dtime_sec*1E-6/OCE_rho_liq) ) |
---|
466 | |
---|
467 | ## Glace et neige |
---|
468 | if NEMO == 3.6 : |
---|
469 | ICE_ice_beg = d_ICE_beg['v_i_htc1']+d_ICE_beg['v_i_htc2']+d_ICE_beg['v_i_htc3']+d_ICE_beg['v_i_htc4']+d_ICE_beg['v_i_htc5'] |
---|
470 | ICE_ice_end = d_ICE_end['v_i_htc1']+d_ICE_end['v_i_htc2']+d_ICE_end['v_i_htc3']+d_ICE_end['v_i_htc4']+d_ICE_end['v_i_htc5'] |
---|
471 | |
---|
472 | ICE_sno_beg = d_ICE_beg['v_s_htc1']+d_ICE_beg['v_s_htc2']+d_ICE_beg['v_s_htc3']+d_ICE_beg['v_s_htc4']+d_ICE_beg['v_s_htc5'] |
---|
473 | ICE_sno_end = d_ICE_end['v_s_htc1']+d_ICE_end['v_s_htc2']+d_ICE_end['v_s_htc3']+d_ICE_end['v_s_htc4']+d_ICE_end['v_s_htc5'] |
---|
474 | |
---|
475 | ICE_pnd_beg = 0.0 ; ICE_pnd_end = 0.0 |
---|
476 | ICE_fzl_beg = 0.0 ; ICE_fzl_end = 0.0 |
---|
477 | |
---|
478 | ICE_mas_wat_beg = OCE_stock_int ( (ICE_ice_beg*ICE_rho_ice + ICE_sno_beg*ICE_rho_sno) ) |
---|
479 | ICE_mas_wat_end = OCE_stock_int ( (ICE_ice_end*ICE_rho_ice + ICE_sno_end*ICE_rho_sno) ) |
---|
480 | |
---|
481 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
482 | ICE_ice_beg = d_ICE_beg ['v_i'] ; ICE_ice_end = d_ICE_end ['v_i'] |
---|
483 | ICE_sno_beg = d_ICE_beg ['v_s'] ; ICE_sno_end = d_ICE_end ['v_s'] |
---|
484 | ICE_pnd_beg = d_ICE_beg ['v_ip'] ; ICE_pnd_end = d_ICE_end ['v_ip'] |
---|
485 | ICE_fzl_beg = d_ICE_beg ['v_il'] ; ICE_fzl_end = d_ICE_end ['v_il'] |
---|
486 | |
---|
487 | ICE_mas_wat_beg = OCE_stock_int ( d_ICE_beg['snwice_mass'] ) |
---|
488 | ICE_mas_wat_end = OCE_stock_int ( d_ICE_end['snwice_mass'] ) |
---|
489 | |
---|
490 | |
---|
491 | ICE_vol_ice_beg = OCE_stock_int ( ICE_ice_beg ) |
---|
492 | ICE_vol_ice_end = OCE_stock_int ( ICE_ice_end ) |
---|
493 | |
---|
494 | ICE_vol_sno_beg = OCE_stock_int ( ICE_sno_beg ) |
---|
495 | ICE_vol_sno_end = OCE_stock_int ( ICE_sno_end ) |
---|
496 | |
---|
497 | ICE_vol_pnd_beg = OCE_stock_int ( ICE_pnd_beg ) |
---|
498 | ICE_vol_pnd_end = OCE_stock_int ( ICE_pnd_end ) |
---|
499 | |
---|
500 | ICE_vol_fzl_beg = OCE_stock_int ( ICE_fzl_beg ) |
---|
501 | ICE_vol_fzl_end = OCE_stock_int ( ICE_fzl_end ) |
---|
502 | |
---|
503 | #-- Converting to freswater volume |
---|
504 | dICE_vol_ice = ICE_vol_ice_end - ICE_vol_ice_beg |
---|
505 | dICE_mas_ice = dICE_vol_ice * ICE_rho_ice |
---|
506 | |
---|
507 | dICE_vol_sno = ICE_vol_sno_end - ICE_vol_sno_beg |
---|
508 | dICE_mas_sno = dICE_vol_sno * ICE_rho_sno |
---|
509 | |
---|
510 | dICE_vol_pnd = ICE_vol_pnd_end - ICE_vol_pnd_beg |
---|
511 | dICE_mas_pnd = dICE_vol_pnd * ICE_rho_pnd |
---|
512 | |
---|
513 | dICE_vol_fzl= ICE_vol_fzl_end - ICE_vol_fzl_beg |
---|
514 | dICE_mas_fzl = dICE_vol_fzl * ICE_rho_pnd |
---|
515 | |
---|
516 | if NEMO == 3.6 : |
---|
517 | dICE_mas_wat = dICE_mas_ice + dICE_mas_sno |
---|
518 | dSEA_mas_wat = dOCE_mas_wat + dICE_mas_ice + dICE_mas_sno |
---|
519 | |
---|
520 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
521 | dICE_mas_wat = ICE_mas_wat_end - ICE_mas_wat_beg |
---|
522 | dSEA_mas_wat = dOCE_mas_wat + dICE_mas_wat |
---|
523 | |
---|
524 | echo ( 'ICE_vol_ice_beg = {:12.6e} m^3 | ICE_vol_ice_end = {:12.6e} m^3'.format (ICE_vol_ice_beg, ICE_vol_ice_end) ) |
---|
525 | echo ( 'ICE_vol_sno_beg = {:12.6e} m^3 | ICE_vol_sno_end = {:12.6e} m^3'.format (ICE_vol_sno_beg, ICE_vol_sno_end) ) |
---|
526 | echo ( 'ICE_vol_pnd_beg = {:12.6e} m^3 | ICE_vol_pnd_end = {:12.6e} m^3'.format (ICE_vol_pnd_beg, ICE_vol_pnd_end) ) |
---|
527 | echo ( 'ICE_vol_fzl_beg = {:12.6e} m^3 | ICE_vol_fzl_end = {:12.6e} m^3'.format (ICE_vol_fzl_beg, ICE_vol_fzl_end) ) |
---|
528 | |
---|
529 | echo ( 'dICE_vol_ice = {:12.3e} m^3'.format (dICE_vol_ice) ) |
---|
530 | echo ( 'dICE_vol_sno = {:12.3e} m^3'.format (dICE_vol_sno) ) |
---|
531 | echo ( 'dICE_vol_pnd = {:12.3e} m^3'.format (dICE_vol_pnd) ) |
---|
532 | echo ( 'dICE_mas_ice = {:12.3e} m^3'.format (dICE_mas_ice) ) |
---|
533 | echo ( 'dICE_mas_sno = {:12.3e} m^3'.format (dICE_mas_sno) ) |
---|
534 | echo ( 'dICE_mas_pnd = {:12.3e} m^3'.format (dICE_mas_pnd) ) |
---|
535 | echo ( 'dICE_mas_fzl = {:12.3e} m^3'.format (dICE_mas_fzl) ) |
---|
536 | echo ( 'dICE_mas_wat = {:12.3e} m^3'.format (dICE_mas_wat) ) |
---|
537 | |
---|
538 | |
---|
539 | SEA_mas_wat_beg = OCE_mas_wat_beg + ICE_mas_wat_beg |
---|
540 | SEA_mas_wat_end = OCE_mas_wat_end + ICE_mas_wat_end |
---|
541 | |
---|
542 | echo ( '\n------------------------------------------------------------') |
---|
543 | echo ( 'Variation du contenu en eau ocean + glace ' ) |
---|
544 | echo ( 'dMass (ocean) = {:12.6e} kg '.format(dSEA_mas_wat) ) |
---|
545 | echo ( 'dVol (ocean) = {:12.3e} Sv '.format(dSEA_mas_wat/dtime_sec*1E-6/OCE_rho_liq) ) |
---|
546 | echo ( 'dVol (ocean) = {:12.3e} m '.format(dSEA_mas_wat*1E-3/OCE_aire_tot) ) |
---|
547 | |
---|
548 | |
---|
549 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
550 | echo ( '-- ATM changes in stores ' ) |
---|
551 | |
---|
552 | #-- Change in precipitable water from the atmosphere daily and monthly files |
---|
553 | #-- Compute sum weighted by gridcell area (kg/m2) then convert to Sv |
---|
554 | |
---|
555 | # ATM vertical grid |
---|
556 | ATM_Ahyb = d_ATM_his['Ahyb'].squeeze() |
---|
557 | ATM_Bhyb = d_ATM_his['Bhyb'].squeeze() |
---|
558 | klevp1 = ATM_Ahyb.shape[0] |
---|
559 | |
---|
560 | # Surface pressure |
---|
561 | if ICO : |
---|
562 | DYN_ps_beg = d_DYN_beg['ps'] |
---|
563 | DYN_ps_end = d_DYN_end['ps'] |
---|
564 | |
---|
565 | if LMDZ : |
---|
566 | DYN_ps_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) ) |
---|
567 | DYN_ps_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) ) |
---|
568 | |
---|
569 | # 3D Pressure |
---|
570 | DYN_p_beg = ATM_Ahyb + ATM_Bhyb * DYN_ps_beg |
---|
571 | DYN_p_end = ATM_Ahyb + ATM_Bhyb * DYN_ps_end |
---|
572 | |
---|
573 | # Layer thickness |
---|
574 | DYN_sigma_beg = DYN_p_beg[0:-1]*0. |
---|
575 | DYN_sigma_end = DYN_p_end[0:-1]*0. |
---|
576 | |
---|
577 | for k in np.arange (klevp1-1) : |
---|
578 | DYN_sigma_beg[k,:] = (DYN_p_beg[k,:] - DYN_p_beg[k+1,:]) / grav |
---|
579 | DYN_sigma_end[k,:] = (DYN_p_end[k,:] - DYN_p_end[k+1,:]) / grav |
---|
580 | |
---|
581 | DYN_sigma_beg = DYN_sigma_beg.rename ( {'klevp1':'sigs'} ) |
---|
582 | DYN_sigma_end = DYN_sigma_end.rename ( {'klevp1':'sigs'} ) |
---|
583 | |
---|
584 | ##-- Vertical and horizontal integral, and sum of liquid, solid and vapor water phases |
---|
585 | if LMDZ : |
---|
586 | try : |
---|
587 | DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2Ov'] + d_DYN_beg['H2Ol'] + d_DYN_beg['H2Oi']).isel(rlonv=slice(0,-1) ) ) |
---|
588 | DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2Ov'] + d_DYN_end['H2Ol'] + d_DYN_end['H2Oi']).isel(rlonv=slice(0,-1) ) ) |
---|
589 | except : |
---|
590 | DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2O_g'] + d_DYN_beg['H2O_l'] + d_DYN_beg['H2O_s']).isel(rlonv=slice(0,-1) ) ) |
---|
591 | DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2O_g'] + d_DYN_end['H2O_l'] + d_DYN_end['H2O_s']).isel(rlonv=slice(0,-1) ) ) |
---|
592 | if ICO : |
---|
593 | try : |
---|
594 | DYN_wat_beg = (d_DYN_beg['H2O_g'] + d_DYN_beg['H2O_l'] + d_DYN_beg['H2O_s']).rename ( {'lev':'sigs'} ) |
---|
595 | DYN_wat_end = (d_DYN_end['H2O_g'] + d_DYN_end['H2O_l'] + d_DYN_end['H2O_s']).rename ( {'lev':'sigs'} ) |
---|
596 | except : |
---|
597 | DYN_wat_beg = (d_DYN_beg['q'].isel(nq=0) + d_DYN_beg['q'].isel(nq=1) + d_DYN_beg['q'].isel(nq=2) ).rename ( {'lev':'sigs'} ) |
---|
598 | DYN_wat_end = (d_DYN_end['q'].isel(nq=0) + d_DYN_end['q'].isel(nq=1) + d_DYN_end['q'].isel(nq=2) ).rename ( {'lev':'sigs'} ) |
---|
599 | |
---|
600 | DYN_mas_wat_beg = ATM_stock_int (DYN_sigma_beg * DYN_wat_beg) |
---|
601 | DYN_mas_wat_end = ATM_stock_int (DYN_sigma_end * DYN_wat_end) |
---|
602 | |
---|
603 | dDYN_mas_wat = DYN_mas_wat_end - DYN_mas_wat_beg |
---|
604 | |
---|
605 | echo ( '\nVariation du contenu en eau atmosphere (dynamique) ' ) |
---|
606 | echo ( 'DYN_mas_beg = {:12.6e} kg | DYN_mas_end = {:12.6e} kg'.format (DYN_mas_wat_beg, DYN_mas_wat_end) ) |
---|
607 | echo ( 'dMass (atm) = {:12.3e} kg '.format (dDYN_mas_wat) ) |
---|
608 | echo ( 'dMass (atm) = {:12.3e} Sv '.format (dDYN_mas_wat/dtime_sec*1.e-6/ATM_rho) ) |
---|
609 | echo ( 'dMass (atm) = {:12.3e} m '.format (dDYN_mas_wat/ATM_aire_sea_tot/ATM_rho) ) |
---|
610 | |
---|
611 | ATM_sno_beg = d_ATM_beg['SNOW01']*d_ATM_beg['FTER']+d_ATM_beg['SNOW02']*d_ATM_beg['FLIC']+d_ATM_beg['SNOW03']*d_ATM_beg['FOCE']+d_ATM_beg['SNOW04']*d_ATM_beg['FSIC'] |
---|
612 | ATM_sno_end = d_ATM_end['SNOW01']*d_ATM_end['FTER']+d_ATM_end['SNOW02']*d_ATM_end['FLIC']+d_ATM_end['SNOW03']*d_ATM_end['FOCE']+d_ATM_end['SNOW04']*d_ATM_end['FSIC'] |
---|
613 | |
---|
614 | ATM_qs_beg = d_ATM_beg['QS01']*d_ATM_beg['FTER']+d_ATM_beg['QS02']*d_ATM_beg['FLIC']+d_ATM_beg['QS03']*d_ATM_beg['FOCE']+d_ATM_beg['QS04']*d_ATM_beg['FSIC'] |
---|
615 | ATM_qs_end = d_ATM_end['QS01']*d_ATM_end['FTER']+d_ATM_end['QS02']*d_ATM_end['FLIC']+d_ATM_end['QS03']*d_ATM_end['FOCE']+d_ATM_end['QS04']*d_ATM_end['FSIC'] |
---|
616 | |
---|
617 | ATM_qsol_beg = d_ATM_beg['QSOL'] |
---|
618 | ATM_qsol_end = d_ATM_end['QSOL'] |
---|
619 | |
---|
620 | ATM_qs01_beg = d_ATM_beg['QS01'] * d_ATM_beg['FTER'] |
---|
621 | ATM_qs01_end = d_ATM_end['QS01'] * d_ATM_end['FTER'] |
---|
622 | ATM_qs02_beg = d_ATM_beg['QS02'] * d_ATM_beg['FLIC'] |
---|
623 | ATM_qs02_end = d_ATM_end['QS02'] * d_ATM_end['FLIC'] |
---|
624 | ATM_qs03_beg = d_ATM_beg['QS03'] * d_ATM_beg['FOCE'] |
---|
625 | ATM_qs03_end = d_ATM_end['QS03'] * d_ATM_end['FOCE'] |
---|
626 | ATM_qs04_beg = d_ATM_beg['QS04'] * d_ATM_beg['FSIC'] |
---|
627 | ATM_qs04_end = d_ATM_end['QS04'] * d_ATM_end['FSIC'] |
---|
628 | |
---|
629 | if ICO : |
---|
630 | ATM_sno_beg = ATM_sno_beg .rename ( {'points_physiques':'cell_mesh'} ) |
---|
631 | ATM_sno_end = ATM_sno_end .rename ( {'points_physiques':'cell_mesh'} ) |
---|
632 | ATM_qs_beg = ATM_qs_beg .rename ( {'points_physiques':'cell_mesh'} ) |
---|
633 | ATM_qs_end = ATM_qs_end .rename ( {'points_physiques':'cell_mesh'} ) |
---|
634 | ATM_qsol_beg = ATM_qsol_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
635 | ATM_qsol_end = ATM_qsol_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
636 | ATM_qs01_beg = ATM_qs01_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
637 | ATM_qs01_end = ATM_qs01_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
638 | ATM_qs02_beg = ATM_qs02_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
639 | ATM_qs02_end = ATM_qs02_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
640 | ATM_qs03_beg = ATM_qs03_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
641 | ATM_qs03_end = ATM_qs03_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
642 | ATM_qs04_beg = ATM_qs04_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
643 | ATM_qs04_end = ATM_qs04_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
644 | |
---|
645 | echo ('Computing atmosphere integrals') |
---|
646 | ATM_mas_sno_beg = ATM_stock_int ( ATM_sno_beg ) |
---|
647 | ATM_mas_sno_end = ATM_stock_int ( ATM_sno_end ) |
---|
648 | ATM_mas_qs_beg = ATM_stock_int ( ATM_qs_beg ) |
---|
649 | ATM_mas_qs_end = ATM_stock_int ( ATM_qs_end ) |
---|
650 | ATM_mas_qsol_beg = ATM_stock_int ( ATM_qsol_beg ) |
---|
651 | ATM_mas_qsol_end = ATM_stock_int ( ATM_qsol_end ) |
---|
652 | ATM_mas_qs01_beg = ATM_stock_int ( ATM_qs01_beg ) |
---|
653 | ATM_mas_qs01_end = ATM_stock_int ( ATM_qs01_end ) |
---|
654 | ATM_mas_qs02_beg = ATM_stock_int ( ATM_qs02_beg ) |
---|
655 | ATM_mas_qs02_end = ATM_stock_int ( ATM_qs02_end ) |
---|
656 | ATM_mas_qs03_beg = ATM_stock_int ( ATM_qs03_beg ) |
---|
657 | ATM_mas_qs03_end = ATM_stock_int ( ATM_qs03_end ) |
---|
658 | ATM_mas_qs04_beg = ATM_stock_int ( ATM_qs04_beg ) |
---|
659 | ATM_mas_qs04_end = ATM_stock_int ( ATM_qs04_end ) |
---|
660 | |
---|
661 | dATM_mas_sno = ATM_mas_sno_end - ATM_mas_sno_beg |
---|
662 | dATM_mas_qs = ATM_mas_qs_end - ATM_mas_qs_beg |
---|
663 | dATM_mas_qsol = ATM_mas_qsol_end - ATM_mas_qsol_beg |
---|
664 | |
---|
665 | dATM_mas_qs01 = ATM_mas_qs01_end - ATM_mas_qs01_beg |
---|
666 | dATM_mas_qs02 = ATM_mas_qs02_end - ATM_mas_qs02_beg |
---|
667 | dATM_mas_qs03 = ATM_mas_qs03_end - ATM_mas_qs03_beg |
---|
668 | dATM_mas_qs04 = ATM_mas_qs04_end - ATM_mas_qs04_beg |
---|
669 | |
---|
670 | echo ( '\nVariation du contenu en neige atmosphere (calottes)' ) |
---|
671 | echo ( 'ATM_mas_sno_beg = {:12.6e} kg | ATM_mas_sno_end = {:12.6e} kg'.format (ATM_mas_sno_beg, ATM_mas_sno_end) ) |
---|
672 | echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_sno ) ) |
---|
673 | echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_sno/dtime_sec*1e-6/ICE_rho_ice) ) |
---|
674 | echo ( 'dMass (neige atm) = {:12.3e} m '.format (dATM_mas_sno/ATM_aire_sea_tot/ATM_rho) ) |
---|
675 | |
---|
676 | echo ( '\nVariation du contenu humidite du sol' ) |
---|
677 | echo ( 'ATM_mas_qs_beg = {:12.6e} kg | ATM_mas_qs_end = {:12.6e} kg'.format (ATM_mas_qs_beg, ATM_mas_qs_end) ) |
---|
678 | echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_qs ) ) |
---|
679 | echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_qs/dtime_sec*1e-6/ATM_rho) ) |
---|
680 | echo ( 'dMass (neige atm) = {:12.3e} m '.format (dATM_mas_qs/ATM_aire_sea_tot/ATM_rho) ) |
---|
681 | |
---|
682 | echo ( '\nVariation du contenu en eau+neige atmosphere ' ) |
---|
683 | echo ( 'dMass (eau + neige atm) = {:12.3e} kg '.format ( dDYN_mas_wat + dATM_mas_sno) ) |
---|
684 | echo ( 'dMass (eau + neige atm) = {:12.3e} Sv '.format ( (dDYN_mas_wat + dATM_mas_sno)/dtime_sec*1E-6/ATM_rho) ) |
---|
685 | echo ( 'dMass (eau + neige atm) = {:12.3e} m '.format ( (dDYN_mas_wat + dATM_mas_sno)/ATM_aire_sea_tot/ATM_rho) ) |
---|
686 | |
---|
687 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
688 | echo ( '-- SRF changes ' ) |
---|
689 | |
---|
690 | if Routing == 'SIMPLE' : |
---|
691 | RUN_mas_wat_beg = ONE_stock_int ( d_RUN_beg ['fast_reservoir'] + d_RUN_beg ['slow_reservoir'] + d_RUN_beg ['stream_reservoir']) |
---|
692 | RUN_mas_wat_end = ONE_stock_int ( d_RUN_end ['fast_reservoir'] + d_RUN_end ['slow_reservoir'] + d_RUN_end ['stream_reservoir']) |
---|
693 | |
---|
694 | if Routing == 'SECHIBA' : |
---|
695 | RUN_mas_wat_beg = ONE_stock_int ( d_SRF_beg['fastres'] + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \ |
---|
696 | + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres'] ) |
---|
697 | RUN_mas_wat_end = ONE_stock_int ( d_SRF_end['fastres'] + d_SRF_end['slowres'] + d_SRF_end['streamres'] \ |
---|
698 | + d_SRF_end['floodres'] + d_SRF_end['lakeres'] + d_SRF_end['pondres'] ) |
---|
699 | |
---|
700 | dRUN_mas_wat = RUN_mas_wat_end - RUN_mas_wat_beg |
---|
701 | |
---|
702 | echo ( '\nWater content in routing ' ) |
---|
703 | echo ( 'RUN_mas_wat_beg = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_end, RUN_mas_wat_end) ) |
---|
704 | echo ( 'dMass (routing) = {:12.3e} kg '.format(dRUN_mas_wat) ) |
---|
705 | echo ( 'dMass (routing) = {:12.3e} Sv '.format(dRUN_mas_wat/dtime_sec*1E-9) ) |
---|
706 | echo ( 'dMass (routing) = {:12.3e} m '.format(dRUN_mas_wat/OCE_aire_tot*1E-3) ) |
---|
707 | |
---|
708 | print ('Reading SRF restart') |
---|
709 | tot_watveg_beg = d_SRF_beg['tot_watveg_beg'] ; tot_watveg_beg = tot_watveg_beg .where (tot_watveg_beg < 1E10, 0.) |
---|
710 | tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; tot_watsoil_beg = tot_watsoil_beg.where (tot_watsoil_beg< 1E10, 0.) |
---|
711 | snow_beg = d_SRF_beg['snow_beg'] ; snow_beg = snow_beg .where (snow_beg < 1E10, 0.) |
---|
712 | |
---|
713 | tot_watveg_end = d_SRF_end['tot_watveg_beg'] ; tot_watveg_end = tot_watveg_end .where (tot_watveg_end < 1E10, 0.) |
---|
714 | tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; tot_watsoil_end = tot_watsoil_end.where (tot_watsoil_end< 1E10, 0.) |
---|
715 | snow_end = d_SRF_end['snow_beg'] ; snow_end = snow_end .where (snow_end < 1E10, 0.) |
---|
716 | |
---|
717 | if LMDZ : |
---|
718 | tot_watveg_beg = lmdz.geo2point (tot_watveg_beg) |
---|
719 | tot_watsoil_beg = lmdz.geo2point (tot_watsoil_beg) |
---|
720 | snow_beg = lmdz.geo2point (snow_beg) |
---|
721 | tot_watveg_end = lmdz.geo2point (tot_watveg_end) |
---|
722 | tot_watsoil_end = lmdz.geo2point (tot_watsoil_end) |
---|
723 | snow_end = lmdz.geo2point (snow_end) |
---|
724 | |
---|
725 | SRF_wat_beg = tot_watveg_beg + tot_watsoil_beg + snow_beg |
---|
726 | SRF_wat_end = tot_watveg_end + tot_watsoil_end + snow_end |
---|
727 | |
---|
728 | #SRF_mas_wat_beg = d_SRF_beg['tot_watveg_beg']+d_SRF_beg['tot_watsoil_beg'] + d_SRF_beg['snow_beg'] |
---|
729 | #SRF_mas_wat_end = d_SRF_end['tot_watveg_beg']+d_SRF_end['tot_watsoil_beg'] + d_SRF_end['snow_beg'] |
---|
730 | |
---|
731 | #if LMDZ : |
---|
732 | # tot_watveg_beg = tot_watveg_beg .rename ( {'y':'points_phyiques'} ) |
---|
733 | # tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'points_phyiques'} ) |
---|
734 | # snow_beg = snow_beg .rename ( {'y':'points_phyiques'} ) |
---|
735 | # tot_watveg_end = tot_watveg_end .rename ( {'y':'points_phyiques'} ) |
---|
736 | # tot_watsoil_end = tot_watsoil_end.rename ( {'y':'points_phyiques'} ) |
---|
737 | # snow_end = snow_end .rename ( {'y':'points_phyiques'} ) |
---|
738 | # SRF_wat_beg = SRF_wat_beg .rename ( {'y':'points_phyiques'} ) |
---|
739 | # SRF_wat_end = SRF_wat_end .rename ( {'y':'points_phyiques'} ) |
---|
740 | if ICO : |
---|
741 | tot_watveg_beg = tot_watveg_beg .rename ( {'y':'cell_mesh'} ) |
---|
742 | tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'cell_mesh'} ) |
---|
743 | snow_beg = snow_beg .rename ( {'y':'cell_mesh'} ) |
---|
744 | tot_watveg_end = tot_watveg_end .rename ( {'y':'cell_mesh'} ) |
---|
745 | tot_watsoil_end = tot_watsoil_end.rename ( {'y':'cell_mesh'} ) |
---|
746 | snow_end = snow_end .rename ( {'y':'cell_mesh'} ) |
---|
747 | SRF_wat_beg = SRF_wat_beg .rename ( {'y':'cell_mesh'} ) |
---|
748 | SRF_wat_end = SRF_wat_end .rename ( {'y':'cell_mesh'} ) |
---|
749 | |
---|
750 | print ('Computing integrals') |
---|
751 | |
---|
752 | print ( ' 1/6', end='' ) ; sys.stdout.flush () |
---|
753 | SRF_mas_watveg_beg = ATM_stock_int ( tot_watveg_beg ) |
---|
754 | print ( ' 2/6', end='' ) ; sys.stdout.flush () |
---|
755 | SRF_mas_watsoil_beg = ATM_stock_int ( tot_watsoil_beg ) |
---|
756 | print ( ' 3/6', end='' ) ; sys.stdout.flush () |
---|
757 | SRF_mas_snow_beg = ATM_stock_int ( snow_beg ) |
---|
758 | print ( ' 4/6', end='' ) ; sys.stdout.flush () |
---|
759 | SRF_mas_watveg_end = ATM_stock_int ( tot_watveg_end ) |
---|
760 | print ( ' 5/6', end='' ) ; sys.stdout.flush () |
---|
761 | SRF_mas_watsoil_end = ATM_stock_int ( tot_watsoil_end ) |
---|
762 | print ( ' 6/6', end='' ) ; sys.stdout.flush () |
---|
763 | SRF_mas_snow_end = ATM_stock_int ( snow_end ) |
---|
764 | print (' -- ') ; sys.stdout.flush () |
---|
765 | |
---|
766 | dSRF_mas_watveg = SRF_mas_watveg_end - SRF_mas_watveg_beg |
---|
767 | dSRF_mas_watsoil = SRF_mas_watsoil_end - SRF_mas_watsoil_beg |
---|
768 | dSRF_mas_snow = SRF_mas_snow_end - SRF_mas_snow_beg |
---|
769 | |
---|
770 | echo ('\nLes differents reservoirs') |
---|
771 | echo ( 'SRF_mas_watveg_beg = {:12.6e} kg | SRF_mas_watveg_end = {:12.6e} kg '.format (SRF_mas_watveg_beg , SRF_mas_watveg_end) ) |
---|
772 | echo ( 'SRF_mas_watsoil_beg = {:12.6e} kg | SRF_mas_watsoil_end = {:12.6e} kg '.format (SRF_mas_watsoil_beg, SRF_mas_watsoil_end) ) |
---|
773 | echo ( 'SRF_mas_snow_beg = {:12.6e} kg | SRF_mas_snow_end = {:12.6e} kg '.format (SRF_mas_snow_beg , SRF_mas_snow_end) ) |
---|
774 | |
---|
775 | echo ( 'dMass (watveg) = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_watveg , dSRF_mas_watveg /dtime_sec*1E-9, dSRF_mas_watveg /OCE_aire_tot*1E-3) ) |
---|
776 | echo ( 'dMass (watsoil) = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_watsoil, dSRF_mas_watsoil/dtime_sec*1E-9, dSRF_mas_watsoil/OCE_aire_tot*1E-3) ) |
---|
777 | echo ( 'dMass (sno) = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_snow , dSRF_mas_snow /dtime_sec*1E-9, dSRF_mas_snow /OCE_aire_tot*1E-3 ) ) |
---|
778 | |
---|
779 | SRF_mas_wat_beg = SRF_mas_watveg_beg + SRF_mas_watsoil_beg + SRF_mas_snow_beg |
---|
780 | SRF_mas_wat_end = SRF_mas_watveg_end + SRF_mas_watsoil_end + SRF_mas_snow_end |
---|
781 | dSRF_mas_wat = SRF_mas_wat_end - SRF_mas_wat_beg |
---|
782 | |
---|
783 | echo ( '\nWater content in surface ' ) |
---|
784 | echo ( 'SRF_mas_wat_beg = {:12.6e} kg | SRF_mas_wat_end = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) ) |
---|
785 | echo ( 'dMass (water srf) = {:12.3e} kg '.format (dSRF_mas_wat) ) |
---|
786 | echo ( 'dMass (water srf) = {:12.3e} Sv '.format (dSRF_mas_wat/dtime_sec*1E-6/ATM_rho) ) |
---|
787 | echo ( 'dMass (water srf) = {:12.3e} m '.format (dSRF_mas_wat/ATM_aire_sea_tot/ATM_rho) ) |
---|
788 | |
---|
789 | echo ( '\nWater content in ATM + SRF + RUN ' ) |
---|
790 | echo ( 'mas_wat_beg = {:12.6e} kg | mas_wat_end = {:12.6e} kg '. |
---|
791 | format (DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg, |
---|
792 | DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) ) |
---|
793 | echo ( 'dMass (water atm+srf+run) = {:12.6e} kg '.format ( dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat) ) |
---|
794 | echo ( 'dMass (water atm+srf+run) = {:12.3e} Sv '.format ((dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/dtime_sec*1E-6/ATM_rho) ) |
---|
795 | echo ( 'dMass (water atm+srf+run) = {:12.3e} m '.format ((dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/ATM_aire_sea_tot/ATM_rho) ) |
---|
796 | |
---|
797 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
798 | echo ( '-- Change in all components' ) |
---|
799 | echo ( 'mas_wat_beg = {:12.6e} kg | mas_wat_end = {:12.6e} kg'. |
---|
800 | format (SEA_mas_wat_beg + DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg, |
---|
801 | SEA_mas_wat_end + DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) ) |
---|
802 | echo ( 'dMass (water CPL) = {:12.3e} kg '.format ( dSEA_mas_wat + dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat) ) |
---|
803 | echo ( 'dMass (water CPL) = {:12.3e} Sv '.format ((dSEA_mas_wat + dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/dtime_sec*1E-9) ) |
---|
804 | echo ( 'dMass (water CPL) = {:12.3e} m '.format ((dSEA_mas_wat + dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/OCE_aire_tot*1E-3) ) |
---|
805 | |
---|
806 | |
---|