Changeset 2440 in lmdz_wrf
- Timestamp:
- Apr 16, 2019, 4:34:27 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2423 r2440 25468 25468 def get_time(values, ncfile, variable): 25469 25469 """ Function to provide the closest time-step to a given time 25470 values= [timevalue];[units] 25470 values= [timevalue];[units];[calendar] 25471 25471 [timevalue]: CF value of time to look for 25472 25472 [units]: CF units of time [Tunit] since [date] ('!' for spaces) 25473 [calenadar]: CF calendar used by the data 25473 25474 ncfile= file from which provide the information 25474 25475 variable= [timevarn] name of the variable with the CF-times ('WRFtime' for WRF … … 25482 25483 quit() 25483 25484 25484 expectargs = '[timevalue];[units] '25485 expectargs = '[timevalue];[units];[calendar]' 25485 25486 gen.check_arguments(fname, values, expectargs, ';') 25486 25487 25487 25488 timevalue = np.float(values.split(';')[0]) 25488 25489 uTunits = values.split(';')[1].replace('!',' ') 25490 calendar = np.float(values.split(';')[2]) 25489 25491 25490 25492 onc = NetCDFFile(ncfile, 'r') … … 25500 25502 otime = onc.variables['Times'] 25501 25503 timev0, timeu = compute_WRFtime(otime[:]) 25504 timec = 'gregorian' 25502 25505 else: 25503 25506 otime = onc.variables[variable] 25504 25507 timev0 = otime[:] 25505 25508 timeu = otime.units 25506 25509 timea = otime.ncattrs() 25510 if gen.searchInlist(timea, 'calendar'): 25511 timec = otime.calendar 25512 else: 25513 print warnmsg 25514 print ' ' + fname + ": time variable '" + variable + "' without " + \ 25515 " 'calendar' attribute !!" 25516 print " assuming 'gregorian'" 25517 timec = 'gregorian' 25507 25518 onc.close() 25508 25519 25520 # Checking calendar consistency 25521 if calendar != timec: 25522 print errmsg 25523 print ' ' + fname + ": different calendars found !!" 25524 print " input calendar: '" + calendar + "' calendar in data '" +timec + "'" 25525 quit(-1) 25526 25527 if calendar == 'noleap' or calendar == '365d': 25528 # Adding leap days to avoid dephase (thus, imposing 'gregorian' calendar) 25529 gregtime = gen.impose_gregorian(timev0, uTunits, calendar) 25530 25509 25531 # Referring to the same units 25510 reftvals = gen.coincident_CFtimes( timev0, uTunits, timeu)25532 reftvals = gen.coincident_CFtimes(gregtime, uTunits, timeu) 25511 25533 25512 25534 # looking for minimum distance
Note: See TracChangeset
for help on using the changeset viewer.