Changeset 2265 in lmdz_wrf
- Timestamp:
- Dec 26, 2018, 4:07:49 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2264 r2265 27177 27177 return 27178 27178 27179 def area_weighted(values, ncfiles, variable): 27180 """ Function to provide an area weighted statistics within two different values 27181 of matrices assuming regular lon/lat projections without taking into account 27182 Earth's curvature 27183 [values]= [strict]:[stats] ':' separated list of values to refine the function 27184 [strict]: give an error if the area of the polygon from the 'reference' file 27185 is not fully covered with data from the 'get' file 27186 [stats]: ',' separated list of space-statistics within each `ref' grid to 27187 provide for each grid cell from the 'get' data 27188 'mean': weghted mean (always provided) 27189 'min': minimum value and is associated weight 27190 'max': maximum value and is associated weight 27191 'mean2': weghted quadratic mean 27192 'stddev': standard deviation 27193 [ncfiles]= ',' separated list of [netcdfref]:[dimvalsref],[netcdfget]:[dimvalsget] 27194 [netcdfref]: netCDF file name to be used as reference or destination 27195 [netcdfget]: netCDF file name to get the values to be space-weighted into 27196 destination 27197 [dimvalsref]/[dimvalsget]: ';' separated list of values indicating necessary 27198 data from each file 27199 [dimvals]= [dimxn];[varxn];[slicedim];[dimyn];[varyn];[slicedim] 27200 [dimxn]: name of the dimension along the x-axis 27201 [varxn]: name of the variable with the values of dimxn 27202 [slicedim]: series of values to define the slicing of the variable 27203 * [integer]: which value of the dimension 27204 * -1: all along the dimension 27205 * -9: last value of the dimension 27206 * [beg]@[end]@[freq] slice from [beg] to [end] every [freq] 27207 * NOTE, no dim name all the dimension size 27208 [variable]= ',' separated list of variables from 'get' file to area-weight into 27209 'ref' ('all, for all that variables with dimensions dimxn and dimyn) 27210 """ 27211 fname = 'area_weighted' 27212 27213 if values == 'h': 27214 print fname + '_____________________________________________________________' 27215 print area_weighted.__doc__ 27216 quit() 27217 27218 statsavail = ['mean', 'min', 'max', 'mean2', 'stddev'] 27219 27220 expectargs = '[strict]:[stats]' 27221 gen.check_arguments(fname, values, expectargs, ':') 27222 27223 strict = gen.Str_bool(values.split(':')[[0]) 27224 stats = values.split(':')[[0].split(',') 27225 27226 for stn in stats: 27227 if not gen.searchInlist(statsavail, stn): 27228 print errormsg 27229 print ' ' + fname + ": statistics '" + stn + "' not ready !!" 27230 print ' available ones:', statsavail 27231 quit(-1) 27232 27233 files = ncfiles.split(',') 27234 if len(files) != 2: 27235 print errormsg 27236 print ' ' + fname + ": wrong value for [ncfiles]: '" + ncfiles + '" !!" 27237 print " information for 2 files must be provided as '[netcdfref]:" + \ 27238 "[dimvalsref],[netcdfget]:[dimvalsget]'" 27239 quit(-1) 27240 27241 iif = 0 27242 for fileinf in files: 27243 expectargs = '[netcdfname]:[dimvals]' 27244 gen.check_arguments(fname, fileinf, expectargs, ':') 27245 27246 if iif == 0: 27247 netcdfrefn = fileinf.split(':')[0] 27248 dimvalsref = fileinf.split(':')[1].split(';') 27249 27250 if not os.path.isfile(netcdfrefn): 27251 print errormsg 27252 print ' ' + fname + ": reference file '" + netcdfrefn + \ 27253 "' does not exist !!" 27254 quit(-1) 27255 27256 if len(dimvalsref) != 6: 27257 print errormsg 27258 print ' ' + fname + ": wrong number of dimension-values !!" 27259 print ' 6 values are expected and you provided', len(dimvalsref) 27260 print " values must be '[dimxn];[varxn];[slicedim];[dimyn];" + \ 27261 "[varyn];[slicedim]'" 27262 quit(-1) 27263 27264 oncref = NetCDFFile(netcdfrefn, 'r') 27265 27266 refdimxn = dimvalsref[0] 27267 refvarxn = dimvalsref[0] 27268 slicedimx = dimvalsref[0] 27269 dimxn = dimvalsref[0] 27270 27271 27272 27273 27274 elif: 27275 netcdfgetn = fileinf.split(':')[0] 27276 dimvalsget = fileinf.split(':')[1].split(';') 27277 iif = iif + 1 27278 27279 # Getting values 27280 27281 27282 27283 return 27179 27284 27180 27285 #quit()
Note: See TracChangeset
for help on using the changeset viewer.