- Timestamp:
- Mar 18, 2015, 4:16:58 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r342 r362 144 144 return boolv 145 145 146 146 147 def variables_values(varName): 148 """ Function to provide values to plot the different variables values from ASCII file 149 'variables_values.dat' 150 variables_values(varName) 151 [varName]= name of the variable 152 return: [var name], [std name], [minimum], [maximum], 153 [long name]('|' for spaces), [units], [color palette] (following: 154 http://matplotlib.org/1.3.1/examples/color/colormaps_reference.html) 155 [varn]: original name of the variable 156 NOTE: It might be better doing it with an external ASII file. But then we 157 got an extra dependency... 158 >>> variables_values('WRFght') 159 ['z', 'geopotential_height', 0.0, 80000.0, 'geopotential|height', 'm2s-2', 'rainbow'] 160 """ 161 fname='variables_values' 162 163 if varName == 'h': 164 print fname + '_____________________________________________________________' 165 print variables_values.__doc__ 166 quit() 167 168 infile = 'variables_values.dat' 169 170 if not os.path.isfile(infile): 171 print errormsg 172 print ' ' + fname + ": File '" + infile + "' does not exist !!" 173 quit(-1) 174 175 # Variable name might come with a statistical surname... 176 stats=['min','max','mean','stdv', 'sum'] 177 178 ifst = False 179 for st in stats: 180 if varName.find(st) > -1: 181 print ' '+ fname + ": varibale '" + varName + "' with a statistical "+\ 182 " surname: '",st,"' !!" 183 Lst = len(st) 184 LvarName = len(varName) 185 varn = varName[0:LvarName - Lst] 186 ifst = True 187 break 188 if not ifst: 189 varn = varName 190 191 ncf = open('variables_values.dat', 'r') 192 193 for line in ncf: 194 if line[0:1] != '#': 195 values = line.replace('\n','').split(',') 196 if len(values) != 8: 197 print errormsg 198 print "problem in varibale:'", values[0], \ 199 'it should have 8 values and it has',len(values) 200 quit(-1) 201 202 if varn[0:6] == 'varDIM': 203 # Variable from a dimension (all with 'varDIM' prefix) 204 Lvarn = len(varn) 205 varvals = [varn[6:Lvarn+1], varn[6:Lvarn+1], 0., 1., \ 206 "variable|from|size|of|dimension|'" + varn[6:Lvarn+1] + "'", '1', \ 207 'rainbow'] 208 else: 209 varvals = [values[1].replace(' ',''), values[2].replace(' ',''), \ 210 np.float(values[3]), np.float(values[4]),values[5].replace(' ',''),\ 211 values[6].replace(' ',''), values[7].replace(' ','')] 212 if values[0] == varn: 213 print varvals 214 ncf.close() 215 return varvals 216 break 217 218 print errormsg 219 print ' ' + fname + ": variable '" + varn + "' not defined !!!" 220 quit(-1) 221 222 return 223 224 def variables_values_old(varName): 147 225 """ Function to provide values to plot the different variables 148 226 variables_values(varName)
Note: See TracChangeset
for help on using the changeset viewer.