def read_ERA5(t0, dtRange, pre=False, vshift=0): """ Generator reading the ERA5 data. The loop is infinite; ERA5 data are called when required until the end of the parcel loop. The output contain a function that gives the pressure of the tropo^pause as a function of lon and lat in the FullAMA domain""" # initial time for internal loop current_time = t0 while True: try: if (current_time in blacklist): raise BlacklistError() # defining a new object is necessary to avoid messing dat if an error occurs dat = ECMWF('FULL-EA', current_time) dat._get_T() dat._mkp() dats = dat.shift2west(-179) # extraction in a domain that encompasses FullAMA datr0 = dats.extract(latRange=[-5, 55], lonRange=[-15, 165], varss=['P', 'T']) del dat, dats datr0._WMO() datr0.fP = RegularGridInterpolator( (np.arange(-5, 56), np.arange(-15, 166)), datr0.d2d['pwmo'], bounds_error=True) print('get ERA5 tropopause for ', current_time) try: del datr except: pass # intended for the first pass when datr undefined datr = datr0 # datr as a view of datr0 # We reproduce here the same sequence as for the satellite file # although perhapsnot appropriate (the ERA5 data are instantaneous) if pre: datr.tf = current_time + dtRange datr.ti = current_time else: datr.tf = current_time datr.ti = current_time - dtRange except BlacklistError: print('blacklisted date for GridSat', current_time) # extend the lease while keeping the old dat datr.ti -= dtRange except FileNotFoundError: print('ERA5 file not found ', current_time) # extend the lease while keeping the old dat datr.ti -= dtRange current_time -= dtRange yield datr
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)
if args.year is not None: year = args.year if args.month1 is not None: month1 = args.month1 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']
FAFfile = current_date.strftime('SAFNWC-PTOP-%Y-%m-%d-%H:%M.pkl') fullname = os.path.join(SAF_dir, current_date.strftime('%Y/%m/%Y-%m-%d'), FAFfile) # First try to get the SAFNWC file try: with gzip.open(fullname, 'rb') as file: [ptop, cloud_flag] = pickle.load(file) except IOError: print('date', current_date, ' file not found ', FAFfile) print(current_date, 'is skipped') current_date += timedelta(hours=1) continue # The get the ECMWF data data = ECMWF('STC', current_date) data._get_T() data._mkp() data.close() # find time ir_start = int((current_date - date_beg).total_seconds()) # process the cloud tops above cut_level ptop_temp = np.ma.masked_greater(ptop, cut_level) ct = (cloud_flag >> 24) & 0xFF if cloud_type == 'high': filt = (ct == 8) | (ct == 9) | ((ct >= 11) & (ct <= 14)) elif cloud_type == 'meanhigh': filt = (ct == 8) | (ct == 9) | (ct == 12) | (ct == 13) elif cloud_type == 'veryhigh': filt = (ct == 9) | (ct == 13) ptop_temp[~filt] = np.ma.masked # apply same mask to other fields
# out of the interval date1 = datetime(mean_date.year,mean_date.month,mean_date.day,mean_date.hour - mean_date.hour%3) date2 = date1 + timedelta(hours=3) 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
from datetime import datetime #import pickle,gzip #import matplotlib.pyplot as plt from os.path import join from ECMWF_N import ECMWF date = datetime(2017, 8, 23, 3) dat = ECMWF('FULL-EA', date, exp='VOZ') #date = datetime(2020,1,23,6) #dat = ECMWF('OPZ',date) #date = datetime(2017,8,10,0) #dat = ECMWF('STC',date) #%% dat._get_T() dat._get_var('VO') dat._get_U() dat._get_V() dat._mkp() dat._mkthet() #%% print('now call mkpv') dat._mkpv() #%% #dats = dat.interpolPT([350,370,395,430],varList=['PV'],lonRange=(50,120),latRange=(0,50)) dats = dat.extract(varss='All', lonRange=(240, 330), latRange=(-80, -30))
part0['nact_lastNH'] = 0 part0['flag'] = np.empty(0,dtype=int) part0['ir_start'] = np.empty(0,dtype=int) part0['x'] = np.empty(0,dtype=float) 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