Esempio n. 1
0
def plot_parker(coords,data,varname='',title=None,region='',filename='/Users/lederer/tmp/rompy.mickett.png',n=1,x_axis_style='kilometers',resolution='i',x_axis_offset=0,clim=None,cmap=None,labeled_contour_gap=None, caxis_label=None):
	fig = Figure(facecolor='white',figsize=(12.0,9.0))
	fontsize = 8
	
	cmap,sm,norm =  make_cmap_sm_norm(d=data,clim=clim,cmap=cmap)
	
	ax1 = fig.add_axes([0.1, 0.55, 0.65, 0.4]) # top 20 meters
	ax2 = fig.add_axes([0.1, 0.1, 0.65, 0.4]) # full column
	ax3 = fig.add_axes([0.7, 0.55, 0.3, 0.4],axis_bgcolor='white')#'#298FAF') # map of domain containing curtain
	cax = fig.add_axes([0.84, 0.1, 0.02, 0.4],frameon=False) # subplot for the color axis
	
	x_axis_as_km = utils.coords_to_km(coords)
	station_locations = x_axis_as_km[0:-1:n]

	my_plot11 = ax1.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot12 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)
	
	if labeled_contour_gap is not None:
		if int(labeled_contour_gap) == labeled_contour_gap:
			contour_label_fmt = '%d'
		else:
			contour_label_fmt = '%1.2f'
		
		solid_contours = np.arange(clim[0],clim[-1],labeled_contour_gap)

		my_plot13 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax1.clabel(my_plot13,inline=True,fmt=contour_label_fmt,fontsize=fontsize)


	my_plot14 = ax1.plot(station_locations, 1.5*np.ones(len(station_locations)),'v',color='grey')
	
	ax1.fill_between(x_axis_as_km,coords['zm'][0,:],ax1.get_ylim()[0],color='grey')

	ax1.set_ylim((-20,2))
	ax1.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax1.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	
	
	my_plot21 = ax2.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot22 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)

	if labeled_contour_gap is not None:
		my_plot23 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax2.clabel(my_plot23,inline=True,fmt=contour_label_fmt,fontsize=fontsize)

	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],-1000.0,color='grey')
	ax2.set_ylim((np.min(coords['zm'][:])-20.0),2)
	
	ax2.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax2.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	my_colorbar = fig.colorbar(sm,cax=cax)
	if not caxis_label == None:
		my_colorbar.set_label(caxis_label)
	
	if labeled_contour_gap is not None:
		my_colorbar.add_lines(my_plot23)
	
	if title==None:
		ax1.set_title('%s %s from a ROMS run' % (region,varname))
	else:
		ax1.set_title(title)
	
	ax1.set_ylabel('depth in meters',position=(0.05,0))
	ax1.set_xticks(station_locations)
	ax1.set_xticklabels('')
	
	if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
			td = 10 #tick_distance
			
			left_most_tick_label = -x_axis_offset + (x_axis_offset % td)
			left_most_tick = left_most_tick_label + x_axis_offset
						
			ax2.set_xticks(np.arange(left_most_tick,x_axis_as_km[-1],td))
			ax2.set_xticklabels([int(num) for num in np.arange(left_most_tick_label, x_axis_as_km[-1],td)])
			
#			ax2.set_xticks(td*np.arange(x_axis_as_km[-1]/td) + (x_axis_offset % td))
#			ax2.set_xticklabels([int(num) for num in np.arange(-int(x_axis_offset - x_axis_offset % td),x_axis_as_km[-1],td)])
			for xticklabel in ax2.get_xticklabels():
				xticklabel.set_fontsize(fontsize)
			ax2.set_xlabel('Kilometers')

	elif x_axis_style == 'stations' or x_axis_style == 'station':
		if region == 'Hood Canal':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.hood_canal_station_list(),size=fontsize)
			ax2.set_xlabel('Station ID')
			
		elif region == 'Main Basin':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.main_basin_station_list(),size=fontsize)
	 		ax2.set_xlabel('Station ID') 			
 	else:
 		ax2.set_xticks(x_axis_as_km)
 		ax2.set_xticklabels('')
		ax2.set_xlabel('Kilometers')
	
	# make map in the top right corner
	# these lat lon values are derived from the curtain defined for the plot
#	lllat = np.min(coords['ym'])
#	urlat = np.max(coords['ym'])
#	lllon = np.min(coords['xm'])
#	urlon = np.max(coords['xm'])
	
#	lat lon values for the inset map show a close-up of the Puget Sound
	lllat = 47.0
	urlat = 48.5
	lllon = -123.3
	urlon = -122.2
	
	
	m = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution=resolution,ax=ax3)
	x,y = m(*(coords['xm'],coords['ym']))
#	pcm = m.plot(x,y,'r')
	m.drawcoastlines(linewidth=0.5)
	m.fillcontinents(color='#ECECEC')
	pcm1 = m.plot(x,y,'r',linewidth=0.5)
	pcm2 = m.plot(x[0:-1:n],y[0:-1:n],'.k')
	
	FigureCanvas(fig).print_png(filename)
	
