def get_dataframe(cases=None, minutes=None): data = {"case": [], "bbyp": [], "czdp": [], "echotvar": []} cprecip = pd.DataFrame(data=data) for c in cases: " sprof data" "*****************************************************" dbz, vvel, ht, ts, ts2, dayt = sprof.get_arrays(str(c)) " echo top variance" echotm = sprof.timeserie_echotop(dbz, ht, plot=False, retrieve="km") " layer-averaged variance" partition = read_partition.partition(dayt[0].year) bbht, bbtimeidx = partition.get_bbht(time=dayt) # center = np.nanmax(bbht)+1.0 # bottom = np.nanmax(bbht) bottom = np.asarray(0.0) vvel_mean, _ = sprof.layer_mean(vvel=vvel, height=ht, bottom=bottom) _, dbz_mean = sprof.layer_mean(dbz=dbz, height=ht, bottom=bottom) " compute variance " a = {"echotm": echotm, "vvel_mean": vvel_mean, "dbz_mean": dbz_mean} df = pd.DataFrame(data=a, index=dayt) timeg = pd.TimeGrouper(str(minutes) + "T") dfg = df.groupby(timeg).var() dfg2 = dfg.ix[:] dr_sprof = pd.date_range(dfg2.index[0], periods=len(dfg2), freq=str(minutes) + "T") " sum precip in minutes interval " "*****************************************************" bby, czd, frs, _ = precip.get_data(str(c)) bbyp = bby.precip.groupby(timeg).sum() czdp = czd.precip.groupby(timeg).sum() frsp = frs.precip.groupby(timeg).sum() " use time from sprof to select" inix = bbyp.index.get_loc(dr_sprof[0]) endx = bbyp.index.get_loc(dr_sprof[-1]) bbyp2 = bbyp.ix[inix:endx] czdp2 = czdp.ix[inix:endx] frsp2 = frsp.ix[inix:endx] ratioCB = np.round(czdp2 / bbyp2, 2) ratioCB[np.isinf(ratioCB.values)] = np.nan ratioCF = np.round(czdp2 / frsp2, 2) ratioCF[np.isinf(ratioCF.values)] = np.nan " windprof data " "*****************************************************" wspd, wdir, timestamp, hgt = wprof.make_arrays(case=str(c), surface=True) dr_wprof = pd.date_range(timestamp[0], timestamp[-1], freq="60T") idx_time = np.where((dr_wprof >= dr_sprof[0]) & (dr_wprof < dr_sprof[-1]))[0] " select altitudes " ws00 = np.round(wspd[0, idx_time], 1) wd00 = np.round(wdir[0, idx_time], 0) f = interp1d(hgt, range(0, len(hgt))) idx = int(np.round(f(0.25), 0)) ws025 = np.round(wspd[idx, idx_time], 1) wd025 = np.round(wdir[idx, idx_time], 0) idx = int(np.round(f(1.25), 0)) ws125 = np.round(wspd[idx, idx_time], 1) wd125 = np.round(wdir[idx, idx_time], 0) idx = int(np.round(f(1.75), 0)) ws175 = np.round(wspd[idx, idx_time], 1) wd175 = np.round(wdir[idx, idx_time], 0) idx = int(np.round(f(2.5), 0)) ws250 = np.round(wspd[idx, idx_time], 1) wd250 = np.round(wdir[idx, idx_time], 0) idx = int(np.round(f(3.5), 0)) ws350 = np.round(wspd[idx, idx_time], 1) wd350 = np.round(wdir[idx, idx_time], 0) d = { "case": np.repeat(c, len(bbyp.ix[inix:endx])), "bbyp": bbyp2, "czdp": czdp2, "frsp": frsp2, "echotvar": dfg2["echotm"][:-1], "vvelvar": dfg2["vvel_mean"][:-1], "dbzvar": dfg2["dbz_mean"][:-1], "wsSfc": ws00, "wdSfc": wd00, "ws025": ws025, "wd025": wd025, "ws125": ws125, "wd125": wd125, "ws175": ws175, "wd175": wd175, "ws250": ws250, "wd250": wd250, "ws350": ws350, "wd350": wd350, "ratioCB": ratioCB, "ratioCF": ratioCF, } df = pd.DataFrame(data=d, index=dfg2[:-1].index) cprecip = cprecip.append(df) """ reorder columns """ cprecip = cprecip[ [ "case", "bbyp", "czdp", "frsp", "ratioCB", "ratioCF", "wsSfc", "wdSfc", "ws025", "wd025", "ws125", "wd125", "ws175", "wd175", "ws250", "wd250", "ws350", "wd350", "echotvar", "vvelvar", "dbzvar", ] ] return cprecip
def main(): global extent global dayt casenum = raw_input('\nIndicate case number (i.e. 1): ') dbz,vvel, ht, dayt = read_sprof.retrieve_arrays(base_directory, casenum) extent=[0, len(dayt), 0, len(ht)] ''' set index for time zooming ''' try: idx_st=find_index(dayt,reqdates[casenum]['ini']) idx_end=find_index(dayt,reqdates[casenum]['end']) except KeyError: idx_st=0 idx_end=len(dayt)-1 ''' Precipitation partition **************************''' partition=read_partition.partition(dayt[0].year) bbht=partition.get_bbht() rtype=partition.get_rtype() begdayt=partition.get_begdayt() enddayt=partition.get_enddayt() beg_aux = np.asarray([datetime(t.year, t.month, t.day, t.hour,0,0) for t in begdayt]) end_aux = np.asarray([datetime(t.year, t.month, t.day, t.hour,0,0) for t in enddayt]) dayt_aux=np.asarray([datetime(t.year, t.month, t.day, t.hour,0,0) for t in dayt]) beg_index = np.where(beg_aux==dayt_aux[0])[0][0] end_index = np.where(end_aux==dayt_aux[-1])[0][1] bbht = bbht[beg_index+1:end_index] rtype = rtype[beg_index+1:end_index] begdayt = begdayt[beg_index:end_index] enddayt = enddayt[beg_index:end_index] d = [[t.year, t.month, t.day, t.hour,t.minute] for t in begdayt] idx_be=np.asarray([find_index(dayt,x) for x in d[1:]]) d = [[t.year, t.month, t.day, t.hour,t.minute] for t in enddayt] idx_en=np.asarray([find_index(dayt,x) for x in d[1:]]) idx_bbht=(idx_be+idx_en)/2 ''' Plots **************''' fig,ax=plt.subplots(2,1,sharex=True, figsize=(12,8)) plot_reflectivity(ax[0],dbz,ht, cmap='nipy_spectral',vmin=-20,vmax=60) plot_velocity(ax[1],vvel,ht, cmap='bwr',vmin=-3,vmax=3) f = interp1d(ht, range(len(ht))) ax[0].plot(idx_bbht, f(bbht),marker='o',linestyle='--',color='black') for n, s in enumerate(rtype): if s[0] != 'NaN': ax[0].text(idx_bbht[n], -5, s[0][0].upper(), horizontalalignment='center',clip_on=True) ax[1].plot(idx_bbht, f(bbht),marker='o',linestyle='--',color='black') ' it has to be before set_xlim' # format_xaxis(ax[1],dayt,2,casenum) format_xaxis(ax[1],dayt,labels=True,format='%d\n%H') ax[0].set_xlim([idx_st,idx_end]) ax[0].set_ylim([-10,len(ht)]) ax[1].set_ylim([-10,len(ht)]) fig.subplots_adjust(hspace=.07) ax[1].invert_xaxis() ax[1].set_xlabel(r'$\Leftarrow$'+' Time [UTC]') # ax[1].set_xlabel(' Time [UTC]'+r'$\Rightarrow$') # ax[0].grid(b=True, which='major', color='b', linestyle='-') plt.suptitle('SPROF observations. Date: '+dayt[0].strftime('%Y-%b')) plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.1) plt.draw() # plt.show() plt.show(block=False)
def get_dataframe(cases=None,minutes=None): data={'case':[], 'bbyp':[], 'czdp': [], 'echotvar':[]} cprecip=pd.DataFrame(data=data) for c in cases: ' sprof data' '*****************************************************' dbz,vvel,ht,ts,ts2,dayt = sprof.get_arrays(str(c)) ' echo top variance' echotm = sprof.timeserie_echotop(dbz,ht,plot=False,retrieve='km') ' layer-averaged variance' partition=read_partition.partition(dayt[0].year) bbht,bbtimeidx=partition.get_bbht(time=dayt) # center = np.nanmax(bbht)+1.0 # bottom = np.nanmax(bbht) bottom = np.asarray(0.) vvel_mean,_=sprof.layer_mean(vvel=vvel,height=ht,bottom=bottom) _,dbz_mean=sprof.layer_mean(dbz=dbz,height=ht,bottom=bottom) ' compute variance ' a={'echotm':echotm, 'vvel_mean':vvel_mean, 'dbz_mean':dbz_mean} df = pd.DataFrame(data=a,index=dayt) timeg=pd.TimeGrouper(str(minutes)+'T') dfg = df.groupby(timeg).var() dfg2=dfg.ix[:] dr_sprof=pd.date_range(dfg2.index[0],periods=len(dfg2),freq=str(minutes)+'T') ' sum precip in minutes interval ' '*****************************************************' bby,czd,frs,_ = precip.get_data(str(c)) bbyp = bby.precip.groupby(timeg).sum() czdp = czd.precip.groupby(timeg).sum() frsp = frs.precip.groupby(timeg).sum() ' use time from sprof to select' inix = bbyp.index.get_loc(dr_sprof[0]) endx = bbyp.index.get_loc(dr_sprof[-1]) bbyp2=bbyp.ix[inix:endx] czdp2=czdp.ix[inix:endx] frsp2=frsp.ix[inix:endx] ratioCB = np.round(czdp2/bbyp2,2) ratioCB[np.isinf(ratioCB.values)]=np.nan ratioCF = np.round(czdp2/frsp2,2) ratioCF[np.isinf(ratioCF.values)]=np.nan ' windprof data ' '*****************************************************' wspd,wdir,timestamp,hgt = wprof.make_arrays(case=str(c),surface=True) dr_wprof = pd.date_range(timestamp[0],timestamp[-1], freq='60T') idx_time = np.where((dr_wprof>=dr_sprof[0]) & (dr_wprof<dr_sprof[-1]))[0] ' select altitudes ' ws00=np.round(wspd[0,idx_time],1) wd00=np.round(wdir[0,idx_time],0) f = interp1d(hgt,range(0,len(hgt))) idx = int(np.round(f(0.25), 0)) ws025=np.round(wspd[idx, idx_time],1) wd025=np.round(wdir[idx, idx_time],0) idx = int(np.round(f(1.25), 0)) ws125=np.round(wspd[idx, idx_time],1) wd125=np.round(wdir[idx, idx_time],0) idx = int(np.round(f(1.75), 0)) ws175=np.round(wspd[idx, idx_time],1) wd175=np.round(wdir[idx, idx_time],0) idx = int(np.round(f(2.5), 0)) ws250=np.round(wspd[idx, idx_time],1) wd250=np.round(wdir[idx, idx_time],0) idx = int(np.round(f(3.5), 0)) ws350=np.round(wspd[idx, idx_time],1) wd350=np.round(wdir[idx, idx_time],0) d={'case':np.repeat(c, len(bbyp.ix[inix:endx])), 'bbyp':bbyp2, 'czdp': czdp2, 'frsp': frsp2, 'echotvar':dfg2['echotm'][:-1], 'vvelvar':dfg2['vvel_mean'][:-1], 'dbzvar':dfg2['dbz_mean'][:-1], 'wsSfc': ws00, 'wdSfc': wd00, 'ws025': ws025, 'wd025': wd025, 'ws125': ws125, 'wd125': wd125, 'ws175': ws175, 'wd175': wd175, 'ws250': ws250, 'wd250': wd250, 'ws350': ws350, 'wd350': wd350, 'ratioCB': ratioCB, 'ratioCF':ratioCF} df=pd.DataFrame(data=d, index=dfg2[:-1].index,) cprecip=cprecip.append(df) ''' reorder columns ''' cprecip=cprecip[['case', 'bbyp', 'czdp','frsp', 'ratioCB', 'ratioCF', 'wsSfc', 'wdSfc', 'ws025','wd025', 'ws125','wd125', 'ws175','wd175', 'ws250','wd250', 'ws350','wd350', 'echotvar','vvelvar','dbzvar']] return cprecip