- Timestamp:
- Mar 11, 2019, 10:16:24 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2400 r2402 26116 26116 'hour': statistics within full hours [00:00 - 59:59] 26117 26117 'minute': statistics within full minutes [00 - 59] 26118 'agg'[tunit]: aggregation of multiple values to the same period [tunit] 26119 [tunit]: period to aggregate: year, month, day, hour, minute 26118 26120 [amount]: quantity of periods to group 26119 26121 [statn]: statistics to compute … … 26134 26136 Lperiodn = {'year': 'yearly', 'month': 'monthly', 'day': 'daily', \ 26135 26137 'LTday': 'local-time daily', 'hour': 'hourly', 'minute': 'minutely', \ 26136 'agg season': 'seasonalaggregation'}26138 'agg': 'aggregation'} 26137 26139 Lstatn = {'min': 'minimum', 'max': 'maximum', 'mean': 'mean', \ 26138 26140 'mean2': 'quadratic mean', 'std': 'standard deviation', \ 26139 26141 'percentiles': 'percentiles'} 26140 26142 availcftunits = ['days', 'hours', 'minutes', 'seconds'] 26143 availagg = ['year', 'month', 'day', 'hour', 'minute', 'second'] 26141 26144 26142 26145 if values == 'h': … … 26284 26287 time_desc) 26285 26288 statslices[iTst] = [Ntimeslice, timeslice] 26289 26290 print 'Lluis slices period:', period, 'amount:', amount, ' ________' 26291 for it in range(Ntimeslice): 26292 print it, ':', timeslice[it] 26286 26293 26287 26294 # Creation of output file … … 26354 26361 'statistics:', statn, " ..." 26355 26362 26356 # Adding period dimension and variables 26357 if not gen.searchInlist(onewnc.dimensions, periodn+'_time'): 26363 if not onewnc.dimensions.has_key(periodn+'_time'): 26358 26364 newdim = onewnc.createDimension(periodn+'_time', Ntslc) 26359 newvart = onewnc.createVariable(periodn+'_time', 'f8', 26365 newvart = onewnc.createVariable(periodn+'_time', 'f8', \ 26360 26366 (periodn+'_time')) 26361 basicvardef(newvart, periodn+'_time', 'time for ' + periodn, timeu) 26362 newvart.setncattr('calendar', timec) 26363 newvart.setncattr('bounds', periodn+'_time_bounds') 26364 newvarb = onewnc.createVariable(periodn+'_time_bounds', 'f8', \ 26365 (periodn+'_time', 'bounds')) 26366 basicvardef(newvarb, periodn+'_time_bounds', 'time boundaries for '+ \ 26367 periodn, timeu) 26368 newvarb.setncattr('calendar', timec) 26369 for it in range(Ntslc): 26370 timeslcev = tslcs[it] 26371 islc = timevc[timeslcev[0]] 26372 eslc = timevc[timeslcev[1]] 26367 # Adding period dimension and variables 26368 if periodn[0:3] != 'agg': 26369 basicvardef(newvart, periodn+'_time', 'time for ' + periodn, timeu) 26370 newvart.setncattr('calendar', timec) 26371 newvart.setncattr('bounds', periodn+'_time_bounds') 26372 newvarb = onewnc.createVariable(periodn+'_time_bounds', 'f8', \ 26373 (periodn+'_time', 'bounds')) 26374 basicvardef(newvarb, periodn+'_time_bounds', 'time boundaries for '+ \ 26375 periodn, timeu) 26376 newvarb.setncattr('calendar', timec) 26377 for it in range(Ntslc): 26378 timeslcev = tslcs[it] 26379 islc = timevc[timeslcev[0]] 26380 eslc = timevc[timeslcev[1]] 26373 26381 26374 newvart[it] = (eslc + islc) / 2. 26375 newvarb[it,:] = [islc, eslc] 26376 onewnc.sync() 26382 newvart[it] = (eslc + islc) / 2. 26383 newvarb[it,:] = [islc, eslc] 26384 onewnc.sync() 26385 else: 26386 # Time units lose any sense, thus redefining them 26387 PerN = periodn[3:len(periodn)] 26388 if PerN == 'year': 26389 dtsec = 365 * 24 * 3600 26390 elif PerN == 'month': 26391 dtsec = 365 * 24 * 3600 26392 elif PerN == 'day': 26393 dtsec = 24 * 3600 26394 elif PerN == 'hour': 26395 dtsec = 3600 26396 elif PerN == 'minute': 26397 dtsec = 60 26398 elif PerN == 'second': 26399 dtsec = 1 26400 else: 26401 print errormsg 26402 print ' ' + fname + ": aggregation over '" + PerN + "' not " + \ 26403 "ready !!" 26404 print ' available ones:', availagg 26405 quit(-1) 26406 26407 # Getting slices in axis-time units 26408 ut = timeu.split(' ')[0] 26409 if ut == 'year': dtsec / (365 * 24 * 3600.) 26410 elif ut == 'month': dtsec / (365 * 24 * 3600.) 26411 elif ut == 'day': dtsec / (24 * 3600.) 26412 elif ut == 'hour': dtsec / (3600.) 26413 elif ut == 'minute': dtsec / (60.) 26414 elif ut == 'second': dtsec / 1. 26415 26416 timeslcev = tslcs[0] 26417 firstval = timevc[timeslcev[0]] 26418 basicvardef(newvart, periodn+'_time', 'time for ' + periodn, timeu) 26419 newvart.setncattr('calendar', timec) 26420 newvart.setncattr('bounds', periodn+'_time_bounds') 26421 newvarb = onewnc.createVariable(periodn+'_time_bounds', 'f8', \ 26422 (periodn+'_time', 'bounds')) 26423 basicvardef(newvarb, periodn+'_time_bounds', 'time boundaries' + \ 26424 ' for ' + periodn, timeu) 26425 newvarb.setncattr('calendar', timec) 26426 for it in range(Ntslc-1): 26427 timeslcev = tslcs[it] 26428 Nvalsslc = len(timeslcev) 26429 print 'timeslcev:', tslcs[it], 'Nvals:', Nvalsslc 26430 islc = newvart[it]+dtsec/2 26431 timeslcev = tslcs[it+1] 26432 eslc = newvart[it]-dtsec/2 26433 print it, ' Lluis islc:', islc, 'eslc:', eslc 26434 newvart[it] = dtsec 26435 newvarb[it,:] = [islc, eslc] 26436 onewnc.sync() 26377 26437 26378 26438 for varn in varnames: … … 26439 26499 if statn == 'std': varunits = '(' + varunits + ')**2)' 26440 26500 CFvarattr = gen.variables_values(varn) 26441 Lname = Lstatn[statn] + ' ' + Lperiodn[periodn] + ' ' + \ 26442 CFvarattr[4].replace('|',' ') 26501 if periodn[0:3] != 'agg': 26502 Lname = Lstatn[statn] + ' ' + Lperiodn[periodn] + ' ' + \ 26503 CFvarattr[4].replace('|',' ') 26504 else: 26505 PerN = periodn[3:len(periodn)+1] 26506 Lname = Lstatn[statn] + ' ' + Lperiodn[PerN] + ' ' +Lperiodn['agg']+ \ 26507 ' ' + CFvarattr[4].replace('|',' ') 26508 26443 26509 add_varattrs(onc,onewnc,[varn],[newvarn]) 26444 26510 basicvardef(newvarv, newvarn, Lname, varunits)
Note: See TracChangeset
for help on using the changeset viewer.