Esempio n. 2
0
def plot_mickett(coords,data,varname='',region='',filename='/Users/lederer/tmp/rompy.mickett.png',n=1,x_axis_style='kilometers',x_axis_offset=0,clim=None,cmap=None,labeled_contour_gap=None):
	fig = Figure(facecolor='white')
	fontsize = 8
	
	cmap,sm,norm =  make_cmap_sm_norm(d=data,clim=clim,cmap=cmap)
	
	ax1 = fig.add_axes([0.1, 0.55, 0.75, 0.4])
	ax2 = fig.add_axes([0.1, 0.1, 0.75, 0.4])
	cax = fig.add_axes([0.9, 0.1, 0.02, 0.8],frameon=False)
	
	x_axis_as_km = utils.coords_to_km(coords)
	station_locations = x_axis_as_km[0:-1:n]
# 	
# 	if not clim == None:
# 		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
# 		sm = ScalarMappable(norm=norm,cmap=cmap)
# 		sm.set_clim(vmin=clim[0],vmax=clim[-1])
# 		sm.set_array(np.array([0]))
# 	else:
# 		norm = None	
# 	
	my_plot11 = ax1.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot12 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)
	
	if labeled_contour_gap is not None:
		if int(labeled_contour_gap) == labeled_contour_gap:
			contour_label_fmt = '%d'
		else:
			contour_label_fmt = '%1.2f'
		
		solid_contours = np.arange(clim[0],clim[-1],labeled_contour_gap)
#		ax1_xlim = ax1.get_xlim()
		my_plot13 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax1.clabel(my_plot13,inline=True,fmt=contour_label_fmt,fontsize=fontsize)
#		ax1.set_xlim(ax1_xlim)

	my_plot14 = ax1.plot(station_locations, 1.5*np.ones(len(station_locations)),'v',color='grey')
	
	ax1.fill_between(x_axis_as_km,coords['zm'][0,:],ax1.get_ylim()[0],color='grey')
#	ax1.set_ylim((-20,ax1.get_ylim()[1]))
	ax1.set_ylim((-20,2))
	ax1.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax1.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	
	
	my_plot21 = ax2.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot22 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)

	if labeled_contour_gap is not None:
		
#		ax2_xlim = ax2.get_xlim()
		my_plot23 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax2.clabel(my_plot23,inline=True,fmt=contour_label_fmt,fontsize=fontsize)
#		ax2.set_xlim = ax2_xlim
#	print(ax2.get_ylim())
#	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],ax2.get_ylim()[0],color='grey')
	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],-1000.0,color='grey')
#	ax2.set_ylim(ax2.get_ylim()[0],2)
#	print(ax2.get_ylim())
	ax2.set_ylim((np.min(coords['zm'][:])-20.0),2)
#	print(ax2.get_ylim())
	
	ax2.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax2.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
# 	if clim == None:
# 		sm = my_plot11
	
	my_colorbar = fig.colorbar(sm,cax=cax)
	if labeled_contour_gap is not None:
		my_colorbar.add_lines(my_plot23)
	
	ax1.set_title('%s %s from a ROMS run' % (region,varname))
	ax1.set_ylabel('depth in meters',position=(0.05,0))
#	ax1.set_xticks(10*np.arange(x_axis_as_km[-1]/10))
	ax1.set_xticks(station_locations)
	ax1.set_xticklabels('')
	
	if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
			#tick_list = x_axis_as_km[::n]
			#ax2.set_xticks(tick_list)
			#ax2.set_xticklabels([int(tick) for tick in tick_list],size=fontsize)
			td = 10 #tick_distance
			
			ax2.set_xticks(td*np.arange(x_axis_as_km[-1]/td) + (x_axis_offset % td))
			ax2.set_xticklabels([int(num) for num in np.arange(-int(x_axis_offset - x_axis_offset % td),x_axis_as_km[-1],td)])
			for xticklabel in ax2.get_xticklabels():
				xticklabel.set_fontsize(fontsize)
			ax2.set_xlabel('Kilometers')

	elif x_axis_style == 'stations' or x_axis_style == 'station':
		if region == 'Hood Canal':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.hood_canal_station_list(),size=fontsize)
			ax2.set_xlabel('Station ID')
			
		elif region == 'Main Basin':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.main_basin_station_list(),size=fontsize)
	 		ax2.set_xlabel('Station ID') 			
 	else:
 		ax2.set_xticks(x_axis_as_km)
 		ax2.set_xticklabels('')
		ax2.set_xlabel('Kilometers')
	
	FigureCanvas(fig).print_png(filename)
