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 | ## Import system modules |
---|
23 | import sys, os, shutil, subprocess |
---|
24 | import numpy as np |
---|
25 | import configparser, re |
---|
26 | |
---|
27 | ## Creates parser |
---|
28 | config = configparser.ConfigParser() |
---|
29 | config.optionxform = str # To keep capitals |
---|
30 | |
---|
31 | config['Files'] = {} |
---|
32 | config['System'] = {} |
---|
33 | |
---|
34 | ##-- Some physical constants |
---|
35 | #-- Earth Radius |
---|
36 | Ra = 6366197.7236758135 |
---|
37 | #-- Gravity |
---|
38 | Grav = 9.81 |
---|
39 | #-- Ice volumic mass (kg/m3) in LIM3 |
---|
40 | ICE_rho_ice = 917.0 |
---|
41 | #-- Snow volumic mass (kg/m3) in LIM3 |
---|
42 | ICE_rho_sno = 330.0 |
---|
43 | #-- Ocean water volumic mass (kg/m3) in NEMO |
---|
44 | OCE_rho_liq = 1026. |
---|
45 | #-- Water volumic mass in atmosphere |
---|
46 | ATM_rho = 1.0e3 |
---|
47 | #-- Water volumic mass in surface reservoirs |
---|
48 | SRF_rho = 1.0e3 |
---|
49 | #-- Water volumic mass of rivers |
---|
50 | RUN_rho = 1.0e3 |
---|
51 | |
---|
52 | ## Read experiment parameters |
---|
53 | ATM = None ; ORCA = None ; NEMO = None ; OCE_relax = False ; OCE_icb = False ; Coupled = False ; Routing = None |
---|
54 | |
---|
55 | # Arguments passed |
---|
56 | print ( "Name of Python script:", sys.argv[0] ) |
---|
57 | IniFile = sys.argv[1] |
---|
58 | print ("Input file : ", IniFile ) |
---|
59 | config.read (IniFile) |
---|
60 | |
---|
61 | def setBool (chars) : |
---|
62 | '''Convert specific char string in boolean if possible''' |
---|
63 | setBool = chars |
---|
64 | for key in configparser.ConfigParser.BOOLEAN_STATES.keys () : |
---|
65 | if chars.lower() == key : setBool = configparser.ConfigParser.BOOLEAN_STATES[key] |
---|
66 | return setBool |
---|
67 | |
---|
68 | def setNum (chars) : |
---|
69 | '''Convert specific char string in integer or real if possible''' |
---|
70 | if type (chars) == str : |
---|
71 | realnum = re.compile ("^[-+]?[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?$") |
---|
72 | isReal = realnum.match(chars.strip()) != None |
---|
73 | isInt = chars.strip().isdigit() |
---|
74 | if isReal : |
---|
75 | if isInt : setNum = int (chars) |
---|
76 | else : setNum = float (chars) |
---|
77 | else : setNum = chars |
---|
78 | else : setNum = chars |
---|
79 | return setNum |
---|
80 | |
---|
81 | print ('[Experiment]') |
---|
82 | for VarName in config['Experiment'].keys() : |
---|
83 | locals()[VarName] = config['Experiment'][VarName] |
---|
84 | locals()[VarName] = setBool (locals()[VarName]) |
---|
85 | locals()[VarName] = setNum (locals()[VarName]) |
---|
86 | print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) ) |
---|
87 | |
---|
88 | # ### |
---|
89 | ICO = ( 'ICO' in ATM ) |
---|
90 | LMDZ = ( 'LMD' in ATM ) |
---|
91 | |
---|
92 | ### |
---|
93 | ## Import system modules |
---|
94 | import sys, os, shutil, subprocess |
---|
95 | import configparser, re |
---|
96 | |
---|
97 | config = configparser.ConfigParser() |
---|
98 | config['Files'] = {} |
---|
99 | |
---|
100 | # Where do we run ? |
---|
101 | SysName, NodeName, Release, Version, Machine = os.uname() |
---|
102 | TGCC = ( 'irene' in NodeName ) |
---|
103 | IDRIS = ( 'jeanzay' in NodeName ) |
---|
104 | |
---|
105 | ## Set site specific libIGCM directories, and other specific stuff |
---|
106 | if TGCC : |
---|
107 | CPU = subprocess.getoutput ( 'lscpu | grep "Model name"' ) |
---|
108 | if "Intel(R) Xeon(R) Platinum" in CPU : Machine = 'irene' |
---|
109 | if "AMD" in CPU : Machine = 'irene-amd' |
---|
110 | |
---|
111 | ARCHIVE = subprocess.getoutput ( f'ccc_home --cccstore -d {Project} -u {User}' ) |
---|
112 | STORAGE = subprocess.getoutput ( f'ccc_home --cccwork -d {Project} -u {User}' ) |
---|
113 | SCRATCHDIR = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' ) |
---|
114 | R_IN = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM') |
---|
115 | rebuild = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' ) |
---|
116 | |
---|
117 | ## Specific to run at TGCC. |
---|
118 | # Needed before importing a NetCDF library (netCDF4, xarray, cmds, etc ...) |
---|
119 | import mpi4py |
---|
120 | mpi4py.rc.initialize = False |
---|
121 | |
---|
122 | ## Creates output directory |
---|
123 | #TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
124 | TmpDir = os.path.join ( '/ccc/scratch/cont003/drf/p86mart', f'WATER_{JobName}_{YearBegin}_{YearEnd}' ) |
---|
125 | |
---|
126 | if IDRIS : |
---|
127 | raise Exception ("Pour IDRIS : repertoires et chemins a definir") |
---|
128 | |
---|
129 | ## Import specific module |
---|
130 | import nemo, lmdz |
---|
131 | ## Now import needed scientific modules |
---|
132 | import xarray as xr |
---|
133 | |
---|
134 | config['Files'][TmpDir] = TmpDir |
---|
135 | |
---|
136 | # Output file |
---|
137 | FileOut = f'ATM_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out' |
---|
138 | f_out = open ( FileOut, mode = 'w' ) |
---|
139 | |
---|
140 | # Function to print to stdout *and* output file |
---|
141 | def echo (string, end='\n') : |
---|
142 | print ( string, end=end ) |
---|
143 | sys.stdout.flush () |
---|
144 | f_out.write ( string + end ) |
---|
145 | f_out.flush () |
---|
146 | return None |
---|
147 | |
---|
148 | ## Set libIGCM directories |
---|
149 | R_OUT = os.path.join ( ARCHIVE , 'IGCM_OUT') |
---|
150 | R_BUF = os.path.join ( SCRATCHDIR, 'IGCM_OUT') |
---|
151 | |
---|
152 | L_EXP = os.path.join (TagName, SpaceName, ExperimentName, JobName) |
---|
153 | R_SAVE = os.path.join ( R_OUT, L_EXP ) |
---|
154 | R_BUFR = os.path.join ( R_BUF, L_EXP ) |
---|
155 | POST_DIR = os.path.join ( R_BUF, L_EXP, 'Out' ) |
---|
156 | REBUILD_DIR = os.path.join ( R_BUF, L_EXP, 'REBUILD' ) |
---|
157 | R_BUF_KSH = os.path.join ( R_BUFR, 'Out' ) |
---|
158 | R_FIGR = os.path.join ( STORAGE, 'IGCM_OUT', L_EXP ) |
---|
159 | |
---|
160 | #if os.path.isdir (TmpDir) : shutil.rmtree ( TmpDir ) |
---|
161 | if not os.path.isdir (TmpDir) : os.mkdir (TmpDir) |
---|
162 | TmpDirOCE = os.path.join (TmpDir, 'OCE') |
---|
163 | TmpDirICE = os.path.join (TmpDir, 'ICE') |
---|
164 | if not os.path.exists (TmpDirOCE) : os.mkdir (TmpDirOCE ) |
---|
165 | if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE ) |
---|
166 | |
---|
167 | echo ( f'Working in TMPDIR : {TmpDir}' ) |
---|
168 | |
---|
169 | echo ( f'\nDealing with {L_EXP}' ) |
---|
170 | |
---|
171 | #-- Model output directories |
---|
172 | if Freq == "MO" : FreqDir = os.path.join ('Output' , 'MO' ) |
---|
173 | if Freq == "SE" : FreqDir = os.path.join ('Analyse', 'SE' ) |
---|
174 | dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir ) |
---|
175 | dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir ) |
---|
176 | |
---|
177 | echo ( f'The analysis relies on files from the following model output directories : ' ) |
---|
178 | echo ( f'{dir_ATM_his}' ) |
---|
179 | echo ( f'{dir_SRF_his}' ) |
---|
180 | |
---|
181 | #-- Files Names |
---|
182 | if Freq == 'MO' : FileCommon = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M' |
---|
183 | if Freq == 'SE' : FileCommon = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M' |
---|
184 | |
---|
185 | echo ('\nOpen history files' ) |
---|
186 | file_ATM_his = os.path.join ( dir_ATM_his, f'{FileCommon}_histmth.nc' ) |
---|
187 | file_SRF_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) |
---|
188 | if Routing == 'ORCHIDEE' : |
---|
189 | file_RUN_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) |
---|
190 | if Routing == 'SIMPLE' : |
---|
191 | file_RUN_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) |
---|
192 | |
---|
193 | d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
194 | d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
195 | if Routing == 'ORCHIDEE' : |
---|
196 | d_RUN_his = d_SRF_his |
---|
197 | if Routing == 'SIMPLE' : |
---|
198 | d_RUN_his = xr.open_dataset ( file_RUN_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
199 | |
---|
200 | echo ( file_ATM_his ) |
---|
201 | echo ( file_SRF_his ) |
---|
202 | echo ( file_RUN_his ) |
---|
203 | |
---|
204 | |
---|
205 | config['Files']['file_ATM_his'] = file_ATM_his |
---|
206 | config['Files']['file_SRF_his'] = file_SRF_his |
---|
207 | config['Files']['file_RUN_his'] = file_SRF_his |
---|
208 | |
---|
209 | ## Compute run length |
---|
210 | dtime = ( d_ATM_his.time_counter_bounds.max() - d_ATM_his.time_counter_bounds.min() ) |
---|
211 | echo ('\nRun length : {:8.2f} days'.format ( (dtime/np.timedelta64(1, "D")).values ) ) |
---|
212 | dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds |
---|
213 | |
---|
214 | ## Compute length of each period |
---|
215 | dtime_per = (d_ATM_his.time_counter_bounds[:,-1] - d_ATM_his.time_counter_bounds[:,0] ) |
---|
216 | echo ('\nPeriods lengths (days) : {:} days'.format ( (dtime_per/np.timedelta64(1, "D")).values ) ) |
---|
217 | dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds |
---|
218 | dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] ) |
---|
219 | |
---|
220 | #-- Open restart files |
---|
221 | YearRes = YearBegin - 1 # Year of the restart of beginning of simulation |
---|
222 | YearPre = YearBegin - PackFrequency # Year to find the tarfile of the restart of beginning of simulation |
---|
223 | |
---|
224 | echo (f'Restart dates - Start : {YearRes}-12-31 / End : {YearEnd}-12-31 ') |
---|
225 | |
---|
226 | file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' ) |
---|
227 | file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' ) |
---|
228 | |
---|
229 | echo ( f'{file_restart_beg}' ) |
---|
230 | echo ( f'{file_restart_end}' ) |
---|
231 | |
---|
232 | file_ATM_beg = f'ATM_{JobName}_{YearRes}1231_restartphy.nc' |
---|
233 | file_ATM_end = f'ATM_{JobName}_{YearEnd}1231_restartphy.nc' |
---|
234 | if LMDZ : |
---|
235 | file_DYN_beg = f'ATM_{JobName}_{YearRes}1231_restart.nc' |
---|
236 | file_DYN_end = f'ATM_{JobName}_{YearEnd}1231_restart.nc' |
---|
237 | if ICO : |
---|
238 | file_DYN_beg = f'ICO_{JobName}_{YearRes}1231_restart.nc' |
---|
239 | file_DYN_end = f'ICO_{JobName}_{YearEnd}1231_restart.nc' |
---|
240 | file_SRF_beg = f'SRF_{JobName}_{YearRes}1231_sechiba_rest.nc' |
---|
241 | file_SRF_end = f'SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc' |
---|
242 | liste_beg = [file_ATM_beg, file_DYN_beg, file_SRF_beg, ] |
---|
243 | liste_end = [file_ATM_end, file_DYN_end, file_SRF_end, ] |
---|
244 | echo ( f'{file_ATM_beg}') |
---|
245 | echo ( f'{file_ATM_end}') |
---|
246 | echo ( f'{file_SRF_beg}') |
---|
247 | echo ( f'{file_SRF_end}') |
---|
248 | |
---|
249 | if Routing == 'SIMPLE' : |
---|
250 | file_RUN_beg = f'SRF_{JobName}_{YearRes}1231_routing_restart.nc' |
---|
251 | file_RUN_end = f'SRF_{JobName}_{YearEnd}1231_routing_restart.nc' |
---|
252 | liste_beg.append ( file_RUN_beg ) |
---|
253 | liste_end.append ( file_RUN_end ) |
---|
254 | echo ( f'{file_RUN_beg}') |
---|
255 | echo ( f'{file_RUN_end}') |
---|
256 | |
---|
257 | echo ('\nExtract restart files from tar : ATM, ICO and SRF') |
---|
258 | for resFile in liste_beg : |
---|
259 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
260 | command = f'cd {TmpDir} ; tar xf {file_restart_beg} {resFile}' |
---|
261 | echo ( command ) |
---|
262 | os.system ( command ) |
---|
263 | |
---|
264 | for resFile in liste_end : |
---|
265 | if not os.path.exists ( os.path.join (TmpDir, resFile) ) : |
---|
266 | command = f'cd {TmpDir} ; tar xf {file_restart_end} {resFile}' |
---|
267 | echo ( command ) |
---|
268 | os.system ( command ) |
---|
269 | |
---|
270 | config['Files']['file_ATM_beg'] = file_ATM_beg |
---|
271 | config['Files']['file_ATM_end'] = file_ATM_end |
---|
272 | config['Files']['file_SRF_beg'] = file_SRF_beg |
---|
273 | config['Files']['file_SRF_end'] = file_SRF_end |
---|
274 | if Routing == 'SIMPLE' : |
---|
275 | config['Files']['file_RUN_beg'] = file_RUN_beg |
---|
276 | config['Files']['file_RUN_end'] = file_RUN_end |
---|
277 | config['Files']['file_DYN_beg'] = file_DYN_beg |
---|
278 | config['Files']['file_DYN_end'] = file_DYN_end |
---|
279 | |
---|
280 | echo ('\nOpening ATM SRF and ICO restart files') |
---|
281 | d_ATM_beg = xr.open_dataset ( os.path.join (TmpDir, file_ATM_beg), decode_times=False, decode_cf=True).squeeze() |
---|
282 | d_ATM_end = xr.open_dataset ( os.path.join (TmpDir, file_ATM_end), decode_times=False, decode_cf=True).squeeze() |
---|
283 | d_SRF_beg = xr.open_dataset ( os.path.join (TmpDir, file_SRF_beg), decode_times=False, decode_cf=True).squeeze() |
---|
284 | d_SRF_end = xr.open_dataset ( os.path.join (TmpDir, file_SRF_end), decode_times=False, decode_cf=True).squeeze() |
---|
285 | d_DYN_beg = xr.open_dataset ( os.path.join (TmpDir, file_DYN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
286 | d_DYN_end = xr.open_dataset ( os.path.join (TmpDir, file_DYN_end), decode_times=False, decode_cf=True).squeeze() |
---|
287 | |
---|
288 | for var in d_SRF_beg.variables : |
---|
289 | d_SRF_beg[var] = d_SRF_beg[var].where ( d_SRF_beg[var]<1.e20, 0.) |
---|
290 | d_SRF_end[var] = d_SRF_end[var].where ( d_SRF_end[var]<1.e20, 0.) |
---|
291 | |
---|
292 | if ICO : |
---|
293 | d_RUN_beg = xr.open_dataset ( os.path.join (TmpDir, file_RUN_beg), decode_times=False, decode_cf=True).squeeze() |
---|
294 | d_RUN_end = xr.open_dataset ( os.path.join (TmpDir, file_RUN_end), decode_times=False, decode_cf=True).squeeze() |
---|
295 | |
---|
296 | echo ( file_ATM_beg ) |
---|
297 | echo ( file_ATM_end ) |
---|
298 | echo ( file_DYN_beg ) |
---|
299 | echo ( file_DYN_end ) |
---|
300 | echo ( file_SRF_beg ) |
---|
301 | echo ( file_SRF_end ) |
---|
302 | if Routing == 'SIMPLE' : |
---|
303 | echo ( file_RUN_beg ) |
---|
304 | echo ( file_RUN_end ) |
---|
305 | |
---|
306 | def ATM_stock_int (stock) : |
---|
307 | '''Integrate stock on atmosphere grid''' |
---|
308 | ATM_stock_int = np.sum ( np.sort ( (stock * DYN_aire).to_masked_array().ravel()) ) |
---|
309 | return ATM_stock_int |
---|
310 | |
---|
311 | def ATM_flux_int (flux) : |
---|
312 | '''Integrate flux on atmosphere grid''' |
---|
313 | ATM_stock_int = np.sum ( np.sort ( (flux * dtime_per_sec * ATM_aire).to_masked_array().ravel()) ) |
---|
314 | return ATM_stock_int |
---|
315 | |
---|
316 | def ONE_stock_int (stock) : |
---|
317 | '''Sum stock ''' |
---|
318 | ONE_stock_int = np.sum ( np.sort ( (stock).to_masked_array().ravel()) ) |
---|
319 | return ONE_stock_int |
---|
320 | |
---|
321 | def ONE_flux_int (flux) : |
---|
322 | '''Sum flux ''' |
---|
323 | ONE_flux_int = np.sum ( np.sort ( (flux * dtime_per_sec ).to_masked_array().ravel()) ) |
---|
324 | return ONE_flux_int |
---|
325 | |
---|
326 | # ATM grid with cell surfaces |
---|
327 | if ICO : |
---|
328 | jpja, jpia = d_ATM_his['aire'][0].shape |
---|
329 | file_ATM_aire = os.path.join ( R_IN, 'ATM', 'GRID', f'aire_{ATM}_to_{jpia}x{jpja}.nc' ) |
---|
330 | config['Files']['file_ATM_aire'] = file_ATM_aire |
---|
331 | echo ('Aire sur grille reguliere :', file_ATM_aire) |
---|
332 | d_ATM_aire = xr.open_dataset ( file_ATM_aire, decode_times=False ).squeeze() |
---|
333 | ATM_aire = lmdz.geo2point ( d_ATM_aire ['aire'].squeeze(), cumulPoles=True ) |
---|
334 | ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] ) |
---|
335 | ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] + d_ATM_his ['fract_lic'][0] ) |
---|
336 | SRF_aire = lmdz.geo2point ( d_SRF_his ['Areas'] * d_SRF_his ['Contfrac'] ) |
---|
337 | |
---|
338 | if LMDZ : |
---|
339 | ATM_aire = lmdz.geo2point ( d_ATM_his ['aire'][0], cumulPoles=True ) |
---|
340 | ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] ) |
---|
341 | ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] ) |
---|
342 | SRF_aire = lmdz.geo2point ( d_SRF_his['Areas'] * d_SRF_his['Contfrac'] ) |
---|
343 | |
---|
344 | SRF_aire = SRF_aire.where ( SRF_aire < 1E15, 0.) |
---|
345 | |
---|
346 | if ICO : |
---|
347 | # Area on icosahedron grid |
---|
348 | file_DYN_aire = os.path.join ( R_IN, 'ATM', 'GRID', ATM+'_grid.nc' ) |
---|
349 | d_DYN_aire = xr.open_dataset ( file_DYN_aire, decode_times=False).squeeze() |
---|
350 | d_DYN_aire = d_DYN_aire.rename ( {'cell':'cell_mesh'} ) |
---|
351 | DYN_aire = d_DYN_aire['aire'] |
---|
352 | |
---|
353 | DYN_fsea = d_DYN_aire ['fract_oce'] + d_DYN_aire ['fract_sic'] |
---|
354 | DYN_flnd = 1.0 - DYN_fsea |
---|
355 | |
---|
356 | if LMDZ : |
---|
357 | DYN_aire = ATM_aire |
---|
358 | DYN_fsea = ATM_fsea |
---|
359 | DYN_flnd = ATM_flnd |
---|
360 | |
---|
361 | #if LMDZ : |
---|
362 | # d_ATM_beg = d_ATM_beg.assign ( coords={'lon':d_ATM_beg.lon*180./np.pi} ) |
---|
363 | |
---|
364 | ATM_aire_sea = ATM_aire * ATM_fsea |
---|
365 | ATM_aire_sea_tot = ONE_stock_int ( ATM_aire_sea ) |
---|
366 | |
---|
367 | ATM_aire_tot = ONE_stock_int (ATM_aire) |
---|
368 | ATM_aire_sea_tot = ONE_stock_int (ATM_aire*ATM_fsea) |
---|
369 | |
---|
370 | |
---|
371 | echo ( 'Aire atmosphere/4pi R^2 : {:12.5f}'.format(ATM_aire_tot/(Ra*Ra*4*np.pi) ) ) |
---|
372 | |
---|
373 | if ( np.abs (ATM_aire_tot/(Ra*Ra*4*np.pi) - 1.0) > 0.01 ) : |
---|
374 | raise Exception ('Erreur surface interpolee sur grille reguliere') |
---|
375 | |
---|
376 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
377 | echo ( '-- ATM changes in stores ' ) |
---|
378 | |
---|
379 | #-- Change in precipitable water from the atmosphere daily and monthly files |
---|
380 | #-- Compute sum weighted by gridcell area (kg/m2) then convert to Sv |
---|
381 | |
---|
382 | # ATM vertical grid |
---|
383 | ATM_Ahyb = d_ATM_his['Ahyb'].squeeze() |
---|
384 | ATM_Bhyb = d_ATM_his['Bhyb'].squeeze() |
---|
385 | |
---|
386 | # Surface pressure |
---|
387 | if ICO : |
---|
388 | DYN_ps_beg = d_DYN_beg['ps'] |
---|
389 | DYN_ps_end = d_DYN_end['ps'] |
---|
390 | |
---|
391 | if LMDZ : |
---|
392 | DYN_ps_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) ) |
---|
393 | DYN_ps_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) ) |
---|
394 | |
---|
395 | # 3D Pressure |
---|
396 | DYN_p_beg = ATM_Ahyb + ATM_Bhyb * DYN_ps_beg |
---|
397 | DYN_p_end = ATM_Ahyb + ATM_Bhyb * DYN_ps_end |
---|
398 | |
---|
399 | if ICO : klevp1, cell_mesh = DYN_p_beg.shape |
---|
400 | if LMDZ : klevp1, points_physiques = DYN_p_beg.shape |
---|
401 | klev = klevp1 - 1 |
---|
402 | |
---|
403 | # Layer thickness |
---|
404 | if ICO : |
---|
405 | DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, cell_mesh )), dims=('sigs', 'cell_mesh' ), coords=(np.arange(klev), np.arange(cell_mesh) ) ) |
---|
406 | DYN_dsigma_end = xr.DataArray ( np.empty( (klev, cell_mesh )), dims=('sigs', 'cell_mesh' ), coords=(np.arange(klev), np.arange(cell_mesh) ) ) |
---|
407 | if LMDZ : |
---|
408 | DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) ) |
---|
409 | DYN_dsigma_end = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) ) |
---|
410 | |
---|
411 | for k in np.arange (klevp1-1) : |
---|
412 | DYN_dsigma_beg[k,:] = DYN_p_beg[k,:] - DYN_p_beg[k+1,:] |
---|
413 | DYN_dsigma_end[k,:] = DYN_p_end[k,:] - DYN_p_end[k+1,:] |
---|
414 | |
---|
415 | ##-- Vertical and horizontal integral, and sum of liquid, solid and vapor water phases |
---|
416 | if LMDZ : |
---|
417 | try : |
---|
418 | DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2Ov'] + d_DYN_beg['H2Ol'] + d_DYN_beg['H2Oi'] ).isel(rlonv=slice(0,-1) ) ) |
---|
419 | DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2Ov'] + d_DYN_end['H2Ol'] + d_DYN_end['H2Oi'] ).isel(rlonv=slice(0,-1) ) ) |
---|
420 | except : |
---|
421 | 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) ) ) |
---|
422 | 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) ) ) |
---|
423 | if ICO : |
---|
424 | try : |
---|
425 | DYN_wat_beg = (d_DYN_beg['H2O_g'] + d_DYN_beg['H2O_l'] + d_DYN_beg['H2O_s']).rename ( {'lev':'sigs'} ) |
---|
426 | DYN_wat_end = (d_DYN_end['H2O_g'] + d_DYN_end['H2O_l'] + d_DYN_end['H2O_s']).rename ( {'lev':'sigs'} ) |
---|
427 | except : |
---|
428 | 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'} ) |
---|
429 | 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'} ) |
---|
430 | |
---|
431 | # Integral |
---|
432 | DYN_mas_wat_beg = ATM_stock_int (DYN_dsigma_beg * DYN_wat_beg) / Grav |
---|
433 | DYN_mas_wat_end = ATM_stock_int (DYN_dsigma_end * DYN_wat_end) / Grav |
---|
434 | |
---|
435 | dDYN_mas_wat = DYN_mas_wat_end - DYN_mas_wat_beg |
---|
436 | |
---|
437 | echo ( '\nVariation du contenu en eau atmosphere (dynamique) ' ) |
---|
438 | echo ( 'DYN_mas_beg = {:12.6e} kg | DYN_mas_end = {:12.6e} kg'.format (DYN_mas_wat_beg, DYN_mas_wat_end) ) |
---|
439 | echo ( 'dMass (atm) = {:12.3e} kg '.format (dDYN_mas_wat) ) |
---|
440 | echo ( 'dMass (atm) = {:12.3e} Sv '.format (dDYN_mas_wat/dtime_sec*1.e-6/ATM_rho) ) |
---|
441 | echo ( 'dMass (atm) = {:12.3e} m '.format (dDYN_mas_wat/ATM_aire_sea_tot/ATM_rho) ) |
---|
442 | |
---|
443 | 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'] |
---|
444 | 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'] |
---|
445 | |
---|
446 | 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'] |
---|
447 | 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'] |
---|
448 | |
---|
449 | ATM_qsol_beg = d_ATM_beg['QSOL'] |
---|
450 | ATM_qsol_end = d_ATM_end['QSOL'] |
---|
451 | |
---|
452 | ATM_qs01_beg = d_ATM_beg['QS01'] * d_ATM_beg['FTER'] |
---|
453 | ATM_qs01_end = d_ATM_end['QS01'] * d_ATM_end['FTER'] |
---|
454 | ATM_qs02_beg = d_ATM_beg['QS02'] * d_ATM_beg['FLIC'] |
---|
455 | ATM_qs02_end = d_ATM_end['QS02'] * d_ATM_end['FLIC'] |
---|
456 | ATM_qs03_beg = d_ATM_beg['QS03'] * d_ATM_beg['FOCE'] |
---|
457 | ATM_qs03_end = d_ATM_end['QS03'] * d_ATM_end['FOCE'] |
---|
458 | ATM_qs04_beg = d_ATM_beg['QS04'] * d_ATM_beg['FSIC'] |
---|
459 | ATM_qs04_end = d_ATM_end['QS04'] * d_ATM_end['FSIC'] |
---|
460 | |
---|
461 | if ICO : |
---|
462 | ATM_sno_beg = ATM_sno_beg .rename ( {'points_physiques':'cell_mesh'} ) |
---|
463 | ATM_sno_end = ATM_sno_end .rename ( {'points_physiques':'cell_mesh'} ) |
---|
464 | ATM_qs_beg = ATM_qs_beg .rename ( {'points_physiques':'cell_mesh'} ) |
---|
465 | ATM_qs_end = ATM_qs_end .rename ( {'points_physiques':'cell_mesh'} ) |
---|
466 | ATM_qsol_beg = ATM_qsol_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
467 | ATM_qsol_end = ATM_qsol_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
468 | ATM_qs01_beg = ATM_qs01_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
469 | ATM_qs01_end = ATM_qs01_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
470 | ATM_qs02_beg = ATM_qs02_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
471 | ATM_qs02_end = ATM_qs02_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
472 | ATM_qs03_beg = ATM_qs03_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
473 | ATM_qs03_end = ATM_qs03_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
474 | ATM_qs04_beg = ATM_qs04_beg.rename ( {'points_physiques':'cell_mesh'} ) |
---|
475 | ATM_qs04_end = ATM_qs04_end.rename ( {'points_physiques':'cell_mesh'} ) |
---|
476 | |
---|
477 | ATM_mas_sno_beg = ATM_stock_int ( ATM_sno_beg ) |
---|
478 | ATM_mas_sno_end = ATM_stock_int ( ATM_sno_end ) |
---|
479 | ATM_mas_qs_beg = ATM_stock_int ( ATM_qs_beg ) |
---|
480 | ATM_mas_qs_end = ATM_stock_int ( ATM_qs_end ) |
---|
481 | ATM_mas_qsol_beg = ATM_stock_int ( ATM_qsol_beg ) |
---|
482 | ATM_mas_qsol_end = ATM_stock_int ( ATM_qsol_end ) |
---|
483 | ATM_mas_qs01_beg = ATM_stock_int ( ATM_qs01_beg ) |
---|
484 | ATM_mas_qs01_end = ATM_stock_int ( ATM_qs01_end ) |
---|
485 | ATM_mas_qs02_beg = ATM_stock_int ( ATM_qs02_beg ) |
---|
486 | ATM_mas_qs02_end = ATM_stock_int ( ATM_qs02_end ) |
---|
487 | ATM_mas_qs03_beg = ATM_stock_int ( ATM_qs03_beg ) |
---|
488 | ATM_mas_qs03_end = ATM_stock_int ( ATM_qs03_end ) |
---|
489 | ATM_mas_qs04_beg = ATM_stock_int ( ATM_qs04_beg ) |
---|
490 | ATM_mas_qs04_end = ATM_stock_int ( ATM_qs04_end ) |
---|
491 | |
---|
492 | dATM_mas_sno = ATM_mas_sno_end - ATM_mas_sno_beg |
---|
493 | dATM_mas_qs = ATM_mas_qs_end - ATM_mas_qs_beg |
---|
494 | dATM_mas_qsol = ATM_mas_qsol_end - ATM_mas_qsol_beg |
---|
495 | |
---|
496 | dATM_mas_qs01 = ATM_mas_qs01_end - ATM_mas_qs01_beg |
---|
497 | dATM_mas_qs02 = ATM_mas_qs02_end - ATM_mas_qs02_beg |
---|
498 | dATM_mas_qs03 = ATM_mas_qs03_end - ATM_mas_qs03_beg |
---|
499 | dATM_mas_qs04 = ATM_mas_qs04_end - ATM_mas_qs04_beg |
---|
500 | |
---|
501 | echo ( '\nVariation du contenu en neige atmosphere (calottes)' ) |
---|
502 | echo ( 'ATM_mas_sno_beg = {:12.6e} kg | ATM_mas_sno_end = {:12.6e} kg'.format (ATM_mas_sno_beg, ATM_mas_sno_end) ) |
---|
503 | echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_sno ) ) |
---|
504 | echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_sno/dtime_sec*1e-6/ICE_rho_ice) ) |
---|
505 | echo ( 'dMass (neige atm) = {:12.3e} m '.format (dATM_mas_sno/ATM_aire_sea_tot/ATM_rho) ) |
---|
506 | |
---|
507 | echo ( '\nVariation du contenu humidite du sol' ) |
---|
508 | echo ( 'ATM_mas_qs_beg = {:12.6e} kg | ATM_mas_qs_end = {:12.6e} kg'.format (ATM_mas_qs_beg, ATM_mas_qs_end) ) |
---|
509 | echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_qs ) ) |
---|
510 | echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_qs/dtime_sec*1e-6/ATM_rho) ) |
---|
511 | echo ( 'dMass (neige atm) = {:12.3e} m '.format (dATM_mas_qs/ATM_aire_sea_tot/ATM_rho) ) |
---|
512 | |
---|
513 | echo ( '\nVariation du contenu en eau+neige atmosphere ' ) |
---|
514 | echo ( 'dMass (eau + neige atm) = {:12.3e} kg '.format ( dDYN_mas_wat + dATM_mas_sno) ) |
---|
515 | echo ( 'dMass (eau + neige atm) = {:12.3e} Sv '.format ( (dDYN_mas_wat + dATM_mas_sno)/dtime_sec*1E-6/ATM_rho) ) |
---|
516 | echo ( 'dMass (eau + neige atm) = {:12.3e} m '.format ( (dDYN_mas_wat + dATM_mas_sno)/ATM_aire_sea_tot/ATM_rho) ) |
---|
517 | |
---|
518 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
519 | echo ( '-- SRF changes ' ) |
---|
520 | |
---|
521 | # dSoilHum_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=(maxvegetfrac*DelSoilMoist_daily)*Contfrac' ${file} -gridarea ${file}` |
---|
522 | # dInterce_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelIntercept_daily*Contfrac' ${file} -gridarea ${file}` |
---|
523 | # dSWE_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelSWE_daily*Contfrac' ${file} -gridarea ${file}` |
---|
524 | # dStream_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delstreamr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
525 | # dFastR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfastr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
526 | # dSlowR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delslowr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
527 | # dFlood_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfloodr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
528 | # dPond_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delpondr_daily*Contfrac' ${file} -gridarea ${file}` |
---|
529 | # dLake_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=dellakevol_daily*Contfrac' ${file} -gridarea ${file}` |
---|
530 | #echo 'dSTOCK (Sv) Soil Intercept SWE Stream FastR SlowR Lake Pond Flood=' $dSoilHum_in_Sv, $dInterce_in_Sv, $dSWE_in_Sv, $dStream_in_Sv, $dFastR_in_Sv, $dSlowR_in_Sv, $dLake_in_Sv, $dPond_in_Sv, $dFlood_in_Sv >> ${fileout} |
---|
531 | #dSRF_tot=`python -c "print $dSoilHum_in_Sv+$dInterce_in_Sv+$dSWE_in_Sv+$dStream_in_Sv+$dFastR_in_Sv+$dSlowR_in_Sv+$dLake_in_Sv+$dPond_in_Sv+$dFlood_in_Sv"` |
---|
532 | #echo 'dSTOCK (Sv) total='${dSRF_tot} >> ${fileout} |
---|
533 | |
---|
534 | |
---|
535 | if Routing == 'SIMPLE' : |
---|
536 | RUN_mas_wat_beg = ONE_stock_int ( d_RUN_beg ['fast_reservoir'] + d_RUN_beg ['slow_reservoir'] + d_RUN_beg ['stream_reservoir'] ) |
---|
537 | RUN_mas_wat_end = ONE_stock_int ( d_RUN_end ['fast_reservoir'] + d_RUN_end ['slow_reservoir'] + d_RUN_end ['stream_reservoir'] ) |
---|
538 | |
---|
539 | if Routing == 'ORCHIDEE' : |
---|
540 | RUN_mas_wat_beg = ONE_stock_int ( d_SRF_beg['fastres'] + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \ |
---|
541 | + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres'] ) |
---|
542 | RUN_mas_wat_end = ONE_stock_int ( d_SRF_end['fastres'] + d_SRF_end['slowres'] + d_SRF_end['streamres'] \ |
---|
543 | + d_SRF_end['floodres'] + d_SRF_end['lakeres'] + d_SRF_end['pondres'] ) |
---|
544 | |
---|
545 | dRUN_mas_wat = RUN_mas_wat_end - RUN_mas_wat_beg |
---|
546 | |
---|
547 | echo ( '\nWater content in routing ' ) |
---|
548 | echo ( 'RUN_mas_wat_beg = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_end, RUN_mas_wat_end) ) |
---|
549 | echo ( 'dMass (routing) = {:12.3e} kg '.format(dRUN_mas_wat) ) |
---|
550 | echo ( 'dMass (routing) = {:12.3e} Sv '.format(dRUN_mas_wat/dtime_sec*1E-9) ) |
---|
551 | echo ( 'dMass (routing) = {:12.3e} m '.format(dRUN_mas_wat/ATM_aire_sea_tot*1E-3) ) |
---|
552 | |
---|
553 | print ('Reading SRF restart') |
---|
554 | tot_watveg_beg = d_SRF_beg['tot_watveg_beg'] ; tot_watveg_beg = tot_watveg_beg .where (tot_watveg_beg < 1E10, 0.) |
---|
555 | tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; tot_watsoil_beg = tot_watsoil_beg.where (tot_watsoil_beg< 1E10, 0.) |
---|
556 | snow_beg = d_SRF_beg['snow_beg'] ; snow_beg = snow_beg .where (snow_beg < 1E10, 0.) |
---|
557 | |
---|
558 | tot_watveg_end = d_SRF_end['tot_watveg_beg'] ; tot_watveg_end = tot_watveg_end .where (tot_watveg_end < 1E10, 0.) |
---|
559 | tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; tot_watsoil_end = tot_watsoil_end.where (tot_watsoil_end< 1E10, 0.) |
---|
560 | snow_end = d_SRF_end['snow_beg'] ; snow_end = snow_end .where (snow_end < 1E10, 0.) |
---|
561 | |
---|
562 | if LMDZ : |
---|
563 | tot_watveg_beg = lmdz.geo2point (tot_watveg_beg) |
---|
564 | tot_watsoil_beg = lmdz.geo2point (tot_watsoil_beg) |
---|
565 | snow_beg = lmdz.geo2point (snow_beg) |
---|
566 | tot_watveg_end = lmdz.geo2point (tot_watveg_end) |
---|
567 | tot_watsoil_end = lmdz.geo2point (tot_watsoil_end) |
---|
568 | snow_end = lmdz.geo2point (snow_end) |
---|
569 | |
---|
570 | # Stock dSoilHum dInterce dSWE dStream dFastR dSlowR dLake dPond dFlood |
---|
571 | |
---|
572 | SRF_wat_beg = tot_watveg_beg + tot_watsoil_beg + snow_beg |
---|
573 | SRF_wat_end = tot_watveg_end + tot_watsoil_end + snow_end |
---|
574 | |
---|
575 | if ICO : |
---|
576 | tot_watveg_beg = tot_watveg_beg .rename ( {'y':'cell_mesh'} ) |
---|
577 | tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'cell_mesh'} ) |
---|
578 | snow_beg = snow_beg .rename ( {'y':'cell_mesh'} ) |
---|
579 | tot_watveg_end = tot_watveg_end .rename ( {'y':'cell_mesh'} ) |
---|
580 | tot_watsoil_end = tot_watsoil_end.rename ( {'y':'cell_mesh'} ) |
---|
581 | snow_end = snow_end .rename ( {'y':'cell_mesh'} ) |
---|
582 | SRF_wat_beg = SRF_wat_beg .rename ( {'y':'cell_mesh'} ) |
---|
583 | SRF_wat_end = SRF_wat_end .rename ( {'y':'cell_mesh'} ) |
---|
584 | |
---|
585 | print ('Computing integrals') |
---|
586 | |
---|
587 | print ( ' 1/6', end='' ) ; sys.stdout.flush () |
---|
588 | SRF_mas_watveg_beg = ATM_stock_int ( tot_watveg_beg ) |
---|
589 | print ( ' 2/6', end='' ) ; sys.stdout.flush () |
---|
590 | SRF_mas_watsoil_beg = ATM_stock_int ( tot_watsoil_beg ) |
---|
591 | print ( ' 3/6', end='' ) ; sys.stdout.flush () |
---|
592 | SRF_mas_snow_beg = ATM_stock_int ( snow_beg ) |
---|
593 | print ( ' 4/6', end='' ) ; sys.stdout.flush () |
---|
594 | SRF_mas_watveg_end = ATM_stock_int ( tot_watveg_end ) |
---|
595 | print ( ' 5/6', end='' ) ; sys.stdout.flush () |
---|
596 | SRF_mas_watsoil_end = ATM_stock_int ( tot_watsoil_end ) |
---|
597 | print ( ' 6/6', end='' ) ; sys.stdout.flush () |
---|
598 | SRF_mas_snow_end = ATM_stock_int ( snow_end ) |
---|
599 | print (' -- ') ; sys.stdout.flush () |
---|
600 | |
---|
601 | dSRF_mas_watveg = SRF_mas_watveg_end - SRF_mas_watveg_beg |
---|
602 | dSRF_mas_watsoil = SRF_mas_watsoil_end - SRF_mas_watsoil_beg |
---|
603 | dSRF_mas_snow = SRF_mas_snow_end - SRF_mas_snow_beg |
---|
604 | |
---|
605 | echo ('\nLes differents reservoirs') |
---|
606 | echo ( 'SRF_mas_watveg_beg = {:12.6e} kg | SRF_mas_watveg_end = {:12.6e} kg '.format (SRF_mas_watveg_beg , SRF_mas_watveg_end ) ) |
---|
607 | echo ( 'SRF_mas_watsoil_beg = {:12.6e} kg | SRF_mas_watsoil_end = {:12.6e} kg '.format (SRF_mas_watsoil_beg , SRF_mas_watsoil_end ) ) |
---|
608 | echo ( 'SRF_mas_snow_beg = {:12.6e} kg | SRF_mas_snow_end = {:12.6e} kg '.format (SRF_mas_snow_beg , SRF_mas_snow_end ) ) |
---|
609 | |
---|
610 | 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 /ATM_aire_sea_tot*1E-3) ) |
---|
611 | 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 /ATM_aire_sea_tot*1E-3) ) |
---|
612 | 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 /ATM_aire_sea_tot*1E-3) ) |
---|
613 | |
---|
614 | SRF_mas_wat_beg = SRF_mas_watveg_beg + SRF_mas_watsoil_beg + SRF_mas_snow_beg |
---|
615 | SRF_mas_wat_end = SRF_mas_watveg_end + SRF_mas_watsoil_end + SRF_mas_snow_end |
---|
616 | dSRF_mas_wat = SRF_mas_wat_end - SRF_mas_wat_beg |
---|
617 | |
---|
618 | echo ( '\nWater content in surface ' ) |
---|
619 | echo ( 'SRF_mas_wat_beg = {:12.6e} kg | SRF_mas_wat_end = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) ) |
---|
620 | echo ( 'dMass (water srf) = {:12.3e} kg '.format (dSRF_mas_wat) ) |
---|
621 | echo ( 'dMass (water srf) = {:12.3e} Sv '.format (dSRF_mas_wat/dtime_sec*1E-6/ATM_rho) ) |
---|
622 | echo ( 'dMass (water srf) = {:12.3e} m '.format (dSRF_mas_wat/ATM_aire_sea_tot/ATM_rho) ) |
---|
623 | |
---|
624 | echo ( '\nWater content in ATM + SRF + RUN ' ) |
---|
625 | echo ( 'mas_wat_beg = {:12.6e} kg | mas_wat_end = {:12.6e} kg '. |
---|
626 | format (DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg, |
---|
627 | DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) ) |
---|
628 | echo ( 'dMass (water atm+srf+run) = {:12.6e} kg '.format ( dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat) ) |
---|
629 | 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) ) |
---|
630 | 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) ) |
---|
631 | |
---|
632 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
633 | echo ( '-- ATM Fluxes ' ) |
---|
634 | |
---|
635 | ATM_wbilo_oce = lmdz.geo2point ( d_ATM_his ['wbilo_oce'] ) |
---|
636 | ATM_wbilo_sic = lmdz.geo2point ( d_ATM_his ['wbilo_sic'] ) |
---|
637 | ATM_wbilo_ter = lmdz.geo2point ( d_ATM_his ['wbilo_ter'] ) |
---|
638 | ATM_wbilo_lic = lmdz.geo2point ( d_ATM_his ['wbilo_lic'] ) |
---|
639 | ATM_runofflic = lmdz.geo2point ( d_ATM_his ['runofflic'] ) |
---|
640 | ATM_fqcalving = lmdz.geo2point ( d_ATM_his ['fqcalving'] ) |
---|
641 | ATM_fqfonte = lmdz.geo2point ( d_ATM_his ['fqfonte'] ) |
---|
642 | ATM_precip = lmdz.geo2point ( d_ATM_his ['precip'] ) |
---|
643 | ATM_snowf = lmdz.geo2point ( d_ATM_his ['snow'] ) |
---|
644 | ATM_evap = lmdz.geo2point ( d_ATM_his ['evap'] ) |
---|
645 | ATM_bilo = ATM_wbilo_oce + ATM_wbilo_ter + ATM_wbilo_lic + ATM_wbilo_sic |
---|
646 | |
---|
647 | RUN_coastalflow = lmdz.geo2point ( d_RUN_his ['coastalflow'] ) |
---|
648 | RUN_riverflow = lmdz.geo2point ( d_RUN_his ['riverflow'] ) |
---|
649 | RUN_runoff = lmdz.geo2point ( d_RUN_his ['runoff'] ) |
---|
650 | RUN_drainage = lmdz.geo2point ( d_RUN_his ['drainage'] ) |
---|
651 | RUN_riversret = lmdz.geo2point ( d_RUN_his ['riversret'] ) |
---|
652 | |
---|
653 | SRF_evap = lmdz.geo2point ( d_SRF_his ['evap'] ) |
---|
654 | SRF_snowf = lmdz.geo2point ( d_SRF_his ['snowf'] ) |
---|
655 | SRF_TWS = lmdz.geo2point ( d_SRF_his ['TWS'] ) |
---|
656 | SRF_subli = lmdz.geo2point ( d_SRF_his ['subli'] ) |
---|
657 | SRF_transpir = lmdz.geo2point ( np.sum(d_SRF_his ['transpir'], axis=1) ) ; SRF_transpir.attrs['units'] = d_SRF_his ['transpir'].attrs['units'] |
---|
658 | |
---|
659 | def mmd2SI ( Var) : |
---|
660 | '''Change unit from mm/d or m^3/s to kg/s if needed''' |
---|
661 | if 'units' in VarT.attrs : |
---|
662 | if VarT.attrs['units'] in ['m^3/s', 'm3/s', 'm3.s-3'] : |
---|
663 | VarT.values = VarT.values * ATM_rho ; VarT.attrs['units'] = 'kg/s' |
---|
664 | if VarT.attrs['units'] == 'mm/d' : |
---|
665 | VarT.values = VarT.values * ATM_rho * (1e-3/86400.) ; VarT.attrs['units'] = 'kg/s' |
---|
666 | |
---|
667 | for var in ['runoff', 'drainage', 'riversret', 'coastalflow', 'riverflow'] : |
---|
668 | VarT = locals()['RUN_' + var] |
---|
669 | mmd2SI (VarT) |
---|
670 | |
---|
671 | for var in ['evap', 'snowf', 'TWS', 'subli', 'transpir'] : |
---|
672 | VarT = locals()['SRF_' + var] |
---|
673 | mmd2SI (VarT) |
---|
674 | |
---|
675 | RUN_input = RUN_runoff + RUN_drainage |
---|
676 | RUN_output = RUN_coastalflow + RUN_riverflow |
---|
677 | |
---|
678 | ATM_wbilo_sea = ATM_wbilo_oce + ATM_wbilo_sic |
---|
679 | |
---|
680 | ATM_flx_oce = ATM_flux_int ( ATM_wbilo_oce ) |
---|
681 | ATM_flx_sic = ATM_flux_int ( ATM_wbilo_sic ) |
---|
682 | ATM_flx_sea = ATM_flux_int ( ATM_wbilo_sea ) |
---|
683 | ATM_flx_ter = ATM_flux_int ( ATM_wbilo_ter ) |
---|
684 | ATM_flx_lic = ATM_flux_int ( ATM_wbilo_lic ) |
---|
685 | ATM_flx_calving = ATM_flux_int ( ATM_fqcalving ) |
---|
686 | ATM_flx_qfonte = ATM_flux_int ( ATM_fqfonte ) |
---|
687 | ATM_flx_precip = ATM_flux_int ( ATM_precip ) |
---|
688 | ATM_flx_snowf = ATM_flux_int ( ATM_snowf ) |
---|
689 | ATM_flx_evap = ATM_flux_int ( ATM_evap ) |
---|
690 | ATM_flx_runlic = ATM_flux_int ( ATM_runofflic ) |
---|
691 | |
---|
692 | RUN_flx_coastal = ONE_flux_int ( RUN_coastalflow) |
---|
693 | RUN_flx_river = ONE_flux_int ( RUN_riverflow ) |
---|
694 | RUN_flx_drainage = ATM_flux_int ( RUN_drainage ) |
---|
695 | RUN_flx_riversret = ATM_flux_int ( RUN_riversret ) |
---|
696 | RUN_flx_runoff = ATM_flux_int ( RUN_runoff ) |
---|
697 | RUN_flx_input = ATM_flux_int ( RUN_input ) |
---|
698 | RUN_flx_output = ONE_flux_int ( RUN_output ) |
---|
699 | |
---|
700 | ATM_flx_emp = ATM_flx_evap - ATM_flx_precip |
---|
701 | ATM_flx_bilo = ATM_flx_oce + ATM_flx_sic + ATM_flx_ter + ATM_flx_lic |
---|
702 | RUN_flx_bil = RUN_flx_input - RUN_flx_output |
---|
703 | |
---|
704 | RUN_flx_rivcoa = RUN_flx_coastal + RUN_flx_river |
---|
705 | |
---|
706 | ATM_flx_bilo2 = ATM_flux_int (ATM_bilo) |
---|
707 | |
---|
708 | |
---|
709 | echo (' wbilo_oce {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_oce , ATM_flx_oce / dtime_sec*1E-6/ATM_rho, ATM_flx_oce /ATM_aire_sea_tot/ATM_rho )) |
---|
710 | echo (' wbilo_sic {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_sic , ATM_flx_sic / dtime_sec*1E-6/ATM_rho, ATM_flx_sic /ATM_aire_sea_tot/ATM_rho )) |
---|
711 | echo (' wbilo_sic+oce {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_sea , ATM_flx_sea / dtime_sec*1E-6/ATM_rho, ATM_flx_sea /ATM_aire_sea_tot/ATM_rho )) |
---|
712 | echo (' wbilo_ter {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_ter , ATM_flx_ter / dtime_sec*1E-6/ATM_rho, ATM_flx_ter /ATM_aire_sea_tot/ATM_rho )) |
---|
713 | echo (' wbilo_lic {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_lic , ATM_flx_lic / dtime_sec*1E-6/ATM_rho, ATM_flx_lic /ATM_aire_sea_tot/ATM_rho )) |
---|
714 | echo (' Sum wbilo_* {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_bilo , ATM_flx_bilo / dtime_sec*1E-6/ATM_rho, ATM_flx_bilo /ATM_aire_sea_tot/ATM_rho )) |
---|
715 | echo (' E-P {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_emp , ATM_flx_emp / dtime_sec*1E-6/ATM_rho, ATM_flx_emp /ATM_aire_sea_tot/ATM_rho )) |
---|
716 | echo (' calving {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_calving , ATM_flx_calving / dtime_sec*1E-6/ATM_rho, ATM_flx_calving /ATM_aire_sea_tot/ATM_rho )) |
---|
717 | echo (' fqfonte {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_qfonte , ATM_flx_qfonte / dtime_sec*1E-6/ATM_rho, ATM_flx_qfonte /ATM_aire_sea_tot/ATM_rho )) |
---|
718 | echo (' precip {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_precip , ATM_flx_precip / dtime_sec*1E-6/ATM_rho, ATM_flx_precip /ATM_aire_sea_tot/ATM_rho )) |
---|
719 | echo (' snowf {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_snowf , ATM_flx_snowf / dtime_sec*1E-6/ATM_rho, ATM_flx_snowf /ATM_aire_sea_tot/ATM_rho )) |
---|
720 | echo (' evap {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_evap , ATM_flx_evap / dtime_sec*1E-6/ATM_rho, ATM_flx_evap /ATM_aire_sea_tot/ATM_rho )) |
---|
721 | echo (' coastalflow {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_coastal , RUN_flx_coastal / dtime_sec*1E-6/ATM_rho, RUN_flx_coastal /ATM_aire_sea_tot/ATM_rho )) |
---|
722 | echo (' riverflow {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_river , RUN_flx_river / dtime_sec*1E-6/ATM_rho, RUN_flx_river /ATM_aire_sea_tot/ATM_rho )) |
---|
723 | echo (' river+coastal {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_rivcoa , RUN_flx_rivcoa / dtime_sec*1E-6/ATM_rho, RUN_flx_rivcoa /ATM_aire_sea_tot/ATM_rho )) |
---|
724 | echo (' drainage {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_drainage , RUN_flx_drainage / dtime_sec*1E-6/ATM_rho, RUN_flx_drainage /ATM_aire_sea_tot/ATM_rho )) |
---|
725 | echo (' riversret {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_riversret, RUN_flx_riversret/ dtime_sec*1E-6/ATM_rho, RUN_flx_riversret/ATM_aire_sea_tot/ATM_rho )) |
---|
726 | echo (' runoff {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_runoff , RUN_flx_runoff / dtime_sec*1E-6/ATM_rho, RUN_flx_runoff /ATM_aire_sea_tot/ATM_rho )) |
---|
727 | echo (' river in {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_input , RUN_flx_input / dtime_sec*1E-6/ATM_rho, RUN_flx_input /ATM_aire_sea_tot/ATM_rho )) |
---|
728 | echo (' river out {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_output , RUN_flx_output / dtime_sec*1E-6/ATM_rho, RUN_flx_output /ATM_aire_sea_tot/ATM_rho )) |
---|
729 | echo (' river bil {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_bil , RUN_flx_bil / dtime_sec*1E-6/ATM_rho, RUN_flx_bil /ATM_aire_sea_tot/ATM_rho )) |
---|
730 | echo (' runoff lic {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_runlic , ATM_flx_runlic / dtime_sec*1E-6/ATM_rho, ATM_flx_runlic /ATM_aire_sea_tot/ATM_rho )) |
---|
731 | |
---|
732 | ATM_flx_budget = -ATM_flx_sea + ATM_flx_calving + ATM_flx_runlic #+ ATM_flx_qfonte + RUN_flx_river |
---|
733 | echo ('\n Global {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_budget , ATM_flx_budget / dtime_sec*1E-9, ATM_flx_budget /ATM_aire_sea_tot/ATM_rho )) |
---|
734 | |
---|
735 | #echo (' E-P-R {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_emp , ATM_flx_emp / dtime_sec*1E-6/ATM_rho, ATM_flx_emp /ATM_aire_sea_tot/ATM_rho )) |
---|
736 | |
---|
737 | |
---|
738 | echo ( '------------------------------------------------------------------------------------' ) |
---|
739 | echo ( '-- SECHIBA fluxes' ) |
---|
740 | |
---|
741 | |
---|
742 | SRF_flx_evap = ATM_flux_int ( SRF_evap ) |
---|
743 | SRF_flx_snowf = ATM_flux_int ( SRF_snowf ) |
---|
744 | SRF_flx_subli = ATM_flux_int ( SRF_subli ) |
---|
745 | SRF_flx_transpir = ATM_flux_int ( SRF_transpir ) |
---|
746 | |
---|
747 | echo (' evap {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_evap , SRF_flx_evap / dtime_sec*1E-6/ATM_rho, SRF_flx_evap /ATM_aire_sea_tot/ATM_rho )) |
---|
748 | echo (' snowf {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_snowf , SRF_flx_snowf / dtime_sec*1E-6/ATM_rho, SRF_flx_snowf /ATM_aire_sea_tot/ATM_rho )) |
---|
749 | echo (' subli {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_subli , SRF_flx_subli / dtime_sec*1E-6/ATM_rho, SRF_flx_subli /ATM_aire_sea_tot/ATM_rho )) |
---|
750 | echo (' transpir {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_transpir , SRF_flx_transpir / dtime_sec*1E-6/ATM_rho, SRF_flx_transpir /ATM_aire_sea_tot/ATM_rho )) |
---|