Changeset 2768 in lmdz_wrf for trunk/tools
- Timestamp:
- Nov 18, 2019, 3:46:52 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2709 r2768 1471 1471 1472 1472 attvar = var.ncattrs() 1473 if searchInlist(attvar, values):1473 if gen.searchInlist(attvar, values): 1474 1474 attr = var.delncattr(values) 1475 1475 else: … … 1495 1495 1496 1496 attvar = ncf.ncattrs() 1497 if searchInlist(attvar, values):1497 if gen.searchInlist(attvar, values): 1498 1498 attr = ncf.delncattr(values) 1499 1499 else: … … 2890 2890 # Checking fill value 2891 2891 ## 2892 if searchInlist(varattr, '_FillValue'):2892 if gen.searchInlist(varattr, '_FillValue'): 2893 2893 varfil = var._FillValue 2894 2894 else: … … 2925 2925 newvar = ncfo.variables['time'] 2926 2926 newvarattrs = newvar.ncattrs() 2927 if searchInlist(newvarattrs, 'bounds'):2927 if gen.searchInlist(newvarattrs, 'bounds'): 2928 2928 if newvar.getncattr('bounds') == 'time_bnds': 2929 2929 ncf = NetCDFFile(ncfile,'r') … … 3080 3080 # Checking fill value 3081 3081 ## 3082 if searchInlist(varattr, '_FillValue'):3082 if gen.searchInlist(varattr, '_FillValue'): 3083 3083 varfil = var._FillValue 3084 3084 else: … … 3115 3115 newvar = ncfo.variables['time'] 3116 3116 newvarattrs = newvar.ncattrs() 3117 if searchInlist(newvarattrs, 'bounds'):3117 if gen.searchInlist(newvarattrs, 'bounds'): 3118 3118 if newvar.getncattr('bounds') == 'time_bnds': 3119 3119 ncf = NetCDFFile(ncfile,'r') … … 5162 5162 for var in ncft.variables: 5163 5163 varobj = ncft.variables[var] 5164 if searchInlist(varobj.dimensions, tname):5164 if gen.searchInlist(varobj.dimensions, tname): 5165 5165 print fname + ': time-sorting variable: "' + var + '" ' 5166 5166 varvals = varobj[:] … … 5754 5754 # Looking if variable has lon and/or lat: 5755 5755 varlonlat = False 5756 if searchInlist(vardims, oldlonlatdim[0]): varlonlat = True5757 if searchInlist(vardims, oldlonlatdim[1]): varlonlat = True5756 if gen.searchInlist(vardims, oldlonlatdim[0]): varlonlat = True 5757 if gen.searchInlist(vardims, oldlonlatdim[1]): varlonlat = True 5758 5758 5759 5759 if varn != oldlon and varn != oldlat and varlonlat: … … 5782 5782 newslice0 = newslice[:] 5783 5783 5784 if searchInlist(vardims,oldlat):5784 if gen.searchInlist(vardims,oldlat): 5785 5785 oldslice0.append(mappairs[0,jnew,inew]) 5786 5786 newslice0.append(jnew) 5787 5787 5788 if searchInlist(vardims,oldlon):5788 if gen.searchInlist(vardims,oldlon): 5789 5789 oldslice0.append(mappairs[1,jnew,inew]) 5790 5790 newslice0.append(inew) … … 5819 5819 newvarval = ovar[:] 5820 5820 5821 if searchInlist(varattrs, '_FillValue'):5821 if gen.searchInlist(varattrs, '_FillValue'): 5822 5822 fvalv = ovar.getncattr('_FillValue') 5823 5823 newvar = ncfnew.createVariable(varn, vartype, tuple(newvardimn), \ … … 7395 7395 otime = objfile.variables['time'] 7396 7396 timevals = otime[:] 7397 if searchInlist(otime.ncattrs(),'units'):7397 if gen.searchInlist(otime.ncattrs(),'units'): 7398 7398 tunits = otime.getncattr['units'] 7399 7399 else: … … 7444 7444 otime = objfile.variables['time'] 7445 7445 timevals = otime[:] 7446 if searchInlist(otime.ncattrs(),'units'):7446 if gen.searchInlist(otime.ncattrs(),'units'): 7447 7447 tunits = otime.getncattr['units'] 7448 7448 else: … … 7462 7462 newvar[it,:,:] = valsvar[inside] 7463 7463 7464 if searchInlist(varobj.ncattrs(),'standard_name'):7464 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 7465 7465 vsname = varobj.getncattr('standard_name') 7466 7466 else: 7467 7467 vsname = varn 7468 if searchInlist(varobj.ncattrs(),'long_name'):7468 if gen.searchInlist(varobj.ncattrs(),'long_name'): 7469 7469 vlname = varobj.getncattr('long_name') 7470 7470 else: 7471 7471 vlname = varn 7472 if searchInlist(varobj.ncattrs(),'units'):7472 if gen.searchInlist(varobj.ncattrs(),'units'): 7473 7473 vunits = varobj.getncattr('units') 7474 7474 else: … … 8256 8256 if opern == 'add': 8257 8257 newvarv[tuple(tnewvar)] = newvarv[tuple(tnewvar)] + varobj[tuple(tslice)] 8258 if searchInlist(varobj.ncattrs(), 'units') and newunits != '-':8258 if gen.searchInlist(varobj.ncattrs(), 'units') and newunits != '-': 8259 8259 newunits = varobj.getncattr('units') 8260 8260 elif opern == 'sub': 8261 8261 newvarv[tuple(tnewvar)] = newvarv[tuple(tnewvar)] - varobj[tuple(tslice)] 8262 if searchInlist(varobj.ncattrs(), 'units') and newunits != '-':8262 if gen.searchInlist(varobj.ncattrs(), 'units') and newunits != '-': 8263 8263 newunits = varobj.getncattr('units') 8264 8264 elif opern == 'mul': … … 8426 8426 if opern == 'add': 8427 8427 newvarv[tuple(tslice)] = newvarv[tuple(prevslice)] + varobj[tuple(tslice)] 8428 if searchInlist(varobj.ncattrs(), 'units') and newunits != '-':8428 if gen.searchInlist(varobj.ncattrs(), 'units') and newunits != '-': 8429 8429 newunits = varobj.getncattr('units') 8430 8430 elif opern == 'sub': 8431 8431 newvarv[tuple(tslice)] = newvarv[tuple(prevslice)] - varobj[tuple(tslice)] 8432 if searchInlist(varobj.ncattrs(), 'units') and newunits != '-':8432 if gen.searchInlist(varobj.ncattrs(), 'units') and newunits != '-': 8433 8433 newunits = varobj.getncattr('units') 8434 8434 elif opern == 'mul': … … 9090 9090 otime = objfile.variables['time'] 9091 9091 timevals = otime[:] 9092 if searchInlist(otime.ncattrs(),'units'):9092 if gen.searchInlist(otime.ncattrs(),'units'): 9093 9093 tunits = otime.getncattr['units'] 9094 9094 else: … … 9146 9146 otime = objfile.variables['time'] 9147 9147 timevals = otime[:] 9148 if searchInlist(otime.ncattrs(),'units'):9148 if gen.searchInlist(otime.ncattrs(),'units'): 9149 9149 tunits = otime.getncattr['units'] 9150 9150 else: … … 9164 9164 newvar[it,:,:,:] = valsvar[inside3D] 9165 9165 9166 if searchInlist(varobj.ncattrs(),'standard_name'):9166 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 9167 9167 vsname = varobj.getncattr('standard_name') 9168 9168 else: 9169 9169 vsname = varn 9170 if searchInlist(varobj.ncattrs(),'long_name'):9170 if gen.searchInlist(varobj.ncattrs(),'long_name'): 9171 9171 vlname = varobj.getncattr('long_name') 9172 9172 else: 9173 9173 vlname = varn 9174 if searchInlist(varobj.ncattrs(),'units'):9174 if gen.searchInlist(varobj.ncattrs(),'units'): 9175 9175 vunits = varobj.getncattr('units') 9176 9176 else: … … 9230 9230 arguments = '[trajfile]@[Tbeg],[lonname],[latname],[zname],[timename],' + \ 9231 9231 '[timekind],[boxsize],[circler]]' 9232 check_arguments(fname,values,arguments,',')9232 gen.check_arguments(fname,values,arguments,',') 9233 9233 9234 9234 trajfile = values.split(',')[0].split('@')[0] … … 9284 9284 varns = [varn] 9285 9285 9286 lonv, latv = lonlat2D(lonobj[:],latobj[:])9286 lonv, latv = gen.lonlat2D(lonobj[:],latobj[:]) 9287 9287 9288 9288 dimx = lonv.shape[1] … … 9293 9293 # Selecting accordingly a trajectory 9294 9294 ## 9295 Ttraj = file_nlines(trajfile,'#')9295 Ttraj = gen.file_nlines(trajfile,'#') 9296 9296 if timekind == 'wrf': 9297 9297 dimt = objfile.variables[timn].shape[0] … … 9342 9342 9343 9343 # Slicing brings to reduce 1 time-step.... ??? 9344 if l ine[0:1] != '#':9344 if len(line) > 1 and line[0:1] != '#': 9345 9345 gtrajvals[it,0] = Tbeg + iline - 1 9346 9346 gtrajvals[it,1] = int(line.split(' ')[1]) … … 9349 9349 9350 9350 if timekind == 'wrf': 9351 gdate = datetimeStr_conversion(timv[gtrajvals[it,0]],'WRFdatetime',\9352 ' matYmdHMS')9353 trajvals[it,0] = realdatetime1_CFcompilant(gdate, '19491201000000',\9351 gdate = gen.datetimeStr_conversion(timv[gtrajvals[it,0]], \ 9352 'WRFdatetime', 'matYmdHMS') 9353 trajvals[it,0]= gen.realdatetime1_CFcompilant(gdate,'19491201000000',\ 9354 9354 'hours') 9355 9355 tunits = 'hours since 1949-12-01 00:00:00' … … 9417 9417 9418 9418 # circle values 9419 circdist[it,:,:] = radius_dist(dimy,dimx,gtrajvals[it,2],gtrajvals[it,1])9419 circdist[it,:,:] = gen.radius_dist(dimy,dimx,gtrajvals[it,2],gtrajvals[it,1]) 9420 9420 if gtrajvals[it,2]-Nrad < 0 or gtrajvals[it,2]+Nrad + 1 > dimy + 1 \ 9421 9421 or gtrajvals[it,1]-Nrad < 0 or gtrajvals[it,1]+Nrad + 1 > dimx + 1: … … 9495 9495 9496 9496 for vn in varns: 9497 vnst = variables_values(vn)[0]9498 if not searchInlist(objfile.variables, vn):9497 vnst = gen.variables_values(vn)[0] 9498 if not gen.searchInlist(objfile.variables, vn): 9499 9499 print errormsg 9500 9500 print ' ' + fname + ": variable name '" + vn + "' is not in file " + \ … … 9529 9529 9530 9530 objofile.createDimension('z', dimz) 9531 newvar = objofile.createVariable(zn, 'f4', ('z'),fill_value=fillValue) 9532 if searchInlist(varzobj.ncattrs(),'standard_name'): 9531 newvar = objofile.createVariable(zn, 'f4', ('z'), \ 9532 fill_value=gen.fillValueF) 9533 if gen.searchInlist(varzobj.ncattrs(),'standard_name'): 9533 9534 vsname = varzobj.getncattr('standard_name') 9534 9535 else: 9535 vsname = variables_values(zn)[1]9536 if searchInlist(varzobj.ncattrs(),'long_name'):9536 vsname = gen.variables_values(zn)[1] 9537 if gen.searchInlist(varzobj.ncattrs(),'long_name'): 9537 9538 vlname = varzobj.getncattr('long_name') 9538 9539 else: 9539 vlname = variables_values(zn)[4].replace('|',' ')9540 if searchInlist(varzobj.ncattrs(),'units'):9540 vlname = gen.variables_values(zn)[4].replace('|',' ') 9541 if gen.searchInlist(varzobj.ncattrs(),'units'): 9541 9542 vunits = varzobj.getncattr('units') 9542 9543 else: 9543 vunits = variables_values(zn)[5].replace('|',' ')9544 vunits = gen.variables_values(zn)[5].replace('|',' ') 9544 9545 9545 9546 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 9586 9587 9587 9588 rvarvalst = np.ones((dimz, Nrad*2+1, Nrad*2+1),dtype=np.float)* \ 9588 fillValue9589 gen.fillValueF 9589 9590 9590 9591 varvalst[tuple(slice2D)] = varobj[tuple(slicev)] … … 9592 9593 9593 9594 # box stats values 9594 maskedvals = ma.masked_values (varvalst, fillValue)9595 maskedvals = ma.masked_values (varvalst, gen.fillValueF) 9595 9596 maskedvals2 = maskedvals*maskedvals 9596 9597 for iz in range(dimz): … … 9660 9661 9661 9662 rvarvalst = np.ones((dimz,Nrad*2+1,Nrad*2+1),dtype=np.float)* \ 9662 fillValue9663 gen.fillValueF 9663 9664 rvarvalst[tuple(cslice2D)] = varobj[tuple(cslicev)] 9664 9665 for iz in range(dimz): … … 9666 9667 zslice = [slice(iz,iz)]+cslice2Dhor 9667 9668 rvarvalst[tuple(zslice)] = np.where(circdist[tuple(tslice)] > \ 9668 np.float(Nrad), fillValue, rvarvalst[tuple(zslice)])9669 np.float(Nrad), gen.fillValueF, rvarvalst[tuple(zslice)]) 9669 9670 9670 9671 rvarvals[it,:,:,:] = rvarvalst 9671 9672 9672 9673 # circle stats values 9673 maskedvals = ma.masked_values (rvarvalst, fillValue)9674 maskedvals = ma.masked_values (rvarvalst, gen.fillValueF) 9674 9675 maskedvals2 = maskedvals*maskedvals 9675 9676 for iz in range(dimz): … … 9707 9708 tslice = [it]+cslicevnoThor 9708 9709 rvarvalst[iz,:,:] = np.where(circdist[tuple(tslice)] > \ 9709 np.float(Nrad), fillValue, rvarvalst[iz,:,:])9710 np.float(Nrad), gen.fillValueF, rvarvalst[iz,:,:]) 9710 9711 9711 9712 rvarvals[it,:,:,:] = rvarvalst 9712 9713 9713 9714 # circle stats values 9714 maskedvals = ma.masked_values (rvarvalst, fillValue)9715 maskedvals = ma.masked_values (rvarvalst, gen.fillValueF) 9715 9716 maskedvals2 = maskedvals*maskedvals 9716 9717 for iz in range(dimz): … … 9728 9729 # variable box values 9729 9730 newvar = objofile.createVariable(vnst + 'box', 'f4', ('time','z','y','x'),\ 9730 fill_value= fillValue)9731 if searchInlist(varobj.ncattrs(),'standard_name'):9731 fill_value=gen.fillValueF) 9732 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 9732 9733 vsname = varobj.getncattr('standard_name') 9733 9734 else: 9734 vsname = variables_values(vn)[1]9735 if searchInlist(varobj.ncattrs(),'long_name'):9735 vsname = gen.variables_values(vn)[1] 9736 if gen.searchInlist(varobj.ncattrs(),'long_name'): 9736 9737 vlname = varobj.getncattr('long_name') 9737 9738 else: 9738 vlname = variables_values(vn)[4].replace('|',' ')9739 if searchInlist(varobj.ncattrs(),'units'):9739 vlname = gen.variables_values(vn)[4].replace('|',' ') 9740 if gen.searchInlist(varobj.ncattrs(),'units'): 9740 9741 vunits = varobj.getncattr('units') 9741 9742 else: 9742 vunits = variables_values(vn)[5].replace('|',' ')9743 vunits = gen.variables_values(vn)[5].replace('|',' ') 9743 9744 9744 9745 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 9748 9749 # center of the trajectory 9749 9750 newvar = objofile.createVariable('trj_' + vnst, 'f', ('time','z'), \ 9750 fill_value= fillValue)9751 fill_value=gen.fillValueF) 9751 9752 newattr = basicvardef(newvar, 'trj_' + vsname, 'value along the ' + \ 9752 9753 'trajectory of '+ vn, vunits) … … 9757 9758 for statn in statnames: 9758 9759 newvar = objofile.createVariable(statn + '_' + vnst,'f',('time','z'),\ 9759 fill_value= fillValue)9760 fill_value=gen.fillValueF) 9760 9761 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 9761 9762 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + vnst, vunits) … … 9766 9767 # variable circle values 9767 9768 newvar = objofile.createVariable(vnst + 'circle','f4',('time','z','yr', \ 9768 'xr'), fill_value= fillValue)9769 if searchInlist(varobj.ncattrs(),'standard_name'):9769 'xr'), fill_value=gen.fillValueF) 9770 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 9770 9771 vsname = varobj.getncattr('standard_name') 9771 9772 else: 9772 vsname = variables_values(vn)[1]9773 if searchInlist(varobj.ncattrs(),'long_name'):9773 vsname = gen.variables_values(vn)[1] 9774 if gen.searchInlist(varobj.ncattrs(),'long_name'): 9774 9775 vlname = varobj.getncattr('long_name') 9775 9776 else: 9776 vlname = variables_values(vn)[4].replace('|',' ')9777 if searchInlist(varobj.ncattrs(),'units'):9777 vlname = gen.variables_values(vn)[4].replace('|',' ') 9778 if gen.searchInlist(varobj.ncattrs(),'units'): 9778 9779 vunits = varobj.getncattr('units') 9779 9780 else: 9780 vunits = variables_values(vn)[5].replace('|',' ')9781 vunits = gen.variables_values(vn)[5].replace('|',' ') 9781 9782 9782 9783 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 9788 9789 for statn in cstatnames: 9789 9790 newvar = objofile.createVariable(statn + '_' + vnst,'f',('time','z'),\ 9790 fill_value= fillValue)9791 fill_value=gen.fillValueF) 9791 9792 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 9792 9793 ' the circle of radius ('+ str(circler)+') of ' + vnst, vunits) … … 9834 9835 slice2D.append(slice(0,xrangeslice[it][1]-xrangeslice[it][0])) 9835 9836 9836 rvarvalst = np.ones((Nrad*2+1, Nrad*2+1),dtype=np.float)* fillValue9837 rvarvalst = np.ones((Nrad*2+1, Nrad*2+1),dtype=np.float)*gen.fillValueF 9837 9838 varvalst[tuple(slice2D)] = varobj[tuple(slicev)] 9838 9839 varvals[it,:,:] = varvalst 9839 9840 9840 9841 # box stats values 9841 maskedvals = ma.masked_values (varvalst, fillValue)9842 maskedvals = ma.masked_values (varvalst, gen.fillValueF) 9842 9843 statvarvals[it,0] = varvalst[box2,box2] 9843 9844 statvarvals[it,1] = maskedvals.min() … … 9905 9906 cslice2D.append(slice(0,maxx - cxrangeslice[it][0])) 9906 9907 9907 rvarvalst = np.ones((Nrad*2+1,Nrad*2+1),dtype=np.float)* fillValue9908 rvarvalst = np.ones((Nrad*2+1,Nrad*2+1),dtype=np.float)*gen.fillValueF 9908 9909 rvarvalst[tuple(cslice2D)] = varobj[tuple(cslicev)] 9909 9910 rvarvalst[tuple(cslice2D)] = np.where(circdist[tuple(cslicev)] >\ 9910 np.float(Nrad), fillValue, rvarvalst[tuple(cslice2D)])9911 np.float(Nrad), gen.fillValueF, rvarvalst[tuple(cslice2D)]) 9911 9912 9912 9913 rvarvals[it,:,:] = rvarvalst 9913 9914 9914 9915 # circle stats values 9915 maskedvals = ma.masked_values (rvarvalst, fillValue)9916 maskedvals = ma.masked_values (rvarvalst, gen.fillValueF) 9916 9917 rstatvarvals[it,0] = rvarvalst[Nrad,Nrad] 9917 9918 rstatvarvals[it,1] = maskedvals.min() … … 9942 9943 cdist = circdist[tuple(cslicevC)] 9943 9944 # circle values 9944 rvarvalst = np.where(cdist > np.float(Nrad), fillValue,rvarvalst)9945 rvarvalst = np.where(cdist > np.float(Nrad),gen.fillValueF,rvarvalst) 9945 9946 rvarvals[it,:,:] = rvarvalst 9946 9947 9947 9948 # circle stats values 9948 maskedvals = ma.masked_values (rvarvalst, fillValue)9949 maskedvals = ma.masked_values (rvarvalst, gen.fillValueF) 9949 9950 rstatvarvals[it,0] = rvarvalst[Nrad,Nrad] 9950 9951 rstatvarvals[it,1] = maskedvals.min() … … 9961 9962 # variable box values 9962 9963 newvar = objofile.createVariable(vnst + 'box', 'f4', ('time', 'y', 'x'), \ 9963 fill_value= fillValue)9964 if searchInlist(varobj.ncattrs(),'standard_name'):9964 fill_value=gen.fillValueF) 9965 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 9965 9966 vsname = varobj.getncattr('standard_name') 9966 9967 else: 9967 vsname = variables_values(vn)[1]9968 if searchInlist(varobj.ncattrs(),'long_name'):9968 vsname = gen.variables_values(vn)[1] 9969 if gen.searchInlist(varobj.ncattrs(),'long_name'): 9969 9970 vlname = varobj.getncattr('long_name') 9970 9971 else: 9971 vlname = variables_values(vn)[4].replace('|',' ')9972 if searchInlist(varobj.ncattrs(),'units'):9972 vlname = gen.variables_values(vn)[4].replace('|',' ') 9973 if gen.searchInlist(varobj.ncattrs(),'units'): 9973 9974 vunits = varobj.getncattr('units') 9974 9975 else: 9975 vunits = variables_values(vn)[5].replace('|',' ')9976 vunits = gen.variables_values(vn)[5].replace('|',' ') 9976 9977 9977 9978 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 9981 9982 # center of the trajectory 9982 9983 newvar = objofile.createVariable('trj_' + vnst, 'f', ('time'), \ 9983 fill_value= fillValue)9984 fill_value=gen.fillValueF) 9984 9985 newattr = basicvardef(newvar, 'trj_' + vsname, 'value along the ' + \ 9985 9986 'trajectory of '+ vnst, vunits) … … 9990 9991 for statn in statnames: 9991 9992 newvar = objofile.createVariable(statn + '_' + vnst, 'f', ('time'), \ 9992 fill_value= fillValue)9993 fill_value=gen.fillValueF) 9993 9994 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 9994 9995 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + vnst, vunits) … … 9999 10000 # variable circle values 10000 10001 newvar = objofile.createVariable(vnst + 'circle','f4',('time','yr','xr'),\ 10001 fill_value= fillValue)10002 if searchInlist(varobj.ncattrs(),'standard_name'):10002 fill_value=gen.fillValueF) 10003 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 10003 10004 vsname = varobj.getncattr('standard_name') 10004 10005 else: 10005 vsname = variables_values(vn)[1]10006 if searchInlist(varobj.ncattrs(),'long_name'):10006 vsname = gen.variables_values(vn)[1] 10007 if gen.searchInlist(varobj.ncattrs(),'long_name'): 10007 10008 vlname = varobj.getncattr('long_name') 10008 10009 else: 10009 vlname = variables_values(vn)[4].replace('|',' ')10010 if searchInlist(varobj.ncattrs(),'units'):10010 vlname = gen.variables_values(vn)[4].replace('|',' ') 10011 if gen.searchInlist(varobj.ncattrs(),'units'): 10011 10012 vunits = varobj.getncattr('units') 10012 10013 else: 10013 vunits = variables_values(vn)[5].replace('|',' ')10014 vunits = gen.variables_values(vn)[5].replace('|',' ') 10014 10015 10015 10016 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 10021 10022 for statn in cstatnames: 10022 10023 newvar = objofile.createVariable(statn + '_' + vnst, 'f', ('time'), \ 10023 fill_value= fillValue)10024 fill_value=gen.fillValueF) 10024 10025 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 10025 10026 ' the circle of radius ('+ str(circler)+') of ' + vnst, vunits) … … 10056 10057 10057 10058 newvar = objofile.createVariable('lon', 'f8', ('time', 'y', 'x'), \ 10058 fill_value= fillValue)10059 fill_value=gen.fillValueF) 10059 10060 newattr = basicvardef(newvar, 'longitude', 'longitude', \ 10060 10061 'degrees west_east') … … 10062 10063 10063 10064 newvar = objofile.createVariable('lat', 'f8', ('time', 'y', 'x'), \ 10064 fill_value= fillValue)10065 fill_value=gen.fillValueF) 10065 10066 newattr = basicvardef(newvar, 'latitude', 'latitude', \ 10066 10067 'degrees north_south') … … 10071 10072 10072 10073 # global attributes 10073 objofile.setncattr('author', 'L. Fita') 10074 objofile.setncattr('institution', 'Laboratire de Meteorologie Dynamique') 10075 objofile.setncattr('university', 'Pierre Marie Curie - Jussieu') 10076 objofile.setncattr('center', 'Centre National de Recherches Scientifiques') 10077 objofile.setncattr('city', 'Paris') 10078 objofile.setncattr('country', 'France') 10079 objofile.setncattr('script', 'nc_var_tools.py') 10080 objofile.setncattr('function', 'compute_tevolboxtraj') 10081 objofile.setncattr('version', '1.0') 10074 add_global_PyNCplot(objofile, 'nc_var_tools', fname, '1.1') 10082 10075 objofile.setncattr('data_file',ncfile) 10083 10076 … … 10358 10351 varattrs = ovar.ncattrs() 10359 10352 10360 if searchInlist(varattrs,'std_name'):10353 if gen.searchInlist(varattrs,'std_name'): 10361 10354 stdn = ovar.getncattr('std_name') 10362 10355 else: 10363 vvalues = variables_values(ovar._name)10356 vvalues = gen.variables_values(ovar._name) 10364 10357 stdn = vvalues[1] 10365 10358 10366 if searchInlist(varattrs,'long_name'):10359 if gen.searchInlist(varattrs,'long_name'): 10367 10360 lonn = ovar.getncattr('long_name') 10368 10361 else: 10369 10362 lonn = vvalues[4].replace('|',' ') 10370 10363 10371 if searchInlist(varattrs,'units'):10364 if gen.searchInlist(varattrs,'units'): 10372 10365 un = ovar.getncattr('units') 10373 10366 else: … … 11108 11101 nvals = len(listline) 11109 11102 if nvals > 0: 11110 if searchInlist(add1,listline[0]):11103 if gen.searchInlist(add1,listline[0]): 11111 11104 nmlval = int(listline[nvals-1].replace(',','')) + 1 11112 11105 onmlobj.write(' ' + listline[0] + ' = ' + str(nmlval) + ',\n') 11113 elif searchInlist(add1value,listline[0]):11106 elif gen.searchInlist(add1value,listline[0]): 11114 11107 if Ndomref == 1: 11115 11108 nmlval = 1 … … 11118 11111 onmlobj.write(' ' + listline[0] + ' = ' + \ 11119 11112 numVector_String(listline[2:nvals+1], ' ') + ' ' +str(nmlval)+',\n') 11120 elif searchInlist(repeatvalue,listline[0]):11113 elif gen.searchInlist(repeatvalue,listline[0]): 11121 11114 nmlval = listline[nvals-1] 11122 11115 onmlobj.write(' ' + listline[0] + ' = ' + \ … … 12630 12623 newnc.createDimension(dimn, len(dimobj)) 12631 12624 12632 if searchInlist(varvobj.ncattrs(),'_FillValue'):12625 if gen.searchInlist(varvobj.ncattrs(),'_FillValue'): 12633 12626 vfillValue = varvobj._FillValue 12634 12627 else: … … 12636 12629 12637 12630 vtype = varvobj.dtype 12638 if searchInlist(dimvhorns,vn):12631 if gen.searchInlist(dimvhorns,vn): 12639 12632 print ' ' + fname + ': dimension values variable!' 12640 12633 print " keeping original values as '" + vn + "' and filtered as '" + \ … … 12651 12644 newvar = newnc.createVariable(vn, vtype, vardims, fill_value = fillValue) 12652 12645 12653 if searchInlist(vardims,dimnh1) or searchInlist(vardims,dimnh2):12646 if gen.searchInlist(vardims,dimnh1) or searchInlist(vardims,dimnh2): 12654 12647 varv = varvobj[:] 12655 12648 varfilt = varvobj[:] 12656 12649 dimh1id = -1 12657 12650 dimh2id = -1 12658 if searchInlist(vardims,dimnh1): dimh1id= vardims.index(dimnh1)12659 if searchInlist(vardims,dimnh2): dimh2id= vardims.index(dimnh2)12651 if gen.searchInlist(vardims,dimnh1): dimh1id= vardims.index(dimnh1) 12652 if gen.searchInlist(vardims,dimnh2): dimh2id= vardims.index(dimnh2) 12660 12653 12661 12654 if dimh1id != -1 and dimh2id != -1: … … 13221 13214 varatts = vno.ncattrs() 13222 13215 13223 if searchInlist(varatts, '_FillValue'):13216 if gen.searchInlist(varatts, '_FillValue'): 13224 13217 fillv = vno.getncattr('_FillValue') 13225 13218 newvar = newnc.createVariable(vn, vtype, vdim, fill_value=fillv) … … 13276 13269 13277 13270 dims = onc.dimensions 13278 if searchInlist(dims, dimname):13271 if gen.searchInlist(dims, dimname): 13279 13272 print errormsg 13280 13273 print ' ' + fname + ": file '" + ncfile + "' already has dimension '" + \ … … 13356 13349 varatts = vno.ncattrs() 13357 13350 13358 if searchInlist(varatts, '_FillValue'):13351 if gen.searchInlist(varatts, '_FillValue'): 13359 13352 fillv = vno.getncattr('_FillValue') 13360 13353 newvar = newnc.createVariable(vn, vtype, vdim, fill_value=fillv) … … 13450 13443 quit(-1) 13451 13444 13452 if searchInlist(varatts, '_FillValue'):13445 if gen.searchInlist(varatts, '_FillValue'): 13453 13446 fillv = varo.getncattr('_FillValue') 13454 13447 newvar = newnc.createVariable(varn, newtype, vardims, fill_value=fillv) … … 13472 13465 varatts = vno.ncattrs() 13473 13466 13474 if searchInlist(varatts, '_FillValue'):13467 if gen.searchInlist(varatts, '_FillValue'): 13475 13468 fillv = vno.getncattr('_FillValue') 13476 13469 newvar = newnc.createVariable(vn, vtype, vdim, fill_value=fillv) … … 13755 13748 else: 13756 13749 for ir in trjSQradii[it].keys(): 13757 if searchInlist(TOTradii,ir): TOTradii.append(ir)13750 if gen.searchInlist(TOTradii,ir): TOTradii.append(ir) 13758 13751 it = it + 1 13759 13752 iline = iline + 1 … … 13800 13793 13801 13794 for vn in varns: 13802 vnst = variables_values(vn)[0]13795 vnst = gen.variables_values(vn)[0] 13803 13796 if not searchInlist(objfile.variables, vn): 13804 13797 print errormsg … … 13835 13828 objofile.createDimension('z', dimz) 13836 13829 newvar = objofile.createVariable(zn, 'f4', ('z'),fill_value=fillValue) 13837 if searchInlist(varzobj.ncattrs(),'standard_name'):13830 if gen.searchInlist(varzobj.ncattrs(),'standard_name'): 13838 13831 vsname = varzobj.getncattr('standard_name') 13839 13832 else: 13840 vsname = variables_values(zn)[1]13841 if searchInlist(varzobj.ncattrs(),'long_name'):13833 vsname = gen.variables_values(zn)[1] 13834 if gen.searchInlist(varzobj.ncattrs(),'long_name'): 13842 13835 vlname = varzobj.getncattr('long_name') 13843 13836 else: 13844 vlname = variables_values(zn)[4].replace('|',' ')13845 if searchInlist(varzobj.ncattrs(),'units'):13837 vlname = gen.variables_values(zn)[4].replace('|',' ') 13838 if gen.searchInlist(varzobj.ncattrs(),'units'): 13846 13839 vunits = varzobj.getncattr('units') 13847 13840 else: 13848 vunits = variables_values(zn)[5].replace('|',' ')13841 vunits = gen.variables_values(zn)[5].replace('|',' ') 13849 13842 13850 13843 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 14055 14048 newvar = objofile.createVariable(vnst + 'box', 'f4', ('time','z','y','x'),\ 14056 14049 fill_value=fillValue) 14057 if searchInlist(varobj.ncattrs(),'standard_name'):14050 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 14058 14051 vsname = varobj.getncattr('standard_name') 14059 14052 else: 14060 vsname = variables_values(vn)[1]14061 if searchInlist(varobj.ncattrs(),'long_name'):14053 vsname = gen.variables_values(vn)[1] 14054 if gen.searchInlist(varobj.ncattrs(),'long_name'): 14062 14055 vlname = varobj.getncattr('long_name') 14063 14056 else: 14064 vlname = variables_values(vn)[4].replace('|',' ')14065 if searchInlist(varobj.ncattrs(),'units'):14057 vlname = gen.variables_values(vn)[4].replace('|',' ') 14058 if gen.searchInlist(varobj.ncattrs(),'units'): 14066 14059 vunits = varobj.getncattr('units') 14067 14060 else: 14068 vunits = variables_values(vn)[5].replace('|',' ')14061 vunits = gen.variables_values(vn)[5].replace('|',' ') 14069 14062 14070 14063 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 14093 14086 newvar = objofile.createVariable(vnst + 'circle','f4',('time','z','yr', \ 14094 14087 'xr'), fill_value=fillValue) 14095 if searchInlist(varobj.ncattrs(),'standard_name'):14088 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 14096 14089 vsname = varobj.getncattr('standard_name') 14097 14090 else: 14098 vsname = variables_values(vn)[1]14099 if searchInlist(varobj.ncattrs(),'long_name'):14091 vsname = gen.variables_values(vn)[1] 14092 if gen.searchInlist(varobj.ncattrs(),'long_name'): 14100 14093 vlname = varobj.getncattr('long_name') 14101 14094 else: 14102 vlname = variables_values(vn)[4].replace('|',' ')14103 if searchInlist(varobj.ncattrs(),'units'):14095 vlname = gen.variables_values(vn)[4].replace('|',' ') 14096 if gen.searchInlist(varobj.ncattrs(),'units'): 14104 14097 vunits = varobj.getncattr('units') 14105 14098 else: 14106 vunits = variables_values(vn)[5].replace('|',' ')14099 vunits = gen.variables_values(vn)[5].replace('|',' ') 14107 14100 14108 14101 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 14290 14283 newvar = objofile.createVariable(vnst + 'box', 'f4', ('time', 'y', 'x'), \ 14291 14284 fill_value=fillValue) 14292 if searchInlist(varobj.ncattrs(),'standard_name'):14285 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 14293 14286 vsname = varobj.getncattr('standard_name') 14294 14287 else: 14295 vsname = variables_values(vn)[1]14296 if searchInlist(varobj.ncattrs(),'long_name'):14288 vsname = gen.variables_values(vn)[1] 14289 if gen.searchInlist(varobj.ncattrs(),'long_name'): 14297 14290 vlname = varobj.getncattr('long_name') 14298 14291 else: 14299 vlname = variables_values(vn)[4].replace('|',' ')14300 if searchInlist(varobj.ncattrs(),'units'):14292 vlname = gen.variables_values(vn)[4].replace('|',' ') 14293 if gen.searchInlist(varobj.ncattrs(),'units'): 14301 14294 vunits = varobj.getncattr('units') 14302 14295 else: 14303 vunits = variables_values(vn)[5].replace('|',' ')14296 vunits = gen.variables_values(vn)[5].replace('|',' ') 14304 14297 14305 14298 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 14328 14321 newvar = objofile.createVariable(vnst + 'circle','f4',('time','yr','xr'),\ 14329 14322 fill_value=fillValue) 14330 if searchInlist(varobj.ncattrs(),'standard_name'):14323 if gen.searchInlist(varobj.ncattrs(),'standard_name'): 14331 14324 vsname = varobj.getncattr('standard_name') 14332 14325 else: 14333 vsname = variables_values(vn)[1]14334 if searchInlist(varobj.ncattrs(),'long_name'):14326 vsname = gen.variables_values(vn)[1] 14327 if gen.searchInlist(varobj.ncattrs(),'long_name'): 14335 14328 vlname = varobj.getncattr('long_name') 14336 14329 else: 14337 vlname = variables_values(vn)[4].replace('|',' ')14338 if searchInlist(varobj.ncattrs(),'units'):14330 vlname = gen.variables_values(vn)[4].replace('|',' ') 14331 if gen.searchInlist(varobj.ncattrs(),'units'): 14339 14332 vunits = varobj.getncattr('units') 14340 14333 else: 14341 vunits = variables_values(vn)[5].replace('|',' ')14334 vunits = gen.variables_values(vn)[5].replace('|',' ') 14342 14335 14343 14336 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 14491 14484 DT = endT - iniT 14492 14485 # Python version depending 14493 if searchInlist(dir(DT), 'total_seconds'):14486 if gen.searchInlist(dir(DT), 'total_seconds'): 14494 14487 diffT = DT.total_seconds() 14495 14488 else: … … 14503 14496 foundclosest = False 14504 14497 for fn in ncobjs.keys(): 14505 if searchInlist(ncobjs[fn], dtv):14498 if gen.searchInlist(ncobjs[fn], dtv): 14506 14499 istep = ncobjs[fn].index(dtv) 14507 14500 … … 14515 14508 DT = endT - iniT 14516 14509 # Python version depending 14517 if searchInlist(dir(DT), 'total_seconds'):14510 if gen.searchInlist(dir(DT), 'total_seconds'): 14518 14511 diffitv = np.abs(DT.total_seconds()) 14519 14512 else: … … 14671 14664 # Removing time dimension from the variable dimensions 14672 14665 Vndims = oVn.dimensions 14673 if searchInlist(Vndims, tdim) and Vn != tvdim:14666 if gen.searchInlist(Vndims, tdim) and Vn != tvdim: 14674 14667 varNOtdimns = [] 14675 14668 varNOtdimvs = []
Note: See TracChangeset
for help on using the changeset viewer.