Esempio n. 3
0
def plot_parker(coords,data,filename='rompy.parker.png',title=None,varname='',region='',n=None,x_axis_style='kilometers',x_axis_offset=0,clim=None,cmap=None,labeled_contour_gap=None, caxis_label=None,inset='Puget Sound',label=None,label_ind=None,ctd_ind=None,**kwargs):
	'''
	
	plot_parker is a plotting routine that simplifies the plotting of ROMS curtain plots. Here's a list of what all the arguments do and what format they should be in:
	
	coords:			coords is a dictionary, specifically one of the return variables from one of the rompy extraction functions
	
	data:			data is numpy array, as returned by a rompy extraction function
	
	filename:		save plot as filename.
	
	title:			[OPTIONAL] a string that will be used as the title in the plot, ignoring any definition for varname or region
	
	varname:		[OPTIONAL] a string of for the variable being plotted. It's only use is in making the title for the plot if the title is not specified
	
	region:			[OPTIONAL] a string of for the region being plotted. It's only use is in making the title for the plot if the title is not specified
	
	n:				[OPTIONAL] used to to define where station carrots are placed on the plot when using the original sections
	
	x_axis_style:	[OPTIONAL] 
	'''
	fig = Figure(facecolor='white',figsize=(12.0,9.0))
	fontsize = 8
	
	cmap,sm,norm =  make_cmap_sm_norm(d=data,clim=clim,cmap=cmap)
	
	ax1 = fig.add_axes([0.1, 0.55, 0.65, 0.4]) # top 20 meters
	ax2 = fig.add_axes([0.1, 0.1, 0.65, 0.4]) # full column
	ax3 = fig.add_axes([0.7, 0.55, 0.3, 0.4],axis_bgcolor='white')#'#298FAF') # map of domain containing curtain
	cax = fig.add_axes([0.84, 0.1, 0.02, 0.4],frameon=False) # subplot for the color axis
	
	x_axis_as_km = utils.coords_to_km(coords)
	
	my_plot11 = ax1.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot12 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)
	
	if labeled_contour_gap is not None:
		if int(labeled_contour_gap) == labeled_contour_gap:
			contour_label_fmt = '%d'
		else:
			contour_label_fmt = '%1.2f'
		
		solid_contours = np.arange(clim[0],clim[-1],labeled_contour_gap)

		my_plot13 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax1.clabel(my_plot13,inline=True,fmt=contour_label_fmt,fontsize=fontsize)

	if n > 0:
		station_locations = x_axis_as_km[0:-1:n]
	elif ctd_ind is not None:
		station_locations = []
		for ctd in ctd_ind:
			station_locations.append(x_axis_as_km[ctd])
	else:
		station_locatons = None
	my_plot14 = ax1.plot(station_locations, 1.5*np.ones(len(station_locations)),'v',color='grey')
				
	ax1.fill_between(x_axis_as_km,coords['zm'][0,:],ax1.get_ylim()[0],color='grey')

	ax1.set_ylim((-20,2))
	ax1.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax1.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	
	
	my_plot21 = ax2.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot22 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)

	if labeled_contour_gap is not None:
		my_plot23 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax2.clabel(my_plot23,inline=True,fmt=contour_label_fmt,fontsize=fontsize)

	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],-1000.0,color='grey')
	ax2.set_ylim((np.min(coords['zm'][:])-20.0),2)
	
	ax2.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax2.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	my_colorbar = fig.colorbar(sm,cax=cax)
	if not caxis_label == None:
		my_colorbar.set_label(caxis_label)
	
	if labeled_contour_gap is not None:
		my_colorbar.add_lines(my_plot23)
	
	if title==None:
		ax1.set_title('%s %s from a ROMS run' % (region,varname))
	else:
		ax1.set_title(title)
	
	ax1.set_ylabel('depth in meters',position=(0.05,0))

	if label is not None and label_ind is not None:
		if len(label) == len(label_ind):
			label_ticks = []
			for i in range(len(label)):
#				ax1.text(x_axis_as_km[label_ind[i]], ax1.get_ylim()[0], label[i], horizontalalignment='center', verticalalignment='center')
				label_ticks.append(x_axis_as_km[label_ind[i]])
			ax1.set_xticks(label_ticks)
			ax1.set_xticklabels(label,size=fontsize)
	else:
		ax1.set_xticks(station_locations)
		ax1.set_xticklabels('')
	
	if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
			td = 10 #tick_distance
			
			left_most_tick_label = -x_axis_offset + (x_axis_offset % td)
			left_most_tick = left_most_tick_label + x_axis_offset
						
			ax2.set_xticks(np.arange(left_most_tick,x_axis_as_km[-1],td))
			ax2.set_xticklabels([int(num) for num in np.arange(left_most_tick_label, x_axis_as_km[-1],td)])
			
#			ax2.set_xticks(td*np.arange(x_axis_as_km[-1]/td) + (x_axis_offset % td))
#			ax2.set_xticklabels([int(num) for num in np.arange(-int(x_axis_offset - x_axis_offset % td),x_axis_as_km[-1],td)])
			for xticklabel in ax2.get_xticklabels():
				xticklabel.set_fontsize(fontsize)
			ax2.set_xlabel('Kilometers')

	elif x_axis_style == 'stations' or x_axis_style == 'station':
		if region == 'Hood Canal':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.hood_canal_station_list(),size=fontsize)
			ax2.set_xlabel('Station ID')
			
		elif region == 'Main Basin':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.main_basin_station_list(),size=fontsize)
	 		ax2.set_xlabel('Station ID') 			
 	else:
 		ax2.set_xticks(x_axis_as_km)
 		ax2.set_xticklabels('')
		ax2.set_xlabel('Kilometers')
	
	# make map in the top right corner
	# these lat lon values are derived from the curtain defined for the plot
