- Timestamp:
- Jun 1, 2016, 3:11:21 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r791 r793 12396 12396 [endi] = -1, maximum value 12397 12397 [inti] = -1, all the values within the range 12398 = 0, single value. [begi] will be taken as the reference value 12398 12399 NOTE: variables without section by the variables are taken allover their size 12399 12400 NOTE2: if inti = 'str', it is assumed that the variable is a string-list of values … … 12425 12426 endvs = np.zeros((Nvars), dtype=int) 12426 12427 intvs = np.zeros((Nvars), dtype=int) 12428 fbegvs = np.zeros((Nvars), dtype=np.float) 12429 fendvs = np.zeros((Nvars), dtype=np.float) 12430 fintvs = np.zeros((Nvars), dtype=np.float) 12427 12431 12428 12432 for ivar in range(Nvars): … … 12460 12464 endvs[ivar] = np.float(val.split(',')[2]) 12461 12465 intvs[ivar] = np.float(val.split(',')[3]) 12466 fbegvs[ivar] = np.float(val.split(',')[1]) 12467 fendvs[ivar] = np.float(val.split(',')[2]) 12468 fintvs[ivar] = np.float(val.split(',')[3]) 12462 12469 ofiletile = ofiletile + '_' + varns[ivar] + '_B' + str(begvs[ivar]) + '-E' + \ 12463 12470 str(endvs[ivar]) + '-I' + str(intvs[ivar]) … … 12513 12520 vardims = ovar.dimensions 12514 12521 12515 if intvs[ivar] != -99.: 12522 if intvs[ivar] == -99.: 12523 ostrvar = nciobj.variables[varns[ivar]] 12524 finalmask = np.ones((ostrvar.shape), dtype= bool) 12525 finalmask[int(begvs[ivar]),:] = False 12526 elif intvs[ivar] == 0.: 12527 vmask = ma.masked_not_equal(vals, fbegvs[ivar]) 12528 finalmask = vmask.mask 12529 if np.all(finalmask == True): 12530 print errormsg 12531 print ' ' + fname + ": variable '" + varns[ivar] + "' does not " + \ 12532 'have value=', fbegvs[ivar] 12533 quit(-1) 12534 else: 12516 12535 if endvs[ivar] == -1: endvs[ivar] = np.max(vals) 12517 12536 maskinf = ma.masked_less(vals, begvs[ivar]) … … 12524 12543 finalmask = maskinf.mask + masksup.mask 12525 12544 idn = 0 12526 else:12527 ostrvar = nciobj.variables[varns[ivar]]12528 finalmask = np.ones((ostrvar.shape), dtype= bool)12529 finalmask[int(begvs[ivar]),:] = False12530 12545 12531 12546 slicedims = {} … … 12537 12552 rightvals = np.where(finalmask, False, True) 12538 12553 12539 if intvs[ivar] != -99.: 12540 slicedims[dn]=[np.min(dinds[rightvals][0,:]), np.max(dinds[rightvals][0,:])+1, None] 12541 else: 12554 if intvs[ivar] == -99.: 12542 12555 if iidim == 0: 12543 12556 slicedims[dn]=[int(begvs[ivar]), int(begvs[ivar]), None] 12544 12557 else: 12545 12558 slicedims[dn]=[0, ddn, None] 12559 elif intvs[ivar] == 0.: 12560 if np.sum(~finalmask,axis=iidim) == 0: 12561 slicedims[dn]=[0, ddn, None] 12562 elif np.sum(~finalmask,axis=iidim) == 1: 12563 ivals = gen.index_mat(finalmask, False) 12564 ival = ivals[iidim] 12565 slicedims[dn]=[ival, ival, None] 12566 else: 12567 print errormsg 12568 print ' ' + fname + ': multiple', np.sum(~finalmask,axis=iidim), \ 12569 'possible values!' 12570 print ' I do not know how to proceed' 12571 quit(-1) 12572 else: 12573 slicedims[dn]=[np.min(dinds[rightvals][0,:]), np.max(dinds[rightvals][0,:])+1, None] 12546 12574 12547 12575 iidim = iidim + 1
Note: See TracChangeset
for help on using the changeset viewer.