- Timestamp:
- Apr 8, 2015, 4:01:25 PM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r383 r396 519 519 odimyu = objdimy.getncattr('units') 520 520 521 # Getting only t at dimensions with coincident names521 # Getting only that dimensions with coincident names 522 522 dimnvx = objdimx.dimensions 523 523 cutslice = [] … … 580 580 581 581 if mapvalue == 'None': mapvalue = None 582 583 print ' ' + fname + ': Lluis shapes valshad:',valshad.shape,'valcont:',valcont.shape584 582 585 583 drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu, \ … … 764 762 if vdimxn == timename: 765 763 timevals = objsf.variables[vdimxn][:] 764 timedims = objsf.variables[vdimxn].dimensions 766 765 dimt = 'x' 767 766 ovalaxis = objsf.variables[vdimyn] … … 769 768 elif vdimyn == timename: 770 769 timevals = objsf.variables[vdimyn][:] 770 timedims = objsf.variables[vdimyn].dimensions 771 771 dimt = 'y' 772 772 ovalaxis = objsf.variables[vdimxn] … … 779 779 timepos, timelabels = drw.CFtimes_plot(timevals, timeunit, timekind, timefmt) 780 780 781 if len(ovalaxis.shape) <= 2: 782 ovalaxisv = ovalaxis[:] 783 784 elif len(ovalaxis.shape) == 3: 785 ovalaxisv = ovalaxis[0,:] 786 else: 787 print errormsg 788 print ' ' + fname + ': shape of dimension variable:', ovalaxis.shape, \ 789 ' not ready!!' 790 quit(-1) 781 # Getting only that dimensions with coincident names 782 dimnvx = ovalaxis.dimensions 783 784 cutslice = [] 785 for idimn in dimsshad: 786 found = False 787 for dimsn in dimnvx: 788 if idimn == dimsn: 789 cutslice.append(slice(0,len(objsf.dimensions[idimn]))) 790 found = True 791 if not found: cutslice.append(0) 792 793 ovalaxisv = ovalaxis[tuple(cutslice)] 794 795 ## if len(ovalaxis.shape) <= 2: 796 ## ovalaxisv = ovalaxis[:] 797 798 ## elif len(ovalaxis.shape) == 3: 799 ## ovalaxisv = ovalaxis[0,:] 800 ## else: 801 ## print errormsg 802 ## print ' ' + fname + ': shape of dimension variable:', ovalaxis.shape, \ 803 ## ' not ready!!' 804 ## quit(-1) 791 805 792 806 if countlabelfmt == 'None': … … 1922 1936 dimxv = dimtvalues[0:dimtsqx] 1923 1937 dimyv = dimtvalues[0:dimt:dimtsqx] 1924 1925 print 'Lluis lens: dimxv, dimyv:',len(dimxv), len(dimyv)1926 1938 1927 1939 dimn = ['time','time'] -
trunk/tools/drawing_tools.py
r385 r396 201 201 202 202 Ndimcut = len(dimslice.split('|')) 203 if Ndimcut == 0: 204 Ndimcut = 1 205 dimcut = list(dimslice) 206 203 207 dimsl = dimslice.split('|') 204 208 … … 207 211 208 212 for idd in range(Ndimvar): 213 found = False 209 214 for idc in range(Ndimcut): 210 215 dimcutn = dimsl[idc].split(':')[0] 211 216 dimcutv = dimsl[idc].split(':')[1] 212 if vardims[idd] == dimcutn: 213 posfrac = dimcutv.find(' :')217 if vardims[idd] == dimcutn: 218 posfrac = dimcutv.find('@') 214 219 if posfrac != -1: 215 inifrac = int(dimcutv.split(' :')[0])216 endfrac = int(dimcutv.split(' :')[1])220 inifrac = int(dimcutv.split('@')[0]) 221 endfrac = int(dimcutv.split('@')[1]) 217 222 varvalsdim.append(slice(inifrac,endfrac)) 218 223 dimnslice.append(vardims[idd]) … … 221 226 varvalsdim.append(slice(0,varobj.shape[idd])) 222 227 dimnslice.append(vardims[idd]) 228 elif int(dimcutv) == -9: 229 varvalsdim.append(int(varobj.shape[idd])-1) 223 230 else: 224 231 varvalsdim.append(int(dimcutv)) 225 232 break 233 if not found and not searchInlist(dimnslice,vardims[idd]): 234 varvalsdim.append(slice(0,varobj.shape[idd])) 235 dimnslice.append(vardims[idd]) 226 236 227 237 varvalues = varobj[tuple(varvalsdim)] … … 1447 1457 elif u == 'kg/(s*m2)': lu='$kgm^{-2}s^{-1}$' 1448 1458 elif u == 'kgm-2s-1': lu='$kgm^{-2}s^{-1}$' 1459 elif u == 'kg m-2 s-1': lu='$kgm^{-2}s^{-1}$' 1449 1460 elif u == '1/m': lu='$m^{-1}$' 1450 1461 elif u == 'm-1': lu='$m^{-1}$' … … 1583 1594 1584 1595 potinterval = np.log10(interval) 1585 print 'LLuis minv, maxv:',minv,maxv,'potinterval:',potinterval1586 1596 Ipotint = int(potinterval) 1587 1597 intvalue = np.float(interval / np.float(Nint)) … … 3692 3702 fname = 'plot_2D_shadow_contour' 3693 3703 3704 3694 3705 if varsv == 'h': 3695 3706 print fname + '_____________________________________________________________' … … 3816 3827 else: 3817 3828 y = np.zeros((dimxv.shape), dtype=np.float) 3818 print 'Lluis shapes y:',y.shape,'dimyv:',dimyv.shape,'dimxv:',dimxv.shape3819 3829 3820 3830 if y.shape[0] == dimyv.shape[0]: -
trunk/tools/nc_var_tools.py
r392 r396 10695 10695 dimt = objfile.variables[timn].shape 10696 10696 10697 print 'Lluis Ttraj:',Ttraj+Tbeg,'dimt:',dimt10698 10699 10697 if Tbeg + Ttraj > dimt: 10700 10698 print errormsg … … 10979 10977 fillValue 10980 10978 10981 print 'Lluis slice2D:',slice2D,'slicev:',slicev10982 10979 varvalst[tuple(slice2D)] = varobj[tuple(slicev)] 10983 10980 varvals[it,:,:,:] = varvalst … … 11935 11932 11936 11933 Ndimcut = len(dimslice.split('|')) 11934 if Ndimcut == 0: 11935 Ndimcut = 1 11936 dimcut = list(dimslice) 11937 11937 11938 dimsl = dimslice.split('|') 11938 11939 … … 11941 11942 11942 11943 for idd in range(Ndimvar): 11944 found = False 11943 11945 for idc in range(Ndimcut): 11944 11946 dimcutn = dimsl[idc].split(':')[0] … … 11960 11962 varvalsdim.append(int(dimcutv)) 11961 11963 break 11964 if not found and not searchInlist(dimnslice,vardims[idd]): 11965 varvalsdim.append(slice(0,varobj.shape[idd])) 11966 dimnslice.append(vardims[idd]) 11962 11967 11963 11968 varvalues = varobj[tuple(varvalsdim)] … … 11994 11999 11995 12000 if Nvardims != Ncutdims: 11996 print errormsg12001 print warnmsg 11997 12002 print ' ' + fname + ': cutting for',Ncutdims,'but variable has:',Nvardims, \ 11998 12003 '!!' 11999 quit(-1)12000 12001 for id c in range(Ncutdims):12004 # quit(-1) 12005 cutdimvals = '' 12006 for idv in range(Nvardims): 12002 12007 found = False 12003 for idv in range(Nvardims): 12008 Lcutdimvals = len(cutdimvals) 12009 for idc in range(Ncutdims): 12004 12010 if vardims[idv] == cutdims[idc].split(':')[0]: 12011 if Lcutdimvals > 0: 12012 cutdimvals = cutdimvals + '|' + cutdims[idc] 12013 else: 12014 cutdimvals = cutdims[idc] 12015 12005 12016 found = True 12006 12017 break 12007 12018 if not found: 12008 print errormsg 12009 print ' ' + fname + ": cutting by '",cutdims[idc].split(':')[0], \ 12010 "' but variable has not it !!!" 12011 print ' variable dims:',vardims 12012 quit(-1) 12013 12014 slicedvar, dimslice = slice_variable(ovar, dimvals) 12019 # print errormsg 12020 # print ' ' + fname + ": cutting by '",cutdims[idc].split(':')[0], \ 12021 # "' but variable has not it !!!" 12022 # print ' variable dims:',vardims 12023 print warnmsg 12024 print ' ' + fname + ": variable has dimension '",vardims[idv], \ 12025 "' but is not cut taking all length !!!" 12026 if Lcutdimvals > 0: 12027 cutdimvals = cutdimvals + '|' + vardims[idv] + ':-1' 12028 else: 12029 cutdimvals = vardims[idv] + ':-1' 12030 # quit(-1) 12031 12032 slicedvar, dimslice = slice_variable(ovar, cutdimvals) 12015 12033 12016 12034 # operation … … 12085 12103 dimvn = values.split(',')[3] 12086 12104 12105 dimsoperS = numVector_String(dimsoper.split(':'),', ') 12087 12106 objnc = NetCDFFile(ncfile, 'r') 12088 12107 … … 12150 12169 objvdim = objnc.variables[vardims[ivdim]] 12151 12170 vdimtype = objvdim.dtype 12152 12153 dimsvdim = objvdim.dimensions 12154 dimvslice = [] 12155 dimvdims = [] 12156 for idmvd in range(len(dimsvdim)): 12157 found = False 12158 for idimv in range(len(newvardimns)): 12159 if dimsvdim[idmvd] == newvardimns[idimv]: 12160 dimvslice.append(slice(0,objvdim.shape[idmvd])) 12161 dimvdims.append(dimsvdim[idmvd]) 12162 found = True 12163 break 12164 if not found: 12165 print warnmsg 12166 print ' ' + fname + ": dimension '" + dimsvdim[idmvd] + \ 12167 "' not found !!" 12168 print " adding it for variable dimension: '" + \ 12169 vardims[ivdim] + "'" 12170 if not objnewnc.dimensions.has_key(dimsvdim[idmvd]): 12171 dsize = len(objnc.dimensions[dimsvdim[idmvd]]) 12172 objnewnc.createDimension(dimsvdim[idmvd], dsize) 12173 dimvslice.append(slice(len(objnc.dimensions[dimsvdim[idmvd]]))) 12174 dimvdims.append(dimsvdim[idmvd]) 12171 newdimvarv, newdimvardimns=operation_alongdims(objvdim,dimvals,dimsoper,operkind) 12172 12173 # Old method introducing new dimension if needed 12174 ## dimsvdim = objvdim.dimensions 12175 ## dimvslice = [] 12176 ## dimvdims = [] 12177 ## for idmvd in range(len(dimsvdim)): 12178 ## found = False 12179 ## for idimv in range(len(newvardimns)): 12180 ## if dimsvdim[idmvd] == newvardimns[idimv]: 12181 ## dimvslice.append(slice(0,objvdim.shape[idmvd])) 12182 ## dimvdims.append(dimsvdim[idmvd]) 12183 ## found = True 12184 ## break 12185 ## if not found: 12186 ## print warnmsg 12187 ## print ' ' + fname + ": dimension '" + dimsvdim[idmvd] + \ 12188 ## "' not found !!" 12189 ## print " adding it for variable dimension: '" + \ 12190 ## vardims[ivdim] + "'" 12191 ## if not objnewnc.dimensions.has_key(dimsvdim[idmvd]): 12192 ## dsize = len(objnc.dimensions[dimsvdim[idmvd]]) 12193 ## objnewnc.createDimension(dimsvdim[idmvd], dsize) 12194 ## dimvslice.append(slice(len(objnc.dimensions[dimsvdim[idmvd]]))) 12195 ## dimvdims.append(dimsvdim[idmvd]) 12175 12196 12176 12197 newvar = objnewnc.createVariable(vardims[ivdim], vdimtype, \ 12177 tuple( dimvdims))12178 newvar[:] = objvdim[tuple(dimvslice)]12198 tuple(newdimvardimns)) 12199 newvar[:] = newdimvarv 12179 12200 dimvattrs = objvdim.ncattrs() 12180 12201 for attrn in dimvattrs: 12181 12202 attrv = objvdim.getncattr(attrn) 12182 12203 newattr = set_attribute(newvar,attrn,attrv) 12204 12205 newattr = set_attribute(newvar, 'operation:', operkind + \ 12206 ' along ' + dimsoperS) 12183 12207 12184 12208 # new variable … … 12200 12224 else: 12201 12225 uname = variables_values(vn)[5] 12202 12203 dimsoperS = numVector_String(dimsoper.split(':'),', ')12204 12226 12205 12227 newvar = objnewnc.createVariable(varname + operkind, 'f4', … … 12505 12527 for indima in range(Ndimvar): 12506 12528 found = False 12507 print ' Lluis:',fname,dimns[indimv],dimvar[indima]12508 12529 if dimns[indimv] == dimvar[indima]: 12509 12530 found = True
Note: See TracChangeset
for help on using the changeset viewer.