#	lllat = np.min(coords['ym'])
#	urlat = np.max(coords['ym'])
#	lllon = np.min(coords['xm'])
#	urlon = np.max(coords['xm'])
	
#	lat lon values for the inset map show a close-up of the Puget Sound
	if inset == 'Puget Sound':
		lllat = 47.0
		urlat = 48.5
		lllon = -123.3
		urlon = -122.2
	elif inset == 'Strait of Georgia':
		lllat = 48.0450
		urlat = 49.4859
		lllon = -123.6237
		urlon = -122.5305

	elif len(inset) == 4:
		lllat = inset[0]
		lllon = inset[1]
		urlat = inset[2]
		urlon = inset[3]
	
	
	m = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution='c',ax=ax3)
	x,y = m(*(coords['xm'],coords['ym']))
#	pcm = m.plot(x,y,'r')
	if inset == 'Puget Sound':
		coast_lon, coast_lat = utils.get_coastline('detailed')
	elif inset == 'Strait of Georgia':
		coast_lon, coast_lat = utils.get_coastline('regional')
# This is a kludge to deal with a bug in matplotlib when plotting a subset of the regional coastline
#		coast_lat[coast_lat<lllat] = np.nan
		coast_lat[coast_lat>urlat] = np.nan
	
#		coast_lon[coast_lon<lllon] = np.nan
#		coast_lon[coast_lon>urlon] = np.nan
	
	coast_lon_proj,coast_lat_proj = m(*(coast_lon,coast_lat))
	
#	m.drawcoastlines(linewidth=0.5)
#	m.fillcontinents(color='#ECECEC')
	m.plot(coast_lon_proj,coast_lat_proj,'k',linewidth=0.5)
	pcm1 = m.plot(x,y,'r',linewidth=0.5)
	if n > 0:
		pcm2 = m.plot(x[0:-1:n],y[0:-1:n],'.k')
	if ctd_ind is not None:
		for ctd in ctd_ind:
			pcm2 = m.plot(x[ctd],y[ctd],'.k')
	
	FigureCanvas(fig).print_png(filename)
	
