def plot_thsections(dbz,vvel,ht,dayt,**kwargs):

	fig,ax = plt.subplots(2,1,sharex=True)

	'colormap for vvel'
	orig_cmap = cm.bwr
	shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')

	' add images and colorbar'
	im0=ax[0].imshow(dbz,interpolation='none',cmap='nipy_spectral',vmin=-20,vmax=60,aspect='auto',origin='lower')
	im1=ax[1].imshow(vvel,interpolation='none',cmap=shifted_cmap,vmin=-10,vmax=4,aspect='auto',origin='lower')
	divider0 = make_axes_locatable(ax[0])
	cax0 = divider0.append_axes("right", size="2%", pad=0.05)
	cbar0 = plt.colorbar(im0, cax=cax0)
	divider1 = make_axes_locatable(ax[1])
	cax1 = divider1.append_axes("right", size="2%", pad=0.05)
	cbar1 = plt.colorbar(im1, cax=cax1)

	if 'echotop' in kwargs:
		echot=kwargs['echotop']
		ax[0].plot(echot,color='k')

	format_yaxis(ax[0],ht)
	format_yaxis(ax[1],ht)

	format_xaxis(ax[1], dayt, minutes_tick=30, labels=True)
	ax[1].invert_xaxis()

	ax[0].set_ylabel('Hgt MSL [km]')
	ax[1].set_ylabel('Hgt MSL [km]')
	ax[1].set_xlabel(r'$\Leftarrow$'+' Time [UTC]')

	plt.subplots_adjust(hspace=0.05)
	plt.suptitle('SPROF observations. Date: '+dayt[0].strftime('%Y-%b'))
	plt.draw()
def plot_thsections_single(ht, dayt, **kwargs):

    matplotlib.rcParams.update({'font.size': 20})
    fig, ax = plt.subplots()
    str_etop = ''
    if 'dbz' in kwargs:
        im = ax.imshow(kwargs['dbz'],
                       interpolation='none',
                       cmap='nipy_spectral',
                       vmin=-30,
                       vmax=60,
                       aspect='auto',
                       origin='lower')
    elif 'vvel' in kwargs:
        orig_cmap = cm.bwr
        shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')
        im = ax.imshow(kwargs['vvel'],
                       interpolation='none',
                       cmap=shifted_cmap,
                       vmin=-10,
                       vmax=4,
                       aspect='auto',
                       origin='lower')

    if 'echotop' in kwargs:
        ax.plot(kwargs['echotop'][0], color='black')
        units = r'$\mathregular{km^{-2}}$'
        str_etop = 'etop_var: {:2.1f}'.format(np.nanvar(kwargs['echotop'][1]))
        str_etop += units

    if 'bband' in kwargs:
        bbht = kwargs['bband'][0]
        idx_bbht = kwargs['bband'][1]
        f = interp1d(ht, range(len(ht)))
        ax.plot(idx_bbht, f(bbht), marker='o', linestyle='--', color='black')

    if kwargs['colorbar']:
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="2%", pad=0.)
        cbar = plt.colorbar(im, cax=cax)

    format_yaxis(ax, ht, toplimit=11)
    format_xaxis(ax, dayt, labels=True, format='%H')
    ax.invert_xaxis()

    str_date = dayt[0].strftime('%Y-%b')
    str_tbeg = dayt[0].strftime(' %dT%H:00') + '-'
    str_tend = (dayt[-1]).strftime('%dT%H:00')
    c = kwargs['case']
    annot = 'Case ' + str(
        c) + ' ' + str_date + str_tbeg + str_tend + ' UTC' + ' ' + str_etop
    ax.text(0.02, 0.02, annot, transform=ax.transAxes, fontsize=14)
    plt.subplots_adjust(top=0.98, bottom=0.05, left=0.04, right=0.91)
    plt.draw()
