1 | !/usr/bin/env python3 |
---|
2 | ### |
---|
3 | ### Script to check water conservation in NEMO |
---|
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 = { |
---|
15 | 'Author' : "$Author$", |
---|
16 | 'Date' : "$Date$", |
---|
17 | 'Revision': "$Revision$", |
---|
18 | 'Id' : "$Id: $", |
---|
19 | 'HeadURL' : "$HeadUrl: $" |
---|
20 | } |
---|
21 | |
---|
22 | ### |
---|
23 | ## Import system modules |
---|
24 | import sys |
---|
25 | import os |
---|
26 | import subprocess |
---|
27 | import configparser |
---|
28 | from pathlib import Path |
---|
29 | |
---|
30 | ## Import needed scientific modules |
---|
31 | import numpy as np |
---|
32 | import xarray as xr |
---|
33 | |
---|
34 | ## Import local module |
---|
35 | import WaterUtils as wu |
---|
36 | import nemo |
---|
37 | |
---|
38 | ## Read command line arguments |
---|
39 | ## --------------------------- |
---|
40 | print ( "Name of Python script:", sys.argv[0] ) |
---|
41 | IniFile = sys.argv[1] |
---|
42 | |
---|
43 | # Test existence of IniFile |
---|
44 | if not os.path.exists (IniFile ) : |
---|
45 | raise FileExistsError ( f"File not found : {IniFile = }" ) |
---|
46 | |
---|
47 | if 'full' in IniFile or 'OCE' in IniFile : |
---|
48 | FullIniFile = IniFile |
---|
49 | else : |
---|
50 | FullIniFile = 'OCE_' + IniFile |
---|
51 | |
---|
52 | |
---|
53 | print ("Output parameter file : ", FullIniFile) |
---|
54 | |
---|
55 | ## Experiment parameters |
---|
56 | ## --------------------- |
---|
57 | dpar = wu.ReadConfig ( IniFile ) |
---|
58 | |
---|
59 | ## Configure all needed parameter from existant parameters |
---|
60 | ## ------------------------------------------------------- |
---|
61 | dpar = wu.SetDatesAndFiles (dpar) |
---|
62 | |
---|
63 | ## Output file with water budget diagnostics |
---|
64 | ## ----------------------------------------- |
---|
65 | f_out = dpar['Files']['f_out'] |
---|
66 | |
---|
67 | ## Put dpar values in local namspace |
---|
68 | ## --------------------------------- |
---|
69 | for Section in dpar.keys () : |
---|
70 | print ( f'\nReading [{Section}]' ) |
---|
71 | for VarName in dpar[Section].keys() : |
---|
72 | locals()[VarName] = dpar[Section][VarName] |
---|
73 | print ( f' {VarName:21} set to : {locals()[VarName]}' ) |
---|
74 | |
---|
75 | ## Debuging and timer |
---|
76 | Timer = wu.functools.partial (wu.Timer, debug=Debug, timer=Timing) |
---|
77 | |
---|
78 | ## Useful functions |
---|
79 | ## ---------------- |
---|
80 | |
---|
81 | # Degrades precision |
---|
82 | if repr (readPrec) == "<class 'numpy.float64'>" or readPrec == float : |
---|
83 | def rprec (ptab) : |
---|
84 | '''This version does nothing |
---|
85 | |
---|
86 | rprec may be use to reduce floating precision when reading history files |
---|
87 | ''' |
---|
88 | return ptab |
---|
89 | else : |
---|
90 | def rprec (ptab) : |
---|
91 | '''Return float with a different precision''' |
---|
92 | return ptab.astype(readPrec).astype(float) |
---|
93 | |
---|
94 | def kg2Sv (val, rho=ATM_RHO) : |
---|
95 | '''From kg to Sverdrup''' |
---|
96 | return val/dtime_sec*1.0e-6/rho |
---|
97 | |
---|
98 | def kg2myear (val, rho=ATM_RHO) : |
---|
99 | '''From kg to m/year''' |
---|
100 | return val/OCE.OCE_aire_tot/rho/NbYear |
---|
101 | |
---|
102 | def var2prt (var, small=False, rho=ATM_RHO) : |
---|
103 | '''Formats value for printing''' |
---|
104 | if small : return var , kg2Sv(var, rho=rho)*1000., kg2myear(var, rho=rho)*1000. |
---|
105 | else : return var , kg2Sv(var, rho=rho) , kg2myear(var, rho=rho) |
---|
106 | |
---|
107 | def prtFlux (Desc, var, Form='F', small=False, rho=ATM_RHO, width=15) : |
---|
108 | '''Pretty print of formattd value''' |
---|
109 | if small : |
---|
110 | if Form in ['f', 'F'] : ff=" {:14.6e} kg | {:12.4f} mSv | {:12.4f} mm/year " |
---|
111 | if Form in ['e', 'E'] : ff=" {:14.6e} kg | {:12.4e} mSv | {:12.4e} mm/year " |
---|
112 | else : |
---|
113 | if Form in ['f', 'F'] : ff=" {:14.6e} kg | {:12.4f} Sv | {:12.4f} m/year " |
---|
114 | if Form in ['e', 'E'] : ff=" {:14.6e} kg | {:12.4e} Sv | {:12.4e} m/year " |
---|
115 | echo ( (' {:>{width}} = ' +ff).format (Desc, *var2prt(var, small, rho=rho), width=width ) ) |
---|
116 | |
---|
117 | def echo (string, end='\n') : |
---|
118 | '''Function to print to stdout *and* output file''' |
---|
119 | print ( str(string), end=end ) |
---|
120 | sys.stdout.flush () |
---|
121 | f_out.write ( str(string) + end ) |
---|
122 | f_out.flush () |
---|
123 | |
---|
124 | ## |
---|
125 | ## Open history files |
---|
126 | ## ------------------ |
---|
127 | |
---|
128 | d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
129 | d_OCE_sca = xr.open_dataset ( file_OCE_sca, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
130 | d_ICE_his = xr.open_dataset ( file_ICE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
131 | |
---|
132 | udims = udims={'y':'y', 'x':'x'} |
---|
133 | d_OCE_his = nemo.unify_dims ( d_OCE_his, **udims, verbose=False ) |
---|
134 | d_OCE_sca = nemo.unify_dims ( d_OCE_sca, **udims, verbose=False ) |
---|
135 | d_ICE_his = nemo.unify_dims ( d_ICE_his, **udims, verbose=False ) |
---|
136 | |
---|
137 | echo ( f'{file_OCE_his = }' ) |
---|
138 | echo ( f'{file_OCE_sca = }' ) |
---|
139 | echo ( f'{file_ICE_his = }' ) |
---|
140 | |
---|
141 | ## Compute run length |
---|
142 | ## ------------------ |
---|
143 | dtime = ( d_OCE_his.time_counter_bounds.max() - d_OCE_his.time_counter_bounds.min() ) |
---|
144 | echo ( f'\nRun length : {(dtime/np.timedelta64(1, "D")).values:8.2f} days' ) |
---|
145 | dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds |
---|
146 | |
---|
147 | ## Compute length of each period |
---|
148 | ## ----------------------------- |
---|
149 | dtime_per = ( d_OCE_his.time_counter_bounds[:,-1] - d_OCE_his.time_counter_bounds[:,0] ) |
---|
150 | echo ( f'\nPeriods lengths (days) : {(dtime_per/np.timedelta64(1, "D")).values}' ) |
---|
151 | dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds |
---|
152 | dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_OCE_his.time_counter,] ) |
---|
153 | dtime_per_sec.attrs['unit'] = 's' |
---|
154 | |
---|
155 | ## Number of years |
---|
156 | NbYear = dtime_sec / YEAR_LENGTH |
---|
157 | |
---|
158 | ## Define restart periods and file names |
---|
159 | ## ------------------------------------- |
---|
160 | dpar = wu.SetRestartNames ( dpar, f_out) |
---|
161 | |
---|
162 | ## Put dpar values in local namespace |
---|
163 | ## ---------------------------------- |
---|
164 | for Section in dpar.keys () : |
---|
165 | print ( f'\nReading [{Section}]' ) |
---|
166 | for VarName in dpar[Section].keys() : |
---|
167 | locals()[VarName] = dpar[Section][VarName] |
---|
168 | print ( f' {VarName:21} set to : {locals()[VarName]}' ) |
---|
169 | |
---|
170 | echo ( f'{tar_restart_beg = }' ) |
---|
171 | echo ( f'{tar_restart_end = }' ) |
---|
172 | |
---|
173 | echo ( f'{file_OCE_beg}' ) |
---|
174 | echo ( f'{file_OCE_end}' ) |
---|
175 | echo ( f'{file_ICE_beg}' ) |
---|
176 | echo ( f'{file_ICE_end}' ) |
---|
177 | |
---|
178 | liste_beg = [file_OCE_beg, file_ICE_beg ] |
---|
179 | liste_end = [file_ATM_end, file_ICE_end ] |
---|
180 | |
---|
181 | ## Write the full configuration |
---|
182 | params_out = open (FullIniFile, 'w', encoding = 'utf-8') |
---|
183 | params = wu.dict2config ( dpar ) |
---|
184 | params.write ( params_out ) |
---|
185 | params_out.close () |
---|
186 | |
---|
187 | echo ('\nExtract and rebuild OCE and ICE restarts') |
---|
188 | def get_ndomain (zfile) : |
---|
189 | echo ( '--- get domain -- ' ) |
---|
190 | echo ( f'{zfile = }' ) |
---|
191 | #d_zfile = xr.open_dataset (zfile, decode_times=False).squeeze() |
---|
192 | #ndomain_opa = d_zfile.attrs['DOMAIN_number_total'] |
---|
193 | #d_zfile.close () |
---|
194 | ndomain_opa = subprocess.getoutput ( f'ls {zfile}_*.nc | wc -l' ) #.format() |
---|
195 | echo ( f'{ndomain_opa = }' ) |
---|
196 | return int (ndomain_opa) |
---|
197 | |
---|
198 | @Timer |
---|
199 | def extract_and_rebuild ( file_name=file_OCE_beg, tar_restart=tar_restart_end, file_dir_comp=FileDirOCE ) : |
---|
200 | '''Extract restart file from tar. Rebuild ocean files if needed''' |
---|
201 | echo ( '---------- extract_and_rebuild --') |
---|
202 | echo ( f'{file_name = }' ) |
---|
203 | echo ( f'{tar_restart }' ) |
---|
204 | echo ( f'{file_dir_comp = }' ) |
---|
205 | error_count = 0 |
---|
206 | if os.path.exists ( file_name ) : |
---|
207 | echo ( f'-- File ready : {file_name = }' ) |
---|
208 | else : |
---|
209 | echo ( f'-- Extracting {file_name = }' ) |
---|
210 | base_resFile = Path (file_name).stem # basename, and remove suffix |
---|
211 | # Try to extract the rebuilded file |
---|
212 | if os.path.exists ( tar_restart ) : |
---|
213 | command = f'cd {file_dir_comp} ; tar xf {tar_restart} {base_resFile}.nc' |
---|
214 | echo ( f'{command = }' ) |
---|
215 | ierr = os.system ( command ) |
---|
216 | if ierr != 0 : |
---|
217 | if not os.path.exists ( os.path.join (FileDir, f'{base_resFile}_0000.nc') ): |
---|
218 | command = f'cd {file_dir_comp} ; tar xf {tar_restart} {base_resFile}_*.nc' |
---|
219 | echo ( f'{command = }' ) |
---|
220 | ierr = os.system ( command ) |
---|
221 | if ierr == 0 : |
---|
222 | echo ( f'tar done : {base_resFile}.nc') |
---|
223 | else : |
---|
224 | if ContinueOnError : |
---|
225 | error_count += 1 |
---|
226 | echo ( f'****** Command failed : {command}' ) |
---|
227 | echo ( '****** Trying to continue' ) |
---|
228 | echo ( ' ') |
---|
229 | else : |
---|
230 | raise OSError ( f'command failed : {command}' ) |
---|
231 | echo ( 'extract ndomain' ) |
---|
232 | ndomain_opa = get_ndomain ( os.path.join (file_dir_comp, f'{base_resFile}') ) |
---|
233 | command = f'cd {file_dir_comp} ; {rebuild} {base_resFile} {ndomain_opa} ; mv {base_resFile}.nc {FileDir}' |
---|
234 | echo ( f'{command = }' ) |
---|
235 | ierr = os.system ( command ) |
---|
236 | if ierr == 0 : |
---|
237 | echo ( f'Rebuild done : {base_resFile}.nc') |
---|
238 | else : |
---|
239 | if ContinueOnError : |
---|
240 | error_count += 1 |
---|
241 | echo ( f'****** Command failed : {command}' ) |
---|
242 | echo ( '****** Trying to continue' ) |
---|
243 | echo ( ' ') |
---|
244 | else : |
---|
245 | raise OSError ( f'command failed : {command}' ) |
---|
246 | else : |
---|
247 | echo ( f'tar done : {base_resFile}') |
---|
248 | command = f'cd {file_dir_comp} ; mv {base_resFile}.nc {FileDir}' |
---|
249 | echo ( f'{command = }' ) |
---|
250 | ierr = os.system ( command ) |
---|
251 | if ierr == 0 : |
---|
252 | echo ( f'command done : {command}' ) |
---|
253 | else : |
---|
254 | if ContinueOnError : |
---|
255 | error_count = 1 |
---|
256 | echo ( f'****** Command failed : {command}' ) |
---|
257 | echo ( '****** Trying to continue' ) |
---|
258 | echo ( ' ') |
---|
259 | else : |
---|
260 | raise OSError ( f'command failed : {command = }' ) |
---|
261 | else : |
---|
262 | echo ( f'****** Tar restart file {tar_restart = } not found ' ) |
---|
263 | if ContinueOnError : |
---|
264 | error_count += 1 |
---|
265 | echo ( '****** Command failed' ) |
---|
266 | echo ( '****** Trying to continue' ) |
---|
267 | echo ( ' ') |
---|
268 | else : |
---|
269 | raise OSError ( f'****** tar file not found {tar_restart = } - Stopping' ) |
---|
270 | return error_count |
---|
271 | |
---|
272 | ErrorCount = 0 |
---|
273 | ErrorCount += extract_and_rebuild ( file_name=file_OCE_beg, tar_restart=tar_restart_beg, file_dir_comp=FileDirOCE ) |
---|
274 | ErrorCount += extract_and_rebuild ( file_name=file_OCE_end, tar_restart=tar_restart_end, file_dir_comp=FileDirOCE ) |
---|
275 | ErrorCount += extract_and_rebuild ( file_name=file_ICE_beg, tar_restart=tar_restart_beg, file_dir_comp=FileDirICE ) |
---|
276 | ErrorCount += extract_and_rebuild ( file_name=file_ICE_end, tar_restart=tar_restart_end, file_dir_comp=FileDirICE ) |
---|
277 | |
---|
278 | ##-- Exit in case of error in the opening file phase |
---|
279 | if ErrorCount > 0 : |
---|
280 | echo ( ' ' ) |
---|
281 | raise RuntimeError ( f'**** Some files missing - Stopping - {ErrorCount = }' ) |
---|
282 | |
---|
283 | echo ('Opening OCE and ICE restart files') |
---|
284 | if NEMO == 3.6 : |
---|
285 | d_OCE_beg = xr.open_dataset ( os.path.join (FileDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
286 | d_OCE_end = xr.open_dataset ( os.path.join (FileDir, file_OCE_end), decode_times=False, decode_cf=True).squeeze() |
---|
287 | d_ICE_beg = xr.open_dataset ( os.path.join (FileDir, file_ICE_beg), decode_times=False, decode_cf=True).squeeze() |
---|
288 | d_ICE_end = xr.open_dataset ( os.path.join (FileDir, file_ICE_end), decode_times=False, decode_cf=True).squeeze() |
---|
289 | if NEMO in [ 4.0, 4.2 ] : |
---|
290 | d_OCE_beg = xr.open_dataset ( os.path.join (FileDir, file_OCE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
291 | d_OCE_end = xr.open_dataset ( os.path.join (FileDir, file_OCE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
292 | d_ICE_beg = xr.open_dataset ( os.path.join (FileDir, file_ICE_beg), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
293 | d_ICE_end = xr.open_dataset ( os.path.join (FileDir, file_ICE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze() |
---|
294 | |
---|
295 | # Get mask and surfaces |
---|
296 | |
---|
297 | dpar, OCE = wu.ComputeGridOCE ( dpar, d_OCE_his, nperio=nperio ) |
---|
298 | |
---|
299 | # sos = d_OCE_his ['sos'][0].squeeze() |
---|
300 | # OCE_msk = nemo.lbc_mask ( xr.where ( sos>0., 1., 0. ), cd_type = 'T', nperio=nperio, sval = 0. ) |
---|
301 | |
---|
302 | # so = sos = d_OCE_his ['sos'][0].squeeze() |
---|
303 | # OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', nperio=nperio, sval = 0. ) |
---|
304 | |
---|
305 | # # lbc_mask removes the duplicate points (periodicity and north fold) |
---|
306 | # OCE.OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', nperio=nperio, sval = 0.0 ) |
---|
307 | # OCE.ICE_aire = OCE_aire |
---|
308 | |
---|
309 | @Timer |
---|
310 | def OCE_stock_int (stock) : |
---|
311 | '''Integrate stock on ocean grid''' |
---|
312 | return wu.P1sum ( stock * OCE.OCE_aire ) |
---|
313 | |
---|
314 | @Timer |
---|
315 | def ONE_stock_int (stock) : |
---|
316 | '''Sum stock''' |
---|
317 | return wu.P1sum ( stock ) |
---|
318 | |
---|
319 | @Timer |
---|
320 | def OCE_flux_int (flux) : |
---|
321 | '''Integrate flux on oce grid''' |
---|
322 | return wu.P1sum ( flux * OCE.OCE_aire * dtime_per_sec ) |
---|
323 | |
---|
324 | @Timer |
---|
325 | def ONE_flux_int (flux) : |
---|
326 | '''Integrate flux on oce grid''' |
---|
327 | return wu.P1sum ( flux * dtime_per_sec ) |
---|
328 | |
---|
329 | #OCE.OCE_aire_tot = ONE_stock_int ( OCE.OCE_aire ) |
---|
330 | #OCE.ICE_aire_tot = ONE_stock_int ( OCE.ICE_aire ) |
---|
331 | |
---|
332 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
333 | echo ( '-- NEMO change in stores (for the records)' ) |
---|
334 | #-- Note that the total number of days of the run should be diagnosed rather than assumed |
---|
335 | #-- Here the result is in Sv |
---|
336 | # |
---|
337 | #-- Change in ocean volume in freshwater equivalent |
---|
338 | |
---|
339 | OCE.OCE_ssh_beg = d_OCE_beg['sshn'] |
---|
340 | OCE.OCE_ssh_end = d_OCE_end['sshn'] |
---|
341 | |
---|
342 | OCE.OCE_sum_ssh_beg = OCE_stock_int ( OCE.OCE_ssh_beg ) |
---|
343 | OCE.OCE_sum_ssh_end = OCE_stock_int ( OCE.OCE_ssh_end ) |
---|
344 | |
---|
345 | if NEMO == 3.6 : |
---|
346 | OCE.OCE_e3tn_beg = d_OCE_beg['fse3t_n'] |
---|
347 | OCE.OCE_e3tn_end = d_OCE_end['fse3t_n'] |
---|
348 | OCE.OCE_sum_e3tn_beg = OCE_stock_int ( OCE.OCE_e3tn_beg * OCE.OCE_msk3) |
---|
349 | OCE.OCE_sum_e3tn_end = OCE_stock_int ( OCE.OCE_e3tn_end * OCE.OCE_msk3) |
---|
350 | |
---|
351 | echo ( f'OCE.OCE_sum_ssh_beg = {OCE.OCE_sum_ssh_beg:12.6e} m^3 - OCE.OCE_sum_ssh_end = {OCE.OCE_sum_ssh_end:12.6e} m^3' ) |
---|
352 | OCE.OCE_diff_ssh_vol = OCE.OCE_sum_ssh_end - OCE.OCE_sum_ssh_beg |
---|
353 | OCE.OCE_diff_ssh_mas = OCE.OCE_diff_ssh_vol * OCE_RHO_LIQ |
---|
354 | |
---|
355 | if NEMO == 3.6 : |
---|
356 | echo ( f'OCE.OCE_sum_e3tn_beg = {OCE.OCE_sum_e3tn_beg:12.6e} m^3 - OCE.OCE_sum_e3tn_end = {OCE.OCE_sum_e3tn_end:12.6e} m^3' ) |
---|
357 | OCE.OCE_diff_e3tn_vol = OCE.OCE_sum_e3tn_end - OCE.OCE_sum_e3tn_beg |
---|
358 | OCE.OCE_diff_e3tn_mas = OCE.OCE_diff_e3tn_vol * OCE_RHO_LIQ |
---|
359 | |
---|
360 | OCE.OCE_diff_vol_wat = OCE.OCE_diff_ssh_vol ; OCE.OCE_diff_mas_wat = OCE.OCE_diff_ssh_mas |
---|
361 | |
---|
362 | echo ( f'dOCE vol = {OCE.OCE_diff_vol_wat :12.3e} m^3' ) |
---|
363 | echo ( f'dOCE ssh = {OCE.OCE_diff_vol_wat/OCE.OCE_aire_tot:12.3e} m ' ) |
---|
364 | prtFlux ( 'dOCE mass ', OCE.OCE_diff_mas_wat, 'e' ) |
---|
365 | |
---|
366 | if NEMO == 3.6 : |
---|
367 | echo ( f'dOCE e3tn vol = {OCE.OCE_diff_e3tn_vol:12.3e} m^3' ) |
---|
368 | prtFlux ( 'dOCE e3tn mass', OCE.OCE_diff_e3tn_mas, 'e' ) |
---|
369 | |
---|
370 | ## Glace et neige |
---|
371 | if NEMO == 3.6 : |
---|
372 | OCE.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'] |
---|
373 | OCE.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'] |
---|
374 | |
---|
375 | OCE.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'] |
---|
376 | OCE.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'] |
---|
377 | |
---|
378 | OCE.ICE_pnd_beg = 0.0 ; OCE.ICE_pnd_end = 0.0 ; OCE.ICE_fzl_beg = 0.0 ; OCE.ICE_fzl_end = 0.0 |
---|
379 | |
---|
380 | OCE.ICE_mas_wat_beg = OCE.ICE_ice_beg*ICE_RHO_ICE + OCE.ICE_sno_beg*ICE_RHO_SNO |
---|
381 | OCE.ICE_mas_wat_end = OCE.ICE_ice_end*ICE_RHO_ICE + OCE.ICE_sno_end*ICE_RHO_SNO |
---|
382 | |
---|
383 | if NEMO in [ 4.0, 4.2 ] : |
---|
384 | OCE.ICE_ice_beg = d_ICE_beg['v_i'] ; OCE.ICE_ice_end = d_ICE_end['v_i'] |
---|
385 | OCE.ICE_sno_beg = d_ICE_beg['v_s'] ; OCE.ICE_sno_end = d_ICE_end['v_s'] |
---|
386 | OCE.ICE_pnd_beg = d_ICE_beg['v_ip'] ; OCE.ICE_pnd_end = d_ICE_end['v_ip'] # Ice ponds |
---|
387 | OCE.ICE_fzl_beg = d_ICE_beg['v_il'] ; OCE.ICE_fzl_end = d_ICE_end['v_il'] # Frozen Ice Ponds |
---|
388 | |
---|
389 | OCE.ICE_mas_wat_beg = OCE_stock_int ( d_ICE_beg['snwice_mass'] ) |
---|
390 | OCE.ICE_mas_wat_end = OCE_stock_int ( d_ICE_end['snwice_mass'] ) |
---|
391 | |
---|
392 | OCE.ICE_vol_ice_beg = OCE_stock_int ( OCE.ICE_ice_beg ) |
---|
393 | OCE.ICE_vol_ice_end = OCE_stock_int ( OCE.ICE_ice_end ) |
---|
394 | |
---|
395 | OCE.ICE_vol_sno_beg = OCE_stock_int ( OCE.ICE_sno_beg ) |
---|
396 | OCE.ICE_vol_sno_end = OCE_stock_int ( OCE.ICE_sno_end ) |
---|
397 | |
---|
398 | OCE.ICE_vol_pnd_beg = OCE_stock_int ( OCE.ICE_pnd_beg ) |
---|
399 | OCE.ICE_vol_pnd_end = OCE_stock_int ( OCE.ICE_pnd_end ) |
---|
400 | |
---|
401 | OCE.ICE_vol_fzl_beg = OCE_stock_int ( OCE.ICE_fzl_beg ) |
---|
402 | OCE.ICE_vol_fzl_end = OCE_stock_int ( OCE.ICE_fzl_end ) |
---|
403 | |
---|
404 | #-- Converting to freswater volume |
---|
405 | OCE.ICE_diff_vol_ice = OCE.ICE_vol_ice_end - OCE.ICE_vol_ice_beg |
---|
406 | OCE.ICE_diff_mas_ice = OCE.ICE_diff_vol_ice * ICE_RHO_ICE |
---|
407 | |
---|
408 | OCE.ICE_diff_vol_sno = OCE.ICE_vol_sno_end - OCE.ICE_vol_sno_beg |
---|
409 | OCE.ICE_diff_mas_sno = OCE.ICE_diff_vol_sno * ICE_RHO_SNO |
---|
410 | |
---|
411 | OCE.ICE_diff_vol_pnd = OCE.ICE_vol_pnd_end - OCE.ICE_vol_pnd_beg |
---|
412 | OCE.ICE_diff_mas_pnd = OCE.ICE_diff_vol_pnd * ICE_RHO_PND |
---|
413 | |
---|
414 | OCE.ICE_diff_vol_fzl= OCE.ICE_vol_fzl_end - OCE.ICE_vol_fzl_beg |
---|
415 | OCE.ICE_diff_mas_fzl = OCE.ICE_diff_vol_fzl * ICE_RHO_PND |
---|
416 | |
---|
417 | if NEMO == 3.6 : |
---|
418 | OCE.ICE_diff_mas_wat = OCE.ICE_diff_mas_ice + OCE.ICE_diff_mas_sno |
---|
419 | OCE.OCE_diff_SEA_mas_wat = OCE.OCE_diff_mas_wat + OCE.ICE_diff_mas_ice + OCE.ICE_diff_mas_sno |
---|
420 | |
---|
421 | if NEMO in [4.0, 4.2 ] : |
---|
422 | OCE.ICE_diff_mas_wat = OCE.ICE_mas_wat_end - OCE.ICE_mas_wat_beg |
---|
423 | OCE.OCE_diff_SEA_mas_wat = OCE.OCE_diff_mas_wat + OCE.ICE_diff_mas_wat |
---|
424 | |
---|
425 | echo ( f'OCE.ICE_vol_ice_beg = {OCE.ICE_vol_ice_beg:12.6e} m^3 | OCE.ICE_vol_ice_end = {OCE.ICE_vol_ice_end:12.6e} m^3' ) |
---|
426 | echo ( f'OCE.ICE_vol_sno_beg = {OCE.ICE_vol_sno_beg:12.6e} m^3 | OCE.ICE_vol_sno_end = {OCE.ICE_vol_sno_end:12.6e} m^3' ) |
---|
427 | echo ( f'OCE.ICE_vol_pnd_beg = {OCE.ICE_vol_pnd_beg:12.6e} m^3 | OCE.ICE_vol_pnd_end = {OCE.ICE_vol_pnd_end:12.6e} m^3' ) |
---|
428 | echo ( f'OCE.ICE_vol_fzl_beg = {OCE.ICE_vol_fzl_beg:12.6e} m^3 | OCE.ICE_vol_fzl_end = {OCE.ICE_vol_fzl_end:12.6e} m^3' ) |
---|
429 | |
---|
430 | echo ( f'OCE.ICE_diff_vol_ice = {OCE.ICE_diff_vol_ice:12.3e} m^3' ) |
---|
431 | echo ( f'OCE.ICE_diff_vol_sno = {OCE.ICE_diff_vol_sno:12.3e} m^3' ) |
---|
432 | echo ( f'OCE.ICE_diff_vol_pnd = {OCE.ICE_diff_vol_pnd:12.3e} m^3' ) |
---|
433 | echo ( f'OCE.ICE_diff_mas_ice = {OCE.ICE_diff_mas_ice:12.3e} m^3' ) |
---|
434 | echo ( f'OCE.ICE_diff_mas_sno = {OCE.ICE_diff_mas_sno:12.3e} m^3' ) |
---|
435 | echo ( f'OCE.ICE_diff_mas_pnd = {OCE.ICE_diff_mas_pnd:12.3e} m^3' ) |
---|
436 | echo ( f'OCE.ICE_diff_mas_fzl = {OCE.ICE_diff_mas_fzl:12.3e} m^3' ) |
---|
437 | |
---|
438 | echo ( '\n------------------------------------------------------------') |
---|
439 | echo ( 'Change in water content (ocean + ice) ' ) |
---|
440 | prtFlux ( 'dMass (ocean)', OCE.OCE_diff_SEA_mas_wat, 'e', True ) |
---|
441 | |
---|
442 | |
---|
443 | ### |
---|
444 | ### And now, working on fluxes !! |
---|
445 | |
---|
446 | # if coupled: |
---|
447 | # emp_oce = evap - precip (including blowing snow) - calving |
---|
448 | # emp_ice = evap - precip (excluding blowing snow) |
---|
449 | # emp_ice = wfx_spr(<0) + wfx_sub(>0) + wfx_snw_sub(v4.0.6) - wfx_err_sub(<0) |
---|
450 | # runoffs = rivers + icebergs |
---|
451 | # empmr = emp_oce - wfx_ice - wfx_snw - wfx_pnd(v4.0.6) - wfx_err_sub - runoffs |
---|
452 | # doce+ice = - evap + precip + calving (emp_oce) |
---|
453 | # + rivers + icebergs (friver+iceberg ou runoffs) |
---|
454 | # + iceshelf (iceshelf) |
---|
455 | # - emp_ice (emp_ice) |
---|
456 | # dice = - emp_ice - wfx_snw - wfx_ice - wfx_pnd(v4.0.6) - wfx_err_sub |
---|
457 | |
---|
458 | #OCE.OCE_emp = evap - precip (including blowing snow) - calving |
---|
459 | #OCE.ICE_emp = wfx_spr(<0) + wfx_sub(>0) + wfx_snw_sub(v4.0.6) - wfx_err_sub(<0) |
---|
460 | |
---|
461 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
462 | echo ( '-- Checks in NEMO - from budget_modipsl.sh (Clément Rousset)' ) |
---|
463 | |
---|
464 | # Read variable and computes integral over space and time |
---|
465 | OCE.OCE_empmr = rprec (d_OCE_his['wfo'] ) ; OCE.OCE_mas_empmr = OCE_flux_int ( OCE.OCE_empmr ) |
---|
466 | OCE.OCE_wfob = rprec (d_OCE_his['wfob'] ) ; OCE.OCE_mas_wfob = OCE_flux_int ( OCE.OCE_wfob ) |
---|
467 | OCE.OCE_emp_oce = rprec (d_OCE_his['emp_oce'] ) ; OCE.OCE_mas_emp_oce = OCE_flux_int ( OCE.OCE_emp_oce ) |
---|
468 | OCE.OCE_emp_ice = rprec (d_OCE_his['emp_ice'] ) ; OCE.OCE_mas_emp_ice = OCE_flux_int ( OCE.OCE_emp_ice ) |
---|
469 | OCE.OCE_iceshelf = rprec (d_OCE_his['iceshelf']) ; OCE.OCE_mas_iceshelf = OCE_flux_int ( OCE.OCE_iceshelf ) |
---|
470 | OCE.OCE_calving = rprec (d_OCE_his['calving'] ) ; OCE.OCE_mas_calving = OCE_flux_int ( OCE.OCE_calving ) |
---|
471 | OCE.OCE_iceberg = rprec (d_OCE_his['iceberg'] ) ; OCE.OCE_mas_iceberg = OCE_flux_int ( OCE.OCE_iceberg ) |
---|
472 | OCE.OCE_friver = rprec (d_OCE_his['friver'] ) ; OCE.OCE_mas_friver = OCE_flux_int ( OCE.OCE_friver ) |
---|
473 | OCE.OCE_runoffs = rprec (d_OCE_his['runoffs'] ) ; OCE.OCE_mas_runoffs = OCE_flux_int ( OCE.OCE_runoffs ) |
---|
474 | if NEMO in [ 4.0, 4.2 ] : |
---|
475 | OCE.OCE_wfxice = rprec (d_OCE_his['vfxice']) ; OCE.OCE_mas_wfxice = OCE_flux_int ( OCE.OCE_wfxice ) |
---|
476 | OCE.OCE_wfxsnw = rprec (d_OCE_his['vfxsnw']) ; OCE.OCE_mas_wfxsnw = OCE_flux_int ( OCE.OCE_wfxsnw ) |
---|
477 | OCE.OCE_wfxsub = rprec (d_OCE_his['vfxsub']) ; OCE.OCE_mas_wfxsub = OCE_flux_int ( OCE.OCE_wfxsub ) |
---|
478 | if NEMO == 3.6 : |
---|
479 | OCE.OCE_wfxice = rprec (d_OCE_his['vfxice'])/nemo.RDAY*ICE_RHO_ICE ; OCE.OCE_mas_wfxice = OCE_flux_int ( OCE.OCE_wfxice ) |
---|
480 | OCE.OCE_wfxsnw = rprec (d_OCE_his['vfxsnw'])/nemo.RDAY*ICE_RHO_SNO ; OCE.OCE_mas_wfxsnw = OCE_flux_int ( OCE.OCE_wfxsnw ) |
---|
481 | OCE.OCE_wfxsub = rprec (d_OCE_his['vfxsub'])/nemo.RDAY*ICE_RHO_SNO ; OCE.OCE_mas_wfxsub = OCE_flux_int ( OCE.OCE_wfxsub ) |
---|
482 | # Additional checks |
---|
483 | OCE.OCE_evap_oce = rprec (d_OCE_his['evap_ao_cea']) ; OCE.OCE_mas_evap_oce = OCE_flux_int ( OCE.OCE_evap_oce ) |
---|
484 | OCE.ICE_evap_ice = rprec (d_OCE_his['subl_ai_cea']) ; OCE.ICE_mas_evap_ice = OCE_flux_int ( OCE.ICE_evap_ice ) |
---|
485 | OCE.OCE_snow_oce = rprec (d_OCE_his['snow_ao_cea']) ; OCE.OCE_mas_snow_oce = OCE_flux_int ( OCE.OCE_snow_oce ) |
---|
486 | OCE.OCE_snow_ice = rprec (d_OCE_his['snow_ai_cea']) ; OCE.OCE_mas_snow_ice = OCE_flux_int ( OCE.OCE_snow_ice ) |
---|
487 | OCE.OCE_rain = rprec (d_OCE_his['rain'] ) ; OCE.OCE_mas_rain = OCE_flux_int ( OCE.OCE_rain ) |
---|
488 | OCE.ICE_wfxsub_err = rprec (d_ICE_his['vfxsub_err'] ) ; OCE.ICE_mas_wfxsub_err = OCE_flux_int ( OCE.ICE_wfxsub_err ) |
---|
489 | if NEMO in [ 4.0, 4.2 ] : |
---|
490 | OCE.ICE_wfxpnd = rprec (d_ICE_his['vfxpnd'] ) ; OCE.ICE_mas_wfxpnd = OCE_flux_int ( OCE.ICE_wfxpnd ) |
---|
491 | OCE.ICE_wfxsnw_sub = rprec (d_ICE_his['vfxsnw_sub']) ; OCE.ICE_mas_wfxsnw_sub = OCE_flux_int ( OCE.ICE_wfxsnw_sub ) |
---|
492 | OCE.ICE_wfxsnw_pre = rprec (d_ICE_his['vfxsnw_pre']) ; OCE.ICE_mas_wfxsnw_pre = OCE_flux_int ( OCE.ICE_wfxsnw_pre ) |
---|
493 | if NEMO == 3.6 : |
---|
494 | OCE.ICE_wfxpnd = 0.0 ; OCE.ICE_mas_wfxpnd = 0.0 |
---|
495 | OCE.ICE_wfxsnw_sub = rprec (d_ICE_his['vfxsub'])/nemo.RDAY*ICE_RHO_SNO ; OCE.ICE_mas_wfxsnw_sub = OCE_flux_int ( OCE.ICE_wfxsnw_sub ) |
---|
496 | OCE.ICE_wfxsnw_pre = rprec (d_ICE_his['vfxspr'])/nemo.RDAY*ICE_RHO_SNO ; OCE.ICE_mas_wfxsnw_pre = OCE_flux_int ( OCE.ICE_wfxsnw_pre ) |
---|
497 | |
---|
498 | OCE.OCE_wfcorr = rprec (d_OCE_his['wfcorr']) ; OCE.OCE_mas_wfcorr = OCE_flux_int ( OCE.OCE_wfcorr ) |
---|
499 | if OCE_relax : |
---|
500 | # ssr and fwb are included in emp=>empmr but not in emp_oce (outputed by sea-ice) |
---|
501 | OCE.OCE_vflx_fwb = rprec (d_OCE_his['vflx_fwb']) ; OCE.OCE_mas_vflx_fwb = OCE_flux_int ( OCE.OCE_vflx_fwb ) |
---|
502 | OCE.OCE_vflx_ssr = rprec (d_OCE_his['vflx_ssr']) ; OCE.OCE_mas_vflx_ssr = OCE_flux_int ( OCE.OCE_vflx_ssr ) |
---|
503 | else : |
---|
504 | OCE.OCE_fwb = 0.0 ; OCE.OCE_mas_fwb = 0.0 |
---|
505 | OCE.OCE_ssr = 0.0 ; OCE.OCE_mas_ssr = 0.0 |
---|
506 | if OCE_icb : |
---|
507 | OCE.OCE_berg_icb = rprec (d_OCE_his['berg_floating_melt']) ; OCE.OCE_mas_berg_icb = OCE_flux_int ( OCE.OCE_berg_icb ) |
---|
508 | OCE.OCE_calving_icb = rprec (d_OCE_his['calving_icb'] ) ; OCE.OCE_mas_calv_icb = OCE_flux_int ( OCE.OCE_calving_icb ) |
---|
509 | else : |
---|
510 | OCE.OCE_berg_icb = 0. ; OCE.OCE_mas_berg_icb = 0. |
---|
511 | OCE.OCE_calv_icb = 0. ; OCE.OCE_mas_calv_icb = 0. |
---|
512 | |
---|
513 | OCE.OCE_mas_emp = OCE.OCE_mas_emp_oce - OCE.OCE_mas_wfxice - OCE.OCE_mas_wfxsnw - OCE.ICE_mas_wfxpnd - OCE.ICE_mas_wfxsub_err |
---|
514 | OCE.OCE_mas_all = OCE.OCE_mas_emp_oce + OCE.OCE_mas_emp_ice - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceshelf |
---|
515 | |
---|
516 | echo ('\n-- Fields:' ) |
---|
517 | prtFlux ('OCE+ICE budget ', OCE.OCE_mas_all , 'e', True) |
---|
518 | prtFlux (' EMPMR ', OCE.OCE_mas_empmr , 'e', True) |
---|
519 | prtFlux (' WFOB ', OCE.OCE_mas_wfob , 'e', True) |
---|
520 | prtFlux (' EMP_OCE ', OCE.OCE_mas_emp_oce , 'e', True) |
---|
521 | prtFlux (' EMP_ICE ', OCE.OCE_mas_emp_ice , 'e', True) |
---|
522 | prtFlux (' EMP ', OCE.OCE_mas_emp , 'e', True) |
---|
523 | prtFlux (' ICEBERG ', OCE.OCE_mas_iceberg , 'e', True) |
---|
524 | prtFlux (' ICESHELF ', OCE.OCE_mas_iceshelf , 'e', True) |
---|
525 | prtFlux (' CALVING ', OCE.OCE_mas_calving , 'e', True) |
---|
526 | prtFlux (' FRIVER ', OCE.OCE_mas_friver , 'e', True) |
---|
527 | prtFlux (' RUNOFFS ', OCE.OCE_mas_runoffs , 'e', True) |
---|
528 | prtFlux (' WFXICE ', OCE.OCE_mas_wfxice , 'e', True) |
---|
529 | prtFlux (' WFXSNW ', OCE.OCE_mas_wfxsnw , 'e', True) |
---|
530 | prtFlux (' WFXSUB ', OCE.OCE_mas_wfxsub , 'e', True) |
---|
531 | prtFlux (' WFXPND ', OCE.ICE_mas_wfxpnd , 'e', True) |
---|
532 | prtFlux (' WFXSNW_SUB ', OCE.ICE_mas_wfxsnw_sub, 'e', True) |
---|
533 | prtFlux (' WFXSNW_PRE ', OCE.ICE_mas_wfxsnw_pre, 'e', True) |
---|
534 | prtFlux (' WFXSUB_ERR ', OCE.ICE_mas_wfxsub_err, 'e', True) |
---|
535 | prtFlux (' EVAP_OCE ', OCE.OCE_mas_evap_oce , 'e' ) |
---|
536 | prtFlux (' EVAP_ICE ', OCE.ICE_mas_evap_ice , 'e', True) |
---|
537 | prtFlux (' SNOW_OCE ', OCE.OCE_mas_snow_oce , 'e', True) |
---|
538 | prtFlux (' SNOW_ICE ', OCE.OCE_mas_snow_ice , 'e', True) |
---|
539 | prtFlux (' RAIN ', OCE.OCE_mas_rain , 'e' ) |
---|
540 | prtFlux (' FWB ', OCE.OCE_mas_fwb , 'e', True) |
---|
541 | prtFlux (' SSR ', OCE.OCE_mas_ssr , 'e', True) |
---|
542 | prtFlux (' WFCORR ', OCE.OCE_mas_wfcorr , 'e', True) |
---|
543 | prtFlux (' BERG_ICB ', OCE.OCE_mas_berg_icb , 'e', True) |
---|
544 | prtFlux (' CALV_ICB ', OCE.OCE_mas_calv_icb , 'e', True) |
---|
545 | |
---|
546 | echo (' ') |
---|
547 | if Coupled : |
---|
548 | prtFlux ( 'Bilan ocean :', -OCE.OCE_mas_emp_oce - OCE.OCE_mas_emp_ice + OCE.OCE_mas_runoffs + OCE.OCE_mas_iceshelf, 'e', True ) |
---|
549 | else : |
---|
550 | prtFlux ( 'Bilan ocean :', -OCE.OCE_mas_emp_oce - OCE.OCE_mas_emp_ice + OCE.OCE_mas_runoffs + OCE.OCE_mas_iceberg + OCE.OCE_mas_calving + OCE.OCE_mas_iceshelf, 'e', True ) |
---|
551 | |
---|
552 | |
---|
553 | echo ('\n===> Comparing ===>' ) |
---|
554 | echo (' WFX OCE = -empmr + iceshelf = {:12.5e} (kg) '.format ( -OCE.OCE_mas_empmr + OCE.OCE_mas_iceshelf) ) |
---|
555 | echo (' versus d OCE = {:12.5e} (kg) '.format ( OCE.OCE_diff_mas_wat) ) |
---|
556 | echo (' WFX ICE+SNW+PND 1 = emp_ice - wfxice - wfxsnw - wfxpnd - wfxsub_err = {:12.5e} (kg) '.format ( -OCE.OCE_mas_emp_ice - OCE.OCE_mas_wfxice - OCE.OCE_mas_wfxsnw - OCE.ICE_mas_wfxpnd - OCE.ICE_mas_wfxsub_err) ) |
---|
557 | echo (' WFX ICE+SNW+PND 2 = -emp_ice + empmr - emp_oce + runoffs = {:12.5e} (kg) '.format ( -OCE.OCE_mas_emp_ice + OCE.OCE_mas_empmr - OCE.OCE_mas_emp_oce + OCE.OCE_mas_runoffs )) |
---|
558 | echo (' versus d ICE+SNW+PND = {:12.5e} (kg) '.format ( OCE.ICE_diff_mas_wat)) # Manque PND ? |
---|
559 | if Coupled : |
---|
560 | echo (' WFX OCE+ICE+SNW+PND = -emp_oce - emp_ice + runoffs + iceshelf = {:12.5e} (kg) '.format ( -OCE.OCE_mas_emp_oce - OCE.OCE_mas_emp_ice + OCE.OCE_mas_runoffs + OCE.OCE_mas_iceshelf)) |
---|
561 | else : |
---|
562 | echo (' WFX OCE+ICE+SNW+PND = -emp_oce - emp_ice + runoffs + iceberg + calving + iceshelf = {:12.5e} (kg) '.format ( -OCE.OCE_mas_emp_oce - OCE.OCE_mas_emp_ice + OCE.OCE_mas_runoffs + OCE.OCE_mas_iceberg + OCE.OCE_mas_calving + OCE.OCE_mas_iceshelf)) |
---|
563 | echo (' versus d OCE+ICE+SNW+PND = {:12.5e} (kg) '.format ( OCE.OCE_diff_SEA_mas_wat )) # Manque PND |
---|
564 | |
---|
565 | echo ('\n===> Leaks ===>') |
---|
566 | echo (' Leak OCE = OCE.OCE_diff_mas_wat + empmr - iceshelf = {:12.3e} (kg) '.format ( OCE.OCE_diff_mas_wat + OCE.OCE_mas_empmr - OCE.OCE_mas_iceshelf) ) |
---|
567 | echo (' = (OCE.OCE_diff_mas_wat + empmr - iceshelf)/abs(OCE.OCE_diff_mas_wat) = {:12.1e} (-) '.format ( (OCE.OCE_diff_mas_wat + OCE.OCE_mas_empmr - OCE.OCE_mas_iceshelf ) / abs (OCE.OCE_diff_mas_wat) ) ) |
---|
568 | echo (' Leak ICE+SNW+PND 1 = OCE.ICE_diff_mas_wat + emp_ice + wfxice + wfxsnw + wfxpnd + wfxsub_err = {:12.3e} (kg) '.format ( OCE.ICE_diff_mas_wat + OCE.OCE_mas_emp_ice + OCE.OCE_mas_wfxice + OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxpnd + OCE.ICE_mas_wfxsub_err ) ) |
---|
569 | echo (' = (OCE.ICE_diff_mas_wat + emp_ice + wfxice + wfxsnw + wfxpnd + wfxsub_err )/OCE.ICE_diff_mas_wat = {:12.1e} (-) '.format ( (OCE.ICE_diff_mas_wat + OCE.OCE_mas_emp_ice + OCE.OCE_mas_wfxice + OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxpnd + OCE.ICE_mas_wfxsub_err)/abs(OCE.ICE_diff_mas_wat)) ) |
---|
570 | echo (' Leak ICE+SNW+PND 2 = OCE.ICE_diff_mas_wat + emp_ice - empmr + emp_oce - runoffs = {:12.3e} (kg) '.format ( OCE.ICE_diff_mas_wat + OCE.OCE_mas_emp_ice - OCE.OCE_mas_empmr + OCE.OCE_mas_emp_oce - OCE.OCE_mas_runoffs )) |
---|
571 | echo (' = (OCE.ICE_diff_mas_wat - empmr + emp_oce - runoffs)/abs(OCE.ICE_diff_mas_wat) = {:12.1e} (-) '.format ( (OCE.ICE_diff_mas_wat - OCE.OCE_mas_empmr + OCE.OCE_mas_emp_oce - OCE.OCE_mas_runoffs)/abs(OCE.ICE_diff_mas_wat)) ) |
---|
572 | echo (' Leak OCE+ICE+SNW+PND = d(ICE+OCE)_mas_wat + emp_oce + emp_ice - runoffs - iceshelf = {:12.3e} (kg) '.format ( OCE.OCE_diff_SEA_mas_wat + OCE.OCE_mas_emp_oce +OCE.OCE_mas_emp_ice - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceshelf )) |
---|
573 | echo (' = (OCE.OCE_diff_SEA_mas_wat + emp_oce + emp_ice - runoffs - iceshelf)*/abs(OCE.OCE_diff_SEA_mas_wat) = {:12.1e} (-) '.format ( (OCE.OCE_diff_SEA_mas_wat + OCE.OCE_mas_emp_oce + OCE.OCE_mas_emp_ice - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceshelf)/abs(OCE.OCE_diff_SEA_mas_wat) ) ) |
---|
574 | |
---|
575 | prtFlux (' Leak OCE ', ( OCE.OCE_diff_mas_wat + OCE.OCE_mas_empmr - OCE.OCE_mas_iceshelf) , 'e', True ) |
---|
576 | prtFlux (' Leak ICE+SNW+PND ', ( OCE.ICE_diff_mas_wat + OCE.OCE_mas_emp_ice + OCE.OCE_mas_wfxice + OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxpnd + OCE.ICE_mas_wfxsub_err ) , 'e', True ) |
---|
577 | prtFlux (' Leak OCE+ICE+SNW+PND ', ( OCE.OCE_diff_SEA_mas_wat + OCE.OCE_mas_emp_oce +OCE.OCE_mas_emp_ice - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceshelf ) , 'e', True ) |
---|
578 | |
---|
579 | # check if emp = emp_ice + emp_oce - calving |
---|
580 | # emp_ice = wfxsub + wfxsnw_sub + wfxsnw_pre - wfxsub_err |
---|
581 | |
---|
582 | echo ('\n===> Checks ===>' ) |
---|
583 | echo (' Check EMPMR = empmr - emp_oce + runoffs + wfxice + wfxsnw + wfxpnd + wfxsub_err = {:12.5e} (kg) '.format ( OCE.OCE_mas_empmr - OCE.OCE_mas_emp_oce + OCE.OCE_mas_runoffs + OCE.OCE_mas_wfxice + OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxpnd + OCE.ICE_mas_wfxsub_err )) |
---|
584 | if Coupled : |
---|
585 | echo (' Check EMP_OCE = emp_oce + fwb + ssr - evap_oce + rain + snow_oce + calving = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce + OCE.OCE_mas_fwb + OCE.OCE_mas_ssr - OCE.OCE_mas_evap_oce + OCE.OCE_mas_rain + OCE.OCE_mas_snow_oce + OCE.OCE_mas_calving )) |
---|
586 | else : |
---|
587 | echo (' Check EMP_OCE = emp_oce + ssr + fwb - evap_oce + rain + snow_oce = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce + OCE.OCE_mas_ssr + OCE.OCE_mas_fwb - OCE.OCE_mas_evap_oce + OCE.OCE_mas_rain + OCE.OCE_mas_snow_oce )) |
---|
588 | echo (' Check EMP_ICE = emp_ice - evap_ice + snow_ice = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_ice - OCE.ICE_mas_evap_ice + OCE.OCE_mas_snow_ice )) |
---|
589 | echo (' Check EMP_ICE vs WFX = emp_ice - wfxsub - wfxsnw_sub - wfxsnw_pre + wfxsub_err = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_ice - OCE.OCE_mas_wfxsub - OCE.ICE_mas_wfxsnw_sub - OCE.ICE_mas_wfxsnw_pre + OCE.ICE_mas_wfxsub_err )) |
---|
590 | |
---|
591 | echo ( '\n------------------------------------------------------------------------------------' ) |
---|
592 | echo ( '-- Computations in the PDF note of Clément Rousset') |
---|
593 | echo ( 'Freshwater budget of the ice-ocean system = emp_oce + emp_ice - runoffs - iceberg - iceshelf = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce + OCE.OCE_mas_emp_ice - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceberg - OCE.OCE_mas_iceshelf )) |
---|
594 | echo ( 'Freshwater budget of the ice-ocean system = emp_oce + emp_ice - friver - iceberg - iceshelf = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce + OCE.OCE_mas_emp_ice - OCE.OCE_mas_friver - OCE.OCE_mas_iceberg - OCE.OCE_mas_iceshelf )) |
---|
595 | echo ( 'Freshwater budget in the ocean = ocean mass change = emp_oce - vfxice - ( vfxsnw + vfxsub_err ) - runoffs - iceshelf = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce - OCE.OCE_mas_wfxice - ( OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxsub_err ) - OCE.OCE_mas_runoffs - OCE.OCE_mas_iceshelf )) |
---|
596 | echo ( 'Freshwater budget in the ocean = ocean mass change = emp_oce - vfxice - ( vfxsnw + vfxsub_err ) - friver - iceshelf = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce - OCE.OCE_mas_wfxice - ( OCE.OCE_mas_wfxsnw + OCE.ICE_mas_wfxsub_err ) - OCE.OCE_mas_friver - OCE.OCE_mas_iceshelf )) |
---|
597 | echo ( 'Freshwater budget in the ice = ice mass change = vfxice + ( vfxsnw + vfxsub + vfxspr ) = {:12.5e} (kg) '.format ( OCE.OCE_mas_wfxice + OCE.OCE_mas_wfxsnw + OCE.OCE_mas_wfxsub + OCE.ICE_mas_wfxsnw_pre )) |
---|
598 | echo ( 'Freshwater flux at the interface [ice/snow]-ocean = vfxice + ( vfxsnw + vfxsub_err ) = {:12.5e} (kg) '.format ( OCE.OCE_mas_wfxsub + OCE.ICE_mas_wfxsnw_pre )) |
---|
599 | echo ( 'Freshwater flux at the interface [ice/snow]-atm = ( vfxsub + vfxspr ) = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_ice + OCE.ICE_mas_wfxsub_err )) |
---|
600 | echo ( 'Freshwater flux at the interface [ice/snow]-atm = emp_ice + vfxsub_err = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_ice + OCE.ICE_mas_wfxsub_err )) |
---|
601 | echo ( 'Freshwater flux at the interface ocean-atm = emp_oce + calving - vfxsub_err = {:12.5e} (kg) '.format ( OCE.OCE_mas_emp_oce + OCE.OCE_mas_calving - OCE.ICE_mas_wfxsub_err )) |
---|
602 | |
---|
603 | echo ( "scsshtot : global_average_sea_level_change = {:12.3e} (m) ".format ( np.sum (d_OCE_sca['scsshtot'] ).values ) ) |
---|
604 | echo ( "scsshtot : global_average_sea_level_change = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['scsshtot'] ).values * OCE.OCE_aire_tot*OCE_RHO_LIQ ) ) |
---|
605 | echo ( "bgvolssh : drift in global mean ssh volume wrt timestep 1 = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['bgvolssh'] ).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
606 | echo ( "bgvole3t : drift in global mean volume variation (e3t) wrt timestep 1 = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['bgvole3t'] ).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
607 | echo ( "bgfrcvol : global mean volume from forcing = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['bgfrcvol'] ).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
608 | echo ( "ibgvol_tot : global mean ice volume = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['ibgvol_tot']).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
609 | echo ( "sbgvol_tot : global mean snow volume = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['sbgvol_tot']).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
610 | echo ( "ibgvolume : drift in ice/snow volume (equivalent ocean volume) = {:12.3e} (kg)".format ( np.sum (d_OCE_sca['ibgvolume'] ).values * 1e9 * OCE_RHO_LIQ ) ) |
---|
611 | |
---|
612 | echo ( ' ' ) |
---|
613 | echo ( f'{Title = }' ) |
---|
614 | |
---|
615 | echo ( 'SVN Information' ) |
---|
616 | for kk in SVN.keys(): |
---|
617 | print ( SVN[kk] ) |
---|
618 | |
---|
619 | ## Write the full configuration |
---|
620 | params_out = open (FullIniFile, 'w', encoding = 'utf-8') |
---|
621 | params = wu.dict2config ( dpar ) |
---|
622 | params.write ( params_out ) |
---|
623 | params_out.close () |
---|