Esempio n. 4
0
def plot_parker(coords,
                data,
                filename='rompy.parker.png',
                title=None,
                varname='',
                region='',
                n=None,
                x_axis_style='kilometers',
                x_axis_offset=0,
                clim=None,
                cmap=None,
                labeled_contour_gap=None,
                caxis_label=None,
                inset='Puget Sound',
                label=None,
                label_ind=None,
                ctd_ind=None,
                **kwargs):
    '''
	
	plot_parker is a plotting routine that simplifies the plotting of ROMS curtain plots. Here's a list of what all the arguments do and what format they should be in:
	
	coords:			coords is a dictionary, specifically one of the return variables from one of the rompy extraction functions
	
	data:			data is numpy array, as returned by a rompy extraction function
	
	filename:		save plot as filename.
	
	title:			[OPTIONAL] a string that will be used as the title in the plot, ignoring any definition for varname or region
	
	varname:		[OPTIONAL] a string of for the variable being plotted. It's only use is in making the title for the plot if the title is not specified
	
	region:			[OPTIONAL] a string of for the region being plotted. It's only use is in making the title for the plot if the title is not specified
	
	n:				[OPTIONAL] used to to define where station carrots are placed on the plot when using the original sections
	
	x_axis_style:	[OPTIONAL] 
	'''
    fig = Figure(facecolor='white', figsize=(12.0, 9.0))
    fontsize = 8

    cmap, sm, norm = make_cmap_sm_norm(d=data, clim=clim, cmap=cmap)

    ax1 = fig.add_axes([0.1, 0.55, 0.65, 0.4])  # top 20 meters
    ax2 = fig.add_axes([0.1, 0.1, 0.65, 0.4])  # full column
    ax3 = fig.add_axes(
        [0.7, 0.55, 0.3, 0.4],
        axis_bgcolor='white')  #'#298FAF') # map of domain containing curtain
    cax = fig.add_axes([0.84, 0.1, 0.02, 0.4],
                       frameon=False)  # subplot for the color axis

    x_axis_as_km = utils.coords_to_km(coords)

    my_plot11 = ax1.contourf(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                             coords['zm'],
                             data,
                             100,
                             norm=norm,
                             cmap=cmap)
    my_plot12 = ax1.contour(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                            coords['zm'],
                            data,
                            100,
                            linewidths=1,
                            linestyle=None,
                            norm=norm,
                            cmap=cmap)

    if labeled_contour_gap is not None:
        if int(labeled_contour_gap) == labeled_contour_gap:
            contour_label_fmt = '%d'
        else:
            contour_label_fmt = '%1.2f'

        solid_contours = np.arange(clim[0], clim[-1], labeled_contour_gap)

        my_plot13 = ax1.contour(np.tile(x_axis_as_km,
                                        (coords['zm'].shape[0], 1)),
                                coords['zm'],
                                data,
                                solid_contours,
                                colors='k',
                                linewidths=0.5)
        ax1.clabel(my_plot13,
                   inline=True,
                   fmt=contour_label_fmt,
                   fontsize=fontsize)

    if n > 0:
        station_locations = x_axis_as_km[0:-1:n]
    elif ctd_ind is not None:
        station_locations = []
        for ctd in ctd_ind:
            station_locations.append(x_axis_as_km[ctd])
    else:
        station_locatons = None
    my_plot14 = ax1.plot(station_locations,
                         1.5 * np.ones(len(station_locations)),
                         'v',
                         color='grey')

    ax1.fill_between(x_axis_as_km,
                     coords['zm'][0, :],
                     ax1.get_ylim()[0],
                     color='grey')

    ax1.set_ylim((-20, 2))
    ax1.set_xlim((0, x_axis_as_km[-1]))
    for yticklabel in ax1.get_yticklabels():
        yticklabel.set_fontsize(fontsize)

    my_plot21 = ax2.contourf(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                             coords['zm'],
                             data,
                             100,
                             norm=norm,
                             cmap=cmap)
    my_plot22 = ax2.contour(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                            coords['zm'],
                            data,
                            100,
                            linewidths=1,
                            linestyle=None,
                            norm=norm,
                            cmap=cmap)

    if labeled_contour_gap is not None:
        my_plot23 = ax2.contour(np.tile(x_axis_as_km,
                                        (coords['zm'].shape[0], 1)),
                                coords['zm'],
                                data,
                                solid_contours,
                                colors='k',
                                linewidths=0.5)
        ax2.clabel(my_plot23,
                   inline=True,
                   fmt=contour_label_fmt,
                   fontsize=fontsize)

    ax2.fill_between(x_axis_as_km, coords['zm'][0, :], -1000.0, color='grey')
    ax2.set_ylim((np.min(coords['zm'][:]) - 20.0), 2)

    ax2.set_xlim((0, x_axis_as_km[-1]))
    for yticklabel in ax2.get_yticklabels():
        yticklabel.set_fontsize(fontsize)

    my_colorbar = fig.colorbar(sm, cax=cax)
    if not caxis_label == None:
        my_colorbar.set_label(caxis_label)

    if labeled_contour_gap is not None:
        my_colorbar.add_lines(my_plot23)

    if title == None:
        ax1.set_title('%s %s from a ROMS run' % (region, varname))
    else:
        ax1.set_title(title)

    ax1.set_ylabel('depth in meters', position=(0.05, 0))

    if label is not None and label_ind is not None:
        if len(label) == len(label_ind):
            label_ticks = []
            for i in range(len(label)):
                #				ax1.text(x_axis_as_km[label_ind[i]], ax1.get_ylim()[0], label[i], horizontalalignment='center', verticalalignment='center')
                label_ticks.append(x_axis_as_km[label_ind[i]])
            ax1.set_xticks(label_ticks)
            ax1.set_xticklabels(label, size=fontsize)
    else:
        ax1.set_xticks(station_locations)
        ax1.set_xticklabels('')

    if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
        td = 10  #tick_distance

        left_most_tick_label = -x_axis_offset + (x_axis_offset % td)
        left_most_tick = left_most_tick_label + x_axis_offset

        ax2.set_xticks(np.arange(left_most_tick, x_axis_as_km[-1], td))
        ax2.set_xticklabels([
            int(num)
            for num in np.arange(left_most_tick_label, x_axis_as_km[-1], td)
        ])

        #			ax2.set_xticks(td*np.arange(x_axis_as_km[-1]/td) + (x_axis_offset % td))
        #			ax2.set_xticklabels([int(num) for num in np.arange(-int(x_axis_offset - x_axis_offset % td),x_axis_as_km[-1],td)])
        for xticklabel in ax2.get_xticklabels():
            xticklabel.set_fontsize(fontsize)
        ax2.set_xlabel('Kilometers')

    elif x_axis_style == 'stations' or x_axis_style == 'station':
        if region == 'Hood Canal':
            tick_list = x_axis_as_km[::n]
            ax2.set_xticks(tick_list)
            ax2.set_xticklabels(utils.hood_canal_station_list(), size=fontsize)
            ax2.set_xlabel('Station ID')

        elif region == 'Main Basin':
            tick_list = x_axis_as_km[::n]
            ax2.set_xticks(tick_list)
            ax2.set_xticklabels(utils.main_basin_station_list(), size=fontsize)
            ax2.set_xlabel('Station ID')
    else:
        ax2.set_xticks(x_axis_as_km)
        ax2.set_xticklabels('')
        ax2.set_xlabel('Kilometers')

    # make map in the top right corner
    # these lat lon values are derived from the curtain defined for the plot