def plot_thsections(dbz, vvel, ht, dayt, **kwargs):

    fig, ax = plt.subplots(2, 1, sharex=True)

    'colormap for vvel'
    orig_cmap = cm.bwr
    shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')

    ' add images and colorbar'
    im0 = ax[0].imshow(dbz,
                       interpolation='none',
                       cmap='nipy_spectral',
                       vmin=-20,
                       vmax=60,
                       aspect='auto',
                       origin='lower')
    im1 = ax[1].imshow(vvel,
                       interpolation='none',
                       cmap=shifted_cmap,
                       vmin=-10,
                       vmax=4,
                       aspect='auto',
                       origin='lower')
    divider0 = make_axes_locatable(ax[0])
    cax0 = divider0.append_axes("right", size="2%", pad=0.05)
    cbar0 = plt.colorbar(im0, cax=cax0)
    divider1 = make_axes_locatable(ax[1])
    cax1 = divider1.append_axes("right", size="2%", pad=0.05)
    cbar1 = plt.colorbar(im1, cax=cax1)

    if 'echotop' in kwargs:
        echot = kwargs['echotop']
        ax[0].plot(echot, color='k')

    format_yaxis(ax[0], ht)
    format_yaxis(ax[1], ht)

    format_xaxis(ax[1], dayt, minutes_tick=30, labels=True)
    ax[1].invert_xaxis()

    ax[0].set_ylabel('Hgt MSL [km]')
    ax[1].set_ylabel('Hgt MSL [km]')
    ax[1].set_xlabel(r'$\Leftarrow$' + ' Time [UTC]')

    plt.subplots_adjust(hspace=0.05)
    plt.suptitle('SPROF observations. Date: ' + dayt[0].strftime('%Y-%b'))
    plt.draw()
def plot_thsections_single(ht,dayt,**kwargs):

	matplotlib.rcParams.update({'font.size':20})
	fig,ax = plt.subplots()
	str_etop=''
	if 'dbz' in kwargs:
		im=ax.imshow(kwargs['dbz'],interpolation='none',cmap='nipy_spectral',vmin=-30,vmax=60,aspect='auto',origin='lower')
	elif 'vvel' in kwargs:
		orig_cmap = cm.bwr
		shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')
		im=ax.imshow(kwargs['vvel'],interpolation='none',cmap=shifted_cmap,vmin=-10,vmax=4,aspect='auto',origin='lower')

	if 'echotop' in kwargs:
		ax.plot(kwargs['echotop'][0],color='black')
		units=r'$\mathregular{km^{-2}}$'
		str_etop='etop_var: {:2.1f}'.format(np.nanvar(kwargs['echotop'][1]))
		str_etop+=units

	if 'bband' in kwargs:
		bbht=kwargs['bband'][0]
		idx_bbht=kwargs['bband'][1]
		f = interp1d(ht, range(len(ht)))
		ax.plot(idx_bbht, f(bbht),marker='o',linestyle='--',color='black')

	if kwargs['colorbar']:
		divider = make_axes_locatable(ax)
		cax = divider.append_axes("right", size="2%", pad=0.)
		cbar = plt.colorbar(im, cax=cax)

	format_yaxis(ax,ht,toplimit=11)
	format_xaxis(ax, dayt, labels=True,format='%H')
	ax.invert_xaxis()

	str_date=dayt[0].strftime('%Y-%b')
	str_tbeg=dayt[0].strftime(' %dT%H:00')+'-'
	str_tend=(dayt[-1]).strftime('%dT%H:00')
	c=kwargs['case']
	annot='Case '+str(c)+' '+str_date+str_tbeg+str_tend+' UTC'+' '+str_etop
	ax.text(0.02,0.02,annot,transform=ax.transAxes,fontsize=14)
	plt.subplots_adjust(top=0.98, bottom=0.05,left=0.04, right=0.91)
	plt.draw()
