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 | # SVN Information |
---|
22 | SVN = { |
---|
23 | 'Author' : "$Author$", |
---|
24 | 'Date' : "$Date$", |
---|
25 | 'Revision': "$Revision$", |
---|
26 | 'Id' : "$Id$", |
---|
27 | 'HeadURL' : "$HeadUrl: $" |
---|
28 | } |
---|
29 | ### |
---|
30 | ### |
---|
31 | ## Import system modules |
---|
32 | import sys |
---|
33 | import os |
---|
34 | import configparser |
---|
35 | |
---|
36 | ## Import needed scientific modules |
---|
37 | import numpy as np |
---|
38 | import xarray as xr |
---|
39 | |
---|
40 | ## Import local modules |
---|
41 | import WaterUtils as wu |
---|
42 | import nemo, lmdz |
---|
43 | |
---|
44 | ## Read command line arguments |
---|
45 | ## --------------------------- |
---|
46 | print ( "Name of Python script:", sys.argv[0] ) |
---|
47 | IniFile = sys.argv[1] |
---|
48 | |
---|
49 | # Test existence of IniFile |
---|
50 | if not os.path.exists (IniFile ) : |
---|
51 | raise FileExistsError ( f"File not found : {IniFile = }" ) |
---|
52 | |
---|
53 | if 'full' in IniFile or 'ATM' in IniFile : |
---|
54 | FullIniFile = IniFile |
---|
55 | else : |
---|
56 | FullIniFile = 'ATM_' + IniFile |
---|
57 | |
---|
58 | print ("Output file : ", FullIniFile ) |
---|
59 | |
---|
60 | ## Experiment parameters |
---|
61 | ## -------------------- |
---|
62 | dpar = wu.ReadConfig ( IniFile ) |
---|
63 | |
---|
64 | ## Configure all needed parameter from existant parameters |
---|
65 | ## ------------------------------------------------------- |
---|
66 | dpar = wu.SetDatesAndFiles ( dpar ) |
---|
67 | |
---|
68 | ## Output file with water budget diagnostics |
---|
69 | ## ----------------------------------------- |
---|
70 | f_out = dpar['Files']['f_out'] |
---|
71 | |
---|
72 | ## Put dpar values in local namespace |
---|
73 | ## ---------------------------------- |
---|
74 | for Section in dpar.keys () : |
---|
75 | print ( f'\nReading [{Section}]' ) |
---|
76 | for VarName in dpar[Section].keys() : |
---|
77 | locals()[VarName] = dpar[Section][VarName] |
---|
78 | print ( f' {VarName:21} set to : {locals()[VarName]}' ) |
---|
79 | |
---|
80 | ## Debuging and timer |
---|
81 | Timer = wu.functools.partial (wu.Timer, debug=Debug, timer=Timing) |
---|
82 | |
---|
83 | ## Useful functions |
---|
84 | ## ---------------- |
---|
85 | if repr(readPrec) == "<class 'numpy.float64'>" or readPrec == float : |
---|
86 | def rprec (ptab) : |
---|
87 | '''This version does nothing |
---|
88 | |
---|
89 | rprec may be use to reduce floating precision when reading history files |
---|
90 | ''' |
---|
91 | return ptab |
---|
92 | else : |
---|
93 | def rprec (ptab) : |
---|
94 | '''Returns float with a different precision''' |
---|
95 | return ptab.astype(readPrec).astype(float) |
---|
96 | |
---|
97 | def kg2Sv (val, rho=ATM_RHO) : |
---|
98 | '''From kg to Sverdrup''' |
---|
99 | return val/dtime_sec*1.0e-6/rho |
---|
100 | |
---|
101 | def kg2myear (val, rho=ATM_RHO) : |
---|
102 | '''From kg to m/year''' |
---|
103 | return val/ATM_aire_sea_tot/rho/NbYear |
---|
104 | |
---|
105 | def var2prt (var, small=False, rho=ATM_RHO) : |
---|
106 | '''Formats value for printing''' |
---|
107 | if small : return var , kg2Sv(var, rho=rho)*1000., kg2myear(var, rho=rho)*1000 |
---|
108 | else : return var , kg2Sv(var, rho=rho) , kg2myear(var, rho=rho) |
---|
109 | |
---|
110 | def prtFlux (Desc, var, Form='F', small=False, rho=ATM_RHO, width=15) : |
---|
111 | '''Pretty print of formattd value''' |
---|
112 | if small : |
---|
113 | if Form in ['f', 'F'] : ff=" {:14.6e} kg | {:12.4f} mSv | {:12.4f} mm/year " |
---|
114 | if Form in ['e', 'E'] : ff=" {:14.6e} kg | {:12.4e} mSv | {:12.4e} mm/year " |
---|
115 | else : |
---|
116 | if Form in ['f', 'F'] : ff=" {:14.6e} kg | {:12.4f} Sv | {:12.4f} m/year " |
---|
117 | if Form in ['e', 'E'] : ff=" {:14.6e} kg | {:12.4e} Sv | {:12.4e} m/year " |
---|
118 | echo ( (' {:>{width}} = ' +ff).format (Desc, *var2prt(var, small=small, rho=rho), width=width ) ) |
---|
119 | return None |
---|
120 | |
---|
121 | def echo (string, end='\n') : |
---|
122 | '''Function to print to stdout *and* output file''' |
---|
123 | print ( str(string), end=end ) |
---|
124 | sys.stdout.flush () |
---|
125 | f_out.write ( str(string) + end ) |
---|
126 | f_out.flush () |
---|
127 | return None |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
133 | if SRF : |
---|
134 | d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
135 | if Routing == 'SECHIBA' : d_RUN_his = d_SRF_his |
---|
136 | if Routing == 'SIMPLE' : d_RUN_his = xr.open_dataset ( file_RUN_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
137 | |
---|
138 | d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
139 | d_OCE_sca = xr.open_dataset ( file_OCE_sca, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
140 | #d_OCE_srf = xr.open_dataset ( file_OCE_srf, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
141 | d_ICE_his = xr.open_dataset ( file_ICE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() |
---|
142 | if NEMO == '3.6' : d_ICE_his = d_ICE_his.rename ( {'y_grid_T':'y', 'x_grid_T':'x'} ) |
---|
143 | |
---|
144 | echo ( f'{file_OCE_his = }' ) |
---|
145 | echo ( f'{file_ICE_his = }' ) |
---|
146 | echo ( f'{file_OCE_sca = }' ) |
---|
147 | echo ( f'{file_OCE_srf = }' ) |
---|
148 | |
---|
149 | ## Compute run length |
---|
150 | ## ------------------ |
---|
151 | dtime = ( d_ATM_his.time_counter_bounds.max() - d_ATM_his.time_counter_bounds.min() ) |
---|
152 | echo ('\nRun length : {:8.2f} days'.format ( (dtime/np.timedelta64(1, "D")).values ) ) |
---|
153 | dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds |
---|
154 | |
---|
155 | ## Compute length of each period |
---|
156 | dtime_per = (d_ATM_his.time_counter_bounds[:,-1] - d_ATM_his.time_counter_bounds[:,0] ) |
---|
157 | echo ('\nPeriods lengths (days) : {:} days'.format ( (dtime_per/np.timedelta64(1, "D")).values ) ) |
---|
158 | dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds |
---|
159 | dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] ) |
---|
160 | dtime_per_sec.attrs['unit'] = 's' |
---|
161 | |
---|
162 | # Number of years |
---|
163 | NbYear = dtime_sec / YEAR_LENGTH |
---|
164 | |
---|
165 | ## Write the full configuration |
---|
166 | ## ---------------------------- |
---|
167 | params_out = open (FullIniFile, 'w', encoding = 'utf-8') |
---|
168 | params = wu.dict2config ( dpar ) |
---|
169 | params.write ( params_out ) |
---|
170 | params_out.close () |
---|
171 | |
---|
172 | # ATM grid with cell surfaces |
---|
173 | if LMDZ : |
---|
174 | echo ('ATM grid with cell surfaces : LMDZ') |
---|
175 | ATM_lat = lmdz.geo2point ( rprec (d_ATM_his ['lat'])+0*rprec (d_ATM_his ['lon']), dim1D='cell' ) |
---|
176 | ATM_lon = lmdz.geo2point ( 0*rprec (d_ATM_his ['lat'])+ rprec (d_ATM_his ['lon']), dim1D='cell' ) |
---|
177 | ATM_aire = lmdz.geo2point ( rprec (d_ATM_his ['aire'] ) [0], cumulPoles=True, dim1D='cell' ) |
---|
178 | ATM_fter = lmdz.geo2point ( rprec (d_ATM_his ['fract_ter'][0]), dim1D='cell' ) |
---|
179 | ATM_foce = lmdz.geo2point ( rprec (d_ATM_his ['fract_oce'][0]), dim1D='cell' ) |
---|
180 | ATM_fsic = lmdz.geo2point ( rprec (d_ATM_his ['fract_sic'][0]), dim1D='cell' ) |
---|
181 | ATM_flic = lmdz.geo2point ( rprec (d_ATM_his ['fract_lic'][0]), dim1D='cell' ) |
---|
182 | if SRF : |
---|
183 | SRF_lat = lmdz.geo2point ( rprec (d_SRF_his ['lat'])+0*rprec (d_SRF_his ['lon']), dim1D='cell' ) |
---|
184 | SRF_lon = lmdz.geo2point ( 0*rprec (d_SRF_his ['lat'])+ rprec (d_SRF_his ['lon']), dim1D='cell' ) |
---|
185 | SRF_aire = lmdz.geo2point ( rprec (d_SRF_his ['Areas']) * rprec (d_SRF_his ['Contfrac']), dim1D='cell', cumulPoles=True ) |
---|
186 | SRF_areas = lmdz.geo2point ( rprec (d_SRF_his ['Areas']) , dim1D='cell', cumulPoles=True ) |
---|
187 | SRF_contfrac = lmdz.geo2point ( rprec (d_SRF_his ['Contfrac']), dim1D='cell' ) |
---|
188 | |
---|
189 | if ICO : |
---|
190 | if ATM_HIS == 'latlon' : |
---|
191 | echo ( 'ATM areas and fractions on latlon grid' ) |
---|
192 | if 'lat_dom_out' in d_ATM_his.variables : |
---|
193 | ATM_lat = lmdz.geo2point ( rprec (d_ATM_his ['lat_dom_out'])+0*rprec (d_ATM_his ['lon_dom_out']), dim1D='cell' ) |
---|
194 | ATM_lon = lmdz.geo2point ( 0*rprec (d_ATM_his ['lat_dom_out'])+ rprec (d_ATM_his ['lon_dom_out']), dim1D='cell' ) |
---|
195 | else : |
---|
196 | ATM_lat = lmdz.geo2point ( rprec (d_ATM_his ['lat'])+0*rprec (d_ATM_his ['lon']), dim1D='cell' ) |
---|
197 | ATM_lon = lmdz.geo2point ( 0*rprec (d_ATM_his ['lat'])+ rprec (d_ATM_his ['lon']), dim1D='cell' ) |
---|
198 | ATM_aire = lmdz.geo2point ( rprec (d_ATM_his ['aire'][0]).squeeze(), cumulPoles=True, dim1D='cell' ) |
---|
199 | ATM_fter = lmdz.geo2point ( rprec (d_ATM_his ['fract_ter'][0]), dim1D='cell' ) |
---|
200 | ATM_foce = lmdz.geo2point ( rprec (d_ATM_his ['fract_oce'][0]), dim1D='cell' ) |
---|
201 | ATM_fsic = lmdz.geo2point ( rprec (d_ATM_his ['fract_sic'][0]), dim1D='cell' ) |
---|
202 | ATM_flic = lmdz.geo2point ( rprec (d_ATM_his ['fract_lic'][0]), dim1D='cell' ) |
---|
203 | |
---|
204 | if ATM_HIS == 'ico' : |
---|
205 | echo ( 'ATM areas and fractions on ICO grid' ) |
---|
206 | ATM_aire = rprec (d_ATM_his ['aire'] [0]).squeeze() |
---|
207 | ATM_lat = rprec (d_ATM_his ['lat'] ) |
---|
208 | ATM_lon = rprec (d_ATM_his ['lon'] ) |
---|
209 | ATM_fter = rprec (d_ATM_his ['fract_ter'][0]) |
---|
210 | ATM_foce = rprec (d_ATM_his ['fract_oce'][0]) |
---|
211 | ATM_fsic = rprec (d_ATM_his ['fract_sic'][0]) |
---|
212 | ATM_flic = rprec (d_ATM_his ['fract_lic'][0]) |
---|
213 | |
---|
214 | if SRF : |
---|
215 | if SRF_HIS == 'latlon' : |
---|
216 | echo ( 'SRF areas and fractions on latlon grid' ) |
---|
217 | if 'lat_domain_landpoints_out' in d_SRF_his : |
---|
218 | SRF_lat = lmdz.geo2point ( rprec (d_SRF_his ['lat_domain_landpoints_out'])+0*rprec (d_SRF_his ['lon_domain_landpoints_out']), dim1D='cell' ) |
---|
219 | SRF_lon = lmdz.geo2point ( 0*rprec (d_SRF_his ['lat_domain_landpoints_out'])+ rprec (d_SRF_his ['lon_domain_landpoints_out']), dim1D='cell' ) |
---|
220 | else : |
---|
221 | if 'lat_domain_landpoints_out' in d_SRF_his : |
---|
222 | SRF_lat = lmdz.geo2point ( rprec (d_SRF_his ['lat_dom_out'])+0*rprec (d_SRF_his ['lon_dom_out']), dim1D='cell' ) |
---|
223 | SRF_lon = lmdz.geo2point ( 0*rprec (d_SRF_his ['lat_dom_out'])+ rprec (d_SRF_his ['lon_dom_out']), dim1D='cell' ) |
---|
224 | else : |
---|
225 | SRF_lat = lmdz.geo2point ( rprec (d_SRF_his ['lat'])+0*rprec (d_SRF_his ['lon']), dim1D='cell' ) |
---|
226 | SRF_lon = lmdz.geo2point ( 0*rprec (d_SRF_his ['lat'])+ rprec (d_SRF_his ['lon']), dim1D='cell' ) |
---|
227 | |
---|
228 | SRF_areas = lmdz.geo2point ( rprec (d_SRF_his ['Areas'] ) , dim1D='cell', cumulPoles=True ) |
---|
229 | SRF_areafrac = lmdz.geo2point ( rprec (d_SRF_his ['AreaFrac']) , dim1D='cell', cumulPoles=True ) |
---|
230 | SRF_contfrac = lmdz.geo2point ( rprec (d_SRF_his ['Contfrac']) , dim1D='cell', cumulPoles=True ) |
---|
231 | SRF_aire = SRF_areafrac |
---|
232 | |
---|
233 | if SRF_HIS == 'ico' : |
---|
234 | echo ( 'SRF areas and fractions on latlon grid' ) |
---|
235 | SRF_lat = rprec (d_SRF_his ['lat'] ) |
---|
236 | SRF_lon = rprec (d_SRF_his ['lon'] ) |
---|
237 | SRF_areas = rprec (d_SRF_his ['Areas'] ) |
---|
238 | SRF_contfrac = rprec (d_SRF_his ['Contfrac']) |
---|
239 | SRF_aire = SRF_areas * SRF_contfrac |
---|
240 | |
---|
241 | ATM_fsea = ATM_foce + ATM_fsic |
---|
242 | ATM_flnd = ATM_fter + ATM_flic |
---|
243 | ATM_aire_fter = ATM_aire * ATM_fter |
---|
244 | ATM_aire_flic = ATM_aire * ATM_flic |
---|
245 | ATM_aire_fsic = ATM_aire * ATM_fsic |
---|
246 | ATM_aire_foce = ATM_aire * ATM_foce |
---|
247 | ATM_aire_flnd = ATM_aire * ATM_flnd |
---|
248 | ATM_aire_fsea = ATM_aire * ATM_fsea |
---|
249 | |
---|
250 | #SRF_aire = SRF_aire.where ( SRF_aire < 1E15, 0.) |
---|
251 | |
---|
252 | # if ICO : |
---|
253 | # if wu.unDefined ('file_DYN_aire') : file_DYN_aire = os.path.join ( R_IN, 'ATM', 'GRID', ATM+'_grid.nc' ) |
---|
254 | # config['Files']['file_DYN_aire'] = file_DYN_aire |
---|
255 | |
---|
256 | # if ICO : |
---|
257 | # # Area on icosahedron grid |
---|
258 | # d_DYN_aire = xr.open_dataset ( file_DYN_aire, decode_times=False ).squeeze() |
---|
259 | |
---|
260 | # DYN_lat = d_DYN_aire['lat'] |
---|
261 | # DYN_lon = d_DYN_aire['lon'] |
---|
262 | |
---|
263 | # DYN_aire = d_DYN_aire['aire'] |
---|
264 | # DYN_fsea = d_DYN_aire['fract_oce'] + d_DYN_aire['fract_sic'] |
---|
265 | # DYN_flnd = 1.0 - DYN_fsea |
---|
266 | # DYN_fter = d_ATM_beg['FTER'] |
---|
267 | # DYN_flic = d_ATM_beg['FLIC'] |
---|
268 | # DYN_aire_fter = DYN_aire * DYN_fter |
---|
269 | |
---|
270 | # if LMDZ : |
---|
271 | # # Area on lon/lat grid |
---|
272 | # DYN_aire = ATM_aire |
---|
273 | # DYN_fsea = ATM_fsea |
---|
274 | # DYN_flnd = ATM_flnd |
---|
275 | # DYN_fter = rprec (d_ATM_beg['FTER']) |
---|
276 | # DYN_flic = rprec (d_ATM_beg['FLIC']) |
---|
277 | # DYN_aire_fter = DYN_aire * DYN_fter |
---|
278 | |
---|
279 | # Functions computing integrals and sum |
---|
280 | # def ATM_stock_int (stock) : |
---|
281 | # '''Integrate (* surface) stock on atmosphere grid''' |
---|
282 | # ATM_stock_int = wu.Psum ( (stock * DYN_aire).to_masked_array().ravel() ) |
---|
283 | # return ATM_stock_int |
---|
284 | |
---|
285 | def ATM_flux_int (flux) : |
---|
286 | '''Integrate (* time * surface) flux on atmosphere grid''' |
---|
287 | ATM_flux_int = wu.Psum ( (flux * dtime_per_sec * ATM_aire).to_masked_array().ravel() ) |
---|
288 | return ATM_flux_int |
---|
289 | |
---|
290 | # def SRF_stock_int (stock) : |
---|
291 | # '''Integrate (* surface) stock on land grid''' |
---|
292 | # ATM_stock_int = wu.Ksum ( ( (stock * DYN_aire_fter).to_masked_array().ravel()) ) |
---|
293 | # return ATM_stock_int |
---|
294 | |
---|
295 | def SRF_flux_int (flux) : |
---|
296 | '''Integrate (* time * surface) flux on land grid''' |
---|
297 | SRF_flux_int = wu.Psum ( (flux * dtime_per_sec * SRF_aire).to_masked_array().ravel() ) |
---|
298 | return SRF_flux_int |
---|
299 | |
---|
300 | # def LIC_flux_int (flux) : |
---|
301 | # '''Integrate (* time * surface) flux on land ice grid''' |
---|
302 | # LIC_flux_int = wu.Psum ( (flux * dtime_per_sec * ATM_aire_flic).to_masked_array().ravel() ) |
---|
303 | # return LIC_flux_int |
---|
304 | |
---|
305 | # def OCE_stock_int (stock) : |
---|
306 | # '''Integrate stock on ocean grid''' |
---|
307 | # OCE_stock_int = np.sum ( np.sort ( (stock * OCE_aire ).to_masked_array().ravel()) ) |
---|
308 | # return OCE_stock_int |
---|
309 | |
---|
310 | def ONE_stock_int (stock) : |
---|
311 | '''Sum stock''' |
---|
312 | ONE_stock_int = wu.Psum ( stock.to_masked_array().ravel() ) |
---|
313 | return ONE_stock_int |
---|
314 | |
---|
315 | def OCE_flux_int (flux) : |
---|
316 | '''Integrate flux on oce grid''' |
---|
317 | OCE_flux_int = wu.Psum ( (flux * OCE_aire * dtime_per_sec).to_masked_array().ravel() ) |
---|
318 | return OCE_flux_int |
---|
319 | |
---|
320 | def ONE_flux_int (flux) : |
---|
321 | '''Integrate flux on oce grid''' |
---|
322 | OCE_flux_int = wu.Psum ( (flux * dtime_per_sec).to_masked_array().ravel() ) |
---|
323 | return OCE_flux_int |
---|
324 | |
---|
325 | # Get mask and surfaces |
---|
326 | sos = d_OCE_his ['sos'][0].squeeze() |
---|
327 | OCE_msk = nemo.lbc_mask ( xr.where ( sos>0, 1., 0.0 ), cd_type = 'T', nperio=nperio ) |
---|
328 | so = sos = d_OCE_his ['sos'][0].squeeze() |
---|
329 | OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0., nperio=nperio ) |
---|
330 | |
---|
331 | # lbc_mask removes the duplicate points (periodicity and north fold) |
---|
332 | OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', sval = 0.0, nperio=nperio ) |
---|
333 | ICE_aire = OCE_aire |
---|
334 | |
---|
335 | ATM_aire_tot = ONE_stock_int (ATM_aire) |
---|
336 | if SRF : |
---|
337 | SRF_aire_tot = ONE_stock_int (SRF_aire) |
---|
338 | OCE_aire_tot = ONE_stock_int (OCE_aire) |
---|
339 | ICE_aire_tot = ONE_stock_int (ICE_aire) |
---|
340 | |
---|
341 | ATM_aire_sea = ATM_aire * ATM_fsea |
---|
342 | ATM_aire_sea_tot = ONE_stock_int ( ATM_aire_sea ) |
---|
343 | |
---|
344 | echo ( '\n====================================================================================' ) |
---|
345 | echo ( f'-- ATM Fluxes -- {Title} ' ) |
---|
346 | |
---|
347 | if ATM_HIS == 'latlon' : |
---|
348 | echo ( ' latlon case' ) |
---|
349 | ATM_wbilo_oce = lmdz.geo2point ( rprec (d_ATM_his ['wbilo_oce']), dim1D='cell' ) |
---|
350 | ATM_wbilo_sic = lmdz.geo2point ( rprec (d_ATM_his ['wbilo_sic']), dim1D='cell' ) |
---|
351 | ATM_wbilo_ter = lmdz.geo2point ( rprec (d_ATM_his ['wbilo_ter']), dim1D='cell' ) |
---|
352 | ATM_wbilo_lic = lmdz.geo2point ( rprec (d_ATM_his ['wbilo_lic']), dim1D='cell' ) |
---|
353 | ATM_runofflic = lmdz.geo2point ( rprec (d_ATM_his ['runofflic']), dim1D='cell' ) |
---|
354 | ATM_fqcalving = lmdz.geo2point ( rprec (d_ATM_his ['fqcalving']), dim1D='cell' ) |
---|
355 | ATM_fqfonte = lmdz.geo2point ( rprec (d_ATM_his ['fqfonte'] ), dim1D='cell' ) |
---|
356 | ATM_precip = lmdz.geo2point ( rprec (d_ATM_his ['precip'] ), dim1D='cell' ) |
---|
357 | ATM_snowf = lmdz.geo2point ( rprec (d_ATM_his ['snow'] ), dim1D='cell' ) |
---|
358 | ATM_evap = lmdz.geo2point ( rprec (d_ATM_his ['evap'] ), dim1D='cell' ) |
---|
359 | ATM_wevap_ter = lmdz.geo2point ( rprec (d_ATM_his ['wevap_ter']), dim1D='cell' ) |
---|
360 | ATM_wevap_oce = lmdz.geo2point ( rprec (d_ATM_his ['wevap_oce']), dim1D='cell' ) |
---|
361 | ATM_wevap_lic = lmdz.geo2point ( rprec (d_ATM_his ['wevap_lic']), dim1D='cell' ) |
---|
362 | ATM_wevap_sic = lmdz.geo2point ( rprec (d_ATM_his ['wevap_sic']), dim1D='cell' ) |
---|
363 | ATM_wrain_ter = lmdz.geo2point ( rprec (d_ATM_his ['wrain_ter']), dim1D='cell' ) |
---|
364 | ATM_wrain_oce = lmdz.geo2point ( rprec (d_ATM_his ['wrain_oce']), dim1D='cell' ) |
---|
365 | ATM_wrain_lic = lmdz.geo2point ( rprec (d_ATM_his ['wrain_lic']), dim1D='cell' ) |
---|
366 | ATM_wrain_sic = lmdz.geo2point ( rprec (d_ATM_his ['wrain_sic']), dim1D='cell' ) |
---|
367 | ATM_wsnow_ter = lmdz.geo2point ( rprec (d_ATM_his ['wsnow_ter']), dim1D='cell' ) |
---|
368 | ATM_wsnow_oce = lmdz.geo2point ( rprec (d_ATM_his ['wsnow_oce']), dim1D='cell' ) |
---|
369 | ATM_wsnow_lic = lmdz.geo2point ( rprec (d_ATM_his ['wsnow_lic']), dim1D='cell' ) |
---|
370 | ATM_wsnow_sic = lmdz.geo2point ( rprec (d_ATM_his ['wsnow_sic']), dim1D='cell' ) |
---|
371 | ATM_runofflic = lmdz.geo2point ( rprec (d_ATM_his ['runofflic']), dim1D='cell' ) |
---|
372 | echo ( f'End of LATLON case') |
---|
373 | |
---|
374 | if ATM_HIS == 'ico' : |
---|
375 | echo (' ico case') |
---|
376 | ATM_wbilo_oce = rprec (d_ATM_his ['wbilo_oce']) |
---|
377 | ATM_wbilo_sic = rprec (d_ATM_his ['wbilo_sic']) |
---|
378 | ATM_wbilo_ter = rprec (d_ATM_his ['wbilo_ter']) |
---|
379 | ATM_wbilo_lic = rprec (d_ATM_his ['wbilo_lic']) |
---|
380 | ATM_runofflic = rprec (d_ATM_his ['runofflic']) |
---|
381 | ATM_fqcalving = rprec (d_ATM_his ['fqcalving']) |
---|
382 | ATM_fqfonte = rprec (d_ATM_his ['fqfonte'] ) |
---|
383 | ATM_precip = rprec (d_ATM_his ['precip'] ) |
---|
384 | ATM_snowf = rprec (d_ATM_his ['snow'] ) |
---|
385 | ATM_evap = rprec (d_ATM_his ['evap'] ) |
---|
386 | ATM_wevap_ter = rprec (d_ATM_his ['wevap_ter']) |
---|
387 | ATM_wevap_oce = rprec (d_ATM_his ['wevap_oce']) |
---|
388 | ATM_wevap_lic = rprec (d_ATM_his ['wevap_lic']) |
---|
389 | ATM_wevap_sic = rprec (d_ATM_his ['wevap_sic']) |
---|
390 | ATM_runofflic = rprec (d_ATM_his ['runofflic']) |
---|
391 | ATM_wevap_ter = rprec (d_ATM_his ['wevap_ter']) |
---|
392 | ATM_wevap_oce = rprec (d_ATM_his ['wevap_oce']) |
---|
393 | ATM_wevap_lic = rprec (d_ATM_his ['wevap_lic']) |
---|
394 | ATM_wevap_sic = rprec (d_ATM_his ['wevap_sic']) |
---|
395 | ATM_wrain_ter = rprec (d_ATM_his ['wrain_ter']) |
---|
396 | ATM_wrain_oce = rprec (d_ATM_his ['wrain_oce']) |
---|
397 | ATM_wrain_lic = rprec (d_ATM_his ['wrain_lic']) |
---|
398 | ATM_wrain_sic = rprec (d_ATM_his ['wrain_sic']) |
---|
399 | ATM_wsnow_ter = rprec (d_ATM_his ['wsnow_ter']) |
---|
400 | ATM_wsnow_oce = rprec (d_ATM_his ['wsnow_oce']) |
---|
401 | ATM_wsnow_lic = rprec (d_ATM_his ['wsnow_lic']) |
---|
402 | ATM_wsnow_sic = rprec (d_ATM_his ['wsnow_sic']) |
---|
403 | echo ( f'End of ico case ') |
---|
404 | |
---|
405 | echo ( 'ATM wprecip_oce' ) |
---|
406 | ATM_wprecip_oce = ATM_wrain_oce + ATM_wsnow_oce |
---|
407 | ATM_wprecip_ter = ATM_wrain_ter + ATM_wsnow_ter |
---|
408 | ATM_wprecip_sic = ATM_wrain_sic + ATM_wsnow_sic |
---|
409 | ATM_wprecip_lic = ATM_wrain_lic + ATM_wsnow_lic |
---|
410 | |
---|
411 | ATM_wbilo = ATM_wbilo_oce + ATM_wbilo_sic + ATM_wbilo_ter + ATM_wbilo_lic |
---|
412 | ATM_wevap = ATM_wevap_oce + ATM_wevap_sic + ATM_wevap_ter + ATM_wevap_lic |
---|
413 | ATM_wprecip = ATM_wprecip_oce + ATM_wprecip_sic + ATM_wprecip_ter + ATM_wprecip_lic |
---|
414 | ATM_wsnow = ATM_wsnow_oce + ATM_wsnow_sic + ATM_wsnow_ter + ATM_wsnow_lic |
---|
415 | ATM_wrain = ATM_wrain_oce + ATM_wrain_sic + ATM_wrain_ter + ATM_wrain_lic |
---|
416 | ATM_wemp = ATM_wevap - ATM_wprecip |
---|
417 | ATM_emp = ATM_evap - ATM_precip |
---|
418 | |
---|
419 | ATM_wprecip_sea = ATM_wprecip_oce + ATM_wprecip_sic |
---|
420 | ATM_wsnow_sea = ATM_wsnow_oce + ATM_wsnow_sic |
---|
421 | ATM_wrain_sea = ATM_wrain_oce + ATM_wrain_sic |
---|
422 | ATM_wbilo_sea = ATM_wbilo_oce + ATM_wbilo_sic |
---|
423 | ATM_wevap_sea = ATM_wevap_sic + ATM_wevap_oce |
---|
424 | |
---|
425 | ATM_wemp_ter = ATM_wevap_ter - ATM_wprecip_ter |
---|
426 | ATM_wemp_oce = ATM_wevap_oce - ATM_wprecip_oce |
---|
427 | ATM_wemp_sic = ATM_wevap_sic - ATM_wprecip_sic |
---|
428 | ATM_wemp_lic = ATM_wevap_lic - ATM_wprecip_lic |
---|
429 | ATM_wemp_sea = ATM_wevap_sic - ATM_wprecip_oce |
---|
430 | |
---|
431 | if SRF : |
---|
432 | if RUN_HIS == 'latlon' : |
---|
433 | echo ( f'RUN costalflow Grille LATLON' ) |
---|
434 | if TestInterp : |
---|
435 | echo ( f'RUN runoff TestInterp' ) |
---|
436 | RUN_runoff = lmdz.geo2point ( rprec (d_RUN_his ['runoff_contfrac_interp'] ) , dim1D='cell' ) |
---|
437 | RUN_drainage = lmdz.geo2point ( rprec (d_RUN_his ['drainage_contfrac_interp']) , dim1D='cell' ) |
---|
438 | else : |
---|
439 | echo ( f'RUN runoff' ) |
---|
440 | RUN_runoff = lmdz.geo2point ( rprec (d_RUN_his ['runoff'] ), dim1D='cell' ) |
---|
441 | RUN_drainage = lmdz.geo2point ( rprec (d_RUN_his ['drainage'] ), dim1D='cell' ) |
---|
442 | |
---|
443 | RUN_coastalflow = lmdz.geo2point ( rprec (d_RUN_his ['coastalflow'] ), dim1D='cell' ) |
---|
444 | RUN_riverflow = lmdz.geo2point ( rprec (d_RUN_his ['riverflow'] ), dim1D='cell' ) |
---|
445 | RUN_riversret = lmdz.geo2point ( rprec (d_RUN_his ['riversret'] ), dim1D='cell' ) |
---|
446 | RUN_coastalflow_cpl = lmdz.geo2point ( rprec (d_RUN_his ['coastalflow_cpl']), dim1D='cell' ) |
---|
447 | RUN_riverflow_cpl = lmdz.geo2point ( rprec (d_RUN_his ['riverflow_cpl'] ), dim1D='cell' ) |
---|
448 | |
---|
449 | if RUN_HIS == 'ico' : |
---|
450 | echo ( f'RUN costalflow Grille ICO' ) |
---|
451 | RUN_coastalflow = rprec (d_RUN_his ['coastalflow']) |
---|
452 | RUN_riverflow = rprec (d_RUN_his ['riverflow'] ) |
---|
453 | RUN_runoff = rprec (d_RUN_his ['runoff'] ) |
---|
454 | RUN_drainage = rprec (d_RUN_his ['drainage'] ) |
---|
455 | RUN_riversret = rprec (d_RUN_his ['riversret'] ) |
---|
456 | |
---|
457 | RUN_coastalflow_cpl = rprec (d_RUN_his ['coastalflow_cpl']) |
---|
458 | RUN_riverflow_cpl = rprec (d_RUN_his ['riverflow_cpl'] ) |
---|
459 | |
---|
460 | ## Correcting units of SECHIBA variables |
---|
461 | def mmd2SI ( Var ) : |
---|
462 | '''Change unit from mm/d or m^3/s to kg/s if needed''' |
---|
463 | if 'units' in VarT.attrs : |
---|
464 | if VarT.attrs['units'] in ['m^3/s', 'm3/s', 'm3.s-1',] : |
---|
465 | VarT.values = VarT.values * ATM_RHO ; VarT.attrs['units'] = 'kg/s' |
---|
466 | if VarT.attrs['units'] == 'mm/d' : |
---|
467 | VarT.values = VarT.values * ATM_RHO * (1e-3/86400.) ; VarT.attrs['units'] = 'kg/s' |
---|
468 | if VarT.attrs['units'] in ['m^3', 'm3', ] : |
---|
469 | VarT.values = VarT.values * ATM_RHO ; VarT.attrs['units'] = 'kg' |
---|
470 | |
---|
471 | for var in [ 'runoff', 'drainage', 'riversret', 'coastalflow', 'riverflow', 'coastalflow_cpl', 'riverflow_cpl' ] : |
---|
472 | VarT = locals()['RUN_' + var] |
---|
473 | mmd2SI (VarT) |
---|
474 | |
---|
475 | #for var in ['evap', 'snowf', 'subli', 'transpir', 'rain', 'emp' ] : |
---|
476 | # VarT = locals()['SRF_' + var] |
---|
477 | # mmd2SI (VarT) |
---|
478 | echo ( f'RUN input' ) |
---|
479 | RUN_input = RUN_runoff + RUN_drainage |
---|
480 | RUN_output = RUN_coastalflow + RUN_riverflow |
---|
481 | |
---|
482 | echo ( f'ATM flw_wbilo' ) |
---|
483 | ATM_flx_wbilo = ATM_flux_int ( ATM_wbilo ) |
---|
484 | ATM_flx_wevap = ATM_flux_int ( ATM_wevap ) |
---|
485 | ATM_flx_wprecip = ATM_flux_int ( ATM_wprecip ) |
---|
486 | ATM_flx_wsnow = ATM_flux_int ( ATM_wsnow ) |
---|
487 | ATM_flx_wrain = ATM_flux_int ( ATM_wrain ) |
---|
488 | ATM_flx_wemp = ATM_flux_int ( ATM_wemp ) |
---|
489 | |
---|
490 | ATM_flx_wbilo_lic = ATM_flux_int ( ATM_wbilo_lic ) |
---|
491 | ATM_flx_wbilo_oce = ATM_flux_int ( ATM_wbilo_oce ) |
---|
492 | ATM_flx_wbilo_sea = ATM_flux_int ( ATM_wbilo_sea ) |
---|
493 | ATM_flx_wbilo_sic = ATM_flux_int ( ATM_wbilo_sic ) |
---|
494 | ATM_flx_wbilo_ter = ATM_flux_int ( ATM_wbilo_ter ) |
---|
495 | ATM_flx_calving = ATM_flux_int ( ATM_fqcalving ) |
---|
496 | ATM_flx_fqfonte = ATM_flux_int ( ATM_fqfonte ) |
---|
497 | |
---|
498 | LIC_flx_calving = ATM_flux_int ( ATM_fqcalving ) |
---|
499 | LIC_flx_fqfonte = ATM_flux_int ( ATM_fqfonte ) |
---|
500 | |
---|
501 | ATM_flx_precip = ATM_flux_int ( ATM_precip ) |
---|
502 | ATM_flx_snowf = ATM_flux_int ( ATM_snowf ) |
---|
503 | ATM_flx_evap = ATM_flux_int ( ATM_evap ) |
---|
504 | ATM_flx_runlic = ATM_flux_int ( ATM_runofflic ) |
---|
505 | |
---|
506 | #LIC_flx_precip = LIC_flux_int ( ATM_precip ) |
---|
507 | #LIC_flx_snowf = LIC_flux_int ( ATM_snowf ) |
---|
508 | #LIC_flx_evap = LIC_flux_int ( ATM_evap ) |
---|
509 | #LIC_flx_runlic = LIC_flux_int ( ATM_runofflic ) |
---|
510 | |
---|
511 | ATM_flx_wrain_ter = ATM_flux_int ( ATM_wrain_ter ) |
---|
512 | ATM_flx_wrain_oce = ATM_flux_int ( ATM_wrain_oce ) |
---|
513 | ATM_flx_wrain_lic = ATM_flux_int ( ATM_wrain_lic ) |
---|
514 | ATM_flx_wrain_sic = ATM_flux_int ( ATM_wrain_sic ) |
---|
515 | ATM_flx_wrain_sea = ATM_flux_int ( ATM_wrain_sea ) |
---|
516 | |
---|
517 | ATM_flx_wsnow_ter = ATM_flux_int ( ATM_wsnow_ter ) |
---|
518 | ATM_flx_wsnow_oce = ATM_flux_int ( ATM_wsnow_oce ) |
---|
519 | ATM_flx_wsnow_lic = ATM_flux_int ( ATM_wsnow_lic ) |
---|
520 | ATM_flx_wsnow_sic = ATM_flux_int ( ATM_wsnow_sic ) |
---|
521 | ATM_flx_wsnow_sea = ATM_flux_int ( ATM_wsnow_sea ) |
---|
522 | |
---|
523 | ATM_flx_wevap_ter = ATM_flux_int ( ATM_wevap_ter ) |
---|
524 | ATM_flx_wevap_oce = ATM_flux_int ( ATM_wevap_oce ) |
---|
525 | ATM_flx_wevap_lic = ATM_flux_int ( ATM_wevap_lic ) |
---|
526 | ATM_flx_wevap_sic = ATM_flux_int ( ATM_wevap_sic ) |
---|
527 | ATM_flx_wevap_sea = ATM_flux_int ( ATM_wevap_sea ) |
---|
528 | ATM_flx_wprecip_lic = ATM_flux_int ( ATM_wprecip_lic ) |
---|
529 | ATM_flx_wprecip_oce = ATM_flux_int ( ATM_wprecip_oce ) |
---|
530 | ATM_flx_wprecip_sic = ATM_flux_int ( ATM_wprecip_sic ) |
---|
531 | ATM_flx_wprecip_ter = ATM_flux_int ( ATM_wprecip_ter ) |
---|
532 | ATM_flx_wprecip_sea = ATM_flux_int ( ATM_wprecip_sea ) |
---|
533 | ATM_flx_wemp_lic = ATM_flux_int ( ATM_wemp_lic ) |
---|
534 | ATM_flx_wemp_oce = ATM_flux_int ( ATM_wemp_oce ) |
---|
535 | ATM_flx_wemp_sic = ATM_flux_int ( ATM_wemp_sic ) |
---|
536 | ATM_flx_wemp_ter = ATM_flux_int ( ATM_wemp_ter ) |
---|
537 | ATM_flx_wemp_sea = ATM_flux_int ( ATM_wemp_sea ) |
---|
538 | |
---|
539 | ATM_flx_emp = ATM_flux_int ( ATM_emp ) |
---|
540 | |
---|
541 | if SRF : |
---|
542 | RUN_flx_coastal = ONE_flux_int ( RUN_coastalflow) |
---|
543 | RUN_flx_river = ONE_flux_int ( RUN_riverflow ) |
---|
544 | RUN_flx_coastal_cpl = ONE_flux_int ( RUN_coastalflow_cpl) |
---|
545 | RUN_flx_river_cpl = ONE_flux_int ( RUN_riverflow_cpl ) |
---|
546 | RUN_flx_drainage = SRF_flux_int ( RUN_drainage ) |
---|
547 | RUN_flx_riversret = SRF_flux_int ( RUN_riversret ) |
---|
548 | RUN_flx_runoff = SRF_flux_int ( RUN_runoff ) |
---|
549 | RUN_flx_input = SRF_flux_int ( RUN_input ) |
---|
550 | RUN_flx_output = ONE_flux_int ( RUN_output ) |
---|
551 | |
---|
552 | RUN_flx_bil = ONE_flux_int ( RUN_input - RUN_output) |
---|
553 | RUN_flx_rivcoa = ONE_flux_int ( RUN_coastalflow + RUN_riverflow) |
---|
554 | |
---|
555 | prtFlux ('wbilo_oce ', ATM_flx_wbilo_oce , 'f' ) |
---|
556 | prtFlux ('wbilo_sic ', ATM_flx_wbilo_sic , 'f' ) |
---|
557 | prtFlux ('wbilo_sic+oce ', ATM_flx_wbilo_sea , 'f' ) |
---|
558 | prtFlux ('wbilo_ter ', ATM_flx_wbilo_ter , 'f' ) |
---|
559 | prtFlux ('wbilo_lic ', ATM_flx_wbilo_lic , 'f' ) |
---|
560 | prtFlux ('Sum wbilo_* ', ATM_flx_wbilo , 'f', True) |
---|
561 | prtFlux ('E-P ', ATM_flx_emp , 'f', True) |
---|
562 | prtFlux ('calving ', ATM_flx_calving , 'f' ) |
---|
563 | prtFlux ('fqfonte ', ATM_flx_fqfonte , 'f' ) |
---|
564 | prtFlux ('precip ', ATM_flx_precip , 'f' ) |
---|
565 | prtFlux ('snowf ', ATM_flx_snowf , 'f' ) |
---|
566 | prtFlux ('evap ', ATM_flx_evap , 'f' ) |
---|
567 | prtFlux ('runoff lic ', ATM_flx_runlic , 'f' ) |
---|
568 | |
---|
569 | prtFlux ('ATM_flx_wevap* ', ATM_flx_wevap , 'f' ) |
---|
570 | prtFlux ('ATM_flx_wrain* ', ATM_flx_wrain , 'f' ) |
---|
571 | prtFlux ('ATM_flx_wsnow* ', ATM_flx_wsnow , 'f' ) |
---|
572 | prtFlux ('ATM_flx_wprecip* ', ATM_flx_wprecip , 'f' ) |
---|
573 | prtFlux ('ATM_flx_wemp* ', ATM_flx_wemp , 'f', True ) |
---|
574 | |
---|
575 | prtFlux ('ERROR evap ', ATM_flx_wevap - ATM_flx_evap , 'e', True ) |
---|
576 | prtFlux ('ERROR precip ', ATM_flx_wprecip - ATM_flx_precip, 'e', True ) |
---|
577 | prtFlux ('ERROR snow ', ATM_flx_wsnow - ATM_flx_snowf , 'e', True ) |
---|
578 | prtFlux ('ERROR emp ', ATM_flx_wemp - ATM_flx_emp , 'e', True ) |
---|
579 | |
---|
580 | if SRF : |
---|
581 | echo ( '\n====================================================================================' ) |
---|
582 | echo ( f'-- RUNOFF Fluxes -- {Title} ' ) |
---|
583 | prtFlux ('coastalflow ', RUN_flx_coastal , 'f' ) |
---|
584 | prtFlux ('riverflow ', RUN_flx_river , 'f' ) |
---|
585 | prtFlux ('coastal_cpl ', RUN_flx_coastal_cpl, 'f' ) |
---|
586 | prtFlux ('riverf_cpl ', RUN_flx_river_cpl , 'f' ) |
---|
587 | prtFlux ('river+coastal ', RUN_flx_rivcoa , 'f' ) |
---|
588 | prtFlux ('drainage ', RUN_flx_drainage , 'f' ) |
---|
589 | prtFlux ('riversret ', RUN_flx_riversret , 'f' ) |
---|
590 | prtFlux ('runoff ', RUN_flx_runoff , 'f' ) |
---|
591 | prtFlux ('river in ', RUN_flx_input , 'f' ) |
---|
592 | prtFlux ('river out ', RUN_flx_output , 'f' ) |
---|
593 | prtFlux ('river bil ', RUN_flx_bil , 'f' ) |
---|
594 | |
---|
595 | echo ( '\n====================================================================================' ) |
---|
596 | echo ( f'-- OCE Fluxes -- {Title} ' ) |
---|
597 | |
---|
598 | # Read variable and computes integral over space and time |
---|
599 | OCE_empmr = rprec (d_OCE_his['wfo'] ) ; OCE_mas_empmr = OCE_flux_int ( OCE_empmr ) |
---|
600 | OCE_wfob = rprec (d_OCE_his['wfob'] ) ; OCE_mas_wfob = OCE_flux_int ( OCE_wfob ) |
---|
601 | OCE_emp_oce = rprec (d_OCE_his['emp_oce'] ) ; OCE_mas_emp_oce = OCE_flux_int ( OCE_emp_oce ) |
---|
602 | OCE_emp_ice = rprec (d_OCE_his['emp_ice'] ) ; OCE_mas_emp_ice = OCE_flux_int ( OCE_emp_ice ) |
---|
603 | OCE_iceshelf = rprec (d_OCE_his['iceshelf']) ; OCE_mas_iceshelf = OCE_flux_int ( OCE_iceshelf ) |
---|
604 | OCE_calving = rprec (d_OCE_his['calving'] ) ; OCE_mas_calving = OCE_flux_int ( OCE_calving ) |
---|
605 | OCE_iceberg = rprec (d_OCE_his['iceberg'] ) ; OCE_mas_iceberg = OCE_flux_int ( OCE_iceberg ) |
---|
606 | OCE_friver = rprec (d_OCE_his['friver'] ) ; OCE_mas_friver = OCE_flux_int ( OCE_friver ) |
---|
607 | OCE_runoffs = rprec (d_OCE_his['runoffs'] ) ; OCE_mas_runoffs = OCE_flux_int ( OCE_runoffs ) |
---|
608 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
609 | OCE_wfxice = rprec (d_OCE_his['vfxice']) ; OCE_mas_wfxice = OCE_flux_int ( OCE_wfxice ) |
---|
610 | OCE_wfxsnw = rprec (d_OCE_his['vfxsnw']) ; OCE_mas_wfxsnw = OCE_flux_int ( OCE_wfxsnw ) |
---|
611 | OCE_wfxsub = rprec (d_OCE_his['vfxsub']) ; OCE_mas_wfxsub = OCE_flux_int ( OCE_wfxsub ) |
---|
612 | if NEMO == 3.6 : |
---|
613 | OCE_wfxice = rprec (d_OCE_his['vfxice'])/86400.*ICE_RHO_ICE ; OCE_mas_wfxice = OCE_flux_int ( OCE_wfxice ) |
---|
614 | OCE_wfxsnw = rprec (d_OCE_his['vfxsnw'])/86400.*ICE_RHO_SNO ; OCE_mas_wfxsnw = OCE_flux_int ( OCE_wfxsnw ) |
---|
615 | OCE_wfxsub = rprec (d_OCE_his['vfxsub'])/86400.*ICE_RHO_SNO ; OCE_mas_wfxsub = OCE_flux_int ( OCE_wfxsub ) |
---|
616 | # Additional checks |
---|
617 | OCE_evap_oce = rprec (d_OCE_his['evap_ao_cea']) ; OCE_mas_evap_oce = OCE_flux_int ( OCE_evap_oce ) |
---|
618 | ICE_evap_ice = rprec (d_OCE_his['subl_ai_cea']) ; ICE_mas_evap_ice = OCE_flux_int ( ICE_evap_ice ) |
---|
619 | OCE_snow_oce = rprec (d_OCE_his['snow_ao_cea']) ; OCE_mas_snow_oce = OCE_flux_int ( OCE_snow_oce ) |
---|
620 | OCE_snow_ice = rprec (d_OCE_his['snow_ai_cea']) ; OCE_mas_snow_ice = OCE_flux_int ( OCE_snow_ice ) |
---|
621 | OCE_rain = rprec (d_OCE_his['rain'] ) ; OCE_mas_rain = OCE_flux_int ( OCE_rain ) |
---|
622 | ICE_wfxsub_err = rprec (d_ICE_his['vfxsub_err'] ) ; ICE_mas_wfxsub_err = OCE_flux_int ( ICE_wfxsub_err ) |
---|
623 | if NEMO == 4.0 or NEMO == 4.2 : |
---|
624 | ICE_wfxpnd = rprec (d_ICE_his['vfxpnd'] ) ; ICE_mas_wfxpnd = OCE_flux_int ( ICE_wfxpnd ) |
---|
625 | ICE_wfxsnw_sub = rprec (d_ICE_his['vfxsnw_sub']) ; ICE_mas_wfxsnw_sub = OCE_flux_int ( ICE_wfxsnw_sub ) |
---|
626 | ICE_wfxsnw_pre = rprec (d_ICE_his['vfxsnw_pre']) ; ICE_mas_wfxsnw_pre = OCE_flux_int ( ICE_wfxsnw_pre ) |
---|
627 | if NEMO == 3.6 : |
---|
628 | ICE_wfxpnd = 0.0 ; ICE_mas_wfxpnd = 0.0 |
---|
629 | ICE_wfxsnw_sub = rprec (d_ICE_his['vfxsub'])/86400.*ICE_RHO_SNO ; ICE_mas_wfxsnw_sub = OCE_flux_int ( ICE_wfxsnw_sub ) |
---|
630 | ICE_wfxsnw_pre = rprec (d_ICE_his['vfxspr'])/86400.*ICE_RHO_SNO ; ICE_mas_wfxsnw_pre = OCE_flux_int ( ICE_wfxsnw_pre ) |
---|
631 | |
---|
632 | OCE_wfcorr = rprec (d_OCE_his['wfcorr']) ; OCE_mas_wfcorr = OCE_flux_int ( OCE_wfcorr ) |
---|
633 | if OCE_relax : |
---|
634 | # ssr and fwb are included in emp=>empmr but not in emp_oce (outputed by sea-ice) |
---|
635 | OCE_vflx_fwb = rprec (d_OCE_his['vflx_fwb']) ; OCE_mas_vflx_fwb = OCE_flux_int ( OCE_vflx_fwb ) |
---|
636 | OCE_vflx_ssr = rprec (d_OCE_his['vflx_ssr']) ; OCE_mas_vflx_ssr = OCE_flux_int ( OCE_vflx_ssr ) |
---|
637 | else : |
---|
638 | OCE_fwb = 0.0 ; OCE_mas_fwb = 0.0 |
---|
639 | OCE_ssr = 0.0 ; OCE_mas_ssr = 0.0 |
---|
640 | if OCE_icb : |
---|
641 | OCE_berg_icb = rprec (d_OCE_his['berg_floating_melt']) ; OCE_mas_berg_icb = OCE_flux_int ( OCE_berg_icb ) |
---|
642 | OCE_calving_icb = rprec (d_OCE_his['calving_icb'] ) ; OCE_mas_calv_icb = OCE_flux_int ( OCE_calving_icb ) |
---|
643 | else : |
---|
644 | OCE_berg_icb = 0. ; OCE_mas_berg_icb = 0. |
---|
645 | OCE_calv_icb = 0. ; OCE_mas_calv_icb = 0. |
---|
646 | |
---|
647 | OCE_mas_emp = OCE_mas_emp_oce - OCE_mas_wfxice - OCE_mas_wfxsnw - ICE_mas_wfxpnd - ICE_mas_wfxsub_err |
---|
648 | OCE_mas_all = OCE_mas_emp_oce + OCE_mas_emp_ice - OCE_mas_runoffs - OCE_mas_iceshelf |
---|
649 | |
---|
650 | prtFlux ('OCE+ICE budget ', OCE_mas_all , 'e', True) |
---|
651 | prtFlux (' EMPMR ', OCE_mas_empmr , 'e', True) |
---|
652 | prtFlux (' WFOB ', OCE_mas_wfob , 'e', True) |
---|
653 | prtFlux (' EMP_OCE ', OCE_mas_emp_oce , 'e', True) |
---|
654 | prtFlux (' EMP_ICE ', OCE_mas_emp_ice , 'e', True) |
---|
655 | prtFlux (' EMP ', OCE_mas_emp , 'e', True) |
---|
656 | prtFlux (' ICEBERG ', OCE_mas_iceberg , 'e', ) |
---|
657 | prtFlux (' ICESHELF ', OCE_mas_iceshelf , 'e', True) |
---|
658 | prtFlux (' CALVING ', OCE_mas_calving , 'e', True) |
---|
659 | prtFlux (' FRIVER ', OCE_mas_friver , 'e', ) |
---|
660 | prtFlux (' RUNOFFS ', OCE_mas_runoffs , 'e', True) |
---|
661 | prtFlux (' WFXICE ', OCE_mas_wfxice , 'e', True) |
---|
662 | prtFlux (' WFXSNW ', OCE_mas_wfxsnw , 'e', True) |
---|
663 | prtFlux (' WFXSUB ', OCE_mas_wfxsub , 'e', True) |
---|
664 | prtFlux (' WFXPND ', ICE_mas_wfxpnd , 'e', True) |
---|
665 | prtFlux (' WFXSNW_SUB ', ICE_mas_wfxsnw_sub, 'e', True) |
---|
666 | prtFlux (' WFXSNW_PRE ', ICE_mas_wfxsnw_pre, 'e', True) |
---|
667 | prtFlux (' WFXSUB_ERR ', ICE_mas_wfxsub_err, 'e', True) |
---|
668 | prtFlux (' EVAP_OCE ', OCE_mas_evap_oce , 'e' ) |
---|
669 | prtFlux (' EVAP_ICE ', ICE_mas_evap_ice , 'e', True) |
---|
670 | prtFlux (' SNOW_OCE ', OCE_mas_snow_oce , 'e', True) |
---|
671 | prtFlux (' SNOW_ICE ', OCE_mas_snow_ice , 'e', True) |
---|
672 | prtFlux (' RAIN ', OCE_mas_rain , 'e' ) |
---|
673 | prtFlux (' FWB ', OCE_mas_fwb , 'e', True) |
---|
674 | prtFlux (' SSR ', OCE_mas_ssr , 'e', True) |
---|
675 | prtFlux (' WFCORR ', OCE_mas_wfcorr , 'e', True) |
---|
676 | prtFlux (' BERG_ICB ', OCE_mas_berg_icb , 'e', True) |
---|
677 | prtFlux (' CALV_ICB ', OCE_mas_calv_icb , 'e', True) |
---|
678 | |
---|
679 | |
---|
680 | echo (' ') |
---|
681 | |
---|
682 | prtFlux ( 'wbilo sea ', ATM_flux_int (ATM_wbilo_sea), 'e', ) |
---|
683 | if SRF : |
---|
684 | prtFlux ( 'costalflow ', ONE_flux_int (RUN_coastalflow), 'e', ) |
---|
685 | prtFlux ( 'riverflow ', RUN_flx_river , 'e', ) |
---|
686 | prtFlux ( 'costalflow ', RUN_flx_coastal, 'e', ) |
---|
687 | prtFlux ( 'runoff ', RUN_flx_river+RUN_flx_coastal, 'e', ) |
---|
688 | |
---|
689 | #ATM_to_OCE = ATM_flux_int (ATM_wbilo_sea) - RUN_flx_river - RUN_flx_coastal - ATM_flx_calving |
---|
690 | ATM_to_OCE = ATM_flux_int (ATM_wbilo_sea) - ATM_flx_river - ATM_flx_coastal - ATM_flx_calving |
---|
691 | #OCE_from_ATM = -OCE_mas_emp_oce - OCE_mas_emp_ice + OCE_mas_runoffs + OCE_mas_iceberg + OCE_mas_calving + OCE_mas_iceshelf |
---|
692 | OCE_from_ATM = OCE_mas_all |
---|
693 | |
---|
694 | prtFlux ( 'ATM_to_OCE ', ATM_to_OCE , 'e', True ) |
---|
695 | prtFlux ( 'OCE_from_ATM', OCE_from_ATM, 'e', True ) |
---|
696 | |
---|
697 | echo ( ' ' ) |
---|
698 | echo ( f'{Title = }' ) |
---|
699 | |
---|
700 | echo ( 'SVN Information' ) |
---|
701 | for kk in SVN.keys(): |
---|
702 | print ( SVN[kk] ) |
---|
703 | |
---|
704 | ## Write the full configuration |
---|
705 | ## ---------------------------- |
---|
706 | params_out = open (FullIniFile, 'w', encoding = 'utf-8') |
---|
707 | params = wu.dict2config ( dpar ) |
---|
708 | params.write ( params_out ) |
---|
709 | params_out.close () |
---|