#	lllat = np.min(coords['ym'])
#	urlat = np.max(coords['ym'])
#	lllon = np.min(coords['xm'])
#	urlon = np.max(coords['xm'])

#	lat lon values for the inset map show a close-up of the Puget Sound
    if inset == 'Puget Sound':
        lllat = 47.0
        urlat = 48.5
        lllon = -123.3
        urlon = -122.2
    elif inset == 'Strait of Georgia':
        lllat = 48.0450
        urlat = 49.4859
        lllon = -123.6237
        urlon = -122.5305
    elif inset == 'JdF_PS':
        lllat = 46.0
        urlat = 49.0
        lllon = -124.9
        urlon = -122.2
    elif len(inset) == 4:
        lllat = inset[0]
        lllon = inset[1]
        urlat = inset[2]
        urlon = inset[3]

    m = Basemap(projection='merc',
                llcrnrlat=lllat,
                urcrnrlat=urlat,
                llcrnrlon=lllon,
                urcrnrlon=urlon,
                resolution='c',
                ax=ax3)
    x, y = m(*(coords['xm'], coords['ym']))
    #	pcm = m.plot(x,y,'r')
    if inset == 'Puget Sound':
        coast_lon, coast_lat = utils.get_coastline('detailed')
    elif inset == 'Strait of Georgia' or inset == 'JdF_PS':
        coast_lon, coast_lat = utils.get_coastline('regional')
        # This is a kludge to deal with a bug in matplotlib when plotting a subset of the regional coastline
        #		coast_lat[coast_lat<lllat] = np.nan
        coast_lat[coast_lat > urlat] = np.nan

#		coast_lon[coast_lon<lllon] = np.nan
#		coast_lon[coast_lon>urlon] = np.nan

    coast_lon_proj, coast_lat_proj = m(*(coast_lon, coast_lat))

    #	m.drawcoastlines(linewidth=0.5)
    #	m.fillcontinents(color='#ECECEC')
    m.plot(coast_lon_proj, coast_lat_proj, 'k', linewidth=0.5)
    pcm1 = m.plot(x, y, 'r', linewidth=0.5)
    if n > 0:
        pcm2 = m.plot(x[0:-1:n], y[0:-1:n], '.k')
    if ctd_ind is not None:
        for ctd in ctd_ind:
            pcm2 = m.plot(x[ctd], y[ctd], '.k')

    FigureCanvas(fig).print_png(filename)
Esempio n. 5
0
def plot_mickett(coords,
                 data,
                 varname='',
                 region='',
                 filename='/Users/lederer/tmp/rompy.mickett.png',
                 n=1,
                 x_axis_style='kilometers',
                 x_axis_offset=0,
                 clim=None,
                 cmap=None,
                 labeled_contour_gap=None):
    fig = Figure(facecolor='white')
    fontsize = 8

    cmap, sm, norm = make_cmap_sm_norm(d=data, clim=clim, cmap=cmap)

    ax1 = fig.add_axes([0.1, 0.55, 0.75, 0.4])
    ax2 = fig.add_axes([0.1, 0.1, 0.75, 0.4])
    cax = fig.add_axes([0.9, 0.1, 0.02, 0.8], frameon=False)

    x_axis_as_km = utils.coords_to_km(coords)
    station_locations = x_axis_as_km[0:-1:n]
    #
    # 	if not clim == None:
    # 		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
    # 		sm = ScalarMappable(norm=norm,cmap=cmap)
    # 		sm.set_clim(vmin=clim[0],vmax=clim[-1])
    # 		sm.set_array(np.array([0]))
    # 	else:
    # 		norm = None
    #
    my_plot11 = ax1.contourf(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                             coords['zm'],
                             data,
                             100,
                             norm=norm,
                             cmap=cmap)
    my_plot12 = ax1.contour(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                            coords['zm'],
                            data,
                            100,
                            linewidths=1,
                            linestyle=None,
                            norm=norm,
                            cmap=cmap)

    if labeled_contour_gap is not None:
        if int(labeled_contour_gap) == labeled_contour_gap:
            contour_label_fmt = '%d'
        else:
            contour_label_fmt = '%1.2f'

        solid_contours = np.arange(clim[0], clim[-1], labeled_contour_gap)
        #		ax1_xlim = ax1.get_xlim()
        my_plot13 = ax1.contour(np.tile(x_axis_as_km,
                                        (coords['zm'].shape[0], 1)),
                                coords['zm'],
                                data,
                                solid_contours,
                                colors='k',
                                linewidths=0.5)
        ax1.clabel(my_plot13,
                   inline=True,
                   fmt=contour_label_fmt,
                   fontsize=fontsize)