def plot_turbulence_spectra(dbz,vvel,ts,ts2,ht,dayt):

	' setup new figure '	
	fig = plt.figure(figsize=(8,10))

	' images axes'
	gs = gridspec.GridSpec(4,1)
	gs.update(top=0.95, bottom=0.46, hspace=.05)
	ax0 = plt.subplot(gs[0])
	ax1 = plt.subplot(gs[1])

	' vvel axis'
	gs = gridspec.GridSpec(1,1)
	gs.update(top=0.7, bottom=0.48,right=0.88)
	ax2 = plt.subplot(gs[0])

	' power spectrum axis'
	gs = gridspec.GridSpec(1,1)
	gs.update(top=0.4, bottom=0.05,right=0.88)
	ax3 = plt.subplot(gs[0])

	'colormap for vvel'
	orig_cmap = cm.bwr
	shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')

	' add images and colorbar'
	im0= ax0.imshow(dbz,interpolation='none',cmap='nipy_spectral',vmin=-20,vmax=60,aspect='auto',origin='lower')
	im1= ax1.imshow(vvel,interpolation='none',cmap=shifted_cmap,vmin=-10,vmax=4,aspect='auto',origin='lower')
	divider0 = make_axes_locatable(ax0)
	cax0 = divider0.append_axes("right", size="2%", pad=0.05)
	cbar0 = plt.colorbar(im0, cax=cax0)
	divider1 = make_axes_locatable(ax1)
	cax1 = divider1.append_axes("right", size="2%", pad=0.05)
	cbar1 = plt.colorbar(im1, cax=cax1)

	' add levels, Doppler velocity, and power spectrum'
	levels=[10, 20,30,40]
	colors=['y', 'k', 'g', 'r']
	variance_y=[0.7, 0.78, 0.86, 0.94]	
	for n,x in enumerate(levels):
		' add levels '
		ax0.plot([x]*len(vvel[x,:]),color=colors[n])
		ax1.plot([x]*len(vvel[x,:]),color=colors[n])

		' get traces at level x'
		trace_doppler=vvel[x,:]
		trace_dbz=dbz[x,:]	

		' extract hydrometeor vvel from Doppler vvel'
		trace_z = 10.**(trace_dbz/10.)
		vvel_hydrometeor = 0.817*trace_z**0.063 # Atlas et al. 1973
		trace_wind = trace_doppler - (-vvel_hydrometeor)

		' plot Doppler velocity at given levels '
		ax2.plot(trace_doppler,color=colors[n])
		ax2.plot(vvel_hydrometeor,color=colors[n])
		ax2.plot(trace_wind,color=colors[n], linestyle=':',linewidth=1)
		ax2.set_ylim([-10,8])

		' add variance annotation '
		variance=np.nanvar(trace_doppler)
		ax2.text(0.2, variance_y[n], 'Variance: '+'{:3.2f}'.format(variance), 
					color=colors[n], transform=ax2.transAxes)

		' create interpolant with regular time grid of 40 seconds'
		asd = check_trace(trace_doppler)
		f=interp1d(ts,asd)
		trace_doppler2= f(ts2)

		' plot power spectrum density'
		if ~np.any(np.isnan(trace_doppler2)):
			print 'level: '+str(x)
			asd = check_trace(trace_wind)
			power_spectrum(ax3, asd,colors[n],linestyle=':',marker=None)
			power_spectrum(ax3,trace_doppler2,colors[n],linestyle='-',marker=None)

	format_yaxis(ax0,ht)
	format_yaxis(ax1,ht)

	format_xaxis(ax0, dayt, freqMinutes=60,labels=False )
	format_xaxis(ax1, dayt, freqMinutes=60,labels=False )
	format_xaxis(ax2, dayt, freqMinutes=60,labels=True )

	ax0.set_ylabel('Hgt MSL [km]')
	ax1.set_ylabel('Hgt MSL [km]')
	ax2.set_ylabel('VVel [ms^-1]')
	ax2.set_xlabel(r'$\Leftarrow$'+' Time [UTC]')

	ax0.set_xlim([0, len(vvel[0,:])])
	ax0.invert_xaxis()
	ax0.set_xticklabels([])
	ax1.set_xlim([0, len(vvel[0,:])])
	# ax1.set_ylim([0, 20])
	ax1.invert_xaxis()
	ax1.set_xticklabels([])	
	ax2.set_xlim([0, len(vvel[0,:])])
	ax2.invert_xaxis()

	plt.suptitle('SPROF observations. Date: '+dayt[0].strftime('%Y-%b'))
	plt.draw()
