def read_ECMWF(date): """ Script reading the ECMWF data. Not a generator as this is synchronized with the 1h part slice. The data are assumed valid over the 1h period that follows the timestamp. This is quite OK for UDR as this quantity is defined as a mean/accumuation over this one-hour period. Cloud-cover is from analysis, therefore as an instantaneous map, but varies less rapidly than the UDR. """ dat = ECMWF('STC',date) dat._get_var('T') dat.attr['dlo'] = (dat.attr['lons'][-1] - dat.attr['lons'][0]) / (dat.nlon-1) dat.attr['dla'] = (dat.attr['lats'][-1] - dat.attr['lats'][0]) / (dat.nlat-1) if dat.attr['Lo1']>dat.attr['Lo2']: dat.attr['Lo1'] = dat.attr['Lo1']-360. #@@ test # print('LoLa ',dat.attr['Lo1'],dat.attr['La1'],dat.attr['dlo'],dat.attr['dla'],\ # dat.attr['levs'][0],len(dat.attr['levs'])) #@@ end test dat._get_var('UDR') #dat._get_var('CC') dat._mkp() dat._mkrho() dat.var['UDR'] /= dat.var['RHO'] dat.close() return dat
def Pinterpol(date): """ Read the ERA5 data and interpolate to the pressure levels. """ dat = ECMWF('FULL-EA', date, exp=['VOZ', 'QN']) dat._get_T() dat._get_var('O3') dat._get_var('Q') dat.close() dat._mkp() dat._mkz() dat2 = dat.shift2west(-20) dat3 = dat2.extract(lonRange=[-10, 160], latRange=[0, 50], varss='All') dat3._WMO() dat4 = dat3.interpolP(pressPa, varList=['Z', 'T', 'Q', 'O3']) dat4.d2d = dat3.d2d return (dat4)
dats[i] = datr.interpolPT(pts, varList=varList, latRange=(20, 50), lonRange=(-30, 90)) elif date >= datetime(2017, 9, 1, 0): dats[i] = dat.interpolPT(pts, varList=varList, latRange=(30, 60), lonRange=(0, 120)) else: datr = dat.shift2west(-180) dats[i] = datr.interpolPT(pts, varList=varList, latRange=(40, 70), lonRange=(-40, 80)) dat.close() date += timedelta(hours=6) i += 1 #%% if predates: outbak = 'ERA5-extract-A-PT5-pre.pkl' outfile = 'ERA5-extract-A-PT5-new.pkl' with gzip.open(outbak, 'wb') as f: pickle.dump(dats, f) with gzip.open('ERA5-extract-A-PT5.pkl', 'rb') as f: dats2 = pickle.load(f) for i2 in range(len(dats2)): dats[i + i2] = dats2[i2] elif postdates: outfile = 'ERA5-extract-A-PT5-post.pkl'
if args.month2 is not None: month2 = args.month2 if args.day1 is not None: day1 = args.day1 if args.day2 is not None: day2 = args.day2 if args.hour1 is not None: hour1 = args.hour1 if args.hour2 is not None: hour2 = args.hour2 date = datetime(year, month1, day1, hour1) while date < datetime(year, month2, day2, hour2): print('processing ', date) outfile = date.strftime('TPP%y%m%d%H.hdf5') fullname = os.path.join(maindir, date.strftime('%Y/%m'), outfile) fdd = ECMWF('FULL-EA', date) fdd._get_T() fdd._mkp() fdd.close() fde = fdd.shift2west(-20) fdf = fde.extract(lonRange=[-10, 160], latRange=[0, 50], varss='All') fdf._CPT() fdf._WMO() tpp = {} tpp['Twmo'] = fdf.d2d['Twmo'] tpp['pwmo'] = fdf.d2d['pwmo'] tpp['Tcold'] = fdf.d2d['Tcold'] tpp['pcold'] = fdf.d2d['pcold'] tpp['nlon'] = fdf.nlon tpp['nlat'] = fdf.nlat tpp['lats'] = fdf.attr['lats'] tpp['lons'] = fdf.attr['lons'] tpp['date'] = fdd.date fl.save(fullname, tpp, compression='zlib')
data, theta_level) # First interpolation to the theta level delta_pf = ENint.total_seconds() numpart = 0 # loop on the EN time while date_p >= date_beg: T_f = T_p.copy() P_f = P_p.copy() if not quiet: print('load new EN file ', date_p) data = ECMWF('FULL-EA', date_p) data._get_var('T') data._mkp() data._mkthet() T_p, P_p = interp3d_thet(data, theta_level) data.close() while date_current >= date_p: # interpol the temperature in time #print('date ',date_current) delta_f = date_f - date_current delta_p = date_current - date_p T_current = (delta_p.total_seconds() / delta_pf) * T_f + ( delta_f.total_seconds() / delta_pf) * T_p P_current = (delta_p.total_seconds() / delta_pf) * P_f + ( delta_f.total_seconds() / delta_pf) * P_p # fill part0 ir_start = -int((date_end - date_current).total_seconds()) idx1 = numpart numpart += bloc_size part0['x'] = np.append(part0['x'], xg)
dtt = (mean_date-date1).total_seconds()/10800 # test whether the selected part of the orbit is totally in the interval enter_date = ref_date + timedelta(seconds=data['time'][0]) exit_date = ref_date + timedelta(seconds=data['time'][-1]) if enter_date < date1: print('beginning of orbit out by',date1-enter_date,dtt) if exit_date > date2: print('beginning of orbit out by',exit_date-date2,dtt) # get ECMWF data for the orbit and generate a curtain over the retained segment # read data for first bracketting date dat1 = ECMWF('FULL-EI',date1) dat1._get_T() dat1._mkp() dat1._mkz() dat1.close() # generate a curtain along the track for first date sect1 = dat1.interpol_orbit(data['longitude'],data['latitude'],varList=['P','T','Z']) del dat1 # read data for second bracketting date dat2 = ECMWF('FULL-EI',date2) dat2._get_T() dat2._mkp() dat2._mkz() dat2.close() # generate a curtain along the track for scond date sect2 = dat2.interpol_orbit(data['longitude'],data['latitude'],varList=['P','T','Z']) del dat2 sect = curtain() #sect.x = sect1.x #sect.y = sect1.y
part0['y'] = np.empty(0,dtype=float) part0['t'] = np.empty(0,dtype=float) part0['p'] = np.empty(0,dtype=float) part0['idx_back'] = np.empty(0,dtype=int) numpart = 0 # Loop on the values of theta for targetTheta in [theta-dTheta, theta, theta+dTheta]: # get the first time date1 = date + timedelta(hours=int(begSeq/3600)) predat = ECMWF('STC',date1) predat._get_T() predat._mkp() predat._mkthet() (fT1,fP1) = interp3d_thet(predat,targetTheta) predat.close() #for n in range(nInt): # finds the boundary id1 = np.where(utc == begSeq)[0][0] id2 = np.where(utc == endSeq)[0][0] # get lat, lon and release time yy = data.var['Lat'][id1:id2+1] xx = data.var['Long'][id1:id2+1] ir_start = utc[id1:id2+1] - 86400 ir_start = ir_start.astype(np.int) #weigthing factor w2 = (utc[id1:id2+1] % 3600) / 3600 # Bloc_size block_size = len(xx)*nsel