#		ax1.set_xlim(ax1_xlim)

    my_plot14 = ax1.plot(station_locations,
                         1.5 * np.ones(len(station_locations)),
                         'v',
                         color='grey')

    ax1.fill_between(x_axis_as_km,
                     coords['zm'][0, :],
                     ax1.get_ylim()[0],
                     color='grey')
    #	ax1.set_ylim((-20,ax1.get_ylim()[1]))
    ax1.set_ylim((-20, 2))
    ax1.set_xlim((0, x_axis_as_km[-1]))
    for yticklabel in ax1.get_yticklabels():
        yticklabel.set_fontsize(fontsize)

    my_plot21 = ax2.contourf(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                             coords['zm'],
                             data,
                             100,
                             norm=norm,
                             cmap=cmap)
    my_plot22 = ax2.contour(np.tile(x_axis_as_km, (coords['zm'].shape[0], 1)),
                            coords['zm'],
                            data,
                            100,
                            linewidths=1,
                            linestyle=None,
                            norm=norm,
                            cmap=cmap)

    if labeled_contour_gap is not None:

        #		ax2_xlim = ax2.get_xlim()
        my_plot23 = ax2.contour(np.tile(x_axis_as_km,
                                        (coords['zm'].shape[0], 1)),
                                coords['zm'],
                                data,
                                solid_contours,
                                colors='k',
                                linewidths=0.5)
        ax2.clabel(my_plot23,
                   inline=True,
                   fmt=contour_label_fmt,
                   fontsize=fontsize)
#		ax2.set_xlim = ax2_xlim
#	print(ax2.get_ylim())
#	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],ax2.get_ylim()[0],color='grey')
    ax2.fill_between(x_axis_as_km, coords['zm'][0, :], -1000.0, color='grey')
    #	ax2.set_ylim(ax2.get_ylim()[0],2)
    #	print(ax2.get_ylim())
    ax2.set_ylim((np.min(coords['zm'][:]) - 20.0), 2)
    #	print(ax2.get_ylim())

    ax2.set_xlim((0, x_axis_as_km[-1]))
    for yticklabel in ax2.get_yticklabels():
        yticklabel.set_fontsize(fontsize)


# 	if clim == None:
# 		sm = my_plot11

    my_colorbar = fig.colorbar(sm, cax=cax)
    if labeled_contour_gap is not None:
        my_colorbar.add_lines(my_plot23)

    ax1.set_title('%s %s from a ROMS run' % (region, varname))
    ax1.set_ylabel('depth in meters', position=(0.05, 0))
    #	ax1.set_xticks(10*np.arange(x_axis_as_km[-1]/10))
    ax1.set_xticks(station_locations)
    ax1.set_xticklabels('')

    if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
        #tick_list = x_axis_as_km[::n]
        #ax2.set_xticks(tick_list)
        #ax2.set_xticklabels([int(tick) for tick in tick_list],size=fontsize)
        td = 10  #tick_distance

        ax2.set_xticks(td * np.arange(x_axis_as_km[-1] / td) +
                       (x_axis_offset % td))
        ax2.set_xticklabels([
            int(num) for num in np.arange(
                -int(x_axis_offset - x_axis_offset % td), x_axis_as_km[-1], td)
        ])
        for xticklabel in ax2.get_xticklabels():
            xticklabel.set_fontsize(fontsize)
        ax2.set_xlabel('Kilometers')

    elif x_axis_style == 'stations' or x_axis_style == 'station':
        if region == 'Hood Canal':
            tick_list = x_axis_as_km[::n]
            ax2.set_xticks(tick_list)
            ax2.set_xticklabels(utils.hood_canal_station_list(), size=fontsize)
            ax2.set_xlabel('Station ID')

        elif region == 'Main Basin':
            tick_list = x_axis_as_km[::n]
            ax2.set_xticks(tick_list)
            ax2.set_xticklabels(utils.main_basin_station_list(), size=fontsize)
            ax2.set_xlabel('Station ID')
    else:
        ax2.set_xticks(x_axis_as_km)
        ax2.set_xticklabels('')
        ax2.set_xlabel('Kilometers')

    FigureCanvas(fig).print_png(filename)
