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 | ## Define Experiment |
---|
23 | if False : |
---|
24 | JobName="TEST-CM72-SIMPLE-ROUTING.12" ; TagName="IPSLCM7" ; SpaceName="DEVT" ; ExperimentName="piControl" ; User="p86caub" ; Project="gencmip6" |
---|
25 | Freq = 'MO' ; YearBegin = 1970 ; YearEnd = 1979 ; PackFrequency = 10 |
---|
26 | ORCA = 'eORCA1.2' ; NEMO=3.6 ; OCE_relax = False ; OCE_icb = False |
---|
27 | ATM = 'ICO40' ; Routing = 'SIMPLE' |
---|
28 | |
---|
29 | if False : |
---|
30 | JobName="TEST-CM72-SIMPLE-ROUTING.10" ; TagName="IPSLCM7" ; SpaceName="DEVT" ; ExperimentName="piControl" ; User="p86caub" ; Project="gencmip6" |
---|
31 | Freq = 'MO' ; YearBegin = 1860 ; YearEnd = 1869 ; PackFrequency = 10 |
---|
32 | ORCA = 'eORCA1.2' ; ATM = 'ICO40' ; Routing = 'SIMPLE' ; NEMO=3.6 ; OCE_relax = False ; OCE_icb = False |
---|
33 | |
---|
34 | if False : |
---|
35 | JobName="VALID-CM622-LR.01" ; TagName="IPSLCM6" ; SpaceName="DEVT" ; ExperimentName="piControl" ; User="p86caub" ; Project="gencmip6" |
---|
36 | Freq = 'MO' ; YearBegin = 1890 ; YearEnd = 1899 ; PackFrequency = 10 |
---|
37 | ORCA = 'eORCA1.2' ; ATM = 'LMD144142' ; Routing = 'ORCHIDEE' ; NEMO=3.6 ; OCE_relax = False ; OCE_icb = False |
---|
38 | |
---|
39 | if True : |
---|
40 | JobName="CM65v420-LR-SKL-pi-05" ; TagName="IPSLCM6" ; SpaceName="DEVT" ; ExperimentName="piControl" ; User="p48ethe" ; Project="gencmip6" |
---|
41 | #Freq = 'MO' ; YearBegin = 1890 ; YearEnd = 1899 ; PackFrequency = 10 |
---|
42 | Freq = 'MO' ; YearBegin = 2340 ; YearEnd = 2349 ; PackFrequency = 10 |
---|
43 | ORCA = 'eORCA1.2' ; ATM = 'LMD144142' ; Routing = 'ORCHIDEE' ; NEMO=4.2 ; OCE_relax = False ; OCE_icb = False ; Coupled = True |
---|
44 | |
---|
45 | Coupled = True |
---|
46 | |
---|
47 | import numpy as np |
---|
48 | ##-- Some physical constants |
---|
49 | #-- Earth Radius |
---|
50 | Ra = 40.e6 / (2. * np.pi) |
---|
51 | #-- Gravity |
---|
52 | g = 9.81 |
---|
53 | #-- Ice density (kg/m3) in LIM3 |
---|
54 | ICE_rho_ice = 917.0 |
---|
55 | #-- Snow density (kg/m3) in LIM3 |
---|
56 | ICE_rho_sno = 330.0 |
---|
57 | #-- Ocean water density (kg/m3) in NEMO |
---|
58 | OCE_rho_liq = 1026. |
---|
59 | #-- Water density in ice pounds in SI3 |
---|
60 | ICE_rho_pnd = 1000. |
---|
61 | |
---|
62 | ### |
---|
63 | ICO = False |
---|
64 | if 'ICO' in ATM : ICO = True |
---|
65 | LMDZ = False |
---|
66 | if 'LMD' in ATM : LMDZ = True |
---|
67 | |
---|
68 | ### |
---|
69 | ## Import system modules |
---|
70 | import sys, os, shutil, subprocess |
---|
71 | |
---|
72 | # Where do we run ? |
---|
73 | TGCC = False ; IDRIS = False |
---|
74 | SysName, NodeName, Release, Version, Machine = os.uname() |
---|
75 | if 'irene' in NodeName : TGCC = True |
---|
76 | if 'jeanzay' in NodeName : IDRIS = True |
---|
77 | |
---|
78 | ## Set site specific libIGCM directories, and other specific stuff |
---|
79 | if TGCC : |
---|
80 | CPU = subprocess.getoutput ( 'lscpu | grep "Model name"' ) |
---|
81 | if "Intel(R) Xeon(R) Platinum" in CPU : Machine = 'irene' |
---|
82 | if "AMD" in CPU : Machine = 'irene-amd' |
---|
83 | |
---|
84 | ARCHIVE = subprocess.getoutput ( f'ccc_home --cccstore -d {Project} -u {User}' ) |
---|
85 | STORAGE = subprocess.getoutput ( f'ccc_home --cccwork -d {Project} -u {User}' ) |
---|
86 | SCRATCHDIR = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' ) |
---|
87 | R_IN = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM') |
---|
88 | rebuild = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' ) |
---|
89 | |
---|
90 | ## Specific to run at TGCC. |
---|
91 | # Needed before importing a NetCDF library (netCDF4, xarray, cmds, etc ...) |
---|
92 | import mpi4py |
---|
93 | mpi4py.rc.initialize = False |
---|
94 | |
---|
95 | ## Creates output directory |
---|
96 | #TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
97 | TmpDir = os.path.join ( '/ccc/scratch/cont003/drf/p86mart', f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
98 | |
---|
99 | if IDRIS : |
---|
100 | raise Exception("Pour IDRIS : repertoires et chemins a definir") |
---|
101 | |
---|
102 | ## Import specific module |
---|
103 | import nemo, lmdz |
---|
104 | ## Now import needed scientific modules |
---|
105 | import xarray as xr |
---|
106 | |
---|
107 | # Output file |
---|
108 | FileOut = f'CPL_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out' |
---|
109 | f_out = open ( FileOut, mode = 'w' ) |
---|
110 | |
---|
111 | # Function to print to stdout *and* output file |
---|
112 | def echo (string) : |
---|
113 | print ( string ) |
---|
114 | f_out.write ( string + '\n' ) |
---|
115 | f_out.flush () |
---|
116 | return None |
---|
117 | |
---|
118 | ## Set libIGCM directories |
---|
119 | R_OUT = os.path.join ( ARCHIVE , 'IGCM_OUT') |
---|
120 | R_BUF = os.path.join ( SCRATCHDIR, 'IGCM_OUT') |
---|
121 | |
---|
122 | L_EXP = os.path.join (TagName, SpaceName, ExperimentName, JobName) |
---|
123 | R_SAVE = os.path.join ( R_OUT, L_EXP ) |
---|
124 | R_BUFR = os.path.join ( R_BUF, L_EXP ) |
---|
125 | POST_DIR = os.path.join ( R_BUF, L_EXP, 'Out' ) |
---|
126 | REBUILD_DIR = os.path.join ( R_BUF, L_EXP, 'REBUILD' ) |
---|
127 | R_BUF_KSH = os.path.join ( R_BUFR, 'Out' ) |
---|
128 | R_FIGR = os.path.join ( STORAGE, 'IGCM_OUT', L_EXP ) |
---|
129 | |
---|
130 | #if os.path.isdir (TmpDir) : shutil.rmtree ( TmpDir ) |
---|
131 | if not os.path.isdir (TmpDir) : os.mkdir (TmpDir) |
---|
132 | TmpDirOCE = os.path.join (TmpDir, 'OCE') |
---|
133 | TmpDirICE = os.path.join (TmpDir, 'ICE') |
---|
134 | if not os.path.exists (TmpDirOCE) : os.mkdir (TmpDirOCE ) |
---|
135 | if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE ) |
---|
136 | |
---|
137 | echo ( f'Working in TMPDIR : {TmpDir}' ) |
---|
138 | |
---|
139 | echo ( f'\nDealing with {L_EXP}' ) |
---|
140 | |
---|
141 | #-- Model output directories |
---|
142 | if Freq == "MO" : FreqDir = os.path.join ('Output' , 'MO' ) |
---|
143 | if Freq == "SE" : FreqDir = os.path.join ('Analyse', 'SE' ) |
---|
144 | dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir ) |
---|
145 | dir_OCE_his = os.path.join ( R_SAVE, "OCE", FreqDir ) |
---|
146 | dir_ICE_his = os.path.join ( R_SAVE, "ICE", FreqDir ) |
---|
147 | dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir ) |
---|
148 | |
---|
149 | echo ( f'The analysis relies on files from the following model output directories : ' ) |
---|
150 | echo ( f'{dir_ATM_his}' ) |
---|
151 | echo ( f'{dir_OCE_his}' ) |
---|
152 | echo ( f'{dir_ICE_his}' ) |
---|
153 | echo ( f'{dir_SRF_his}' ) |
---|
154 | |
---|
155 | #-- Files Names |
---|
156 | if Freq == 'MO' : File = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M' |
---|
157 | if Freq == 'SE' : File = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M' |
---|
158 | |
---|
159 | echo ('\nOpen history files' ) |
---|
160 | file_ATM_his = os.path.join ( dir_ATM_his, f'{File}_histmth.nc' ) |
---|
161 | file_OCE_his = os.path.join ( dir_OCE_his, f'{File}_grid_T.nc' ) |
---|
162 | file_OCE_sca = os.path.join ( dir_OCE_his, f'{File}_scalar.nc' ) |
---|
163 | file_ICE_his = os.path.join ( dir_ICE_his, f'{File}_icemod.nc' ) |
---|
164 | file_SRF_his = os.path.join ( dir_SRF_his, f'{File}_sechiba_history.nc' ) |
---|
165 | file_OCE_srf = os.path.join ( dir_OCE_his, f'{File}_grid_T.nc' ) |
---|
166 | |
---|
167 | d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
168 | d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
169 | d_OCE_sca = xr.open_dataset ( file_OCE_sca, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
170 | d_ICE_his = xr.open_dataset ( file_ICE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
171 | if NEMO == 3.6 :d_ICE_his = d_ICE_his.rename ( {'y_grid_T':'y', 'x_grid_T':'x'} ) |
---|
172 | d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
173 | d_OCE_srf = xr.open_dataset ( file_OCE_srf, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
174 | |
---|
175 | echo ( file_ATM_his ) |
---|
176 | echo ( file_OCE_his ) |
---|
177 | echo ( file_OCE_sca ) |
---|
178 | echo ( file_ICE_his ) |
---|
179 | echo ( file_SRF_his ) |
---|
180 | |
---|
181 | ## Compute run length |
---|
182 | dtime = ( d_ATM_his.time_counter_bounds.max() - d_ATM_his.time_counter_bounds.min() ) |
---|
183 | echo ('\nRun length : {:8.2f} days'.format ( (dtime/np.timedelta64(1, "D")).values ) ) |
---|
184 | dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds |
---|
185 | |
---|
186 | ## Compute length of each period |
---|
187 | dtime_per = (d_ATM_his.time_counter_bounds[:,-1] - d_ATM_his.time_counter_bounds[:,0] ) |
---|
188 | echo ('\nPeriods lengths (days) : {:} days'.format ( (dtime_per/np.timedelta64(1, "D")).values ) ) |
---|
189 | dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds |
---|
190 | dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] ) |
---|
191 | |
---|
192 | #-- Open restart files |
---|
193 | YearRes = YearBegin - 1 # Year of the restart of beginning of simulation |
---|
194 | YearPre = YearBegin - PackFrequency # Year to find the tarfile of the restart of beginning of simulation |
---|
195 | |
---|
196 | echo (f'Restart dates - Start : {YearRes}-12-31 / End : {YearEnd}-12-31 ') |
---|
197 | |
---|
198 | file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' ) |
---|
199 | file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' ) |
---|
200 | |
---|
201 | echo ( f'{file_restart_beg}' ) |
---|
202 | echo ( f'{file_restart_end}' ) |
---|
203 | |
---|
204 | file_OCE_beg = f'OCE_{JobName}_{YearRes}1231_restart.nc' |
---|
205 | file_OCE_end = f'OCE_{JobName}_{YearEnd}1231_restart.nc' |
---|
206 | file_ICE_beg = f'ICE_{JobName}_{YearRes}1231_restart_icemod.nc' |
---|
207 | file_ICE_end = f'ICE_{JobName}_{YearEnd}1231_restart_icemod.nc' |
---|
208 | |
---|
209 | echo ( f'{file_OCE_beg}' ) |
---|
210 | echo ( f'{file_OCE_end}' ) |
---|
211 | echo ( f'{file_ICE_beg}' ) |
---|
212 | echo ( f'{file_ICE_end}' ) |
---|
213 | |
---|
214 | file_ATM_beg = f'ATM_{JobName}_{YearRes}1231_restartphy.nc' |
---|
215 | file_ATM_end = f'ATM_{JobName}_{YearEnd}1231_restartphy.nc' |
---|
216 | if LMDZ : |
---|
217 | file_DYN_beg = f'ATM_{JobName}_{YearRes}1231_restart.nc' |
---|
218 | file_DYN_end = f'ATM_{JobName}_{YearEnd}1231_restart.nc' |
---|
219 | if ICO : |
---|
220 | file_DYN_beg = f'ICO_{JobName}_{YearRes}1231_restart.nc' |
---|
221 | file_DYN_end = f'ICO_{JobName}_{YearEnd}1231_restart.nc' |
---|
222 | file_SRF_beg = f'SRF_{JobName}_{YearRes}1231_sechiba_rest.nc' |
---|
223 | file_SRF_end = f'SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc' |
---|
224 | liste_beg = [file_ATM_beg, file_DYN_beg, file_SRF_beg, ] |
---|
225 | liste_end = [file_ATM_end, file_DYN_end, file_SRF_end, ] |
---|
226 | echo ( f'{file_ATM_beg}') |
---|
227 | echo ( f'{file_ATM_end}') |
---|
228 | echo ( f'{file_SRF_beg}') |
---|
229 | echo ( f'{file_SRF_end}') |
---|
230 | |
---|
231 | if Routing == 'SIMPLE' : |
---|
232 | file_RUN_beg = f'SRF_{JobName}_{YearRes}1231_routing_restart.nc' |
---|
233 | file_RUN_end = f'SRF_{JobName}_{YearEnd}1231_routing_restart.nc' |
---|
234 | liste_beg.append ( file_RUN_beg ) |
---|
235 | liste_end.append ( file_RUN_end ) |
---|
236 | echo ( f'{file_RUN_beg}') |
---|
237 | echo ( f'{file_RUN_end}') |
---|
238 | |
---|
239 | echo ('\nExtract restart files from tar : ATM, ICO and SRF') |
---|
240 | for resFile in liste_beg : |
---|
241 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
242 | command = f'cd {TmpDir} ; tar xf {file_restart_beg} {resFile}' |
---|
243 | echo ( command ) |
---|
244 | os.system ( command ) |
---|
245 | |
---|
246 | for resFile in liste_end : |
---|
247 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
248 | command = f'cd {TmpDir} ; tar xf {file_restart_end} {resFile}' |
---|
249 | echo ( command ) |
---|
250 | os.system ( command ) |
---|
251 | |
---|
252 | echo ('\nOpening ATM SRF and ICO restart files') |
---|
253 | d_ATM_beg = xr.open_dataset ( os.path.join (TmpDir, file_ATM_beg), decode_times=False, decode_cf=True).squeeze() |
---|
254 | d_ATM_end = xr.open_dataset ( os.path.join (TmpDir, file_ATM_end), decode_times=False, decode_cf=True).squeeze() |
---|
255 | d_SRF_beg = xr.open_dataset ( os.path.join (TmpDir, file_SRF_beg), decode_times=False, decode_cf=True).squeeze() |
---|
256 | d_SRF_end = xr.open_dataset ( os.path.join (TmpDir, file_SRF_end), decode_times=False, decode_cf=True).squeeze() |
---|
257 | d_DYN_beg = xr.open_dataset ( os.path.join (TmpDir, file_DYN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
258 | d_DYN_end = xr.open_dataset ( os.path.join (TmpDir, file_DYN_end), decode_times=False, decode_cf=True).squeeze() |
---|
259 | |
---|
260 | for var in d_SRF_beg.variables : |
---|
261 | #d_SRF_beg[var].attrs['_FillValue'] = 1.e20 |
---|
262 | #d_SRF_end[var].attrs['_FillValue'] = 1.e20 |
---|
263 | d_SRF_beg[var] = d_SRF_beg[var].where ( d_SRF_beg[var]<1.e20, 0.) |
---|
264 | d_SRF_end[var] = d_SRF_end[var].where ( d_SRF_end[var]<1.e20, 0.) |
---|
265 | |
---|
266 | if ICO : |
---|
267 | d_RUN_beg = xr.open_dataset ( os.path.join (TmpDir, file_RUN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
268 | d_RUN_end = xr.open_dataset ( os.path.join (TmpDir, file_RUN_end), decode_times=False, decode_cf=True).squeeze() |
---|
269 | |
---|
270 | echo ('\nExtract and rebuild OCE and ICE restarts') |
---|
271 | def get_ndomain (zfile) : |
---|
272 | #d_zfile = xr.open_dataset (zfile, decode_times=False).squeeze() |
---|
273 | #ndomain_opa = d_zfile.attrs['DOMAIN_number_total'] |
---|
274 | #d_zfile.close () |
---|
275 | ndomain_opa = subprocess.getoutput ( f'ls {zfile}_*.nc | wc -l' ).format() |
---|
276 | return int (ndomain_opa) |
---|
277 | |
---|
278 | |
---|
279 | if not os.path.exists ( os.path.join (TmpDir, file_OCE_beg) ) : |
---|
280 | if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart_0000.nc') ): |
---|
281 | command = f'cd {TmpDirOCE} ; tar xf {file_restart_beg} OCE_{JobName}_{YearRes}1231_restart_*.nc' |
---|
282 | echo ( command ) |
---|
283 | os.system ( command ) |
---|
284 | ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart') ) |
---|
285 | command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearRes}1231_restart {ndomain_opa} ; mv {file_OCE_beg} {TmpDir}' |
---|
286 | echo ( command ) |
---|
287 | os.system ( command ) |
---|
288 | echo ( f'Rebuild done : {file_OCE_beg}') |
---|
289 | |
---|
290 | if not os.path.exists ( os.path.join (TmpDir, file_OCE_end) ) : |
---|
291 | if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart_0000.nc') ): |
---|
292 | command = f'cd {TmpDirOCE} ; tar xf {file_restart_end} OCE_{JobName}_{YearEnd}1231_restart_*.nc' |
---|
293 | echo ( command ) |
---|
294 | os.system ( command ) |
---|
295 | ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart') ) |
---|
296 | command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearEnd}1231_restart {ndomain_opa} ; mv {file_OCE_end} {TmpDir}' |
---|
297 | echo ( command ) |
---|
298 | os.system ( command ) |
---|
299 | echo ( f'Rebuild done : {file_OCE_end}') |
---|
300 | |
---|
301 | if not os.path.exists ( os.path.join (TmpDir, file_ICE_beg) ) : |
---|
302 | if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ): |
---|
303 | command = f'cd {TmpDirICE} ; tar xf {file_restart_beg} ICE_{JobName}_{YearRes}1231_restart_icemod_*.nc' |
---|
304 | echo ( command ) |
---|
305 | os.system ( command ) |
---|
306 | ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ) |
---|
307 | command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearRes}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_beg} {TmpDir} ' |
---|
308 | echo ( command ) |
---|
309 | os.system ( command ) |
---|
310 | echo ( f'Rebuild done : {file_OCE_beg}') |
---|
311 | |
---|
312 | if not os.path.exists ( os.path.join (TmpDir, file_ICE_end) ) : |
---|
313 | if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearEnd}1231_restart_icemod') ): |
---|
314 | command = f'cd {TmpDirICE} ; tar xf {file_restart_end} ICE_{JobName}_{YearEnd}1231_restart_icemod_*.nc' |
---|
315 | echo ( command ) |
---|
316 | os.system ( command ) |
---|
317 | ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') ) |
---|
318 | command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearEnd}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_end} {TmpDir}' |
---|
319 | echo ( command ) |
---|
320 | os.system ( command ) |
---|
321 | echo ( f'Rebuild done : {file_ICE_end}') |
---|
322 | |
---|
323 | echo ('Opening OCE and ICE restart files') |
---|
324 | if NEMO == 3.6 : |
---|
325 | d_OCE_beg = xr.open_dataset ( os.path.join (TmpDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
326 | d_OCE_end = xr.open_dataset ( os.path.join (TmpDir, file_OCE_end), decode_times=False, decode_cf=True).squeeze() |
---|
327 | d_ICE_beg = xr.open_dataset ( os.path.join (TmpDir, file_ICE_beg), decode_times=False, decode_cf=True).squeeze() |
---|
328 | d_ICE_end = xr.open_dataset ( os.path.join (TmpDir, file_ICE_end), decode_times=False, decode_cf=True).squeeze() |
---|
329 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
330 | d_OCE_beg = xr.open_dataset ( os.path.join (TmpDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
331 | d_OCE_end = xr.open_dataset ( os.path.join (TmpDir, file_OCE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
332 | d_ICE_beg = xr.open_dataset ( os.path.join (TmpDir, file_ICE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
333 | d_ICE_end = xr.open_dataset ( os.path.join (TmpDir, file_ICE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
334 | |
---|
335 | echo ( file_ATM_beg ) |
---|
336 | echo ( file_ATM_end ) |
---|
337 | echo ( file_DYN_beg ) |
---|
338 | echo ( file_DYN_end ) |
---|
339 | echo ( file_SRF_beg ) |
---|
340 | echo ( file_SRF_end ) |
---|
341 | if Routing == 'SIMPLE' : |
---|
342 | echo ( file_RUN_beg ) |
---|
343 | echo ( file_RUN_end ) |
---|
344 | echo ( file_OCE_beg ) |
---|
345 | echo ( file_OCE_end ) |
---|
346 | echo ( file_ICE_beg ) |
---|
347 | echo ( file_ICE_end ) |
---|
348 | |
---|
349 | # ATM grid with cell surfaces |
---|
350 | if ICO : |
---|
351 | ATM_aire = d_ATM_his ['aire'][0] |
---|
352 | ATM_fsea = d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] |
---|
353 | ATM_flnd = d_ATM_his ['fract_ter'][0] + d_ATM_his ['fract_lic'][0] |
---|
354 | |
---|
355 | if LMDZ : |
---|
356 | ATM_aire = lmdz.geo2point ( d_ATM_his ['aire'][0], cumulPoles=True ) |
---|
357 | ATM_aire2 = lmdz.geo2point ( d_ATM_his ['aire'][0], cumulPoles=False ) |
---|
358 | ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] ) |
---|
359 | ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] ) |
---|
360 | #ATM_aire[0] = np.sum ( d_ATM_his ['aire'][0, 0] ) |
---|
361 | #ATM_aire[-1] = np.sum ( d_ATM_his ['aire'][0,-1] ) |
---|
362 | |
---|
363 | SRF_aire = ATM_aire * ATM_flnd |
---|
364 | |
---|
365 | if ICO : |
---|
366 | # Area on icosahedron grid |
---|
367 | file_DYN_aire = os.path.join ( R_IN, 'ATM', 'GRID', ATM+'_grid.nc' ) |
---|
368 | d_DYN_aire = xr.open_dataset ( file_DYN_aire, decode_times=False).squeeze() |
---|
369 | d_DYN_aire = d_DYN_aire.rename ( {'cell':'cell_mesh'} ) |
---|
370 | DYN_aire = d_DYN_aire['aire'] |
---|
371 | |
---|
372 | DYN_fsea = d_DYN_aire ['fract_oce'] + d_DYN_aire ['fract_sic'] |
---|
373 | DYN_flnd = 1.0 - DYN_fsea |
---|
374 | |
---|
375 | if LMDZ : |
---|
376 | DYN_aire = ATM_aire |
---|
377 | DYN_fsea = ATM_fsea |
---|
378 | DYN_flnd = ATM_flnd |
---|
379 | |
---|
380 | #if LMDZ : |
---|
381 | # d_ATM_beg = d_ATM_beg.assign ( coords={'lon':d_ATM_beg.lon*180./np.pi} ) |
---|
382 | |
---|
383 | # Get mask and surfaces |
---|
384 | sos = d_OCE_his ['sos'][0].squeeze() |
---|
385 | OCE_msk = nemo.lbc_mask ( xr.where ( sos>0, 1., 0.0 ), cd_type = 'T' ) |
---|
386 | so = sos = d_OCE_his ['sos'][0].squeeze() |
---|
387 | OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0. ) |
---|
388 | |
---|
389 | #so = d_OCE_beg ['so'].squeeze() |
---|
390 | #OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0. ) |
---|
391 | #OCE_msk = OCE_msk3[0] |
---|
392 | |
---|
393 | # lbc_mask removes the duplicate points (periodicity and north fold) |
---|
394 | OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', sval = 0.0 ) |
---|
395 | ICE_aire = OCE_aire |
---|
396 | |
---|
397 | ATM_aire_tot = np.sum (ATM_aire).values.item() |
---|
398 | OCE_aire_tot = np.sum (OCE_aire).values.item() |
---|
399 | ICE_aire_tot = np.sum (ICE_aire).values.item() |
---|
400 | |
---|
401 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
402 | echo ( '-- NEMO change in stores (for the records)' ) |
---|
403 | #-- Note that the total number of days of the run should be diagnosed rather than assumed |
---|
404 | #-- Here the result is in Sv |
---|
405 | # |
---|
406 | #-- Change in ocean volume in freshwater equivalent |
---|
407 | |
---|
408 | OCE_ssh_beg = d_OCE_beg['sshn'] |
---|
409 | OCE_ssh_end = d_OCE_end['sshn'] |
---|
410 | OCE_sum_ssh_beg = np.sum ( OCE_ssh_beg * OCE_aire ).values.item() |
---|
411 | OCE_sum_ssh_end = np.sum ( OCE_ssh_end * OCE_aire ).values.item() |
---|
412 | |
---|
413 | OCE_mas_wat_beg = OCE_sum_ssh_beg * OCE_rho_liq |
---|
414 | OCE_mas_wat_end = OCE_sum_ssh_end * OCE_rho_liq |
---|
415 | |
---|
416 | 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) ) |
---|
417 | dOCE_vol_liq = ( OCE_sum_ssh_end - OCE_sum_ssh_beg ) |
---|
418 | dOCE_mas_liq = dOCE_vol_liq * OCE_rho_liq |
---|
419 | dOCE_mas_wat = dOCE_mas_liq |
---|
420 | |
---|
421 | echo ( 'dOCE vol = {:12.3e} m^3'.format (dOCE_vol_liq) ) |
---|
422 | echo ( 'dOCE ssh = {:12.3e} m '.format (dOCE_vol_liq/OCE_aire_tot) ) |
---|
423 | echo ( 'dOCE mass = {:12.3e} kg '.format (dOCE_mas_liq) ) |
---|
424 | echo ( 'dOCE mass = {:12.3e} Sv '.format (dOCE_mas_liq/dtime_sec*1E-6/OCE_rho_liq) ) |
---|
425 | |
---|
426 | ## Glace et neige |
---|
427 | if NEMO == 3.6 : |
---|
428 | 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'] |
---|
429 | 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'] |
---|
430 | |
---|
431 | 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'] |
---|
432 | 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'] |
---|
433 | |
---|
434 | ICE_pnd_beg = 0.0 ; ICE_pnd_end = 0.0 |
---|
435 | ICE_fzl_beg = 0.0 ; ICE_fzl_end = 0.0 |
---|
436 | |
---|
437 | ICE_mas_wat_beg = np.sum ( (ICE_ice_beg*ICE_rho_ice + ICE_sno_beg*ICE_rho_sno)*ICE_aire ).values.item() |
---|
438 | ICE_mas_wat_end = np.sum ( (ICE_ice_end*ICE_rho_ice + ICE_sno_end*ICE_rho_sno)*ICE_aire ).values.item() |
---|
439 | |
---|
440 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
441 | ICE_ice_beg = d_ICE_beg ['v_i'] ; ICE_ice_end = d_ICE_end ['v_i'] |
---|
442 | ICE_sno_beg = d_ICE_beg ['v_s'] ; ICE_sno_end = d_ICE_end ['v_s'] |
---|
443 | ICE_pnd_beg = d_ICE_beg ['v_ip'] ; ICE_pnd_end = d_ICE_end ['v_ip'] |
---|
444 | ICE_fzl_beg = d_ICE_beg ['v_il'] ; ICE_fzl_end = d_ICE_end ['v_il'] |
---|
445 | |
---|
446 | ICE_mas_wat_beg = np.sum ( d_ICE_beg['snwice_mass']*ICE_aire ).values.item() |
---|
447 | ICE_mas_wat_end = np.sum ( d_ICE_end['snwice_mass']*ICE_aire ).values.item() |
---|
448 | |
---|
449 | |
---|
450 | ICE_vol_ice_beg = np.sum ( ICE_ice_beg*ICE_aire ).values.item() |
---|
451 | ICE_vol_ice_end = np.sum ( ICE_ice_end*ICE_aire ).values.item() |
---|
452 | |
---|
453 | ICE_vol_sno_beg = np.sum ( ICE_sno_beg*ICE_aire ).values.item() |
---|
454 | ICE_vol_sno_end = np.sum ( ICE_sno_end*ICE_aire ).values.item() |
---|
455 | |
---|
456 | ICE_vol_pnd_beg = np.sum ( ICE_pnd_beg*ICE_aire ).values.item() |
---|
457 | ICE_vol_pnd_end = np.sum ( ICE_pnd_end*ICE_aire ).values.item() |
---|
458 | |
---|
459 | ICE_vol_fzl_beg = np.sum ( ICE_fzl_beg*ICE_aire ).values.item() |
---|
460 | ICE_vol_fzl_end = np.sum ( ICE_fzl_end*ICE_aire ).values.item() |
---|
461 | |
---|
462 | #-- Converting to freswater volume |
---|
463 | dICE_vol_ice = ICE_vol_ice_end - ICE_vol_ice_beg |
---|
464 | dICE_mas_ice = dICE_vol_ice * ICE_rho_ice |
---|
465 | |
---|
466 | dICE_vol_sno = ICE_vol_sno_end - ICE_vol_sno_beg |
---|
467 | dICE_mas_sno = dICE_vol_sno * ICE_rho_sno |
---|
468 | |
---|
469 | dICE_vol_pnd = ICE_vol_pnd_end - ICE_vol_pnd_beg |
---|
470 | dICE_mas_pnd = dICE_vol_pnd * ICE_rho_pnd |
---|
471 | |
---|
472 | dICE_vol_fzl= ICE_vol_fzl_end - ICE_vol_fzl_beg |
---|
473 | dICE_mas_fzl = dICE_vol_fzl * ICE_rho_pnd |
---|
474 | |
---|
475 | if NEMO == 3.6 : |
---|
476 | dICE_mas_wat = dICE_mas_ice + dICE_mas_sno |
---|
477 | dSEA_mas_wat = dOCE_mas_wat + dICE_mas_ice + dICE_mas_sno |
---|
478 | |
---|
479 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
480 | dICE_mas_wat = ICE_mas_wat_end - ICE_mas_wat_beg |
---|
481 | dSEA_mas_wat = dOCE_mas_wat + dICE_mas_wat |
---|
482 | |
---|
483 | 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) ) |
---|
484 | 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) ) |
---|
485 | 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) ) |
---|
486 | 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) ) |
---|
487 | |
---|
488 | echo ( 'dICE_vol_ice = {:12.3e} m^3'.format (dICE_vol_ice) ) |
---|
489 | echo ( 'dICE_vol_sno = {:12.3e} m^3'.format (dICE_vol_sno) ) |
---|
490 | echo ( 'dICE_vol_pnd = {:12.3e} m^3'.format (dICE_vol_pnd) ) |
---|
491 | echo ( 'dICE_mas_ice = {:12.3e} m^3'.format (dICE_mas_ice) ) |
---|
492 | echo ( 'dICE_mas_sno = {:12.3e} m^3'.format (dICE_mas_sno) ) |
---|
493 | echo ( 'dICE_mas_pnd = {:12.3e} m^3'.format (dICE_mas_pnd) ) |
---|
494 | echo ( 'dICE_mas_fzl = {:12.3e} m^3'.format (dICE_mas_fzl) ) |
---|
495 | echo ( 'dICE_mas_wat = {:12.3e} m^3'.format (dICE_mas_wat) ) |
---|
496 | |
---|
497 | |
---|
498 | SEA_mas_wat_beg = OCE_mas_wat_beg + ICE_mas_wat_beg |
---|
499 | SEA_mas_wat_end = OCE_mas_wat_end + ICE_mas_wat_end |
---|
500 | |
---|
501 | echo ( '\n------------------------------------------------------------') |
---|
502 | echo ( 'Variation du contenu en eau ocean + glace ' ) |
---|
503 | echo ( 'dMass(ocean) = {:12.6e} kg '.format(dSEA_mas_wat) ) |
---|
504 | echo ( 'dVol (ocean) = {:12.3e} Sv '.format(dSEA_mas_wat/dtime_sec*1E-6/OCE_rho_liq) ) |
---|
505 | echo ( 'dVol (ocean) = {:12.3e} m '.format(dSEA_mas_wat*1E-3/OCE_aire_tot) ) |
---|
506 | |
---|
507 | |
---|
508 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
509 | echo ( '-- ATM changes in stores ' ) |
---|
510 | |
---|
511 | #-- Change in precipitable water from the atmosphere daily and monthly files |
---|
512 | #-- Compute sum weighted by gridcell area (kg/m2) then convert to Sv |
---|
513 | |
---|
514 | # ATM vertical grid |
---|
515 | ATM_Ahyb = d_ATM_his['Ahyb'].squeeze() |
---|
516 | ATM_Bhyb = d_ATM_his['Bhyb'].squeeze() |
---|
517 | klevp1 = ATM_Ahyb.shape[0] |
---|
518 | |
---|
519 | # Surface pressure |
---|
520 | if ICO : |
---|
521 | DYN_ps_beg = d_DYN_beg['ps'] |
---|
522 | DYN_ps_end = d_DYN_end['ps'] |
---|
523 | |
---|
524 | if LMDZ : |
---|
525 | DYN_ps_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) ) |
---|
526 | DYN_ps_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) ) |
---|
527 | |
---|
528 | # 3D Pressure |
---|
529 | DYN_p_beg = ATM_Ahyb + ATM_Bhyb * DYN_ps_beg |
---|
530 | DYN_p_end = ATM_Ahyb + ATM_Bhyb * DYN_ps_end |
---|
531 | |
---|
532 | # Layer thickness |
---|
533 | DYN_sigma_beg = DYN_p_beg[0:-1]*0. |
---|
534 | DYN_sigma_end = DYN_p_end[0:-1]*0. |
---|
535 | |
---|
536 | for k in np.arange (klevp1-1) : |
---|
537 | DYN_sigma_beg[k,:] = (DYN_p_beg[k,:] - DYN_p_beg[k+1,:]) / g |
---|
538 | DYN_sigma_end[k,:] = (DYN_p_end[k,:] - DYN_p_end[k+1,:]) / g |
---|
539 | |
---|
540 | DYN_sigma_beg = DYN_sigma_beg.rename ( {'klevp1':'sigs'} ) |
---|
541 | DYN_sigma_end = DYN_sigma_end.rename ( {'klevp1':'sigs'} ) |
---|
542 | |
---|
543 | ##-- Vertical and horizontal integral, and sum of liquid, solid and vapor water phases |
---|
544 | if LMDZ : |
---|
545 | try : |
---|
546 | DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2Ov'] + d_DYN_beg['H2Ol'] + d_DYN_beg['H2Oi']).isel(rlonv=slice(0,-1) ) ) |
---|
547 | DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2Ov'] + d_DYN_end['H2Ol'] + d_DYN_end['H2Oi']).isel(rlonv=slice(0,-1) ) ) |
---|
548 | except : |
---|
549 | 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) ) ) |
---|
550 | 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) ) ) |
---|
551 | if ICO : |
---|
552 | DYN_wat_beg = ( d_DYN_beg['q'][0:4] ).sum (dim = ['nq',] ).rename ( {'lev':'sigs'} ) |
---|
553 | DYN_wat_end = ( d_DYN_end['q'][0:4] ).sum (dim = ['nq',] ).rename ( {'lev':'sigs'} ) |
---|
554 | |
---|
555 | ATM_mas_wat_beg = np.sum (DYN_sigma_beg * DYN_wat_beg * DYN_aire).values.item() |
---|
556 | ATM_mas_wat_end = np.sum (DYN_sigma_end * DYN_wat_end * DYN_aire).values.item() |
---|
557 | |
---|
558 | dATM_mas_wat = ATM_mas_wat_end - ATM_mas_wat_beg |
---|
559 | |
---|
560 | echo ( '\nVariation du contenu en eau atmosphere (dynamique) ' ) |
---|
561 | echo ( 'ATM_mas_beg = {:12.6e} kg - ATM_mas_end = {:12.6e} kg'.format (ATM_mas_wat_beg, ATM_mas_wat_end) ) |
---|
562 | echo ( 'dMass(atm) = {:12.3e} kg '.format (dATM_mas_wat) ) |
---|
563 | echo ( 'dMass(atm) = {:12.3e} Sv '.format (dATM_mas_wat/dtime_sec*1.E-9) ) |
---|
564 | echo ( 'dMass(atm) = {:12.3e}m '.format (dATM_mas_wat/OCE_aire_tot*1E-3) ) |
---|
565 | |
---|
566 | LIC_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'] |
---|
567 | LIC_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'] |
---|
568 | |
---|
569 | if ICO : |
---|
570 | LIC_sno_beg = LIC_sno_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
571 | LIC_sno_end = LIC_sno_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
572 | |
---|
573 | LIC_mas_sno_beg = np.sum ( LIC_sno_beg * DYN_aire ).values.item() |
---|
574 | LIC_mas_sno_end = np.sum ( LIC_sno_end * DYN_aire ).values.item() |
---|
575 | |
---|
576 | dLIC_mas_sno = LIC_mas_sno_end - LIC_mas_sno_beg |
---|
577 | |
---|
578 | echo ( '\nVariation du contenu en neige atmosphere (calottes)' ) |
---|
579 | echo ( 'LIC_mas_sno_beg = {:12.6e} kg - LIC_mas_sno_end = {:12.6e} kg'.format (LIC_mas_sno_beg, LIC_mas_sno_end) ) |
---|
580 | echo ( 'dMass(neige atm) = {:12.3e} kg '.format (dLIC_mas_sno ) ) |
---|
581 | echo ( 'dMass(neige atm) = {:12.3e} Sv '.format (dLIC_mas_sno/dtime_sec*1E-6/ICE_rho_ice) ) |
---|
582 | echo ( 'dMass(neige atm) = {:12.3e} m '.format (dLIC_mas_sno/OCE_aire_tot*1E-3) ) |
---|
583 | |
---|
584 | echo ( '\nVariation du contenu en eau+neige atmosphere ' ) |
---|
585 | echo ( 'dMass(eau + neige atm) = {:12.3e} kg '.format ( dATM_mas_wat + dLIC_mas_sno) ) |
---|
586 | echo ( 'dMass(eau + neige atm) = {:12.3e} Sv '.format ( (dATM_mas_wat + dLIC_mas_sno)/dtime_sec*1E-9) ) |
---|
587 | echo ( 'dMass(eau + neige atm) = {:12.3e} m '.format ( (dATM_mas_wat + dLIC_mas_sno)/OCE_aire_tot*1E-3) ) |
---|
588 | |
---|
589 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
590 | echo ( '-- SRF changes ' ) |
---|
591 | |
---|
592 | if Routing == 'SIMPLE' : |
---|
593 | RUN_mas_wat_beg = np.sum ( d_RUN_beg ['fast_reservoir'] + d_RUN_beg ['slow_reservoir'] + d_RUN_beg ['stream_reservoir']).values.item() |
---|
594 | RUN_mas_wat_end = np.sum ( d_RUN_end ['fast_reservoir'] + d_RUN_end ['slow_reservoir'] + d_RUN_end ['stream_reservoir']).values.item() |
---|
595 | |
---|
596 | if Routing == 'ORCHIDEE' : |
---|
597 | RUN_mas_wat_beg = np.sum ( d_SRF_beg['fastres'] + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \ |
---|
598 | + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres'] ) .values.item() |
---|
599 | RUN_mas_wat_end = np.sum ( d_SRF_end['fastres'] + d_SRF_end['slowres'] + d_SRF_end['streamres'] \ |
---|
600 | + d_SRF_end['floodres'] + d_SRF_end['lakeres'] + d_SRF_end['pondres'] ) .values.item() |
---|
601 | |
---|
602 | dRUN_mas_wat = RUN_mas_wat_end - RUN_mas_wat_beg |
---|
603 | |
---|
604 | echo ( '\nWater content in routing ' ) |
---|
605 | echo ( 'RUN_mas_wat_beg = {:12.6e} kg - RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_end, RUN_mas_wat_end) ) |
---|
606 | echo ( 'dMass(routing) = {:12.3e} kg '.format(dRUN_mas_wat) ) |
---|
607 | echo ( 'dMass(routing) = {:12.3e} Sv '.format(dRUN_mas_wat/dtime_sec*1E-9) ) |
---|
608 | echo ( 'dMass(routing) = {:12.3e} m '.format(dRUN_mas_wat/OCE_aire_tot*1E-3) ) |
---|
609 | |
---|
610 | tot_watveg_beg = d_SRF_beg['tot_watveg_beg'] ; tot_watveg_beg = tot_watveg_beg .where (tot_watveg_beg < 1E10, 0.) |
---|
611 | tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; tot_watsoil_beg = tot_watsoil_beg.where (tot_watsoil_beg< 1E10, 0.) |
---|
612 | snow_beg = d_SRF_beg['snow_beg'] ; snow_beg = snow_beg .where (snow_beg < 1E10, 0.) |
---|
613 | |
---|
614 | tot_watveg_end = d_SRF_end['tot_watveg_beg'] ; tot_watveg_end = tot_watveg_end .where (tot_watveg_end < 1E10, 0.) |
---|
615 | tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; tot_watsoil_end = tot_watsoil_end.where (tot_watsoil_end< 1E10, 0.) |
---|
616 | snow_end = d_SRF_end['snow_beg'] ; snow_end = snow_end .where (snow_end < 1E10, 0.) |
---|
617 | |
---|
618 | SRF_wat_beg = tot_watveg_beg + tot_watsoil_beg + snow_beg |
---|
619 | SRF_wat_end = tot_watveg_end + tot_watsoil_end + snow_end |
---|
620 | |
---|
621 | #SRF_mas_wat_beg = d_SRF_beg['tot_watveg_beg']+d_SRF_beg['tot_watsoil_beg'] + d_SRF_beg['snow_beg'] |
---|
622 | #SRF_mas_wat_end = d_SRF_end['tot_watveg_beg']+d_SRF_end['tot_watsoil_beg'] + d_SRF_end['snow_beg'] |
---|
623 | |
---|
624 | if LMDZ : |
---|
625 | tot_watveg_beg = tot_watveg_beg .rename ( {'y':'points_phyiques'} ) |
---|
626 | tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'points_phyiques'} ) |
---|
627 | snow_beg = snow_beg .rename ( {'y':'points_phyiques'} ) |
---|
628 | tot_watveg_end = tot_watveg_end .rename ( {'y':'points_phyiques'} ) |
---|
629 | tot_watsoil_end = tot_watsoil_end.rename ( {'y':'points_phyiques'} ) |
---|
630 | snow_end = snow_end .rename ( {'y':'points_phyiques'} ) |
---|
631 | SRF_wat_beg = SRF_wat_beg .rename ( {'y':'points_phyiques'} ) |
---|
632 | SRF_wat_end = SRF_wat_end .rename ( {'y':'points_phyiques'} ) |
---|
633 | if ICO : |
---|
634 | tot_watveg_beg = tot_watveg_beg .rename ( {'y':'cell_mesh'} ) |
---|
635 | tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'cell_mesh'} ) |
---|
636 | snow_beg = snow_beg .rename ( {'y':'cell_mesh'} ) |
---|
637 | tot_watveg_end = tot_watveg_end .rename ( {'y':'cell_mesh'} ) |
---|
638 | tot_watsoil_end = tot_watsoil_end.rename ( {'y':'cell_mesh'} ) |
---|
639 | snow_end = snow_end .rename ( {'y':'cell_mesh'} ) |
---|
640 | SRF_wat_beg = SRF_wat_beg .rename ( {'y':'cell_mesh'} ) |
---|
641 | SRF_wat_end = SRF_wat_end .rename ( {'y':'cell_mesh'} ) |
---|
642 | |
---|
643 | SRF_mas_watveg_beg = np.sum ( tot_watveg_beg * SRF_aire).values.item() |
---|
644 | SRF_mas_watsoil_beg = np.sum ( tot_watsoil_beg * SRF_aire).values.item() |
---|
645 | SRF_mas_snow_beg = np.sum ( snow_beg * SRF_aire).values.item() |
---|
646 | SRF_mas_watveg_end = np.sum ( tot_watveg_end * SRF_aire).values.item() |
---|
647 | SRF_mas_watsoil_end = np.sum ( tot_watsoil_end * SRF_aire).values.item() |
---|
648 | SRF_mas_snow_end = np.sum ( snow_end * SRF_aire).values.item() |
---|
649 | |
---|
650 | dSRF_mas_watveg = SRF_mas_watveg_end - SRF_mas_watveg_beg |
---|
651 | dSRF_mas_watsoil = SRF_mas_watsoil_end - SRF_mas_watsoil_beg |
---|
652 | dSRF_mas_snow = SRF_mas_snow_end - SRF_mas_snow_beg |
---|
653 | |
---|
654 | echo ('\nLes differents reservoirs') |
---|
655 | echo ( 'SRF_mas_watveg_beg = {:12.6e} kg - SRF_mas_watveg_end = {:12.6e} kg '.format (SRF_mas_watveg_beg , SRF_mas_watveg_end) ) |
---|
656 | echo ( 'SRF_mas_watsoil_beg = {:12.6e} kg - SRF_mas_watsoil_end = {:12.6e} kg '.format (SRF_mas_watsoil_beg, SRF_mas_watsoil_end) ) |
---|
657 | echo ( 'SRF_mas_snow_beg = {:12.6e} kg - SRF_mas_snow_end = {:12.6e} kg '.format (SRF_mas_snow_beg , SRF_mas_snow_end) ) |
---|
658 | |
---|
659 | 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) ) |
---|
660 | 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) ) |
---|
661 | 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 ) ) |
---|
662 | |
---|
663 | |
---|
664 | SRF_mas_wat_beg = np.sum ( SRF_wat_beg * SRF_aire).values.item() |
---|
665 | SRF_mas_wat_end = np.sum ( SRF_wat_end * SRF_aire).values.item() |
---|
666 | |
---|
667 | dSRF_mas_wat = SRF_mas_wat_end - SRF_mas_wat_beg |
---|
668 | |
---|
669 | echo ( '\nWater content in surface ' ) |
---|
670 | echo ( 'SRF_mas_wat_beg = {:12.6e} kg - SRF_mas_wat_end = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) ) |
---|
671 | echo ( 'dMass(water srf) = {:12.3e} kg '.format (dSRF_mas_wat) ) |
---|
672 | echo ( 'dMass(water srf) = {:12.3e} Sv '.format (dSRF_mas_wat/dtime_sec*1E-9) ) |
---|
673 | echo ( 'dMass(water srf) = {:12.3e} m '.format (dSRF_mas_wat/OCE_aire_tot*1E-3) ) |
---|
674 | |
---|
675 | echo ( '\nWater content in ATM + SRF + RUN ' ) |
---|
676 | echo ( 'mas_wat_beg = {:12.6e} kg '.format (ATM_mas_wat_beg + LIC_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg) ) |
---|
677 | echo ( 'mas_wat_end = {:12.6e} kg '.format (ATM_mas_wat_end + LIC_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) ) |
---|
678 | echo ( 'dMass(water atm+srf+run) = {:12.6e} kg '.format ( dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat) ) |
---|
679 | echo ( 'dMass(water atm+srf+run) = {:12.3e} Sv '.format ((dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/dtime_sec*1E-9) ) |
---|
680 | echo ( 'dMass(water atm+srf+run) = {:12.3e} m '.format ((dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/OCE_aire_tot*1E-3) ) |
---|
681 | |
---|
682 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
683 | echo ( '-- Change in all components' ) |
---|
684 | echo ( 'mas_wat_beg = {:12.6e} kg '.format (SEA_mas_wat_beg + ATM_mas_wat_beg + LIC_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg) ) |
---|
685 | echo ( 'mas_wat_end = {:12.6e} kg '.format (SEA_mas_wat_end + ATM_mas_wat_end + LIC_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) ) |
---|
686 | echo ( 'dMass(water CPL) = {:12.3e} kg '.format ( dSEA_mas_wat + dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat) ) |
---|
687 | echo ( 'dMass(water CPL) = {:12.3e} Sv '.format ((dSEA_mas_wat + dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/dtime_sec*1E-9) ) |
---|
688 | echo ( 'dMass(water CPL) = {:12.3e} m '.format ((dSEA_mas_wat + dATM_mas_wat + dLIC_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/OCE_aire_tot*1E-3) ) |
---|
689 | |
---|
690 | |
---|