[365] | 1 | # Pthon script to comput diagnostics |
---|
| 2 | # L. Fita, LMD. CNR, UPMC-Jussieu, Paris, France |
---|
| 3 | # File diagnostics.inf provides the combination of variables to get the desired diagnostic |
---|
[772] | 4 | # To be used with module_ForDiagnostics.F90, module_ForDiagnosticsVars.F90, module_generic.F90 |
---|
[1150] | 5 | # foudre: f2py -m module_ForDiagnostics --f90exec=/usr/bin/gfortran-4.7 -c module_generic.F90 module_ForDiagnosticsVars.F90 module_ForDiagnostics.F90 >& run_f2py.log |
---|
| 6 | # ciclad: f2py --f90flags="-fPIC" --f90exec=/usr/bin/gfortran -L/opt/canopy-1.3.0/Canopy_64bit/System/lib/ -L/usr/lib64/ -L/opt/canopy-1.3.0/Canopy_64bit/System/lib/ -m module_ForDiagnostics -c module_generic.F90 module_ForDiagnosticsVars.F90 module_ForDiagnostics.F90 >& run_f2py.log |
---|
[1149] | 7 | |
---|
[413] | 8 | ## e.g. # diagnostics.py -d 'Time@time,bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -v 'clt|CLDFRA,cllmh|CLDFRA@WRFp,RAINTOT|RAINC@RAINNC@XTIME' -f WRF_LMDZ/NPv31/wrfout_d01_1980-03-01_00:00:00 |
---|
| 9 | ## e.g. # diagnostics.py -f /home/lluis/PY/diagnostics.inf -d variable_combo -v WRFprc |
---|
[365] | 10 | |
---|
| 11 | from optparse import OptionParser |
---|
| 12 | import numpy as np |
---|
| 13 | from netCDF4 import Dataset as NetCDFFile |
---|
| 14 | import os |
---|
| 15 | import re |
---|
| 16 | import nc_var_tools as ncvar |
---|
[756] | 17 | import generic_tools as gen |
---|
[654] | 18 | import datetime as dtime |
---|
[1163] | 19 | import module_ForDiag as fdin |
---|
[365] | 20 | |
---|
| 21 | main = 'diagnostics.py' |
---|
| 22 | errormsg = 'ERROR -- error -- ERROR -- error' |
---|
| 23 | warnmsg = 'WARNING -- warning -- WARNING -- warning' |
---|
| 24 | |
---|
[654] | 25 | # Constants |
---|
| 26 | grav = 9.81 |
---|
| 27 | |
---|
[365] | 28 | # Gneral information |
---|
| 29 | ## |
---|
| 30 | def reduce_spaces(string): |
---|
| 31 | """ Function to give words of a line of text removing any extra space |
---|
| 32 | """ |
---|
| 33 | values = string.replace('\n','').split(' ') |
---|
| 34 | vals = [] |
---|
| 35 | for val in values: |
---|
| 36 | if len(val) > 0: |
---|
| 37 | vals.append(val) |
---|
| 38 | |
---|
| 39 | return vals |
---|
| 40 | |
---|
| 41 | def variable_combo(varn,combofile): |
---|
| 42 | """ Function to provide variables combination from a given variable name |
---|
| 43 | varn= name of the variable |
---|
| 44 | combofile= ASCII file with the combination of variables |
---|
| 45 | [varn] [combo] |
---|
| 46 | [combo]: '@' separated list of variables to use to generate [varn] |
---|
| 47 | [WRFdt] to get WRF time-step (from general attributes) |
---|
| 48 | >>> variable_combo('WRFprls','/home/lluis/PY/diagnostics.inf') |
---|
| 49 | deaccum@RAINNC@XTIME@prnc |
---|
| 50 | """ |
---|
| 51 | fname = 'variable_combo' |
---|
| 52 | |
---|
| 53 | if varn == 'h': |
---|
| 54 | print fname + '_____________________________________________________________' |
---|
| 55 | print variable_combo.__doc__ |
---|
| 56 | quit() |
---|
| 57 | |
---|
| 58 | if not os.path.isfile(combofile): |
---|
| 59 | print errormsg |
---|
| 60 | print ' ' + fname + ": file with combinations '" + combofile + \ |
---|
| 61 | "' does not exist!!" |
---|
| 62 | quit(-1) |
---|
| 63 | |
---|
| 64 | objf = open(combofile, 'r') |
---|
| 65 | |
---|
| 66 | found = False |
---|
| 67 | for line in objf: |
---|
| 68 | linevals = reduce_spaces(line) |
---|
| 69 | varnf = linevals[0] |
---|
| 70 | combo = linevals[1].replace('\n','') |
---|
| 71 | if varn == varnf: |
---|
| 72 | found = True |
---|
| 73 | break |
---|
| 74 | |
---|
| 75 | if not found: |
---|
| 76 | print errormsg |
---|
| 77 | print ' ' + fname + ": variable '" + varn + "' not found in '" + combofile +\ |
---|
| 78 | "' !!" |
---|
| 79 | combo='ERROR' |
---|
| 80 | |
---|
| 81 | objf.close() |
---|
| 82 | |
---|
| 83 | return combo |
---|
| 84 | |
---|
| 85 | # Mathematical operators |
---|
| 86 | ## |
---|
[649] | 87 | def compute_accum(varv, dimns, dimvns): |
---|
| 88 | """ Function to compute the accumulation of a variable |
---|
| 89 | compute_accum(varv, dimnames, dimvns) |
---|
| 90 | [varv]= values to accum (assuming [t,]) |
---|
| 91 | [dimns]= list of the name of the dimensions of the [varv] |
---|
| 92 | [dimvns]= list of the name of the variables with the values of the |
---|
| 93 | dimensions of [varv] |
---|
| 94 | """ |
---|
| 95 | fname = 'compute_accum' |
---|
| 96 | |
---|
| 97 | deacdims = dimns[:] |
---|
| 98 | deacvdims = dimvns[:] |
---|
| 99 | |
---|
| 100 | slicei = [] |
---|
| 101 | slicee = [] |
---|
| 102 | |
---|
| 103 | Ndims = len(varv.shape) |
---|
| 104 | for iid in range(0,Ndims): |
---|
| 105 | slicei.append(slice(0,varv.shape[iid])) |
---|
| 106 | slicee.append(slice(0,varv.shape[iid])) |
---|
| 107 | |
---|
| 108 | slicee[0] = np.arange(varv.shape[0]) |
---|
| 109 | slicei[0] = np.arange(varv.shape[0]) |
---|
| 110 | slicei[0][1:varv.shape[0]] = np.arange(varv.shape[0]-1) |
---|
| 111 | |
---|
| 112 | vari = varv[tuple(slicei)] |
---|
| 113 | vare = varv[tuple(slicee)] |
---|
| 114 | |
---|
| 115 | ac = vari*0. |
---|
| 116 | for it in range(1,varv.shape[0]): |
---|
| 117 | ac[it,] = ac[it-1,] + vare[it,] |
---|
| 118 | |
---|
| 119 | return ac, deacdims, deacvdims |
---|
| 120 | |
---|
[365] | 121 | def compute_deaccum(varv, dimns, dimvns): |
---|
| 122 | """ Function to compute the deaccumulation of a variable |
---|
| 123 | compute_deaccum(varv, dimnames, dimvns) |
---|
| 124 | [varv]= values to deaccum (assuming [t,]) |
---|
| 125 | [dimns]= list of the name of the dimensions of the [varv] |
---|
| 126 | [dimvns]= list of the name of the variables with the values of the |
---|
| 127 | dimensions of [varv] |
---|
| 128 | """ |
---|
| 129 | fname = 'compute_deaccum' |
---|
| 130 | |
---|
| 131 | deacdims = dimns[:] |
---|
| 132 | deacvdims = dimvns[:] |
---|
| 133 | |
---|
| 134 | slicei = [] |
---|
| 135 | slicee = [] |
---|
| 136 | |
---|
| 137 | Ndims = len(varv.shape) |
---|
| 138 | for iid in range(0,Ndims): |
---|
| 139 | slicei.append(slice(0,varv.shape[iid])) |
---|
| 140 | slicee.append(slice(0,varv.shape[iid])) |
---|
| 141 | |
---|
| 142 | slicee[0] = np.arange(varv.shape[0]) |
---|
| 143 | slicei[0] = np.arange(varv.shape[0]) |
---|
| 144 | slicei[0][1:varv.shape[0]] = np.arange(varv.shape[0]-1) |
---|
| 145 | |
---|
| 146 | vari = varv[tuple(slicei)] |
---|
| 147 | vare = varv[tuple(slicee)] |
---|
| 148 | |
---|
| 149 | deac = vare - vari |
---|
| 150 | |
---|
| 151 | return deac, deacdims, deacvdims |
---|
| 152 | |
---|
| 153 | def derivate_centered(var,dim,dimv): |
---|
| 154 | """ Function to compute the centered derivate of a given field |
---|
| 155 | centered derivate(n) = (var(n-1) + var(n+1))/(2*dn). |
---|
| 156 | [var]= variable |
---|
| 157 | [dim]= which dimension to compute the derivate |
---|
| 158 | [dimv]= dimension values (can be of different dimension of [var]) |
---|
| 159 | >>> derivate_centered(np.arange(16).reshape(4,4)*1.,1,1.) |
---|
| 160 | [[ 0. 1. 2. 0.] |
---|
| 161 | [ 0. 5. 6. 0.] |
---|
| 162 | [ 0. 9. 10. 0.] |
---|
| 163 | [ 0. 13. 14. 0.]] |
---|
| 164 | """ |
---|
| 165 | |
---|
| 166 | fname = 'derivate_centered' |
---|
| 167 | |
---|
| 168 | vark = var.dtype |
---|
| 169 | |
---|
| 170 | if hasattr(dimv, "__len__"): |
---|
| 171 | # Assuming that the last dimensions of var [..., N, M] are the same of dimv [N, M] |
---|
| 172 | if len(var.shape) != len(dimv.shape): |
---|
| 173 | dimvals = np.zeros((var.shape), dtype=vark) |
---|
| 174 | if len(var.shape) - len(dimv.shape) == 1: |
---|
| 175 | for iz in range(var.shape[0]): |
---|
| 176 | dimvals[iz,] = dimv |
---|
| 177 | elif len(var.shape) - len(dimv.shape) == 2: |
---|
| 178 | for it in range(var.shape[0]): |
---|
| 179 | for iz in range(var.shape[1]): |
---|
| 180 | dimvals[it,iz,] = dimv |
---|
| 181 | else: |
---|
| 182 | print errormsg |
---|
| 183 | print ' ' + fname + ': dimension difference between variable', \ |
---|
| 184 | var.shape,'and variable with dimension values',dimv.shape, \ |
---|
| 185 | ' not ready !!!' |
---|
| 186 | quit(-1) |
---|
| 187 | else: |
---|
| 188 | dimvals = dimv |
---|
| 189 | else: |
---|
| 190 | # dimension values are identical everywhere! |
---|
| 191 | # from: http://stackoverflow.com/questions/16807011/python-how-to-identify-if-a-variable-is-an-array-or-a-scalar |
---|
| 192 | dimvals = np.ones((var.shape), dtype=vark)*dimv |
---|
| 193 | |
---|
| 194 | derivate = np.zeros((var.shape), dtype=vark) |
---|
| 195 | if dim > len(var.shape) - 1: |
---|
| 196 | print errormsg |
---|
| 197 | print ' ' + fname + ': dimension',dim,' too big for given variable of ' + \ |
---|
| 198 | 'shape:', var.shape,'!!!' |
---|
| 199 | quit(-1) |
---|
| 200 | |
---|
| 201 | slicebef = [] |
---|
| 202 | sliceaft = [] |
---|
| 203 | sliceder = [] |
---|
| 204 | |
---|
| 205 | for id in range(len(var.shape)): |
---|
| 206 | if id == dim: |
---|
| 207 | slicebef.append(slice(0,var.shape[id]-2)) |
---|
| 208 | sliceaft.append(slice(2,var.shape[id])) |
---|
| 209 | sliceder.append(slice(1,var.shape[id]-1)) |
---|
| 210 | else: |
---|
| 211 | slicebef.append(slice(0,var.shape[id])) |
---|
| 212 | sliceaft.append(slice(0,var.shape[id])) |
---|
| 213 | sliceder.append(slice(0,var.shape[id])) |
---|
| 214 | |
---|
| 215 | if hasattr(dimv, "__len__"): |
---|
| 216 | derivate[tuple(sliceder)] = (var[tuple(slicebef)] + var[tuple(sliceaft)])/ \ |
---|
| 217 | ((dimvals[tuple(sliceaft)] - dimvals[tuple(slicebef)])) |
---|
| 218 | print (dimvals[tuple(sliceaft)] - dimvals[tuple(slicebef)]) |
---|
| 219 | else: |
---|
| 220 | derivate[tuple(sliceder)] = (var[tuple(slicebef)] + var[tuple(sliceaft)])/ \ |
---|
| 221 | (2.*dimv) |
---|
| 222 | |
---|
| 223 | # print 'before________' |
---|
| 224 | # print var[tuple(slicebef)] |
---|
| 225 | |
---|
| 226 | # print 'after________' |
---|
| 227 | # print var[tuple(sliceaft)] |
---|
| 228 | |
---|
| 229 | return derivate |
---|
| 230 | |
---|
| 231 | def rotational_z(Vx,Vy,pos): |
---|
| 232 | """ z-component of the rotatinoal of horizontal vectorial field |
---|
| 233 | \/ x (Vx,Vy,Vz) = \/xVy - \/yVx |
---|
| 234 | [Vx]= Variable component x |
---|
| 235 | [Vy]= Variable component y |
---|
| 236 | [pos]= poisition of the grid points |
---|
| 237 | >>> rotational_z(np.arange(16).reshape(4,4)*1., np.arange(16).reshape(4,4)*1., 1.) |
---|
| 238 | [[ 0. 1. 2. 0.] |
---|
| 239 | [ -4. 0. 0. -7.] |
---|
| 240 | [ -8. 0. 0. -11.] |
---|
| 241 | [ 0. 13. 14. 0.]] |
---|
| 242 | """ |
---|
| 243 | |
---|
| 244 | fname = 'rotational_z' |
---|
| 245 | |
---|
| 246 | ndims = len(Vx.shape) |
---|
| 247 | rot1 = derivate_centered(Vy,ndims-1,pos) |
---|
| 248 | rot2 = derivate_centered(Vx,ndims-2,pos) |
---|
| 249 | |
---|
| 250 | rot = rot1 - rot2 |
---|
| 251 | |
---|
| 252 | return rot |
---|
| 253 | |
---|
| 254 | # Diagnostics |
---|
| 255 | ## |
---|
| 256 | |
---|
| 257 | def var_clt(cfra): |
---|
| 258 | """ Function to compute the total cloud fraction following 'newmicro.F90' from |
---|
| 259 | LMDZ using 1D vertical column values |
---|
| 260 | [cldfra]= cloud fraction values (assuming [[t],z,y,x]) |
---|
| 261 | """ |
---|
| 262 | ZEPSEC=1.0E-12 |
---|
| 263 | |
---|
| 264 | fname = 'var_clt' |
---|
| 265 | |
---|
| 266 | zclear = 1. |
---|
| 267 | zcloud = 0. |
---|
| 268 | |
---|
| 269 | dz = cfra.shape[0] |
---|
| 270 | for iz in range(dz): |
---|
| 271 | zclear =zclear*(1.-np.max([cfra[iz],zcloud]))/(1.-np.min([zcloud,1.-ZEPSEC])) |
---|
| 272 | clt = 1. - zclear |
---|
| 273 | zcloud = cfra[iz] |
---|
| 274 | |
---|
| 275 | return clt |
---|
| 276 | |
---|
| 277 | def compute_clt(cldfra, dimns, dimvns): |
---|
| 278 | """ Function to compute the total cloud fraction following 'newmicro.F90' from |
---|
| 279 | LMDZ |
---|
| 280 | compute_clt(cldfra, dimnames) |
---|
| 281 | [cldfra]= cloud fraction values (assuming [[t],z,y,x]) |
---|
| 282 | [dimns]= list of the name of the dimensions of [cldfra] |
---|
| 283 | [dimvns]= list of the name of the variables with the values of the |
---|
| 284 | dimensions of [cldfra] |
---|
| 285 | """ |
---|
| 286 | fname = 'compute_clt' |
---|
| 287 | |
---|
| 288 | cltdims = dimns[:] |
---|
| 289 | cltvdims = dimvns[:] |
---|
| 290 | |
---|
| 291 | if len(cldfra.shape) == 4: |
---|
| 292 | clt = np.zeros((cldfra.shape[0],cldfra.shape[2],cldfra.shape[3]), \ |
---|
| 293 | dtype=np.float) |
---|
| 294 | dx = cldfra.shape[3] |
---|
| 295 | dy = cldfra.shape[2] |
---|
| 296 | dz = cldfra.shape[1] |
---|
| 297 | dt = cldfra.shape[0] |
---|
| 298 | cltdims.pop(1) |
---|
| 299 | cltvdims.pop(1) |
---|
| 300 | |
---|
| 301 | for it in range(dt): |
---|
| 302 | for ix in range(dx): |
---|
| 303 | for iy in range(dy): |
---|
| 304 | zclear = 1. |
---|
| 305 | zcloud = 0. |
---|
| 306 | ncvar.percendone(it*dx*dy + ix*dy + iy, dx*dy*dt, 5, 'diagnosted') |
---|
| 307 | clt[it,iy,ix] = var_clt(cldfra[it,:,iy,ix]) |
---|
| 308 | |
---|
| 309 | else: |
---|
| 310 | clt = np.zeros((cldfra.shape[1],cldfra.shape[2]), dtype=np.float) |
---|
| 311 | dx = cldfra.shape[2] |
---|
| 312 | dy = cldfra.shape[1] |
---|
| 313 | dy = cldfra.shape[0] |
---|
| 314 | cltdims.pop(0) |
---|
| 315 | cltvdims.pop(0) |
---|
| 316 | for ix in range(dx): |
---|
| 317 | for iy in range(dy): |
---|
| 318 | zclear = 1. |
---|
| 319 | zcloud = 0. |
---|
| 320 | ncvar.percendone(ix*dy + iy, dx*dy*dt, 5, 'diagnosted') |
---|
| 321 | clt[iy,ix] = var_clt(cldfra[:,iy,ix]) |
---|
| 322 | |
---|
| 323 | return clt, cltdims, cltvdims |
---|
| 324 | |
---|
[772] | 325 | def Forcompute_clt(cldfra, dimns, dimvns): |
---|
| 326 | """ Function to compute the total cloud fraction following 'newmicro.F90' from |
---|
| 327 | LMDZ via a Fortran module |
---|
| 328 | compute_clt(cldfra, dimnames) |
---|
| 329 | [cldfra]= cloud fraction values (assuming [[t],z,y,x]) |
---|
| 330 | [dimns]= list of the name of the dimensions of [cldfra] |
---|
| 331 | [dimvns]= list of the name of the variables with the values of the |
---|
| 332 | dimensions of [cldfra] |
---|
| 333 | """ |
---|
| 334 | fname = 'Forcompute_clt' |
---|
| 335 | |
---|
| 336 | cltdims = dimns[:] |
---|
| 337 | cltvdims = dimvns[:] |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | if len(cldfra.shape) == 4: |
---|
| 341 | clt = np.zeros((cldfra.shape[0],cldfra.shape[2],cldfra.shape[3]), \ |
---|
| 342 | dtype=np.float) |
---|
| 343 | dx = cldfra.shape[3] |
---|
| 344 | dy = cldfra.shape[2] |
---|
| 345 | dz = cldfra.shape[1] |
---|
| 346 | dt = cldfra.shape[0] |
---|
| 347 | cltdims.pop(1) |
---|
| 348 | cltvdims.pop(1) |
---|
| 349 | |
---|
| 350 | clt = fdin.module_fordiagnostics.compute_clt4d2(cldfra[:]) |
---|
| 351 | |
---|
| 352 | else: |
---|
| 353 | clt = np.zeros((cldfra.shape[1],cldfra.shape[2]), dtype=np.float) |
---|
| 354 | dx = cldfra.shape[2] |
---|
| 355 | dy = cldfra.shape[1] |
---|
| 356 | dy = cldfra.shape[0] |
---|
| 357 | cltdims.pop(0) |
---|
| 358 | cltvdims.pop(0) |
---|
| 359 | |
---|
| 360 | clt = fdin.module_fordiagnostics.compute_clt3d1(cldfra[:]) |
---|
| 361 | |
---|
| 362 | return clt, cltdims, cltvdims |
---|
| 363 | |
---|
[365] | 364 | def var_cllmh(cfra, p): |
---|
| 365 | """ Fcuntion to compute cllmh on a 1D column |
---|
| 366 | """ |
---|
| 367 | |
---|
| 368 | fname = 'var_cllmh' |
---|
| 369 | |
---|
| 370 | ZEPSEC =1.0E-12 |
---|
| 371 | prmhc = 440.*100. |
---|
| 372 | prmlc = 680.*100. |
---|
| 373 | |
---|
| 374 | zclearl = 1. |
---|
| 375 | zcloudl = 0. |
---|
| 376 | zclearm = 1. |
---|
| 377 | zcloudm = 0. |
---|
| 378 | zclearh = 1. |
---|
| 379 | zcloudh = 0. |
---|
| 380 | |
---|
| 381 | dvz = cfra.shape[0] |
---|
| 382 | |
---|
| 383 | cllmh = np.ones((3), dtype=np.float) |
---|
| 384 | |
---|
| 385 | for iz in range(dvz): |
---|
| 386 | if p[iz] < prmhc: |
---|
| 387 | cllmh[2] = cllmh[2]*(1.-np.max([cfra[iz], zcloudh]))/(1.- \ |
---|
| 388 | np.min([zcloudh,1.-ZEPSEC])) |
---|
| 389 | zcloudh = cfra[iz] |
---|
| 390 | elif p[iz] >= prmhc and p[iz] < prmlc: |
---|
| 391 | cllmh[1] = cllmh[1]*(1.-np.max([cfra[iz], zcloudm]))/(1.- \ |
---|
| 392 | np.min([zcloudm,1.-ZEPSEC])) |
---|
| 393 | zcloudm = cfra[iz] |
---|
| 394 | elif p[iz] >= prmlc: |
---|
| 395 | cllmh[0] = cllmh[0]*(1.-np.max([cfra[iz], zcloudl]))/(1.- \ |
---|
| 396 | np.min([zcloudl,1.-ZEPSEC])) |
---|
| 397 | zcloudl = cfra[iz] |
---|
| 398 | |
---|
| 399 | cllmh = 1.- cllmh |
---|
| 400 | |
---|
| 401 | return cllmh |
---|
| 402 | |
---|
[772] | 403 | def Forcompute_cllmh(cldfra, pres, dimns, dimvns): |
---|
| 404 | """ Function to compute cllmh: low/medium/hight cloud fraction following newmicro.F90 from LMDZ via Fortran subroutine |
---|
| 405 | compute_clt(cldfra, pres, dimns, dimvns) |
---|
| 406 | [cldfra]= cloud fraction values (assuming [[t],z,y,x]) |
---|
| 407 | [pres] = pressure field |
---|
| 408 | [dimns]= list of the name of the dimensions of [cldfra] |
---|
| 409 | [dimvns]= list of the name of the variables with the values of the |
---|
| 410 | dimensions of [cldfra] |
---|
| 411 | """ |
---|
| 412 | fname = 'Forcompute_cllmh' |
---|
| 413 | |
---|
| 414 | cllmhdims = dimns[:] |
---|
| 415 | cllmhvdims = dimvns[:] |
---|
| 416 | |
---|
| 417 | if len(cldfra.shape) == 4: |
---|
| 418 | dx = cldfra.shape[3] |
---|
| 419 | dy = cldfra.shape[2] |
---|
| 420 | dz = cldfra.shape[1] |
---|
| 421 | dt = cldfra.shape[0] |
---|
| 422 | cllmhdims.pop(1) |
---|
| 423 | cllmhvdims.pop(1) |
---|
| 424 | |
---|
| 425 | cllmh = fdin.module_fordiagnostics.compute_cllmh4d2(cldfra[:], pres[:]) |
---|
| 426 | |
---|
| 427 | else: |
---|
| 428 | dx = cldfra.shape[2] |
---|
| 429 | dy = cldfra.shape[1] |
---|
| 430 | dz = cldfra.shape[0] |
---|
| 431 | cllmhdims.pop(0) |
---|
| 432 | cllmhvdims.pop(0) |
---|
| 433 | |
---|
| 434 | cllmh = fdin.module_fordiagnostics.compute_cllmh3d1(cldfra[:], pres[:]) |
---|
| 435 | |
---|
| 436 | return cllmh, cllmhdims, cllmhvdims |
---|
| 437 | |
---|
[365] | 438 | def compute_cllmh(cldfra, pres, dimns, dimvns): |
---|
| 439 | """ Function to compute cllmh: low/medium/hight cloud fraction following newmicro.F90 from LMDZ |
---|
| 440 | compute_clt(cldfra, pres, dimns, dimvns) |
---|
| 441 | [cldfra]= cloud fraction values (assuming [[t],z,y,x]) |
---|
| 442 | [pres] = pressure field |
---|
| 443 | [dimns]= list of the name of the dimensions of [cldfra] |
---|
| 444 | [dimvns]= list of the name of the variables with the values of the |
---|
| 445 | dimensions of [cldfra] |
---|
| 446 | """ |
---|
| 447 | fname = 'compute_cllmh' |
---|
| 448 | |
---|
| 449 | cllmhdims = dimns[:] |
---|
| 450 | cllmhvdims = dimvns[:] |
---|
| 451 | |
---|
| 452 | if len(cldfra.shape) == 4: |
---|
| 453 | dx = cldfra.shape[3] |
---|
| 454 | dy = cldfra.shape[2] |
---|
| 455 | dz = cldfra.shape[1] |
---|
| 456 | dt = cldfra.shape[0] |
---|
| 457 | cllmhdims.pop(1) |
---|
| 458 | cllmhvdims.pop(1) |
---|
| 459 | |
---|
| 460 | cllmh = np.ones(tuple([3, dt, dy, dx]), dtype=np.float) |
---|
| 461 | |
---|
| 462 | for it in range(dt): |
---|
| 463 | for ix in range(dx): |
---|
| 464 | for iy in range(dy): |
---|
| 465 | ncvar.percendone(it*dx*dy + ix*dy + iy, dx*dy*dt, 5, 'diagnosted') |
---|
| 466 | cllmh[:,it,iy,ix] = var_cllmh(cldfra[it,:,iy,ix], pres[it,:,iy,ix]) |
---|
| 467 | |
---|
| 468 | else: |
---|
| 469 | dx = cldfra.shape[2] |
---|
| 470 | dy = cldfra.shape[1] |
---|
| 471 | dz = cldfra.shape[0] |
---|
| 472 | cllmhdims.pop(0) |
---|
| 473 | cllmhvdims.pop(0) |
---|
| 474 | |
---|
| 475 | cllmh = np.ones(tuple([3, dy, dx]), dtype=np.float) |
---|
| 476 | |
---|
| 477 | for ix in range(dx): |
---|
| 478 | for iy in range(dy): |
---|
| 479 | ncvar.percendone(ix*dy + iy,dx*dy, 5, 'diagnosted') |
---|
| 480 | cllmh[:,iy,ix] = var_cllmh(cldfra[:,iy,ix], pres[:,iy,ix]) |
---|
| 481 | |
---|
| 482 | return cllmh, cllmhdims, cllmhvdims |
---|
| 483 | |
---|
| 484 | def var_virtualTemp (temp,rmix): |
---|
| 485 | """ This function returns virtual temperature in K, |
---|
| 486 | temp: temperature [K] |
---|
| 487 | rmix: mixing ratio in [kgkg-1] |
---|
| 488 | """ |
---|
| 489 | |
---|
| 490 | fname = 'var_virtualTemp' |
---|
| 491 | |
---|
| 492 | virtual=temp*(0.622+rmix)/(0.622*(1.+rmix)) |
---|
| 493 | |
---|
| 494 | return virtual |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | def var_mslp(pres, psfc, ter, tk, qv): |
---|
| 498 | """ Function to compute mslp on a 1D column |
---|
| 499 | """ |
---|
| 500 | |
---|
| 501 | fname = 'var_mslp' |
---|
| 502 | |
---|
| 503 | N = 1.0 |
---|
| 504 | expon=287.04*.0065/9.81 |
---|
| 505 | pref = 40000. |
---|
| 506 | |
---|
| 507 | # First find where about 400 hPa is located |
---|
| 508 | dz=len(pres) |
---|
| 509 | |
---|
| 510 | kref = -1 |
---|
| 511 | pinc = pres[0] - pres[dz-1] |
---|
| 512 | |
---|
| 513 | if pinc < 0.: |
---|
| 514 | for iz in range(1,dz): |
---|
| 515 | if pres[iz-1] >= pref and pres[iz] < pref: |
---|
| 516 | kref = iz |
---|
| 517 | break |
---|
| 518 | else: |
---|
| 519 | for iz in range(dz-1): |
---|
| 520 | if pres[iz] >= pref and pres[iz+1] < pref: |
---|
| 521 | kref = iz |
---|
| 522 | break |
---|
| 523 | |
---|
| 524 | if kref == -1: |
---|
| 525 | print errormsg |
---|
| 526 | print ' ' + fname + ': no reference pressure:',pref,'found!!' |
---|
| 527 | print ' values:',pres[:] |
---|
| 528 | quit(-1) |
---|
| 529 | |
---|
| 530 | mslp = 0. |
---|
| 531 | |
---|
| 532 | # We are below both the ground and the lowest data level. |
---|
| 533 | |
---|
| 534 | # First, find the model level that is closest to a "target" pressure |
---|
| 535 | # level, where the "target" pressure is delta-p less that the local |
---|
| 536 | # value of a horizontally smoothed surface pressure field. We use |
---|
| 537 | # delta-p = 150 hPa here. A standard lapse rate temperature profile |
---|
| 538 | # passing through the temperature at this model level will be used |
---|
| 539 | # to define the temperature profile below ground. This is similar |
---|
| 540 | # to the Benjamin and Miller (1990) method, using |
---|
| 541 | # 700 hPa everywhere for the "target" pressure. |
---|
| 542 | |
---|
| 543 | # ptarget = psfc - 15000. |
---|
| 544 | ptarget = 70000. |
---|
| 545 | dpmin=1.e4 |
---|
| 546 | kupper = 0 |
---|
| 547 | if pinc > 0.: |
---|
| 548 | for iz in range(dz-1,0,-1): |
---|
| 549 | kupper = iz |
---|
| 550 | dp=np.abs( pres[iz] - ptarget ) |
---|
| 551 | if dp < dpmin: exit |
---|
| 552 | dpmin = np.min([dpmin, dp]) |
---|
| 553 | else: |
---|
| 554 | for iz in range(dz): |
---|
| 555 | kupper = iz |
---|
| 556 | dp=np.abs( pres[iz] - ptarget ) |
---|
| 557 | if dp < dpmin: exit |
---|
| 558 | dpmin = np.min([dpmin, dp]) |
---|
| 559 | |
---|
| 560 | pbot=np.max([pres[0], psfc]) |
---|
| 561 | # zbot=0. |
---|
| 562 | |
---|
| 563 | # tbotextrap=tk(i,j,kupper,itt)*(pbot/pres_field(i,j,kupper,itt))**expon |
---|
| 564 | # tvbotextrap=virtual(tbotextrap,qv(i,j,1,itt)) |
---|
| 565 | |
---|
| 566 | # data_out(i,j,itt,1) = (zbot+tvbotextrap/.0065*(1.-(interp_levels(1)/pbot)**expon)) |
---|
| 567 | tbotextrap = tk[kupper]*(psfc/ptarget)**expon |
---|
| 568 | tvbotextrap = var_virtualTemp(tbotextrap, qv[kupper]) |
---|
| 569 | mslp = psfc*( (tvbotextrap+0.0065*ter)/tvbotextrap)**(1./expon) |
---|
| 570 | |
---|
| 571 | return mslp |
---|
| 572 | |
---|
| 573 | def compute_mslp(pressure, psurface, terrain, temperature, qvapor, dimns, dimvns): |
---|
| 574 | """ Function to compute mslp: mean sea level pressure following p_interp.F90 from WRF |
---|
| 575 | var_mslp(pres, ter, tk, qv, dimns, dimvns) |
---|
| 576 | [pressure]= pressure field [Pa] (assuming [[t],z,y,x]) |
---|
| 577 | [psurface]= surface pressure field [Pa] |
---|
| 578 | [terrain]= topography [m] |
---|
| 579 | [temperature]= temperature [K] |
---|
| 580 | [qvapor]= water vapour mixing ratio [kgkg-1] |
---|
| 581 | [dimns]= list of the name of the dimensions of [cldfra] |
---|
| 582 | [dimvns]= list of the name of the variables with the values of the |
---|
| 583 | dimensions of [pres] |
---|
| 584 | """ |
---|
| 585 | |
---|
| 586 | fname = 'compute_mslp' |
---|
| 587 | |
---|
| 588 | mslpdims = list(dimns[:]) |
---|
| 589 | mslpvdims = list(dimvns[:]) |
---|
| 590 | |
---|
| 591 | if len(pressure.shape) == 4: |
---|
| 592 | mslpdims.pop(1) |
---|
| 593 | mslpvdims.pop(1) |
---|
| 594 | else: |
---|
| 595 | mslpdims.pop(0) |
---|
| 596 | mslpvdims.pop(0) |
---|
| 597 | |
---|
| 598 | if len(pressure.shape) == 4: |
---|
| 599 | dx = pressure.shape[3] |
---|
| 600 | dy = pressure.shape[2] |
---|
| 601 | dz = pressure.shape[1] |
---|
| 602 | dt = pressure.shape[0] |
---|
| 603 | |
---|
| 604 | mslpv = np.zeros(tuple([dt, dy, dx]), dtype=np.float) |
---|
| 605 | |
---|
| 606 | # Terrain... to 2D ! |
---|
| 607 | terval = np.zeros(tuple([dy, dx]), dtype=np.float) |
---|
| 608 | if len(terrain.shape) == 3: |
---|
| 609 | terval = terrain[0,:,:] |
---|
| 610 | else: |
---|
| 611 | terval = terrain |
---|
| 612 | |
---|
| 613 | for ix in range(dx): |
---|
| 614 | for iy in range(dy): |
---|
| 615 | if terval[iy,ix] > 0.: |
---|
| 616 | for it in range(dt): |
---|
| 617 | mslpv[it,iy,ix] = var_mslp(pressure[it,:,iy,ix], \ |
---|
| 618 | psurface[it,iy,ix], terval[iy,ix], temperature[it,:,iy,ix],\ |
---|
| 619 | qvapor[it,:,iy,ix]) |
---|
| 620 | |
---|
| 621 | ncvar.percendone(it*dx*dy + ix*dy + iy, dx*dy*dt, 5, 'diagnosted') |
---|
| 622 | else: |
---|
| 623 | mslpv[:,iy,ix] = psurface[:,iy,ix] |
---|
| 624 | |
---|
| 625 | else: |
---|
| 626 | dx = pressure.shape[2] |
---|
| 627 | dy = pressure.shape[1] |
---|
| 628 | dz = pressure.shape[0] |
---|
| 629 | |
---|
| 630 | mslpv = np.zeros(tuple([dy, dx]), dtype=np.float) |
---|
| 631 | |
---|
| 632 | # Terrain... to 2D ! |
---|
| 633 | terval = np.zeros(tuple([dy, dx]), dtype=np.float) |
---|
| 634 | if len(terrain.shape) == 3: |
---|
| 635 | terval = terrain[0,:,:] |
---|
| 636 | else: |
---|
| 637 | terval = terrain |
---|
| 638 | |
---|
| 639 | for ix in range(dx): |
---|
| 640 | for iy in range(dy): |
---|
| 641 | ncvar.percendone(ix*dy + iy,dx*dy, 5, 'diagnosted') |
---|
| 642 | if terval[iy,ix] > 0.: |
---|
| 643 | mslpv[iy,ix] = var_mslp(pressure[:,iy,ix], psurface[iy,ix], \ |
---|
| 644 | terval[iy,ix], temperature[:,iy,ix], qvapor[:,iy,ix]) |
---|
| 645 | else: |
---|
| 646 | mslpv[iy,ix] = psfc[iy,ix] |
---|
| 647 | |
---|
| 648 | return mslpv, mslpdims, mslpvdims |
---|
| 649 | |
---|
[642] | 650 | def compute_OMEGAw(omega, p, t, dimns, dimvns): |
---|
| 651 | """ Function to transform OMEGA [Pas-1] to velocities [ms-1] |
---|
| 652 | tacking: https://www.ncl.ucar.edu/Document/Functions/Contributed/omega_to_w.shtml |
---|
| 653 | [omega] = vertical velocity [in ms-1] (assuming [t],z,y,x) |
---|
| 654 | [p] = pressure in [Pa] (assuming [t],z,y,x) |
---|
| 655 | [t] = temperature in [K] (assuming [t],z,y,x) |
---|
| 656 | [dimns]= list of the name of the dimensions of [q] |
---|
| 657 | [dimvns]= list of the name of the variables with the values of the |
---|
| 658 | dimensions of [q] |
---|
| 659 | """ |
---|
| 660 | fname = 'compute_OMEGAw' |
---|
| 661 | |
---|
| 662 | rgas = 287.058 # J/(kg-K) => m2/(s2 K) |
---|
| 663 | g = 9.80665 # m/s2 |
---|
| 664 | |
---|
| 665 | wdims = dimns[:] |
---|
| 666 | wvdims = dimvns[:] |
---|
| 667 | |
---|
| 668 | rho = p/(rgas*t) # density => kg/m3 |
---|
| 669 | w = -omega/(rho*g) |
---|
| 670 | |
---|
| 671 | return w, wdims, wvdims |
---|
| 672 | |
---|
[365] | 673 | def compute_prw(dens, q, dimns, dimvns): |
---|
| 674 | """ Function to compute water vapour path (prw) |
---|
| 675 | [dens] = density [in kgkg-1] (assuming [t],z,y,x) |
---|
| 676 | [q] = mixing ratio in [kgkg-1] (assuming [t],z,y,x) |
---|
| 677 | [dimns]= list of the name of the dimensions of [q] |
---|
| 678 | [dimvns]= list of the name of the variables with the values of the |
---|
| 679 | dimensions of [q] |
---|
| 680 | """ |
---|
| 681 | fname = 'compute_prw' |
---|
| 682 | |
---|
| 683 | prwdims = dimns[:] |
---|
| 684 | prwvdims = dimvns[:] |
---|
| 685 | |
---|
| 686 | if len(q.shape) == 4: |
---|
| 687 | prwdims.pop(1) |
---|
| 688 | prwvdims.pop(1) |
---|
| 689 | else: |
---|
| 690 | prwdims.pop(0) |
---|
| 691 | prwvdims.pop(0) |
---|
| 692 | |
---|
| 693 | data1 = dens*q |
---|
| 694 | prw = np.sum(data1, axis=1) |
---|
| 695 | |
---|
| 696 | return prw, prwdims, prwvdims |
---|
| 697 | |
---|
| 698 | def compute_rh(p, t, q, dimns, dimvns): |
---|
| 699 | """ Function to compute relative humidity following 'Tetens' equation (T,P) ...' |
---|
| 700 | [t]= temperature (assuming [[t],z,y,x] in [K]) |
---|
| 701 | [p] = pressure field (assuming in [hPa]) |
---|
| 702 | [q] = mixing ratio in [kgkg-1] |
---|
| 703 | [dimns]= list of the name of the dimensions of [t] |
---|
| 704 | [dimvns]= list of the name of the variables with the values of the |
---|
| 705 | dimensions of [t] |
---|
| 706 | """ |
---|
| 707 | fname = 'compute_rh' |
---|
| 708 | |
---|
| 709 | rhdims = dimns[:] |
---|
| 710 | rhvdims = dimvns[:] |
---|
| 711 | |
---|
| 712 | data1 = 10.*0.6112*np.exp(17.67*(t-273.16)/(t-29.65)) |
---|
| 713 | data2 = 0.622*data1/(0.01*p-(1.-0.622)*data1) |
---|
| 714 | |
---|
| 715 | rh = q/data2 |
---|
| 716 | |
---|
| 717 | return rh, rhdims, rhvdims |
---|
| 718 | |
---|
[612] | 719 | def compute_td(p, temp, qv, dimns, dimvns): |
---|
| 720 | """ Function to compute the dew point temperature |
---|
| 721 | [p]= pressure [Pa] |
---|
| 722 | [temp]= temperature [C] |
---|
| 723 | [qv]= mixing ratio [kgkg-1] |
---|
| 724 | [dimns]= list of the name of the dimensions of [p] |
---|
| 725 | [dimvns]= list of the name of the variables with the values of the |
---|
| 726 | dimensions of [p] |
---|
| 727 | """ |
---|
| 728 | fname = 'compute_td' |
---|
| 729 | |
---|
| 730 | # print ' ' + fname + ': computing dew-point temperature from TS as t and Tetens...' |
---|
| 731 | # tacking from: http://en.wikipedia.org/wiki/Dew_point |
---|
| 732 | tk = temp |
---|
| 733 | data1 = 10.*0.6112*np.exp(17.67*(tk-273.16)/(tk-29.65)) |
---|
| 734 | data2 = 0.622*data1/(0.01*p-(1.-0.622)*data1) |
---|
| 735 | |
---|
| 736 | rh = qv/data2 |
---|
| 737 | |
---|
| 738 | pa = rh * data1 |
---|
[614] | 739 | td = 257.44*np.log(pa/6.1121)/(18.678-np.log(pa/6.1121)) |
---|
[612] | 740 | |
---|
| 741 | tddims = dimns[:] |
---|
| 742 | tdvdims = dimvns[:] |
---|
| 743 | |
---|
| 744 | return td, tddims, tdvdims |
---|
| 745 | |
---|
[365] | 746 | def turbulence_var(varv, dimvn, dimn): |
---|
| 747 | """ Function to compute the Taylor's decomposition turbulence term from a a given variable |
---|
| 748 | x*=<x^2>_t-(<X>_t)^2 |
---|
| 749 | turbulence_var(varv,dimn) |
---|
| 750 | varv= values of the variable |
---|
| 751 | dimvn= names of the dimension of the variable |
---|
| 752 | dimn= names of the dimensions (as a dictionary with 'X', 'Y', 'Z', 'T') |
---|
| 753 | >>> turbulence_var(np.arange((27)).reshape(3,3,3),['time','y','x'],{'T':'time', 'Y':'y', 'X':'x'}) |
---|
| 754 | [[ 54. 54. 54.] |
---|
| 755 | [ 54. 54. 54.] |
---|
| 756 | [ 54. 54. 54.]] |
---|
| 757 | """ |
---|
| 758 | fname = 'turbulence_varv' |
---|
| 759 | |
---|
| 760 | timedimid = dimvn.index(dimn['T']) |
---|
| 761 | |
---|
| 762 | varv2 = varv*varv |
---|
| 763 | |
---|
| 764 | vartmean = np.mean(varv, axis=timedimid) |
---|
| 765 | var2tmean = np.mean(varv2, axis=timedimid) |
---|
| 766 | |
---|
| 767 | varvturb = var2tmean - (vartmean*vartmean) |
---|
| 768 | |
---|
| 769 | return varvturb |
---|
| 770 | |
---|
| 771 | def compute_turbulence(v, dimns, dimvns): |
---|
| 772 | """ Function to compute the rubulence term of the Taylor's decomposition ...' |
---|
| 773 | x*=<x^2>_t-(<X>_t)^2 |
---|
| 774 | [v]= variable (assuming [[t],z,y,x]) |
---|
| 775 | [dimns]= list of the name of the dimensions of [v] |
---|
| 776 | [dimvns]= list of the name of the variables with the values of the |
---|
| 777 | dimensions of [v] |
---|
| 778 | """ |
---|
| 779 | fname = 'compute_turbulence' |
---|
| 780 | |
---|
| 781 | turbdims = dimns[:] |
---|
| 782 | turbvdims = dimvns[:] |
---|
| 783 | |
---|
| 784 | turbdims.pop(0) |
---|
| 785 | turbvdims.pop(0) |
---|
| 786 | |
---|
| 787 | v2 = v*v |
---|
| 788 | |
---|
| 789 | vartmean = np.mean(v, axis=0) |
---|
| 790 | var2tmean = np.mean(v2, axis=0) |
---|
| 791 | |
---|
| 792 | turb = var2tmean - (vartmean*vartmean) |
---|
| 793 | |
---|
| 794 | return turb, turbdims, turbvdims |
---|
| 795 | |
---|
[612] | 796 | def compute_wds(u, v, dimns, dimvns): |
---|
| 797 | """ Function to compute the wind direction |
---|
| 798 | [u]= W-E wind direction [ms-1, knot, ...] |
---|
| 799 | [v]= N-S wind direction [ms-1, knot, ...] |
---|
| 800 | [dimns]= list of the name of the dimensions of [u] |
---|
| 801 | [dimvns]= list of the name of the variables with the values of the |
---|
| 802 | dimensions of [u] |
---|
| 803 | """ |
---|
| 804 | fname = 'compute_wds' |
---|
| 805 | |
---|
| 806 | # print ' ' + fname + ': computing wind direction as ATAN2(v,u) ...' |
---|
| 807 | theta = np.arctan2(v,u) |
---|
| 808 | theta = np.where(theta < 0., theta + 2.*np.pi, theta) |
---|
| 809 | |
---|
| 810 | wds = 360.*theta/(2.*np.pi) |
---|
| 811 | |
---|
| 812 | wdsdims = dimns[:] |
---|
| 813 | wdsvdims = dimvns[:] |
---|
| 814 | |
---|
| 815 | return wds, wdsdims, wdsvdims |
---|
| 816 | |
---|
| 817 | def compute_wss(u, v, dimns, dimvns): |
---|
| 818 | """ Function to compute the wind speed |
---|
| 819 | [u]= W-E wind direction [ms-1, knot, ...] |
---|
| 820 | [v]= N-S wind direction [ms-1, knot, ...] |
---|
| 821 | [dimns]= list of the name of the dimensions of [u] |
---|
| 822 | [dimvns]= list of the name of the variables with the values of the |
---|
| 823 | dimensions of [u] |
---|
| 824 | """ |
---|
| 825 | fname = 'compute_wss' |
---|
| 826 | |
---|
| 827 | # print ' ' + fname + ': computing wind speed as SQRT(v**2 + u**2) ...' |
---|
| 828 | wss = np.sqrt(u*u + v*v) |
---|
| 829 | |
---|
| 830 | wssdims = dimns[:] |
---|
| 831 | wssvdims = dimvns[:] |
---|
| 832 | |
---|
| 833 | return wss, wssdims, wssvdims |
---|
| 834 | |
---|
[365] | 835 | def timeunits_seconds(dtu): |
---|
| 836 | """ Function to transform a time units to seconds |
---|
| 837 | timeunits_seconds(timeuv) |
---|
| 838 | [dtu]= time units value to transform in seconds |
---|
| 839 | """ |
---|
| 840 | fname='timunits_seconds' |
---|
| 841 | |
---|
| 842 | if dtu == 'years': |
---|
| 843 | times = 365.*24.*3600. |
---|
| 844 | elif dtu == 'weeks': |
---|
| 845 | times = 7.*24.*3600. |
---|
| 846 | elif dtu == 'days': |
---|
| 847 | times = 24.*3600. |
---|
| 848 | elif dtu == 'hours': |
---|
| 849 | times = 3600. |
---|
| 850 | elif dtu == 'minutes': |
---|
| 851 | times = 60. |
---|
| 852 | elif dtu == 'seconds': |
---|
| 853 | times = 1. |
---|
| 854 | elif dtu == 'miliseconds': |
---|
| 855 | times = 1./1000. |
---|
| 856 | else: |
---|
| 857 | print errormsg |
---|
| 858 | print ' ' + fname + ": time units '" + dtu + "' not ready !!" |
---|
| 859 | quit(-1) |
---|
| 860 | |
---|
| 861 | return times |
---|
| 862 | |
---|
| 863 | ####### ###### ##### #### ### ## # |
---|
| 864 | comboinf="\nIF -d 'variable_combo', provides information of the combination to obtain -v [varn] with the ASCII file with the combinations as -f [combofile]" |
---|
| 865 | |
---|
| 866 | parser = OptionParser() |
---|
| 867 | parser.add_option("-f", "--netCDF_file", dest="ncfile", help="file to use", metavar="FILE") |
---|
| 868 | parser.add_option("-d", "--dimensions", dest="dimns", |
---|
[772] | 869 | help="[dimtn]@[dtvn],[dimzn]@[dzvn],[...,[dimxn]@[dxvn]], ',' list with the couples [dimDn]@[dDvn], [dimDn], name of the dimension D and name of the variable [dDvn] with the values of the dimension" + comboinf, |
---|
[365] | 870 | metavar="LABELS") |
---|
| 871 | parser.add_option("-v", "--variables", dest="varns", |
---|
| 872 | help=" [varn1]|[var11]@[...[varN1]],[...,[varnM]|[var1M]@[...[varLM]]] ',' list of variables to compute [varnK] and its necessary ones [var1K]...[varPK]", metavar="VALUES") |
---|
| 873 | |
---|
| 874 | (opts, args) = parser.parse_args() |
---|
| 875 | |
---|
| 876 | ####### ####### |
---|
| 877 | ## MAIN |
---|
| 878 | ####### |
---|
[649] | 879 | availdiags = ['ACRAINTOT', 'accum', 'clt', 'cllmh', 'deaccum', 'LMDZrh', 'mslp', \ |
---|
| 880 | 'OMEGAw', 'RAINTOT', \ |
---|
[959] | 881 | 'rvors', 'td', 'turbulence', 'WRFgeop', 'WRFp', 'WRFrvors', 'ws', 'wds', 'wss', \ |
---|
[914] | 882 | 'WRFheight', 'WRFua', 'WRFva'] |
---|
[365] | 883 | |
---|
[649] | 884 | methods = ['accum', 'deaccum'] |
---|
| 885 | |
---|
[365] | 886 | # Variables not to check |
---|
[612] | 887 | NONcheckingvars = ['cllmh', 'deaccum', 'TSrhs', 'TStd', 'TSwds', 'TSwss', 'WRFbils', \ |
---|
| 888 | 'WRFdens', 'WRFgeop', \ |
---|
| 889 | 'WRFp', 'WRFtd', \ |
---|
[365] | 890 | 'WRFpos', 'WRFprc', 'WRFprls', 'WRFrh', 'LMDZrh', 'LMDZrhs', 'WRFrhs', 'WRFrvors', \ |
---|
[914] | 891 | 'WRFt', 'WRFtime', 'WRFua', 'WRFva', 'WRFwds', 'WRFwss', 'WRFheight'] |
---|
[365] | 892 | |
---|
| 893 | ofile = 'diagnostics.nc' |
---|
| 894 | |
---|
| 895 | dimns = opts.dimns |
---|
| 896 | varns = opts.varns |
---|
| 897 | |
---|
| 898 | # Special method. knowing variable combination |
---|
| 899 | ## |
---|
| 900 | if opts.dimns == 'variable_combo': |
---|
| 901 | print warnmsg |
---|
| 902 | print ' ' + main + ': knowing variable combination !!!' |
---|
| 903 | combination = variable_combo(opts.varns,opts.ncfile) |
---|
| 904 | print ' COMBO: ' + combination |
---|
| 905 | quit(-1) |
---|
| 906 | |
---|
| 907 | if not os.path.isfile(opts.ncfile): |
---|
| 908 | print errormsg |
---|
| 909 | print ' ' + main + ": file '" + opts.ncfile + "' does not exist !!" |
---|
| 910 | quit(-1) |
---|
| 911 | |
---|
| 912 | ncobj = NetCDFFile(opts.ncfile, 'r') |
---|
| 913 | |
---|
| 914 | # File creation |
---|
| 915 | newnc = NetCDFFile(ofile,'w') |
---|
| 916 | |
---|
| 917 | # dimensions |
---|
| 918 | dimvalues = dimns.split(',') |
---|
| 919 | dnames = [] |
---|
| 920 | dvnames = [] |
---|
| 921 | |
---|
| 922 | for dimval in dimvalues: |
---|
| 923 | dnames.append(dimval.split('@')[0]) |
---|
| 924 | dvnames.append(dimval.split('@')[1]) |
---|
| 925 | |
---|
| 926 | # diagnostics to compute |
---|
| 927 | diags = varns.split(',') |
---|
| 928 | Ndiags = len(diags) |
---|
| 929 | |
---|
| 930 | # Looking for specific variables that might be use in more than one diagnostic |
---|
[654] | 931 | WRFgeop_compute = False |
---|
[365] | 932 | WRFp_compute = False |
---|
| 933 | WRFt_compute = False |
---|
| 934 | WRFrh_compute = False |
---|
| 935 | WRFght_compute = False |
---|
| 936 | WRFdens_compute = False |
---|
| 937 | WRFpos_compute = False |
---|
[654] | 938 | WRFtime_compute = False |
---|
[365] | 939 | |
---|
| 940 | for idiag in range(Ndiags): |
---|
| 941 | if diags[idiag].split('|')[1].find('@') == -1: |
---|
| 942 | depvars = diags[idiag].split('|')[1] |
---|
[654] | 943 | if depvars == 'WRFgeop':WRFgeop_compute = True |
---|
[365] | 944 | if depvars == 'WRFp': WRFp_compute = True |
---|
| 945 | if depvars == 'WRFt': WRFt_compute = True |
---|
| 946 | if depvars == 'WRFrh': WRFrh_compute = True |
---|
| 947 | if depvars == 'WRFght': WRFght_compute = True |
---|
| 948 | if depvars == 'WRFdens': WRFdens_compute = True |
---|
| 949 | if depvars == 'WRFpos': WRFpos_compute = True |
---|
[654] | 950 | if depvars == 'WRFtime': WRFtime_compute = True |
---|
[365] | 951 | else: |
---|
| 952 | depvars = diags[idiag].split('|')[1].split('@') |
---|
[756] | 953 | if gen.searchInlist(depvars, 'WRFgeop'): WRFgeop_compute = True |
---|
| 954 | if gen.searchInlist(depvars, 'WRFp'): WRFp_compute = True |
---|
| 955 | if gen.searchInlist(depvars, 'WRFt'): WRFt_compute = True |
---|
| 956 | if gen.searchInlist(depvars, 'WRFrh'): WRFrh_compute = True |
---|
| 957 | if gen.searchInlist(depvars, 'WRFght'): WRFght_compute = True |
---|
| 958 | if gen.searchInlist(depvars, 'WRFdens'): WRFdens_compute = True |
---|
| 959 | if gen.searchInlist(depvars, 'WRFpos'): WRFpos_compute = True |
---|
| 960 | if gen.searchInlist(depvars, 'WRFtime'): WRFtime_compute = True |
---|
[365] | 961 | |
---|
[654] | 962 | if WRFgeop_compute: |
---|
| 963 | print ' ' + main + ': Retrieving geopotential value from WRF as PH + PHB' |
---|
| 964 | dimv = ncobj.variables['PH'].shape |
---|
| 965 | WRFgeop = ncobj.variables['PH'][:] + ncobj.variables['PHB'][:] |
---|
| 966 | |
---|
[365] | 967 | if WRFp_compute: |
---|
| 968 | print ' ' + main + ': Retrieving pressure value from WRF as P + PB' |
---|
| 969 | dimv = ncobj.variables['P'].shape |
---|
| 970 | WRFp = ncobj.variables['P'][:] + ncobj.variables['PB'][:] |
---|
| 971 | |
---|
| 972 | if WRFght_compute: |
---|
| 973 | print ' ' + main + ': computing geopotential height from WRF as PH + PHB ...' |
---|
| 974 | WRFght = ncobj.variables['PH'][:] + ncobj.variables['PHB'][:] |
---|
| 975 | |
---|
| 976 | if WRFrh_compute: |
---|
| 977 | print ' ' + main + ": computing relative humidity from WRF as 'Tetens'" + \ |
---|
| 978 | ' equation (T,P) ...' |
---|
| 979 | p0=100000. |
---|
| 980 | p=ncobj.variables['P'][:] + ncobj.variables['PB'][:] |
---|
| 981 | tk = (ncobj.variables['T'][:] + 300.)*(p/p0)**(2./7.) |
---|
| 982 | qv = ncobj.variables['QVAPOR'][:] |
---|
| 983 | |
---|
| 984 | data1 = 10.*0.6112*np.exp(17.67*(tk-273.16)/(tk-29.65)) |
---|
| 985 | data2 = 0.622*data1/(0.01*p-(1.-0.622)*data1) |
---|
| 986 | |
---|
| 987 | WRFrh = qv/data2 |
---|
| 988 | |
---|
| 989 | if WRFt_compute: |
---|
| 990 | print ' ' + main + ': computing temperature from WRF as inv_potT(T + 300) ...' |
---|
| 991 | p0=100000. |
---|
| 992 | p=ncobj.variables['P'][:] + ncobj.variables['PB'][:] |
---|
| 993 | |
---|
| 994 | WRFt = (ncobj.variables['T'][:] + 300.)*(p/p0)**(2./7.) |
---|
| 995 | |
---|
| 996 | if WRFdens_compute: |
---|
| 997 | print ' ' + main + ': computing air density from WRF as ((MU + MUB) * ' + \ |
---|
| 998 | 'DNW)/g ...' |
---|
| 999 | |
---|
| 1000 | # Just we need in in absolute values: Size of the central grid cell |
---|
| 1001 | ## dxval = ncobj.getncattr('DX') |
---|
| 1002 | ## dyval = ncobj.getncattr('DY') |
---|
| 1003 | ## mapfac = ncobj.variables['MAPFAC_M'][:] |
---|
| 1004 | ## area = dxval*dyval*mapfac |
---|
| 1005 | |
---|
| 1006 | mu = (ncobj.variables['MU'][:] + ncobj.variables['MUB'][:]) |
---|
| 1007 | dnw = ncobj.variables['DNW'][:] |
---|
| 1008 | |
---|
| 1009 | WRFdens = np.zeros((mu.shape[0], dnw.shape[1], mu.shape[1], mu.shape[2]), \ |
---|
| 1010 | dtype=np.float) |
---|
| 1011 | levval = np.zeros((mu.shape[1], mu.shape[2]), dtype=np.float) |
---|
| 1012 | |
---|
| 1013 | for it in range(mu.shape[0]): |
---|
| 1014 | for iz in range(dnw.shape[1]): |
---|
| 1015 | levval.fill(np.abs(dnw[it,iz])) |
---|
| 1016 | WRFdens[it,iz,:,:] = levval |
---|
| 1017 | WRFdens[it,iz,:,:] = mu[it,:,:]*WRFdens[it,iz,:,:]/grav |
---|
| 1018 | |
---|
| 1019 | if WRFpos_compute: |
---|
| 1020 | # WRF positions from the lowest-leftest corner of the matrix |
---|
| 1021 | print ' ' + main + ': computing position from MAPFAC_M as sqrt(DY*j**2 + ' + \ |
---|
| 1022 | 'DX*x**2)*MAPFAC_M ...' |
---|
| 1023 | |
---|
| 1024 | mapfac = ncobj.variables['MAPFAC_M'][:] |
---|
| 1025 | |
---|
| 1026 | distx = np.float(ncobj.getncattr('DX')) |
---|
| 1027 | disty = np.float(ncobj.getncattr('DY')) |
---|
| 1028 | |
---|
| 1029 | print 'distx:',distx,'disty:',disty |
---|
| 1030 | |
---|
| 1031 | dx = mapfac.shape[2] |
---|
| 1032 | dy = mapfac.shape[1] |
---|
| 1033 | dt = mapfac.shape[0] |
---|
| 1034 | |
---|
| 1035 | WRFpos = np.zeros((dt, dy, dx), dtype=np.float) |
---|
| 1036 | |
---|
| 1037 | for i in range(1,dx): |
---|
| 1038 | WRFpos[0,0,i] = distx*i/mapfac[0,0,i] |
---|
| 1039 | for j in range(1,dy): |
---|
| 1040 | i=0 |
---|
| 1041 | WRFpos[0,j,i] = WRFpos[0,j-1,i] + disty/mapfac[0,j,i] |
---|
| 1042 | for i in range(1,dx): |
---|
| 1043 | # WRFpos[0,j,i] = np.sqrt((disty*j)**2. + (distx*i)**2.)/mapfac[0,j,i] |
---|
| 1044 | # WRFpos[0,j,i] = np.sqrt((disty*j)**2. + (distx*i)**2.) |
---|
| 1045 | WRFpos[0,j,i] = WRFpos[0,j,i-1] + distx/mapfac[0,j,i] |
---|
| 1046 | |
---|
| 1047 | for it in range(1,dt): |
---|
| 1048 | WRFpos[it,:,:] = WRFpos[0,:,:] |
---|
| 1049 | |
---|
[654] | 1050 | if WRFtime_compute: |
---|
| 1051 | print ' ' + main + ': computing time from WRF as CFtime(Times) ...' |
---|
| 1052 | |
---|
| 1053 | refdate='19491201000000' |
---|
| 1054 | tunitsval='minutes' |
---|
| 1055 | |
---|
| 1056 | timeobj = ncobj.variables['Times'] |
---|
| 1057 | timewrfv = timeobj[:] |
---|
| 1058 | |
---|
| 1059 | yrref=refdate[0:4] |
---|
| 1060 | monref=refdate[4:6] |
---|
| 1061 | dayref=refdate[6:8] |
---|
| 1062 | horref=refdate[8:10] |
---|
| 1063 | minref=refdate[10:12] |
---|
| 1064 | secref=refdate[12:14] |
---|
| 1065 | |
---|
| 1066 | refdateS = yrref + '-' + monref + '-' + dayref + ' ' + horref + ':' + minref + \ |
---|
| 1067 | ':' + secref |
---|
| 1068 | |
---|
| 1069 | dt = timeobj.shape[0] |
---|
| 1070 | WRFtime = np.zeros((dt), dtype=np.float) |
---|
| 1071 | |
---|
| 1072 | for it in range(dt): |
---|
[865] | 1073 | wrfdates = gen.datetimeStr_conversion(timewrfv[it,:],'WRFdatetime', 'matYmdHMS') |
---|
| 1074 | WRFtime[it] = gen.realdatetime1_CFcompilant(wrfdates, refdate, tunitsval) |
---|
[654] | 1075 | |
---|
| 1076 | tunits = tunitsval + ' since ' + refdateS |
---|
| 1077 | |
---|
[365] | 1078 | ### ## # |
---|
| 1079 | # Going for the diagnostics |
---|
| 1080 | ### ## # |
---|
| 1081 | print ' ' + main + ' ...' |
---|
| 1082 | |
---|
| 1083 | for idiag in range(Ndiags): |
---|
| 1084 | print ' diagnostic:',diags[idiag] |
---|
| 1085 | diag = diags[idiag].split('|')[0] |
---|
| 1086 | depvars = diags[idiag].split('|')[1].split('@') |
---|
| 1087 | if diags[idiag].split('|')[1].find('@') != -1: |
---|
| 1088 | depvars = diags[idiag].split('|')[1].split('@') |
---|
| 1089 | if depvars[0] == 'deaccum': diag='deaccum' |
---|
[649] | 1090 | if depvars[0] == 'accum': diag='accum' |
---|
[365] | 1091 | for depv in depvars: |
---|
| 1092 | if not ncobj.variables.has_key(depv) and not \ |
---|
[756] | 1093 | gen.searchInlist(NONcheckingvars, depv) and \ |
---|
[865] | 1094 | not gen.searchInlist(methods, depv) and not depvars[0] == 'deaccum' \ |
---|
| 1095 | and not depvars[0] == 'accum': |
---|
[365] | 1096 | print errormsg |
---|
| 1097 | print ' ' + main + ": file '" + opts.ncfile + \ |
---|
| 1098 | "' does not have variable '" + depv + "' !!" |
---|
| 1099 | quit(-1) |
---|
| 1100 | else: |
---|
| 1101 | depvars = diags[idiag].split('|')[1] |
---|
| 1102 | if not ncobj.variables.has_key(depvars) and not \ |
---|
[756] | 1103 | gen.searchInlist(NONcheckingvars, depvars) and \ |
---|
| 1104 | not gen.searchInlist(methods, depvars): |
---|
| 1105 | print errormsg |
---|
[365] | 1106 | print ' ' + main + ": file '" + opts.ncfile + \ |
---|
| 1107 | "' does not have variable '" + depvars + "' !!" |
---|
| 1108 | quit(-1) |
---|
| 1109 | |
---|
| 1110 | print "\n Computing '" + diag + "' from: ", depvars, '...' |
---|
| 1111 | |
---|
| 1112 | # acraintot: accumulated total precipitation from WRF RAINC, RAINNC |
---|
| 1113 | if diag == 'ACRAINTOT': |
---|
| 1114 | |
---|
| 1115 | var0 = ncobj.variables[depvars[0]] |
---|
| 1116 | var1 = ncobj.variables[depvars[1]] |
---|
| 1117 | diagout = var0[:] + var1[:] |
---|
| 1118 | |
---|
| 1119 | dnamesvar = var0.dimensions |
---|
| 1120 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1121 | |
---|
[649] | 1122 | ncvar.insert_variable(ncobj, 'pracc', diagout, dnamesvar, dvnamesvar, newnc) |
---|
[365] | 1123 | |
---|
[649] | 1124 | # accum: acumulation of any variable as (Variable, time [as [tunits] |
---|
| 1125 | # from/since ....], newvarname) |
---|
| 1126 | elif diag == 'accum': |
---|
| 1127 | |
---|
| 1128 | var0 = ncobj.variables[depvars[0]] |
---|
| 1129 | var1 = ncobj.variables[depvars[1]] |
---|
| 1130 | |
---|
| 1131 | dnamesvar = var0.dimensions |
---|
| 1132 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1133 | |
---|
| 1134 | diagout, diagoutd, diagoutvd = compute_accum(var0,dnamesvar,dvnamesvar) |
---|
| 1135 | |
---|
| 1136 | CFvarn = ncvar.variables_values(depvars[0])[0] |
---|
| 1137 | |
---|
| 1138 | # Removing the flux |
---|
| 1139 | if depvars[1] == 'XTIME': |
---|
| 1140 | dtimeunits = var1.getncattr('description') |
---|
| 1141 | tunits = dtimeunits.split(' ')[0] |
---|
| 1142 | else: |
---|
| 1143 | dtimeunits = var1.getncattr('units') |
---|
| 1144 | tunits = dtimeunits.split(' ')[0] |
---|
| 1145 | |
---|
| 1146 | dtime = (var1[1] - var1[0])*timeunits_seconds(tunits) |
---|
| 1147 | |
---|
| 1148 | ncvar.insert_variable(ncobj, CFvarn + 'acc', diagout*dtime, diagoutd, diagoutvd, newnc) |
---|
| 1149 | |
---|
[365] | 1150 | # cllmh with cldfra, pres |
---|
| 1151 | elif diag == 'cllmh': |
---|
| 1152 | |
---|
| 1153 | var0 = ncobj.variables[depvars[0]] |
---|
| 1154 | if depvars[1] == 'WRFp': |
---|
| 1155 | var1 = WRFp |
---|
| 1156 | else: |
---|
| 1157 | var01 = ncobj.variables[depvars[1]] |
---|
| 1158 | if len(size(var1.shape)) < len(size(var0.shape)): |
---|
| 1159 | var1 = np.brodcast_arrays(var01,var0)[0] |
---|
| 1160 | else: |
---|
| 1161 | var1 = var01 |
---|
| 1162 | |
---|
[772] | 1163 | diagout, diagoutd, diagoutvd = Forcompute_cllmh(var0,var1,dnames,dvnames) |
---|
| 1164 | |
---|
[365] | 1165 | ncvar.insert_variable(ncobj, 'cll', diagout[0,:], diagoutd, diagoutvd, newnc) |
---|
| 1166 | ncvar.insert_variable(ncobj, 'clm', diagout[1,:], diagoutd, diagoutvd, newnc) |
---|
| 1167 | ncvar.insert_variable(ncobj, 'clh', diagout[2,:], diagoutd, diagoutvd, newnc) |
---|
| 1168 | |
---|
| 1169 | # clt with cldfra |
---|
| 1170 | elif diag == 'clt': |
---|
| 1171 | |
---|
| 1172 | var0 = ncobj.variables[depvars] |
---|
[772] | 1173 | diagout, diagoutd, diagoutvd = Forcompute_clt(var0,dnames,dvnames) |
---|
[365] | 1174 | ncvar.insert_variable(ncobj, 'clt', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1175 | |
---|
| 1176 | # deaccum: deacumulation of any variable as (Variable, time [as [tunits] |
---|
| 1177 | # from/since ....], newvarname) |
---|
| 1178 | elif diag == 'deaccum': |
---|
| 1179 | |
---|
| 1180 | var0 = ncobj.variables[depvars[1]] |
---|
| 1181 | var1 = ncobj.variables[depvars[2]] |
---|
| 1182 | |
---|
| 1183 | dnamesvar = var0.dimensions |
---|
| 1184 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1185 | |
---|
| 1186 | diagout, diagoutd, diagoutvd = compute_deaccum(var0,dnamesvar,dvnamesvar) |
---|
| 1187 | |
---|
| 1188 | # Transforming to a flux |
---|
| 1189 | if depvars[2] == 'XTIME': |
---|
| 1190 | dtimeunits = var1.getncattr('description') |
---|
| 1191 | tunits = dtimeunits.split(' ')[0] |
---|
| 1192 | else: |
---|
| 1193 | dtimeunits = var1.getncattr('units') |
---|
| 1194 | tunits = dtimeunits.split(' ')[0] |
---|
| 1195 | |
---|
| 1196 | dtime = (var1[1] - var1[0])*timeunits_seconds(tunits) |
---|
| 1197 | ncvar.insert_variable(ncobj, depvars[3], diagout/dtime, diagoutd, diagoutvd, newnc) |
---|
| 1198 | |
---|
| 1199 | # LMDZrh (pres, t, r) |
---|
| 1200 | elif diag == 'LMDZrh': |
---|
| 1201 | |
---|
| 1202 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1203 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1204 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1205 | |
---|
| 1206 | diagout, diagoutd, diagoutvd = compute_rh(var0,var1,var2,dnames,dvnames) |
---|
[1079] | 1207 | ncvar.insert_variable(ncobj, 'hur', diagout, diagoutd, diagoutvd, newnc) |
---|
[365] | 1208 | |
---|
| 1209 | # LMDZrhs (psol, t2m, q2m) |
---|
| 1210 | elif diag == 'LMDZrhs': |
---|
| 1211 | |
---|
| 1212 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1213 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1214 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1215 | |
---|
| 1216 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1217 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1218 | |
---|
| 1219 | diagout, diagoutd, diagoutvd = compute_rh(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
| 1220 | |
---|
[1079] | 1221 | ncvar.insert_variable(ncobj, 'hurs', diagout, diagoutd, diagoutvd, newnc) |
---|
[365] | 1222 | |
---|
| 1223 | # mslp: mean sea level pressure (pres, psfc, terrain, temp, qv) |
---|
| 1224 | elif diag == 'mslp' or diag == 'WRFmslp': |
---|
| 1225 | |
---|
| 1226 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1227 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1228 | var4 = ncobj.variables[depvars[4]][:] |
---|
| 1229 | |
---|
| 1230 | if diag == 'WRFmslp': |
---|
| 1231 | var0 = WRFp |
---|
| 1232 | var3 = WRFt |
---|
| 1233 | dnamesvar = ncobj.variables['P'].dimensions |
---|
| 1234 | else: |
---|
| 1235 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1236 | var3 = ncobj.variables[depvars[3]][:] |
---|
| 1237 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1238 | |
---|
| 1239 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1240 | |
---|
| 1241 | diagout, diagoutd, diagoutvd = compute_mslp(var0, var1, var2, var3, var4, \ |
---|
| 1242 | dnamesvar, dvnamesvar) |
---|
| 1243 | |
---|
| 1244 | ncvar.insert_variable(ncobj, 'psl', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1245 | |
---|
[642] | 1246 | # OMEGAw (omega, p, t) from NCL formulation (https://www.ncl.ucar.edu/Document/Functions/Contributed/omega_to_w.shtml) |
---|
| 1247 | elif diag == 'OMEGAw': |
---|
| 1248 | |
---|
| 1249 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1250 | var1 = ncobj.variables[depvars[1]][:] |
---|
[643] | 1251 | var2 = ncobj.variables[depvars[2]][:] |
---|
[642] | 1252 | |
---|
| 1253 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1254 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1255 | |
---|
| 1256 | diagout, diagoutd, diagoutvd = compute_OMEGAw(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
| 1257 | |
---|
| 1258 | ncvar.insert_variable(ncobj, 'wa', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1259 | |
---|
[365] | 1260 | # raintot: instantaneous total precipitation from WRF as (RAINC + RAINC) / dTime |
---|
| 1261 | elif diag == 'RAINTOT': |
---|
| 1262 | |
---|
| 1263 | var0 = ncobj.variables[depvars[0]] |
---|
| 1264 | var1 = ncobj.variables[depvars[1]] |
---|
[445] | 1265 | if depvars[2] != 'WRFtime': |
---|
[443] | 1266 | var2 = ncobj.variables[depvars[2]] |
---|
[654] | 1267 | else: |
---|
| 1268 | var2 = np.arange(var0.shape[0], dtype=int) |
---|
[365] | 1269 | |
---|
| 1270 | var = var0[:] + var1[:] |
---|
| 1271 | |
---|
| 1272 | dnamesvar = var0.dimensions |
---|
| 1273 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1274 | |
---|
| 1275 | diagout, diagoutd, diagoutvd = compute_deaccum(var,dnamesvar,dvnamesvar) |
---|
| 1276 | |
---|
| 1277 | # Transforming to a flux |
---|
[654] | 1278 | if var2.shape[0] > 1: |
---|
[600] | 1279 | if depvars[2] != 'WRFtime': |
---|
| 1280 | dtimeunits = var2.getncattr('units') |
---|
| 1281 | tunits = dtimeunits.split(' ')[0] |
---|
| 1282 | |
---|
| 1283 | dtime = (var2[1] - var2[0])*timeunits_seconds(tunits) |
---|
| 1284 | else: |
---|
| 1285 | var2 = ncobj.variables['Times'] |
---|
| 1286 | time1 = var2[0,:] |
---|
| 1287 | time2 = var2[1,:] |
---|
| 1288 | tmf1 = '' |
---|
| 1289 | tmf2 = '' |
---|
| 1290 | for ic in range(len(time1)): |
---|
| 1291 | tmf1 = tmf1 + time1[ic] |
---|
| 1292 | tmf2 = tmf2 + time2[ic] |
---|
[654] | 1293 | dtdate1 = dtime.datetime.strptime(tmf1,"%Y-%m-%d_%H:%M:%S") |
---|
| 1294 | dtdate2 = dtime.datetime.strptime(tmf2,"%Y-%m-%d_%H:%M:%S") |
---|
[600] | 1295 | diffdate12 = dtdate2 - dtdate1 |
---|
| 1296 | dtime = diffdate12.total_seconds() |
---|
| 1297 | print 'dtime:',dtime |
---|
[442] | 1298 | else: |
---|
[600] | 1299 | print warnmsg |
---|
| 1300 | print ' ' + fname + ": only 1 time-step for '" + diag + "' !!" |
---|
| 1301 | print ' leaving a zero value!' |
---|
| 1302 | diagout = var0*0. |
---|
| 1303 | dtime=1. |
---|
[442] | 1304 | |
---|
[365] | 1305 | ncvar.insert_variable(ncobj, 'pr', diagout/dtime, diagoutd, diagoutvd, newnc) |
---|
| 1306 | |
---|
[612] | 1307 | # rhs (psfc, t, q) from TimeSeries files |
---|
| 1308 | elif diag == 'TSrhs': |
---|
| 1309 | |
---|
| 1310 | p0=100000. |
---|
| 1311 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1312 | var1 = (ncobj.variables[depvars[1]][:])*(var0/p0)**(2./7.) |
---|
| 1313 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1314 | |
---|
| 1315 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1316 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1317 | |
---|
| 1318 | diagout, diagoutd, diagoutvd = compute_rh(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
| 1319 | |
---|
[1079] | 1320 | ncvar.insert_variable(ncobj, 'hurs', diagout, diagoutd, diagoutvd, newnc) |
---|
[612] | 1321 | |
---|
| 1322 | # td (psfc, t, q) from TimeSeries files |
---|
[613] | 1323 | elif diag == 'TStd' or diag == 'td': |
---|
[612] | 1324 | |
---|
| 1325 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1326 | var1 = ncobj.variables[depvars[1]][:] - 273.15 |
---|
| 1327 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1328 | |
---|
| 1329 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1330 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1331 | |
---|
| 1332 | diagout, diagoutd, diagoutvd = compute_td(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
| 1333 | |
---|
| 1334 | ncvar.insert_variable(ncobj, 'tds', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1335 | |
---|
| 1336 | # td (psfc, t, q) from TimeSeries files |
---|
[616] | 1337 | elif diag == 'TStdC' or diag == 'tdC': |
---|
[612] | 1338 | |
---|
| 1339 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1340 | # Temperature is already in degrees Celsius |
---|
| 1341 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1342 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1343 | |
---|
| 1344 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1345 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1346 | |
---|
| 1347 | diagout, diagoutd, diagoutvd = compute_td(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
| 1348 | |
---|
| 1349 | ncvar.insert_variable(ncobj, 'tds', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1350 | |
---|
| 1351 | # wds (u, v) |
---|
| 1352 | elif diag == 'TSwds' or diag == 'wds' : |
---|
| 1353 | |
---|
| 1354 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1355 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1356 | |
---|
| 1357 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1358 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1359 | |
---|
| 1360 | diagout, diagoutd, diagoutvd = compute_wds(var0,var1,dnamesvar,dvnamesvar) |
---|
| 1361 | |
---|
| 1362 | ncvar.insert_variable(ncobj, 'wds', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1363 | |
---|
| 1364 | # wss (u, v) |
---|
[613] | 1365 | elif diag == 'TSwss' or diag == 'wss': |
---|
[612] | 1366 | |
---|
| 1367 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1368 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1369 | |
---|
| 1370 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1371 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1372 | |
---|
| 1373 | diagout, diagoutd, diagoutvd = compute_wss(var0,var1,dnamesvar,dvnamesvar) |
---|
| 1374 | |
---|
| 1375 | ncvar.insert_variable(ncobj, 'wss', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1376 | |
---|
[365] | 1377 | # turbulence (var) |
---|
| 1378 | elif diag == 'turbulence': |
---|
| 1379 | |
---|
| 1380 | var0 = ncobj.variables[depvars][:] |
---|
| 1381 | |
---|
| 1382 | dnamesvar = list(ncobj.variables[depvars].dimensions) |
---|
| 1383 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1384 | |
---|
| 1385 | diagout, diagoutd, diagoutvd = compute_turbulence(var0,dnamesvar,dvnamesvar) |
---|
[959] | 1386 | valsvar = gen.variables_values(depvars) |
---|
[365] | 1387 | |
---|
[959] | 1388 | newvarn = depvars + 'turb' |
---|
| 1389 | print main + '; Lluis newvarn:', newvarn |
---|
| 1390 | ncvar.insert_variable(ncobj, newvarn, diagout, diagoutd, |
---|
[365] | 1391 | diagoutvd, newnc) |
---|
[959] | 1392 | print main + '; Lluis variables:', newnc.variables.keys() |
---|
| 1393 | varobj = newnc.variables[newvarn] |
---|
[365] | 1394 | attrv = varobj.long_name |
---|
| 1395 | attr = varobj.delncattr('long_name') |
---|
| 1396 | newattr = ncvar.set_attribute(varobj, 'long_name', attrv + \ |
---|
| 1397 | " Taylor decomposition turbulence term") |
---|
| 1398 | |
---|
[390] | 1399 | # WRFbils fom WRF as HFX + LH |
---|
| 1400 | elif diag == 'WRFbils': |
---|
| 1401 | |
---|
| 1402 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1403 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1404 | |
---|
| 1405 | diagout = var0 + var1 |
---|
[867] | 1406 | dnamesvar = list(ncobj.variables[depvars[0]].dimensions) |
---|
| 1407 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
[390] | 1408 | |
---|
[867] | 1409 | ncvar.insert_variable(ncobj, 'bils', diagout, dnamesvar, dvnamesvar, newnc) |
---|
[390] | 1410 | |
---|
[654] | 1411 | # WRFgeop geopotential from WRF as PH + PHB |
---|
| 1412 | elif diag == 'WRFgeop': |
---|
| 1413 | |
---|
| 1414 | diagout = WRFgeop |
---|
| 1415 | |
---|
| 1416 | ncvar.insert_variable(ncobj, 'zg', diagout, dnames, dvnames, newnc) |
---|
| 1417 | |
---|
[390] | 1418 | # WRFp pressure from WRF as P + PB |
---|
[365] | 1419 | elif diag == 'WRFp': |
---|
| 1420 | |
---|
| 1421 | diagout = WRFp |
---|
| 1422 | |
---|
| 1423 | ncvar.insert_variable(ncobj, 'pres', diagout, dnames, dvnames, newnc) |
---|
| 1424 | |
---|
| 1425 | # WRFpos |
---|
| 1426 | elif diag == 'WRFpos': |
---|
| 1427 | |
---|
| 1428 | dnamesvar = ncobj.variables['MAPFAC_M'].dimensions |
---|
| 1429 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1430 | |
---|
| 1431 | ncvar.insert_variable(ncobj, 'WRFpos', WRFpos, dnamesvar, dvnamesvar, newnc) |
---|
| 1432 | |
---|
| 1433 | # WRFprw WRF water vapour path WRFdens, QVAPOR |
---|
| 1434 | elif diag == 'WRFprw': |
---|
| 1435 | |
---|
| 1436 | var0 = WRFdens |
---|
| 1437 | var1 = ncobj.variables[depvars[1]] |
---|
| 1438 | |
---|
| 1439 | dnamesvar = list(var1.dimensions) |
---|
| 1440 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1441 | |
---|
| 1442 | diagout, diagoutd, diagoutvd = compute_prw(var0, var1, dnamesvar,dvnamesvar) |
---|
| 1443 | |
---|
| 1444 | ncvar.insert_variable(ncobj, 'prw', diagout, diagoutd, diagoutvd, newnc) |
---|
| 1445 | |
---|
| 1446 | # WRFrh (P, T, QVAPOR) |
---|
| 1447 | elif diag == 'WRFrh': |
---|
| 1448 | |
---|
| 1449 | dnamesvar = list(ncobj.variables[depvars[2]].dimensions) |
---|
| 1450 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1451 | |
---|
[878] | 1452 | ncvar.insert_variable(ncobj, 'hur', WRFrh, dnames, dvnames, newnc) |
---|
[365] | 1453 | |
---|
| 1454 | # WRFrhs (PSFC, T2, Q2) |
---|
| 1455 | elif diag == 'WRFrhs': |
---|
| 1456 | |
---|
| 1457 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1458 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1459 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1460 | |
---|
| 1461 | dnamesvar = list(ncobj.variables[depvars[2]].dimensions) |
---|
| 1462 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1463 | |
---|
| 1464 | diagout, diagoutd, diagoutvd = compute_rh(var0,var1,var2,dnamesvar,dvnamesvar) |
---|
[878] | 1465 | ncvar.insert_variable(ncobj, 'hurs', diagout, diagoutd, diagoutvd, newnc) |
---|
[365] | 1466 | |
---|
| 1467 | # rvors (u10, v10, WRFpos) |
---|
| 1468 | elif diag == 'WRFrvors': |
---|
| 1469 | |
---|
| 1470 | var0 = ncobj.variables[depvars[0]] |
---|
| 1471 | var1 = ncobj.variables[depvars[1]] |
---|
| 1472 | |
---|
| 1473 | diagout = rotational_z(var0, var1, distx) |
---|
| 1474 | |
---|
| 1475 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1476 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1477 | |
---|
| 1478 | ncvar.insert_variable(ncobj, 'rvors', diagout, dnamesvar, dvnamesvar, newnc) |
---|
| 1479 | |
---|
[884] | 1480 | # WRFt (T, P, PB) |
---|
| 1481 | elif diag == 'WRFt': |
---|
| 1482 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1483 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1484 | var2 = ncobj.variables[depvars[2]][:] |
---|
[654] | 1485 | |
---|
[884] | 1486 | p0=100000. |
---|
| 1487 | p=var1 + var2 |
---|
| 1488 | |
---|
| 1489 | WRFt = (var0 + 300.)*(p/p0)**(2./7.) |
---|
| 1490 | |
---|
| 1491 | dnamesvar = list(ncobj.variables[depvars[0]].dimensions) |
---|
| 1492 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1493 | |
---|
| 1494 | ncvar.insert_variable(ncobj, 'ta', WRFt, dnames, dvnames, newnc) |
---|
| 1495 | |
---|
[914] | 1496 | # WRFua (U, V, SINALPHA, COSALPHA) to be rotated !! |
---|
| 1497 | elif diag == 'WRFua': |
---|
| 1498 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1499 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1500 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1501 | var3 = ncobj.variables[depvars[3]][:] |
---|
| 1502 | |
---|
| 1503 | # un-staggering variables |
---|
| 1504 | unstgdims = [var0.shape[0], var0.shape[1], var0.shape[2], var0.shape[3]-1] |
---|
| 1505 | ua = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1506 | unstgvar0 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1507 | unstgvar1 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1508 | unstgvar0 = 0.5*(var0[:,:,:,0:var0.shape[3]-1] + var0[:,:,:,1:var0.shape[3]]) |
---|
| 1509 | unstgvar1 = 0.5*(var1[:,:,0:var1.shape[2]-1,:] + var1[:,:,1:var1.shape[2],:]) |
---|
| 1510 | |
---|
| 1511 | for iz in range(var0.shape[1]): |
---|
| 1512 | ua[:,iz,:,:] = unstgvar0[:,iz,:,:]*var3 - unstgvar1[:,iz,:,:]*var2 |
---|
| 1513 | |
---|
[959] | 1514 | # dnamesvar = list(ncobj.variables[depvars[0]].dimensions) |
---|
| 1515 | dnamesvar = ['Time','bottom_top','south_north','west_east'] |
---|
[914] | 1516 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1517 | |
---|
| 1518 | ncvar.insert_variable(ncobj, 'ua', ua, dnames, dvnames, newnc) |
---|
| 1519 | |
---|
| 1520 | # WRFua (U, V, SINALPHA, COSALPHA) to be rotated !! |
---|
| 1521 | elif diag == 'WRFva': |
---|
| 1522 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1523 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1524 | var2 = ncobj.variables[depvars[2]][:] |
---|
| 1525 | var3 = ncobj.variables[depvars[3]][:] |
---|
| 1526 | |
---|
| 1527 | # un-staggering variables |
---|
| 1528 | unstgdims = [var0.shape[0], var0.shape[1], var0.shape[2], var0.shape[3]-1] |
---|
| 1529 | va = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1530 | unstgvar0 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1531 | unstgvar1 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1532 | unstgvar0 = 0.5*(var0[:,:,:,0:var0.shape[3]-1] + var0[:,:,:,1:var0.shape[3]]) |
---|
| 1533 | unstgvar1 = 0.5*(var1[:,:,0:var1.shape[2]-1,:] + var1[:,:,1:var1.shape[2],:]) |
---|
| 1534 | for iz in range(var0.shape[1]): |
---|
| 1535 | va[:,iz,:,:] = unstgvar0[:,iz,:,:]*var2 + unstgvar1[:,iz,:,:]*var3 |
---|
| 1536 | |
---|
[959] | 1537 | dnamesvar = ['Time','bottom_top','south_north','west_east'] |
---|
[914] | 1538 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1539 | |
---|
| 1540 | ncvar.insert_variable(ncobj, 'va', va, dnames, dvnames, newnc) |
---|
| 1541 | |
---|
| 1542 | # WRFtime |
---|
[654] | 1543 | elif diag == 'WRFtime': |
---|
| 1544 | |
---|
| 1545 | diagout = WRFtime |
---|
| 1546 | |
---|
| 1547 | dnamesvar = ['Time'] |
---|
| 1548 | dvnamesvar = ['Times'] |
---|
| 1549 | |
---|
| 1550 | ncvar.insert_variable(ncobj, 'time', diagout, dnamesvar, dvnamesvar, newnc) |
---|
| 1551 | |
---|
[959] | 1552 | # ws (U, V) |
---|
| 1553 | elif diag == 'ws': |
---|
| 1554 | |
---|
| 1555 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1556 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1557 | # un-staggering variables |
---|
| 1558 | unstgdims = [var0.shape[0], var0.shape[1], var0.shape[2], var0.shape[3]-1] |
---|
| 1559 | va = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1560 | unstgvar0 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1561 | unstgvar1 = np.zeros(tuple(unstgdims), dtype=np.float) |
---|
| 1562 | unstgvar0 = 0.5*(var0[:,:,:,0:var0.shape[3]-1] + var0[:,:,:,1:var0.shape[3]]) |
---|
| 1563 | unstgvar1 = 0.5*(var1[:,:,0:var1.shape[2]-1,:] + var1[:,:,1:var1.shape[2],:]) |
---|
| 1564 | |
---|
| 1565 | dnamesvar = ['Time','bottom_top','south_north','west_east'] |
---|
| 1566 | diagout = np.sqrt(unstgvar0*unstgvar0 + unstgvar1*unstgvar1) |
---|
| 1567 | |
---|
| 1568 | # dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1569 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1570 | |
---|
| 1571 | ncvar.insert_variable(ncobj, 'ws', diagout, dnamesvar, dvnamesvar, newnc) |
---|
| 1572 | |
---|
[365] | 1573 | # wss (u10, v10) |
---|
| 1574 | elif diag == 'wss': |
---|
| 1575 | |
---|
| 1576 | var0 = ncobj.variables[depvars[0]][:] |
---|
| 1577 | var1 = ncobj.variables[depvars[1]][:] |
---|
| 1578 | |
---|
| 1579 | diagout = np.sqrt(var0*var0 + var1*var1) |
---|
| 1580 | |
---|
| 1581 | dnamesvar = ncobj.variables[depvars[0]].dimensions |
---|
| 1582 | dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames) |
---|
| 1583 | |
---|
| 1584 | ncvar.insert_variable(ncobj, 'wss', diagout, dnamesvar, dvnamesvar, newnc) |
---|
| 1585 | |
---|
[654] | 1586 | # WRFheight height from WRF geopotential as WRFGeop/g |
---|
| 1587 | elif diag == 'WRFheight': |
---|
| 1588 | |
---|
| 1589 | diagout = WRFgeop/grav |
---|
| 1590 | |
---|
| 1591 | ncvar.insert_variable(ncobj, 'zhgt', diagout, dnames, dvnames, newnc) |
---|
| 1592 | |
---|
[365] | 1593 | else: |
---|
| 1594 | print errormsg |
---|
| 1595 | print ' ' + main + ": diagnostic '" + diag + "' not ready!!!" |
---|
| 1596 | print ' available diagnostics: ', availdiags |
---|
| 1597 | quit(-1) |
---|
| 1598 | |
---|
| 1599 | newnc.sync() |
---|
| 1600 | |
---|
| 1601 | # end of diagnostics |
---|
| 1602 | |
---|
| 1603 | # Global attributes |
---|
| 1604 | ## |
---|
| 1605 | atvar = ncvar.set_attribute(newnc, 'program', 'diagnostics.py') |
---|
| 1606 | atvar = ncvar.set_attribute(newnc, 'version', '1.0') |
---|
| 1607 | atvar = ncvar.set_attribute(newnc, 'author', 'Fita Borrell, Lluis') |
---|
| 1608 | atvar = ncvar.set_attribute(newnc, 'institution', 'Laboratoire Meteorologie ' + \ |
---|
| 1609 | 'Dynamique') |
---|
| 1610 | atvar = ncvar.set_attribute(newnc, 'university', 'Universite Pierre et Marie ' + \ |
---|
| 1611 | 'Curie -- Jussieu') |
---|
| 1612 | atvar = ncvar.set_attribute(newnc, 'centre', 'Centre national de la recherche ' + \ |
---|
| 1613 | 'scientifique') |
---|
| 1614 | atvar = ncvar.set_attribute(newnc, 'city', 'Paris') |
---|
| 1615 | atvar = ncvar.set_attribute(newnc, 'original_file', opts.ncfile) |
---|
| 1616 | |
---|
| 1617 | gorigattrs = ncobj.ncattrs() |
---|
| 1618 | |
---|
| 1619 | for attr in gorigattrs: |
---|
| 1620 | attrv = ncobj.getncattr(attr) |
---|
| 1621 | atvar = ncvar.set_attribute(newnc, attr, attrv) |
---|
| 1622 | |
---|
| 1623 | ncobj.close() |
---|
| 1624 | newnc.close() |
---|
| 1625 | |
---|
| 1626 | print '\n' + main + ': successfull writting of diagnostics file "' + ofile + '" !!!' |
---|