def ret_times(iyear,eyear,lmon, sunit, scalendar, stepday,model=False): ldtime = [] ltnum = [] if model ==False: ihour = 0 else: ihour = cmip_para.ret_lhour_6hr_cmip(model)[0] if ihour == 6: ihour = 0 #------- for year in range(iyear, eyear+1): for mon in lmon: idtime = netCDF4.netcdftime.datetime(year, mon,1,ihour,0) itnum = netCDF4.date2num(idtime, sunit, scalendar) tnum = itnum - stepday while 1==1: tnum = tnum + stepday dtime = netCDF4.num2date(tnum, sunit, scalendar) #------------ mont = dtime.month #-- check --- if mont != mon: break #------------ ldtime.append(dtime) ltnum.append(tnum) #--------- return array(ldtime), array(ltnum)
if (target <= leapdate) & (leapdate < today): target = target + datetime.timedelta(-1) elif (target >= leapdate ) & (leapdate > today): target = target + datetime.timedelta(1) #----------- return target #****************************************************** for expr, model, var in [[expr,model,var] for expr in lexpr for model in lmodel for var in lvar]: #---------------------- iyear, eyear = dyrange[expr] sunit, scalendar = cmip_para.ret_unit_calendar(model, expr) ens = cmip_para.ret_ens(model,expr,var) a1dtime,a1tnum = cmip_func.ret_times(iyear,eyear,lmon,sunit,scalendar,stepday,model=model) lhour = cmip_para.ret_lhour_6hr_cmip(model) mhour = lhour[1] # middle time of day #---------------------- for dtime, tnum in map(None, a1dtime, a1tnum): #************* year,mon,day,hour = dtime.year, dtime.month, dtime.day, dtime.hour #--- check hour -- if hour != mhour: continue #----------------- stime = "%04d%02d%02d0000"%(year,mon,day) #---- idir_root = "/media/disk2/data/CMIP5/sa.one.%s.%s/%s"%(model,expr,var) idir = idir_root + "/%04d%02d"%(year, mon) odir_root = "/media/disk2/data/CMIP5/sa.one.%s.%s/%s.run.mean"%(model,expr,var)