Changeset 290 in lmdz_wrf
- Timestamp:
- Feb 25, 2015, 5:24:36 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r289 r290 10259 10259 check_arguments(fname,len(arguments.split(',')),arguments,',',8) 10260 10260 10261 ofile = 'tevolboxtraj_' + varn + '.nc'10261 ofile = 'tevolboxtraj_' + varn.replace(',','-') + '.nc' 10262 10262 10263 10263 trajfile = values.split(',')[0].split('@')[0] … … 10325 10325 timv = timobj[:] 10326 10326 10327 if not searchInlist(objfile.variables, varn):10328 print errormsg10329 print ' ' + fname + ": variable name '" + varn + "' is not in file " + \10330 ncfile + '" !!!!!'10331 quit(-1)10332 10327 10333 10328 # Selecting accordingly a trajectory … … 10522 10517 ## 10523 10518 ivar = 0 10524 print 'Lluis varns:',varns10525 10519 10526 10520 for vn in varns: 10521 if not searchInlist(objfile.variables, vn): 10522 print errormsg 10523 print ' ' + fname + ": variable name '" + vn + "' is not in file " + \ 10524 ncfile + '" !!!!!' 10525 quit(-1) 10526 10527 10527 varobj = objfile.variables[vn] 10528 10528 Nvardims = len(varobj.shape) … … 10556 10556 vsname = varzobj.getncattr('standard_name') 10557 10557 else: 10558 vsname = variables_values( varn)[1]10558 vsname = variables_values(zn)[1] 10559 10559 if searchInlist(varzobj.ncattrs(),'long_name'): 10560 10560 vlname = varzobj.getncattr('long_name') 10561 10561 else: 10562 vlname = variables_values( varn)[4].replace('|',' ')10562 vlname = variables_values(zn)[4].replace('|',' ') 10563 10563 if searchInlist(varzobj.ncattrs(),'units'): 10564 10564 vunits = varzobj.getncattr('units') 10565 10565 else: 10566 vunits = variables_values( varn)[5].replace('|',' ')10566 vunits = variables_values(zn)[5].replace('|',' ') 10567 10567 10568 10568 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 10697 10697 maskedvals2 = maskedvals*maskedvals 10698 10698 for iz in range(dimz): 10699 rtatvarvals[it, :,0] = varvalst[:,box2,box2]10699 rtatvarvals[it,iz,0] = varvalst[iz,box2,box2] 10700 10700 rtatvarvals[it,iz,1] = np.min(varvalst[iz,:,:]) 10701 10701 rtatvarvals[it,iz,2] = np.max(varvalst[iz,:,:]) … … 10727 10727 10728 10728 rvarvalst = varobj[tuple(cslicev)] 10729 cdist = circdist[tuple([it] + cslicevnoThor)]10730 10729 # circle values 10731 10730 for iz in range(dimz): … … 10741 10740 for iz in range(dimz): 10742 10741 rstatvarvals[it,iz,0] = rvarvalst[iz,Nrad,Nrad] 10743 rstatvarvals[it,iz,1] = maskedvals .min()10744 rstatvarvals[it,iz,2] = maskedvals .max()10745 rstatvarvals[it,iz,3] = maskedvals .mean()10742 rstatvarvals[it,iz,1] = maskedvals[iz,:,:].min() 10743 rstatvarvals[it,iz,2] = maskedvals[iz,:,:].max() 10744 rstatvarvals[it,iz,3] = maskedvals[iz,:,:].mean() 10746 10745 rstatvarvals[it,iz,4] = maskedvals2[iz,:,:].mean() 10747 10746 rstatvarvals[it,iz,5] = np.sqrt(rstatvarvals[it,iz,4] - \ … … 10751 10750 10752 10751 # variable box values 10753 newvar = objofile.createVariable(v arn + 'box', 'f4', ('time','z','y','x'),\10752 newvar = objofile.createVariable(vn + 'box', 'f4', ('time','z','y','x'),\ 10754 10753 fill_value=fillValue) 10755 10754 if searchInlist(varobj.ncattrs(),'standard_name'): 10756 10755 vsname = varobj.getncattr('standard_name') 10757 10756 else: 10758 vsname = variables_values(v arn)[1]10757 vsname = variables_values(vn)[1] 10759 10758 if searchInlist(varobj.ncattrs(),'long_name'): 10760 10759 vlname = varobj.getncattr('long_name') 10761 10760 else: 10762 vlname = variables_values(v arn)[4].replace('|',' ')10761 vlname = variables_values(vn)[4].replace('|',' ') 10763 10762 if searchInlist(varobj.ncattrs(),'units'): 10764 10763 vunits = varobj.getncattr('units') 10765 10764 else: 10766 vunits = variables_values(v arn)[5].replace('|',' ')10765 vunits = variables_values(vn)[5].replace('|',' ') 10767 10766 10768 10767 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 10771 10770 10772 10771 # center of the trajectory 10773 newvar = objofile.createVariable('trj_' + v arn, 'f', ('time','z'), \10772 newvar = objofile.createVariable('trj_' + vn, 'f', ('time','z'), \ 10774 10773 fill_value=fillValue) 10775 10774 newattr = basicvardef(newvar, 'trj_' + vsname, 'value along the ' + \ 10776 'trajectory of '+ v arn, vunits)10775 'trajectory of '+ vn, vunits) 10777 10776 newvar[:] = statvarvals[:,:,0] 10778 10777 … … 10780 10779 ist = 0 10781 10780 for statn in statnames: 10782 newvar = objofile.createVariable(statn + '_' + v arn,'f',('time','z'),\10781 newvar = objofile.createVariable(statn + '_' + vn,'f',('time','z'), \ 10783 10782 fill_value=fillValue) 10784 10783 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 10785 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + v arn, vunits)10784 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + vn, vunits) 10786 10785 newvar[:] = statvarvals[:,:,ist+1] 10787 10786 # newattr = set_attributek(newvar,'_FillValue',fillValue,'npfloat') … … 10789 10788 10790 10789 # variable circle values 10791 newvar = objofile.createVariable(v arn + 'circle','f4',('time','z','yr',\10790 newvar = objofile.createVariable(vn + 'circle','f4',('time','z','yr', \ 10792 10791 'xr'), fill_value=fillValue) 10793 10792 if searchInlist(varobj.ncattrs(),'standard_name'): 10794 10793 vsname = varobj.getncattr('standard_name') 10795 10794 else: 10796 vsname = variables_values(v arn)[1]10795 vsname = variables_values(vn)[1] 10797 10796 if searchInlist(varobj.ncattrs(),'long_name'): 10798 10797 vlname = varobj.getncattr('long_name') 10799 10798 else: 10800 vlname = variables_values(v arn)[4].replace('|',' ')10799 vlname = variables_values(vn)[4].replace('|',' ') 10801 10800 if searchInlist(varobj.ncattrs(),'units'): 10802 10801 vunits = varobj.getncattr('units') 10803 10802 else: 10804 vunits = variables_values(v arn)[5].replace('|',' ')10803 vunits = variables_values(vn)[5].replace('|',' ') 10805 10804 10806 10805 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 10811 10810 ist = 0 10812 10811 for statn in cstatnames: 10813 newvar = objofile.createVariable(statn + '_' + v arn,'f',('time','z'),\10812 newvar = objofile.createVariable(statn + '_' + vn,'f',('time','z'),\ 10814 10813 fill_value=fillValue) 10815 10814 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 10816 ' the circle of radius ('+ str(circler)+') of ' + v arn, vunits)10815 ' the circle of radius ('+ str(circler)+') of ' + vn, vunits) 10817 10816 newvar[:] = rstatvarvals[:,:,ist+1] 10818 10817 # newattr = set_attributek(newvar,'_FillValue',fillValue,'npfloat') … … 10973 10972 10974 10973 # variable box values 10975 newvar = objofile.createVariable(v arn + 'box', 'f4', ('time', 'y', 'x'), \10974 newvar = objofile.createVariable(vn + 'box', 'f4', ('time', 'y', 'x'), \ 10976 10975 fill_value=fillValue) 10977 10976 if searchInlist(varobj.ncattrs(),'standard_name'): 10978 10977 vsname = varobj.getncattr('standard_name') 10979 10978 else: 10980 vsname = variables_values(v arn)[1]10979 vsname = variables_values(vn)[1] 10981 10980 if searchInlist(varobj.ncattrs(),'long_name'): 10982 10981 vlname = varobj.getncattr('long_name') 10983 10982 else: 10984 vlname = variables_values(v arn)[4].replace('|',' ')10983 vlname = variables_values(vn)[4].replace('|',' ') 10985 10984 if searchInlist(varobj.ncattrs(),'units'): 10986 10985 vunits = varobj.getncattr('units') 10987 10986 else: 10988 vunits = variables_values(v arn)[5].replace('|',' ')10987 vunits = variables_values(vn)[5].replace('|',' ') 10989 10988 10990 10989 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 10993 10992 10994 10993 # center of the trajectory 10995 newvar = objofile.createVariable('trj_' + v arn, 'f', ('time'), \10994 newvar = objofile.createVariable('trj_' + vn, 'f', ('time'), \ 10996 10995 fill_value=fillValue) 10997 10996 newattr = basicvardef(newvar, 'trj_' + vsname, 'value along the ' + \ 10998 'trajectory of '+ v arn, vunits)10997 'trajectory of '+ vn, vunits) 10999 10998 newvar[:] = statvarvals[:,0] 11000 10999 … … 11002 11001 ist = 0 11003 11002 for statn in statnames: 11004 newvar = objofile.createVariable(statn + '_' + v arn, 'f', ('time'),\11003 newvar = objofile.createVariable(statn + '_' + vn, 'f', ('time'), \ 11005 11004 fill_value=fillValue) 11006 11005 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 11007 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + v arn, vunits)11006 ' the box ('+str(boxs)+'x'+str(boxs)+') of ' + vn, vunits) 11008 11007 newvar[:] = statvarvals[:,ist+1] 11009 11008 # newattr = set_attributek(newvar,'_FillValue',fillValue,'npfloat') … … 11011 11010 11012 11011 # variable circle values 11013 newvar = objofile.createVariable(v arn + 'circle','f4',('time','yr','xr'),\11012 newvar = objofile.createVariable(vn + 'circle','f4',('time','yr','xr'),\ 11014 11013 fill_value=fillValue) 11015 11014 if searchInlist(varobj.ncattrs(),'standard_name'): 11016 11015 vsname = varobj.getncattr('standard_name') 11017 11016 else: 11018 vsname = variables_values(v arn)[1]11017 vsname = variables_values(vn)[1] 11019 11018 if searchInlist(varobj.ncattrs(),'long_name'): 11020 11019 vlname = varobj.getncattr('long_name') 11021 11020 else: 11022 vlname = variables_values(v arn)[4].replace('|',' ')11021 vlname = variables_values(vn)[4].replace('|',' ') 11023 11022 if searchInlist(varobj.ncattrs(),'units'): 11024 11023 vunits = varobj.getncattr('units') 11025 11024 else: 11026 vunits = variables_values(v arn)[5].replace('|',' ')11025 vunits = variables_values(vn)[5].replace('|',' ') 11027 11026 11028 11027 newattr = basicvardef(newvar, vsname, vlname, vunits) … … 11033 11032 ist = 0 11034 11033 for statn in cstatnames: 11035 newvar = objofile.createVariable(statn + '_' + v arn, 'f', ('time'), \11034 newvar = objofile.createVariable(statn + '_' + vn, 'f', ('time'), \ 11036 11035 fill_value=fillValue) 11037 11036 newattr = basicvardef(newvar, statn + '_' + vsname, vstlname[ist] + \ 11038 ' the circle of radius ('+ str(circler)+') of ' + v arn, vunits)11037 ' the circle of radius ('+ str(circler)+') of ' + vn, vunits) 11039 11038 newvar[:] = rstatvarvals[:,ist+1] 11040 11039 # newattr = set_attributek(newvar,'_FillValue',fillValue,'npfloat')
Note: See TracChangeset
for help on using the changeset viewer.