Esempio n. 6
0
def plot_parker(coords,data,varname='',title=None,region='',filename='/Users/lederer/tmp/rompy.mickett.png',n=1,x_axis_style='kilometers',resolution='i',x_axis_offset=0,clim=None,cmap=None,labeled_contour_gap=None, caxis_label=None):
	fig = Figure(facecolor='white',figsize=(12.0,9.0))
	fontsize = 8
	
	cmap,sm,norm =  make_cmap_sm_norm(d=data,clim=clim,cmap=cmap)
	
	ax1 = fig.add_axes([0.1, 0.55, 0.65, 0.4]) # top 20 meters
	ax2 = fig.add_axes([0.1, 0.1, 0.65, 0.4]) # full column
	ax3 = fig.add_axes([0.7, 0.55, 0.3, 0.4],axis_bgcolor='white')#'#298FAF') # map of domain containing curtain
	cax = fig.add_axes([0.84, 0.1, 0.02, 0.4],frameon=False) # subplot for the color axis
	
	x_axis_as_km = utils.coords_to_km(coords)
	station_locations = x_axis_as_km[0:-1:n]

	my_plot11 = ax1.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot12 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)
	
	if labeled_contour_gap is not None:
		if int(labeled_contour_gap) == labeled_contour_gap:
			contour_label_fmt = '%d'
		else:
			contour_label_fmt = '%1.2f'
		
		solid_contours = np.arange(clim[0],clim[-1],labeled_contour_gap)

		my_plot13 = ax1.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax1.clabel(my_plot13,inline=True,fmt=contour_label_fmt,fontsize=fontsize)


	my_plot14 = ax1.plot(station_locations, 1.5*np.ones(len(station_locations)),'v',color='grey')
	
	ax1.fill_between(x_axis_as_km,coords['zm'][0,:],ax1.get_ylim()[0],color='grey')

	ax1.set_ylim((-20,2))
	ax1.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax1.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	
	
	my_plot21 = ax2.contourf(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,norm=norm,cmap=cmap)
	my_plot22 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,100,linewidths=1,linestyle=None,norm=norm,cmap=cmap)

	if labeled_contour_gap is not None:
		my_plot23 = ax2.contour(np.tile(x_axis_as_km,(coords['zm'].shape[0],1)),coords['zm'],data,solid_contours,colors='k',linewidths=0.5)
		ax2.clabel(my_plot23,inline=True,fmt=contour_label_fmt,fontsize=fontsize)

	ax2.fill_between(x_axis_as_km,coords['zm'][0,:],-1000.0,color='grey')
	ax2.set_ylim((np.min(coords['zm'][:])-20.0),2)
	
	ax2.set_xlim((0,x_axis_as_km[-1]))
	for yticklabel in ax2.get_yticklabels():
		yticklabel.set_fontsize(fontsize)
	
	my_colorbar = fig.colorbar(sm,cax=cax)
	if not caxis_label == None:
		my_colorbar.set_label(caxis_label)
	
	if labeled_contour_gap is not None:
		my_colorbar.add_lines(my_plot23)
	
	if title==None:
		ax1.set_title('%s %s from a ROMS run' % (region,varname))
	else:
		ax1.set_title(title)
	
	ax1.set_ylabel('depth in meters',position=(0.05,0))
	ax1.set_xticks(station_locations)
	ax1.set_xticklabels('')
	
	if x_axis_style == 'kilometers' or x_axis_style == 'kilometer':
			td = 10 #tick_distance
			
			left_most_tick_label = -x_axis_offset + (x_axis_offset % td)
			left_most_tick = left_most_tick_label + x_axis_offset
						
			ax2.set_xticks(np.arange(left_most_tick,x_axis_as_km[-1],td))
			ax2.set_xticklabels([int(num) for num in np.arange(left_most_tick_label, x_axis_as_km[-1],td)])
			
#			ax2.set_xticks(td*np.arange(x_axis_as_km[-1]/td) + (x_axis_offset % td))
#			ax2.set_xticklabels([int(num) for num in np.arange(-int(x_axis_offset - x_axis_offset % td),x_axis_as_km[-1],td)])
			for xticklabel in ax2.get_xticklabels():
				xticklabel.set_fontsize(fontsize)
			ax2.set_xlabel('Kilometers')

	elif x_axis_style == 'stations' or x_axis_style == 'station':
		if region == 'Hood Canal':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.hood_canal_station_list(),size=fontsize)
			ax2.set_xlabel('Station ID')
			
		elif region == 'Main Basin':
			tick_list = x_axis_as_km[::n]
			ax2.set_xticks(tick_list)
			ax2.set_xticklabels(utils.main_basin_station_list(),size=fontsize)
	 		ax2.set_xlabel('Station ID') 			
 	else:
 		ax2.set_xticks(x_axis_as_km)
 		ax2.set_xticklabels('')
		ax2.set_xlabel('Kilometers')
	
	# make map in the top right corner
	# these lat lon values are derived from the curtain defined for the plot
#	lllat = np.min(coords['ym'])
#	urlat = np.max(coords['ym'])
#	lllon = np.min(coords['xm'])
#	urlon = np.max(coords['xm'])
	
#	lat lon values for the inset map show a close-up of the Puget Sound
	lllat = 47.0
	urlat = 48.5
	lllon = -123.3
	urlon = -122.2
	
	
#	m = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution=resolution,ax=ax3)
	m = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution='c',ax=ax3)
	x,y = m(*(coords['xm'],coords['ym']))
#	pcm = m.plot(x,y,'r')
	coast_lon, coast_lat = m(*(utils.get_coastline('detailed')))
#	print(coast_lat)
#	print(coast_lon)
#	m.drawcoastlines(linewidth=0.5)
#	m.fillcontinents(color='#ECECEC')
	m.plot(coast_lon,coast_lat,'k',linewidth=0.5)
	pcm1 = m.plot(x,y,'r',linewidth=0.5)
	pcm2 = m.plot(x[0:-1:n],y[0:-1:n],'.k')
	
	FigureCanvas(fig).print_png(filename)