Example #6
0
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 plot_turbulence_spectra(dbz, vvel, ts, ts2, ht, dayt):

    ' setup new figure '
    fig = plt.figure(figsize=(8, 10))

    ' images axes'
    gs = gridspec.GridSpec(4, 1)
    gs.update(top=0.95, bottom=0.46, hspace=.05)
    ax0 = plt.subplot(gs[0])
    ax1 = plt.subplot(gs[1])

    ' vvel axis'
    gs = gridspec.GridSpec(1, 1)
    gs.update(top=0.7, bottom=0.48, right=0.88)
    ax2 = plt.subplot(gs[0])

    ' power spectrum axis'
    gs = gridspec.GridSpec(1, 1)
    gs.update(top=0.4, bottom=0.05, right=0.88)
    ax3 = plt.subplot(gs[0])

    'colormap for vvel'
    orig_cmap = cm.bwr
    shifted_cmap = shiftedColorMap(orig_cmap, midpoint=0.7, name='shifted')

    ' add images and colorbar'
    im0 = ax0.imshow(dbz,
                     interpolation='none',
                     cmap='nipy_spectral',
                     vmin=-20,
                     vmax=60,
                     aspect='auto',
                     origin='lower')
    im1 = ax1.imshow(vvel,
                     interpolation='none',
                     cmap=shifted_cmap,
                     vmin=-10,
                     vmax=4,
                     aspect='auto',
                     origin='lower')
    divider0 = make_axes_locatable(ax0)
    cax0 = divider0.append_axes("right", size="2%", pad=0.05)
    cbar0 = plt.colorbar(im0, cax=cax0)
    divider1 = make_axes_locatable(ax1)
    cax1 = divider1.append_axes("right", size="2%", pad=0.05)
    cbar1 = plt.colorbar(im1, cax=cax1)

    ' add levels, Doppler velocity, and power spectrum'
    levels = [10, 20, 30, 40]
    colors = ['y', 'k', 'g', 'r']
    variance_y = [0.7, 0.78, 0.86, 0.94]
    for n, x in enumerate(levels):
        ' add levels '
        ax0.plot([x] * len(vvel[x, :]), color=colors[n])
        ax1.plot([x] * len(vvel[x, :]), color=colors[n])

        ' get traces at level x'
        trace_doppler = vvel[x, :]
        trace_dbz = dbz[x, :]

        ' extract hydrometeor vvel from Doppler vvel'
        trace_z = 10.**(trace_dbz / 10.)
        vvel_hydrometeor = 0.817 * trace_z**0.063  # Atlas et al. 1973
        trace_wind = trace_doppler - (-vvel_hydrometeor)

        ' plot Doppler velocity at given levels '
        ax2.plot(trace_doppler, color=colors[n])
        ax2.plot(vvel_hydrometeor, color=colors[n])
        ax2.plot(trace_wind, color=colors[n], linestyle=':', linewidth=1)
        ax2.set_ylim([-10, 8])

        ' add variance annotation '
        variance = np.nanvar(trace_doppler)
        ax2.text(0.2,
                 variance_y[n],
                 'Variance: ' + '{:3.2f}'.format(variance),
                 color=colors[n],
                 transform=ax2.transAxes)

        ' create interpolant with regular time grid of 40 seconds'
        asd = check_trace(trace_doppler)
        f = interp1d(ts, asd)
        trace_doppler2 = f(ts2)

        ' plot power spectrum density'
        if ~np.any(np.isnan(trace_doppler2)):
            print 'level: ' + str(x)
            asd = check_trace(trace_wind)
            power_spectrum(ax3, asd, colors[n], linestyle=':', marker=None)
            power_spectrum(ax3,
                           trace_doppler2,
                           colors[n],
                           linestyle='-',
                           marker=None)

    format_yaxis(ax0, ht)
    format_yaxis(ax1, ht)

    format_xaxis(ax0, dayt, freqMinutes=60, labels=False)
    format_xaxis(ax1, dayt, freqMinutes=60, labels=False)
    format_xaxis(ax2, dayt, freqMinutes=60, labels=True)

    ax0.set_ylabel('Hgt MSL [km]')
    ax1.set_ylabel('Hgt MSL [km]')
    ax2.set_ylabel('VVel [ms^-1]')
    ax2.set_xlabel(r'$\Leftarrow$' + ' Time [UTC]')

    ax0.set_xlim([0, len(vvel[0, :])])
    ax0.invert_xaxis()
    ax0.set_xticklabels([])
    ax1.set_xlim([0, len(vvel[0, :])])
    # ax1.set_ylim([0, 20])
    ax1.invert_xaxis()
    ax1.set_xticklabels([])
    ax2.set_xlim([0, len(vvel[0, :])])
    ax2.invert_xaxis()

    plt.suptitle('SPROF observations. Date: ' + dayt[0].strftime('%Y-%b'))
    plt.draw()