Changeset 1535 in lmdz_wrf
- Timestamp:
- Apr 21, 2017, 9:14:10 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/documentation/ncmanage/compute_opersvarsfiles.html
r1519 r1535 30 30 'add': adding [var] ([prevalues] + [var])<BR> 31 31 'addc',[modval1]: add [modval1] to [prevalues]<BR> 32 'arctan', arctangent [-p1, pi]<BR> 32 33 'centerderiv',[N],[ord],[dim]: un-scaled center [N]-derivative of order [ord] along dimension [dim] of [var]<BR> 33 34 'div': dividing by [var] ([prevalues] / [var])<BR> … … 39 40 'mul': multiplying by [var] ([prevvalues] * [var])<BR> 40 41 'mulc',[modval1]: [prevalues] multiplied by [modval1]<BR> 42 'norm_meanminmax',[NOTnormdims]: normalization of data as: (val-<val>)/(max(val)-min(val)) except along <BR> 43 dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions)<BR> 44 'norm_minmax',[NOTnormdims]: normalization of data as: [2val-(max(val)-min(val)]/[max(val)+min(val)]<BR> 45 except along dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions)<BR> 46 'norm_meanstd',[NOTnormdims]: normalization of data as: (val-<val>)/stdev(val) except along <BR> 47 dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions)<BR> 48 dimensions [NOTnormdims] (':' list of dimension names)<BR> 41 49 'pot': powering with [var] ([prevalues] ** [var])<BR> 42 50 'potc',[modval1]: [prevalues] ** [modval1]<BR> … … 60 68 </DIV> 61 69 <DIV CLASS="valins"> 62 $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@add|wrfout_d01_2001-11-11_00:00:00|T2%west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@subc,273.15|wrfout_d01_2001-11-11_00:00:00|None' -v 'tempC,air!temperature,C'<BR> 63 $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'lon|lon|-1;lat|lat|-1;time_counter|time_counter|-1@forwrdderiv,1,1,2|/ccc/store/cont003/gen7593/fitaborl/etudes/DynamicoESM/aquaplanet/AR40/19800101000000-19810101000000/histday.nc|t2m' -v 'tasderiv,x-derivative|of|air|temperature,K 70 * Transforming temperature from Kelvin to °C<BR> 71 $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@subc,273.15|wrfout_d01_2001-11-11_00:00:00|T2' -v 'tempC,air!temperature,C'<BR> 72 * Computing the x-derivative of first order<BR> 73 $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'lon|lon|-1;lat|lat|-1;time_counter|time_counter|-1@forwrdderiv,1,1,2|histday.nc|t2m' -v 'tasderiv,x-derivative|of|air|temperature,K' <BR> 74 * Normalizing a variable by substracting its mean and weighting by its standard-deviation<BR> 75 $ python ${pyHOME}/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@norm_meanstd,Time|wrfout_d01_1995-01-01_00:00:00|T2' -v 'tasnorm,normalized!2m!temperature!substracting!mean!and!weighting!by!standard!deviation,K' <BR> 76 * Getting height of the frist level from surface from a WRF file<BR> 77 $ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@addc,0|wrfout_d01_1995-01-01_00:00:00|PH%west_east|XLONG|-1;south_north|XLAT|-1;bottom_top_stag|ZNW|1@add|wrfout_d01_1995-01-01_00:00:00|PHB%contoperation@divc,9.81%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@sub|wrfout_d01_1995-01-01_00:00:00|HGT' -v 'height1lev,height!above!surface!of!first!level,m' 78 * Computing wind-direction from a WRF file<BR> 79 $ python $pyHOME/nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@addc,0|wrfout_d01_1995-01-01_00:00:00|V10%west_east|XLONG|-1;south_north|XLAT|-1;Time|WRFtime|-1@arctan|wrfout_d01_1995-01-01_00:00:00|U10%contoperation@mulc,57.2957795131' -v 'wsdir,2m!wind!direction,Degrees' 64 80 </DIV> 65 81 </BODY> -
trunk/tools/generic_tools.py
r1520 r1535 10155 10155 'add': adding matB to matA (matA + matB) 10156 10156 'addc',[modval1]: add [modval1] 10157 'arctan', arctangent of matA (result [-pi, pi]) 10157 10158 'centerderiv',[N],[ord],[dim]: un-scaled center [N]-derivative of order [ord] along dimension [dim] of matA 10158 10159 'div': dividing by matB (matA / matB) … … 10164 10165 'mul': multiplying ny matB (matA * matB) 10165 10166 'mulc',[modval1]: multiply by [modval1] 10167 'norm_meanminmax',[dimns],[normdimns],[idims]: normalization of data of dimensions [dimns] (':' list) as: 10168 (val - <val>)/(max(val)-min(val)) along dimension-names [normdimns] (':' list of names) and 10169 dimension-indices [idims] (':' list of indices) of matA 10170 'norm_minmax',[NOTnormdims]: normalization of data as: [2val-(max(val)-min(val)]/[max(val)+min(val)] 10171 except along dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions) 10172 'norm_meanstd',[dimns],[normdimns],[idims]: normalization of data of dimensions [dimns] (':' list) as: 10173 (val - <val>)/stdev(val) along dimension-names [normdimns] (':' list of names) and dimension-indices 10174 [idims] (':' list of indices) of matA 10166 10175 'pot': powering with matB (matA ** matB) 10167 10176 'potc',[modval1]: [val] ** [modval1] … … 10294 10303 10295 10304 # Dictionary with the description of the operations 10296 Lopn = {'add': '+', 'addc': '+', 'div': '/', 'divc': '/', 'inv': '^(-1)', \ 10297 'lowthres': '<', 'mul': '*', 'mulc': '*', 'pot': '^', 'potc': '^', \ 10298 'repl': 'repl_excpt', 'replbig': 'repl_excpt_bigger', \ 10305 Lopn = {'add': '+', 'addc': '+', 'arctan': 'arctangent', 'div': '/', 'divc': '/',\ 10306 'inv': '^(-1)', 'lowthres': '<', 'mul': '*', 'mulc': '*', \ 10307 'norm_meanminmax': 'Norm_mean_minmax', \ 10308 'norm_minmax': 'Norm_minmax', 'norm_meanstd': 'Norm_mean_devstd', 'pot': '^', \ 10309 'potc': '^', 'repl': 'repl_excpt', 'replbig': 'repl_excpt_bigger', \ 10299 10310 'repless': 'repl_excpt_less', 'sub': '-', 'subc': '-', 'upthres': '<'} 10300 10311 # Operations by constant value … … 10304 10315 10305 10316 # Available operations 10306 opavail = ['add', 'addc', 'centerderiv', 'div', 'divc', 'forwrdderiv', 'inv', \ 10307 'lowthres', 'lowthres@oper', 'mul', 'mulc', 'pot', 'potc', 'repl', 'replbig', \ 10308 'repless', 'sub', 'subc', 'upthres', 'upthres@oper'] 10317 opavail = ['add', 'addc', 'arctan', 'centerderiv', 'div', 'divc', 'forwrdderiv', \ 10318 'inv', \ 10319 'lowthres', 'lowthres@oper', 'mul', 'mulc', 'norm_meanminmax', 'norm_minmax', \ 10320 'norm_meanstd', 'pot', 'potc', 'repl', 'replbig', 'repless', 'sub', 'subc', \ 10321 'upthres', 'upthres@oper'] 10309 10322 opavailc = ['addc', 'divc', 'inv', 'mulc', 'potc', 'subc'] 10310 10323 … … 10315 10328 value1 = retype(opN.split(',')[1], valtype) 10316 10329 Lopn['addc'] = '+' + str(value1) 10330 elif opN[0:6] == 'arctan': 10331 opn = 'arctan' 10332 Lopn['arctan'] = 'arctan' 10317 10333 elif opN[0:11] == 'centerderiv': 10318 10334 opn = 'centerderiv' … … 10390 10406 value1 = retype(opN.split(',')[1], valtype) 10391 10407 Lopn['mulc'] = '*' + str(value1) 10408 elif opN[0:15] == 'norm_meanminmax': 10409 opn = 'norm_meanminmax' 10410 dimns = opN.split(',')[1].split(':') 10411 normdimns = opN.split(',')[2].split(':') 10412 idimsS = opN.split(',')[3].split(':') 10413 idims = tuple(np.array(idimsS, dtype=int)) 10414 Lopn['norm_meanminmax'] = 'Norm_mean_minmax(' + ','.join(normdimns) + ')' 10415 elif opN[0:11] == 'norm_minmax': 10416 opn = 'norm_minmax' 10417 dimns = opN.split(',')[1].split(':') 10418 normdimns = opN.split(',')[2].split(':') 10419 idimsS = opN.split(',')[3].split(':') 10420 idims = tuple(np.array(idimsS, dtype=int)) 10421 Lopn['norm_minmax'] = 'Norm_minmax(' + ','.join(normdimns) + ')' 10422 elif opN[0:12] == 'norm_meanstd': 10423 opn = 'norm_meanstd' 10424 dimns = opN.split(',')[1].split(':') 10425 normdimns = opN.split(',')[2].split(':') 10426 idimsS = opN.split(',')[3].split(':') 10427 idims = tuple(np.array(idimsS, dtype=int)) 10428 Lopn['norm_meanstd'] = 'Norm_mean_std(' + ','.join(normdimns) + ')' 10392 10429 elif opN[0:4] == 'potc': 10393 10430 opn = 'potc' … … 10431 10468 10432 10469 # Carrying on the operation 10470 additional = None 10433 10471 if opn == 'add': 10434 10472 newmat = matA + matB 10435 10473 elif opn == 'addc': 10436 10474 newmat = matA + value1 10475 elif opn == 'arctan': 10476 newmat = np.arctan2(matA,matB) 10437 10477 elif opn == 'centerderiv': 10438 10478 sdim = matAshape[dim] … … 10602 10642 elif opn == 'mulc': 10603 10643 newmat = matA * value1 10644 elif opn == 'norm_meanminmax': 10645 newmat = np.zeros((matA.shape), dtype=matA.dtype) 10646 meanval = np.mean(matA, axis=idims) 10647 minval = np.min(matA, axis=idims) 10648 maxval = np.max(matA, axis=idims) 10649 slices = provide_slices(dimns, matA.shape, normdimns) 10650 Nslices = len(slices) 10651 for islc in range(Nslices): 10652 listv = list(slices[islc]) 10653 for iind in range(len(idims)): 10654 indv = idims[iind] - iind 10655 listv.pop(indv) 10656 newmat[tuple(slices[islc])] = (matA[tuple(slices[islc])] - \ 10657 meanval[tuple(listv)]) / (maxval[tuple(listv)]-minval[tuple(listv)]) 10658 additional = [meanval, minval, maxval] 10659 10660 elif opn == 'norm_minmax': 10661 newmat = np.zeros((matA.shape), dtype=matA.dtype) 10662 minval = np.min(matA, axis=idims) 10663 maxval = np.max(matA, axis=idims) 10664 slices = provide_slices(dimns, matA.shape, normdimns) 10665 Nslices = len(slices) 10666 for islc in range(Nslices): 10667 listv = list(slices[islc]) 10668 for iind in range(len(idims)): 10669 indv = idims[iind] - iind 10670 listv.pop(indv) 10671 xnadd = maxval[tuple(listv)]+minval[tuple(listv)] 10672 xnsub = maxval[tuple(listv)]-minval[tuple(listv)] 10673 newmat[tuple(slices[islc])] = (2.*matA[tuple(slices[islc])]-xnadd)/xnsub 10674 additional = [minval, maxval] 10675 elif opn == 'norm_meanstd': 10676 newmat = np.zeros((matA.shape), dtype=matA.dtype) 10677 meanval = np.mean(matA, axis=idims) 10678 stdval = np.std(matA, axis=idims) 10679 slices = provide_slices(dimns, matA.shape, normdimns) 10680 Nslices = len(slices) 10681 for islc in range(Nslices): 10682 listv = list(slices[islc]) 10683 for iind in range(len(idims)): 10684 indv = idims[iind] - iind 10685 listv.pop(indv) 10686 newmat[tuple(slices[islc])] = (matA[tuple(slices[islc])] - \ 10687 meanval[tuple(listv)]) / stdval[tuple(listv)] 10688 additional = [meanval, stdval] 10604 10689 elif opn == 'pot': 10605 10690 newmat = matA ** matB … … 10641 10726 quit(-1) 10642 10727 10643 return newmat, Lopn[opn] 10728 return newmat, Lopn[opn], additional 10644 10729 10645 10730 def latex_fig_array(figs, obf, figcaption, figlabel, dist='sqr', refsize=0.9, \ -
trunk/tools/nc_var_tools.py
r1533 r1535 7178 7178 (OPER1.FILE1_VAR1 OPER2.FILE2_VAR2), operations are going to be sequentially made 7179 7179 compute_opersvarsfiles(values, varinfo). 7180 NOTE: Values from the first file (with always operation 'add')7181 7180 [prevalues]: values from the previous operations 7181 NOTE: to start with a multiple operations one can use as operation of the first variable 'addc,0' 7182 7182 values= '%' separated list of dimension ranges and file,operation,variable to compute 7183 7183 [dimranges1]@[operfile1var]%[dimranges2]@[operfile2var]%[...[dimrangesM]@[operfileMvar]] … … 7189 7189 int, a single value 7190 7190 [beg,end,frq], from a beginning to an end with a given frequency 7191 'WRFtime': as time variable computed from WRF 'Times' variable 7191 7192 operfilevar: [oper]|[file]|[var] '|' separated list of triplets of [operation], [file], [variable name to use] 7193 NOTE: use 'contoperation' to continue an operation with the result of previous operations [prevalues] 7192 7194 * [oper]: operations (being [prevalues] the values computed until the operation) 7193 7195 'add': adding [var] ([prevalues] + [var]) 7194 7196 'addc',[modval1]: add [modval1] to [prevalues] 7197 'arctan', arctangent [-pi, pi] 7195 7198 'centerderiv',[N],[ord],[dim]: un-scaled center [N]-derivative of order [ord] along dimension [dim] of [var] 7196 7199 'div': dividing by [var] ([prevalues] / [var]) … … 7202 7205 'mul': multiplying by [var] ([prevvalues] * [var]) 7203 7206 'mulc',[modval1]: [prevalues] multiplied by [modval1] 7207 'norm_meanminmax',[NOTnormdims]: normalization of data as: (val-<val>)/(max(val)-min(val)) except along 7208 dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions) 7209 'norm_minmax',[NOTnormdims]: normalization of data as: [2val-(max(val)-min(val)]/[max(val)+min(val)] 7210 except along dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions) 7211 'norm_meanstd',[NOTnormdims]: normalization of data as: (val-<val>)/stdev(val) except along 7212 dimensions [NOTnormdims] (':' list of dimension names, or 'any' for using all dimensions) 7204 7213 'pot': powering with [var] ([prevalues] ** [var]) 7205 7214 'potc',[modval1]: [prevalues] ** [modval1] … … 7218 7227 'lowthres@oper', 'mulc', 'potc', 'subc', 'upthres', 'upthres@oper' 7219 7228 varinfo= [varname],[Lvarname],[varunits] 7220 varname: name of the final variable 7229 varname: name of the final variable (to be used as standard name) 7221 7230 Lvarname: long name of the final variable ('!' for spaces) 7222 7231 varunits: units of the final variable ('!' for spaces) … … 7234 7243 # List of operations which need to be started with a matrix of ones 7235 7244 opinione = ['mul', 'div', 'pot'] 7245 # Operations which need to deal with dimension's names and indices 7246 opdim=['norm_meanminmax', 'norm_meanstd', 'norm_minmax'] 7236 7247 7237 7248 varname = varinfo.split(',')[0] … … 7250 7261 varns = [] 7251 7262 for fileoper in fileopers: 7252 ranges.append(fileoper.split('@')[0]) 7263 print 'fileoper', fileoper 7264 arguments = '[dimranges]@[operfilevar]' 7265 gen.check_arguments(fname, fileoper, arguments, '@') 7253 7266 fnop = fileoper.split('@')[1] 7254 opers.append(fnop.split('|')[0]) 7255 filens.append(fnop.split('|')[1]) 7256 varns.append(fnop.split('|')[2]) 7267 if fileoper.split('@')[0] != 'contoperation': 7268 ranges.append(fileoper.split('@')[0]) 7269 arguments = '[oper]|[file]|[var]' 7270 gen.check_arguments(fname, fnop, arguments, '|') 7271 opers.append(fnop.split('|')[0]) 7272 filens.append(fnop.split('|')[1]) 7273 varns.append(fnop.split('|')[2]) 7274 else: 7275 ranges.append('continuation') 7276 opers.append(fnop) 7277 filens.append('continuation') 7278 varns.append('continuation') 7257 7279 7258 7280 print ' ' + fname + 'Files/Operations to perform _______' 7259 7281 for ifop in range(Nfileopers): 7260 print ' ' + filens[ifop] + ' range: ' + ranges[ifop] + ' operation: ' + \ 7261 opers[ifop] + ' variable: ' + varns[ifop] 7282 if filens[ifop] != 'continuation': 7283 print ' ' + filens[ifop] + ' range: ' + ranges[ifop] + ' operation: '+\ 7284 opers[ifop] + ' variable: ' + varns[ifop] 7285 else: 7286 print ' continuing computation by: ' + opers[ifop] 7262 7287 7263 7288 newunits = '-' … … 7273 7298 # Dictionary with the attributes dictionay of the dimension-variables of the dimensions of `prevalues' 7274 7299 Dadv = {} 7300 # Dictionary with the additional values for certain operations of `prevalues' 7301 Dadditionalv = {} 7302 # Dictionary with the additional dimensions which are not used for certain operations of `prevalues' 7303 Dadditionaldim = {} 7304 # Dictionary with the additional units used for certain operations of `prevalues' 7305 Dadditionalunits = {} 7306 # Dictionary with the Headers for the names of the additional variables 7307 DHadditionalvars = {'norm_meanminmax': ['mean','min','max'], \ 7308 'norm_meanstd': ['mean','std'], 'norm_minmax': ['min','max']} 7275 7309 7276 7310 prevalues = None 7277 7311 for ifv in range(Nfileopers): 7278 oper n= opers[ifv]7312 operN = opers[ifv] 7279 7313 filen = filens[ifv] 7280 7314 varn = varns[ifv] 7281 7315 rng = ranges[ifv].split(';') 7282 if oper n.find(',') != -1:7283 opernS = oper n.split(',')[0]7316 if operN.find(',') != -1: 7317 opernS = operN.split(',')[0] 7284 7318 else: 7285 opernS = oper n7319 opernS = operN 7286 7320 7287 7321 opervars.append(varn) 7288 7322 7289 if not os.path.isfile(filen): 7290 print errormsg 7291 print ' ' + fname + ' file: "' + filen + '" does not exist !!' 7292 quit(-1) 7293 7294 objnc = NetCDFFile(filen, 'r') 7295 7296 # Operation with a variable 7297 if varn != 'None' or prevalues is None: 7298 if not objnc.variables.has_key(varn): 7323 if filen != 'continuation': 7324 if not os.path.isfile(filen): 7299 7325 print errormsg 7300 print ' ' + fname + ': netCDF file "' + filen + \ 7326 print ' ' + fname + ' file: "' + filen + '" does not exist !!' 7327 quit(-1) 7328 7329 objnc = NetCDFFile(filen, 'r') 7330 7331 # Operation with a variable 7332 if varn != 'WRFtime' and not objnc.variables.has_key(varn): 7333 print errormsg 7334 print ' ' + fname + ': netCDF file "' + filen + \ 7301 7335 '" does not have variable "' + varn + '" !!!!' 7302 7336 quit(-1) … … 7317 7351 # Dimension-variable 7318 7352 if not objnc.variables.has_key(dimv): 7319 print warnmsg 7320 print ' ' + fname + ": file '" + filen + "' does not have " + \ 7321 "dimension-variable '" + dimv + "' !!" 7322 print ' keep going on' 7323 #quit(-1) 7353 if dimv == 'WRFtime': 7354 Ddimvs.append([dimn, 'WRFtime', dimr]) 7355 else: 7356 print warnmsg 7357 print ' ' +fname+ ": file '" + filen + "' does not have " + \ 7358 "dimension-variable '" + dimv + "' !!" 7359 print ' keep going on' 7360 #quit(-1) 7324 7361 else: 7325 7362 # Keeping the dimensions 7326 7363 Ddimvs.append([dimn, dimv, dimr]) 7327 7328 7364 # Getting values of the variable 7329 7365 varslice, dimvarvals = SliceVarDict(varobj, dictslice) … … 7332 7368 varvals = slice_createArray(varslice, varobj.dtype) 7333 7369 if len(varvals.shape) > 1: 7334 if varvals.shape[0] != 0: 7335 for ix in range(varvals.shape[0]): 7336 varvals[ix,...] = varobj[ix,...] 7337 else: 7338 for ix in range(varvals.shape[len(varvals.shape)-1]): 7339 varvals[...,ix] = varobj[...,ix] 7370 # if varvals.shape[0] != 0: 7371 # for ix in range(varvals.shape[0]): 7372 # varvals[ix,...] = varobj[tuple(varslice[ix,...])] 7373 # else: 7374 # for ix in range(varvals.shape[len(varvals.shape)-1]): 7375 # varvals[...,ix] = varobj[tuple(varslice[...,ix])] 7376 varvals[:] = varobj[tuple(varslice)] 7340 7377 else: 7341 7378 varvals[:] = varobj[:] 7342 7379 7343 7380 # Getting values of the correspondant dimensions of the variable 7344 7381 for iddd in range(len(Ddimvs)): … … 7347 7384 dimv = DD[1] 7348 7385 dimr = DD[2] 7349 if dimv != 'WRFt ':7386 if dimv != 'WRFtime': 7350 7387 odimv = objnc.variables[dimv] 7351 7388 varslice, Dddv[dimn] = SliceVarDict(odimv, dictslice) … … 7358 7395 Dadv[dimn] = dicattrs 7359 7396 else: 7397 print infmsg 7398 print ' ' + fname + ": computing time-variable from 'WRF'-Time" 7360 7399 datesv = [] 7361 7400 wrft = objnc.variables['Times'] … … 7370 7409 minref=refdate[10:12] 7371 7410 secref=refdate[12:14] 7372 7411 7373 7412 refdateS = yrref + '-' + monref + '-' + dayref + ' ' + horref + \ 7374 7413 ':' + minref + ':' + secref 7375 7414 7376 7415 dt = fdates.shape[0] 7377 7416 cftimes = np.zeros((dt), dtype=np.float) 7378 7417 for it in range(dt): 7379 wrfdates = gen.datetimeStr_conversion( timewrfv[it,:],\7380 7418 wrfdates = gen.datetimeStr_conversion(wrft[it,:], \ 7419 'WRFdatetime', 'matYmdHMS') 7381 7420 cftimes[it] = gen.realdatetime1_CFcompilant(wrfdates, \ 7382 7421 refdate, tunitsval) 7383 7422 tunits = tunitsval + ' since ' + refdateS 7384 Dddv[dimn] = 'Time'7423 Dddv[dimn] = ['Time'] 7385 7424 Ddv[dimn] = cftimes 7386 7425 Dtdv[dimn] = np.float … … 7388 7427 'units': tunitsval + ' since ' + refdateS} 7389 7428 7390 # Getting sizes of the dimensions 7391 for dvn in dimvarvals: 7392 dimobj = objnc.dimensions[dvn] 7393 if dimobj.isunlimited(): 7394 Dds[dvn] = None 7395 else: 7396 Dds[dvn] = len(dimobj) 7397 7398 # operation 7399 if prevalues is None: 7400 # Creation of an empty variable to start with 7401 if gen.searchInlist(opinizero,opernS): 7402 inimat = np.zeros(varvals.shape, dtype=varobj.dtype) 7403 elif gen.searchInlist(opinione,opernS): 7404 inimat = np.ones(varvals.shape, dtype=varobj.dtype) 7405 7406 prevalues, operS = gen.matoperations(opern, varvals, inimat) 7429 # Getting sizes of the dimensions 7430 for dvn in dimvarvals: 7431 dimobj = objnc.dimensions[dvn] 7432 if dimobj.isunlimited(): 7433 Dds[dvn] = None 7434 else: 7435 Dds[dvn] = len(dimobj) 7436 # Checking right slice for each dimension in variable 7437 for dimn in dimvarvals: 7438 found = False 7439 if not gen.searchInlist(Dddv.keys(), dimn): 7440 print errormsg 7441 print ' ' + fname + ": sliced variable has dimension '" + dimn+ \ 7442 "' but there is no slicing-dimension information" 7443 print " add range for the dimension as '[dim]|[dimv]|[range]'" 7444 quit(-1) 7445 7446 else: 7447 # Computing using results of previous computations 7448 varvals = prevalues.copy() 7449 dimvarvals = prevdims 7450 print infmsg 7451 print ' ' + fname + ': continuing operation with previous values' 7452 print ' shape:', varvals.shape 7453 print ' dimensions:', dimvarvals 7454 7455 # Conditions for certain operations 7456 if gen.searchInlist(opdim, opernS): 7457 opn = operN.split(',')[0] 7458 normd = gen.str_list(operN.split(',')[1], ':') 7459 usedims = list(dimvarvals) 7460 if normd[0] != 'any': 7461 normi = [] 7462 for dn in normd: 7463 normi.append(dimvarvals.index(dn)) 7464 usedims.remove(dn) 7465 normi.sort() 7407 7466 else: 7408 print ' ' + fname + ': Lluis opern:', opern 7409 prevalues, operS = gen.matoperations(opern, prevalues, varvals) 7410 operS = ' ' + operS + '[' + varn + ']' 7467 normi = range(len(varvals.shape)) 7468 usedims = 'any' 7469 for iv in range(len(normi)): normi[iv] = str(normi[iv]) 7470 opern = opernS + ',' + ':'.join(dimvarvals) + ',' + \ 7471 operN.split(',')[1] + ',' + ':'.join(normi) 7472 Dadditionaldim[opernS+'@'+varn] = usedims 7473 if varn != 'continuation': 7474 Dadditionalunits[opernS+'@'+varn] = get_varunits(varobj) 7475 else: 7476 Dadditionalunits[opernS+'@'+varn] = '?' 7411 7477 else: 7412 prevalues, operS = gen.matoperations(opern, prevalues) 7413 operS = ' ' + operS 7414 7415 if opern == opers[0]: 7478 opern = operN 7479 7480 if varn != 'continuation': 7481 objnc.close() 7482 7483 # operation 7484 if prevalues is None: 7485 # Creation of an empty variable to start with 7486 if gen.searchInlist(opinizero,opernS): 7487 inimat = np.zeros(varvals.shape, dtype=varobj.dtype) 7488 elif gen.searchInlist(opinione,opernS): 7489 inimat = np.ones(varvals.shape, dtype=varobj.dtype) 7490 else: 7491 inimat = varvals 7492 7493 prevalues, operS, addvs = gen.matoperations(opern, varvals, inimat) 7494 else: 7495 prevalues, operS, addvs = gen.matoperations(opern, prevalues, varvals) 7496 operS = ' ' + operS + '[' + varn + ']' 7497 7498 # elif varn == 'None' and prevalues is not None: 7499 # prevalues, operS, addvs = gen.matoperations(opern, prevalues) 7500 # operS = ' ' + operS 7501 7502 if operN == opers[0]: 7416 7503 operationS = operS 7417 7504 else: 7418 7505 operationS = operationS + operS 7419 7506 7420 objnc.close() 7507 Dadditionalv[opernS+'@'+varn] = addvs 7508 7509 prevdims = list(dimvarvals) 7510 prevsizedims = varvals.shape 7421 7511 7422 7512 # Creation of the new file … … 7451 7541 7452 7542 newattr = basicvardef(newvar, varname, Lvarname, varunits) 7543 7544 # Additional variables. Each necessary dimension to fill up the information will be created as: 7545 # dimension name: dim + '_' + operS + '_' + var 7546 # dimension size: value from the shape of the additional values 7547 7548 for operSvarn in Dadditionalv.keys(): 7549 addvs = Dadditionalv[operSvarn] 7550 if addvs is not None: 7551 operS = operSvarn.split('@')[0] 7552 vnS = operSvarn.split('@')[1] 7553 addopdims = Dadditionaldim[operSvarn] 7554 addunits = Dadditionalunits[operSvarn] 7555 Hvarns = DHadditionalvars[operS] 7556 iHv = 0 7557 if type(addopdims) == type('S') and addopdims == 'any': 7558 for Hvarn in Hvarns: 7559 newvn = Hvarn + '_' + operS + '_' + vnS 7560 newvar = objofile.createVariable(newvn, 'f4') 7561 newvar[:] = addvs[iHv] 7562 Lattr = Hvarn + ' value for operation ' + operS + ' with variable ' + vnS 7563 basicvardef(newvar, newvn, Lattr, addunits) 7564 iHv = iHv + 1 7565 else: 7566 idim = 0 7567 newvdims = [] 7568 for dimn in addopdims: 7569 newdimn = dimn + '_' + operS + '_' + vnS 7570 dsize = addvs[0].shape[idim] 7571 newdim = objofile.createDimension(newdimn,dsize) 7572 newvdims.append(newdimn) 7573 7574 for Hvarn in Hvarns: 7575 newvn = Hvarn + '_' + operS + '_' + vnS 7576 newvar = objofile.createVariable(newvn, 'f4', tuple(newvdims)) 7577 newvar[:] = addvs[iHv] 7578 Lattr = Hvarn + ' value for operation ' + operS + ' with variable ' + vnS 7579 basicvardef(newvar, newvn, Lattr, addunits) 7580 iHv = iHv + 1 7453 7581 7454 7582 # Global attributes
Note: See TracChangeset
for help on using the changeset viewer.