- Timestamp:
- Jun 18, 2016, 11:22:06 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r889 r890 141 141 d[x/y/z/t]: dimensions of the variable 142 142 dn[x/y/z/t]: name of the dimensions of the variable 143 >>> variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time') 143 144 """ 144 145 def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt): 146 from collections import OrderedDict 145 147 totshape = dt*dz*dy*dx 146 147 self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx) 148 self. dimensionsdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx}149 self.dimensions = [dnt, dnz, dny, dnx]148 dimdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx} 149 150 self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx) 151 self.dimensions = OrderedDict(sorted(dimdict.items(), key=lambda t: t[0])) 150 152 self.shape = (dt, dz, dy, dx) 151 153 self.standard_name = 'general_var' … … 155 157 def __getitem__(self, val): 156 158 return self.values[val] 157 158 #variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')159 159 160 160 def varinfile(ncf, filen, emsg, vmsg, varn): … … 8848 8848 mean2, min, sum 8849 8849 """ 8850 8851 8850 fname = 'operation_alongdims' 8852 8851 … … 8965 8964 file_oper_alongdims(values, ncfile, varn) 8966 8965 values= [dimvals],[dimsoper],[opkind],[dimvn] 8967 [dimvals]; [dimname1] :[val1]|[dimdname2]:[val2]|[...[dimnameN]:[valN]]8966 [dimvals]; [dimname1]@[val1]|[dimdname2]@[val2]|[...[dimnameN]@[valN]] 8968 8967 [value]; 8969 8968 * [integer]: which value of the dimension … … 8987 8986 quit() 8988 8987 8989 dimvals = values.split(',')[0] 8988 dimvals = values.split(',')[0].split('@') 8990 8989 dimsoper = values.split(',')[1] 8991 8990 operkind = values.split(',')[2] … … 9013 9012 dimslice = {} 9014 9013 for dv in dimvals: 9015 dnv = dv.s lice('|')[0]9016 dvv = dv.s lice('|')[1]9014 dnv = dv.split('|')[0] 9015 dvv = dv.split('|')[1] 9017 9016 if dvv.find(':') != -1: 9018 beg = int(dvv.s lice(':')[0])9019 end = int(dvv.s lice(':')[1])9017 beg = int(dvv.split(':')[0]) 9018 end = int(dvv.split(':')[1]) 9020 9019 dimslice[dnv] = [beg, end, 1] 9021 9020 else: … … 9041 9040 tocompute = False 9042 9041 for vd in ov.dimensions: 9043 if searchInlist(dimsoper, vd): tocompute = True9042 if gen.searchInlist(dimsoper, vd): tocompute = True 9044 9043 9045 9044 if tocopmute: … … 9116 9115 # global attributes 9117 9116 objnewnc.setncattr('author', 'L. Fita') 9118 objnewnc.setncattr('institution', 'Laboratire de Meteorologie Dynamique') 9117 newattr = set_attributek(newncobj, 'institution', unicode('Laboratoire de M' + \ 9118 unichr(233) + 't' + unichr(233) + 'orologie Dynamique'), 'U') 9119 9119 objnewnc.setncattr('university', 'Pierre Marie Curie - Jussieu') 9120 9120 objnewnc.setncattr('center', 'Centre National de Recherches Scientifiques')
Note: See TracChangeset
for help on using the changeset viewer.