def get_arrays(casenum): dbz,vvel, ht, dayt = read_sprof.retrieve_arrays(base_directory, casenum) reqdates = precip.request_dates_significant(casenum) idx_st=find_index(dayt,reqdates['ini']) idx_end=find_index(dayt,reqdates['end']) dayt=dayt[idx_st:idx_end+1] vvel=vvel[:,idx_st:idx_end+1] dbz=dbz[:,idx_st:idx_end+1] with np.errstate(invalid='ignore'): vvel[vvel<=-10.]=np.nan vvel[vvel>=4.]=np.nan ' add total seconds to array' ts=[] for d in dayt: ts.append((d-dayt[0]).total_seconds()) ' create equally spaced time grid ' day = dayt[0] end = dayt[-1] step = timedelta(seconds=40) ts2 = [] while day < end: result=(day-dayt[0]).total_seconds() ts2.append(result) day += step return dbz,vvel,ht,ts,ts2,dayt
def get_arrays(casenum): dbz, vvel, ht, dayt = read_sprof.retrieve_arrays(base_directory, casenum) reqdates = precip.request_dates_significant(casenum) idx_st = find_index(dayt, reqdates['ini']) idx_end = find_index(dayt, reqdates['end']) dayt = dayt[idx_st:idx_end + 1] vvel = vvel[:, idx_st:idx_end + 1] dbz = dbz[:, idx_st:idx_end + 1] with np.errstate(invalid='ignore'): vvel[vvel <= -10.] = np.nan vvel[vvel >= 4.] = np.nan ' add total seconds to array' ts = [] for d in dayt: ts.append((d - dayt[0]).total_seconds()) ' create equally spaced time grid ' day = dayt[0] end = dayt[-1] step = timedelta(seconds=40) ts2 = [] while day < end: result = (day - dayt[0]).total_seconds() ts2.append(result) day += step return dbz, vvel, ht, ts, ts2, dayt
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)