Exemple #1
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)
	
Exemple #2
0
def plot_map(lon,lat,data,filename='/Users/lederer/tmp/rompy.map.png',resolution='c',clim=None,cmap='banas_hsv_cm',title=None, caxis_label=None):
	fig = Figure(facecolor='white',figsize=(12.0,9.0))
#	ax = fig.add_subplot(111)
	longest_side_size = 24.0
	#ax = fig.add_axes((0.,0.,1.,1.),axisbg='grey')
	
	cmap,sm,norm = make_cmap_sm_norm(d=data,clim=clim,cmap=cmap)
	
	ax1 = fig.add_axes((0.1,0.1,0.4,0.8),axisbg='grey')
	ax2 = fig.add_axes((0.5,0.1,0.4,0.8),axisbg='grey')
	cax = fig.add_axes([0.9, 0.1, 0.02, 0.8],frameon=False)
	lllat = np.min(lat)
	urlat = np.max(lat)
	lllon = np.min(lon)
	urlon = np.max(lon)
	
	# puget sound bounding box
	psbb_lllat = 47.0
	psbb_urlat = 48.5
	psbb_lllon = -123.2
	psbb_urlon = -122.1
	
#	print(lllat,urlat,lllon,urlon)
#	m1 = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution=resolution,ax=ax1)
#	m2 = Basemap(projection='merc',llcrnrlat=psbb_lllat,urcrnrlat=psbb_urlat,llcrnrlon=psbb_lllon,urcrnrlon=psbb_urlon,resolution='f',ax=ax2)
	m1 = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution='c',ax=ax1)
	m2 = Basemap(projection='merc',llcrnrlat=psbb_lllat,urcrnrlat=psbb_urlat,llcrnrlon=psbb_lllon,urcrnrlon=psbb_urlon,resolution='c',ax=ax2)
	x1,y1 = m1(*(lon,lat))
	x2,y2 = m2(*(lon,lat))

# Code to make the map fit snuggly with the png
#print(np.max(x), np.min(x), np.max(y),np.min(y))
#	width = np.max(x) - np.min(x)
#	height = np.max(y) - np.min(y)
	
#	if width >= height:
#		fig.set_size_inches(longest_side_size, (height/width)*longest_side_size)
#	else:
#		fig.set_size_inches((width/height)*longest_side_size, longest_side_size)
#	ax.set_position([0.,0.,1.,1.])




# 	bbox = ax.get_position()
# 	print(bbox.xmin, bbox.xmax, bbox.ymin, bbox.ymax)
# 	
# 	fig.set_size_inches((bbox.xmax - bbox.xmin)*longest_side_size, (bbox.ymax - bbox.ymin)*longest_side_size)
# 	ax.set_position([0.,0.,1.,1.])
# 	bbox = ax.get_position()
# 	print(bbox.xmin, bbox.xmax, bbox.ymin, bbox.ymax)
# 	
# 	
# 	if clim==None:
# 		cmap = banas_hsv_cm(np.min(data[:]),np.min(data[:]),np.max(data[:]),np.max(data[:]))
# 		norm = Normalize(vmin=np.min(data[:]),vmax=np.max(data[:]),clip=False)
# 	elif len(clim) == 2:
# 		cmap = banas_hsv_cm(clim[0],clim[0],clim[1],clim[1],N=20)
# 		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
# 	elif len(clim) == 4:
# 		cmap = banas_hsv_cm(clim[0],clim[1],clim[2],clim[3])
#		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
		
	pcm1 = m1.pcolormesh(x1,y1,data,cmap=cmap,norm=norm)
#	m1.drawcoastlines(linewidth=0.5)
	regional_coast_lon, regional_coast_lat = m1(*(utils.get_coastline('regional')))
	m1.plot(regional_coast_lon,regional_coast_lat,'k',linewidth=0.5)
	
	pcm2 = m2.pcolormesh(x2,y2,data,cmap=cmap,norm=norm)
#	m2.drawcoastlines(linewidth=0.5)
	detailed_coast_lon, detailed_coast_lat = m2(*(utils.get_coastline('detailed')))
	m2.plot(detailed_coast_lon,detailed_coast_lat,'k',linewidth=0.5)
	
	my_colorbar = fig.colorbar(sm,cax=cax)
	if not caxis_label == None:
		my_colorbar.set_label(caxis_label)
	
	if not title == None:
		ax1.set_title(title)
	
	FigureCanvas(fig).print_png(filename)
Exemple #3
0
def plot_map(lon,
             lat,
             data,
             filename='/Users/lederer/tmp/rompy.map.png',
             resolution='c',
             clim=None,
             cmap='banas_hsv_cm',
             title=None,
             caxis_label=None):
    fig = Figure(facecolor='white', figsize=(12.0, 9.0))
    #	ax = fig.add_subplot(111)
    longest_side_size = 24.0
    #ax = fig.add_axes((0.,0.,1.,1.),axisbg='grey')

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

    ax1 = fig.add_axes((0.1, 0.1, 0.4, 0.8), axisbg='grey')
    ax2 = fig.add_axes((0.5, 0.1, 0.4, 0.8), axisbg='grey')
    cax = fig.add_axes([0.9, 0.1, 0.02, 0.8], frameon=False)
    lllat = np.min(lat)
    urlat = np.max(lat)
    lllon = np.min(lon)
    urlon = np.max(lon)

    # puget sound bounding box
    psbb_lllat = 47.0
    psbb_urlat = 48.5
    psbb_lllon = -123.2
    psbb_urlon = -122.1

    #	print(lllat,urlat,lllon,urlon)
    #	m1 = Basemap(projection='merc',llcrnrlat=lllat,urcrnrlat=urlat,llcrnrlon=lllon,urcrnrlon=urlon,resolution=resolution,ax=ax1)
    #	m2 = Basemap(projection='merc',llcrnrlat=psbb_lllat,urcrnrlat=psbb_urlat,llcrnrlon=psbb_lllon,urcrnrlon=psbb_urlon,resolution='f',ax=ax2)
    m1 = Basemap(projection='merc',
                 llcrnrlat=lllat,
                 urcrnrlat=urlat,
                 llcrnrlon=lllon,
                 urcrnrlon=urlon,
                 resolution='c',
                 ax=ax1)
    m2 = Basemap(projection='merc',
                 llcrnrlat=psbb_lllat,
                 urcrnrlat=psbb_urlat,
                 llcrnrlon=psbb_lllon,
                 urcrnrlon=psbb_urlon,
                 resolution='c',
                 ax=ax2)
    x1, y1 = m1(*(lon, lat))
    x2, y2 = m2(*(lon, lat))

    # Code to make the map fit snuggly with the png
    #print(np.max(x), np.min(x), np.max(y),np.min(y))
    #	width = np.max(x) - np.min(x)
    #	height = np.max(y) - np.min(y)

    #	if width >= height:
    #		fig.set_size_inches(longest_side_size, (height/width)*longest_side_size)
    #	else:
    #		fig.set_size_inches((width/height)*longest_side_size, longest_side_size)
    #	ax.set_position([0.,0.,1.,1.])

    # 	bbox = ax.get_position()
    # 	print(bbox.xmin, bbox.xmax, bbox.ymin, bbox.ymax)
    #
    # 	fig.set_size_inches((bbox.xmax - bbox.xmin)*longest_side_size, (bbox.ymax - bbox.ymin)*longest_side_size)
    # 	ax.set_position([0.,0.,1.,1.])
    # 	bbox = ax.get_position()
    # 	print(bbox.xmin, bbox.xmax, bbox.ymin, bbox.ymax)
    #
    #
    # 	if clim==None:
    # 		cmap = banas_hsv_cm(np.min(data[:]),np.min(data[:]),np.max(data[:]),np.max(data[:]))
    # 		norm = Normalize(vmin=np.min(data[:]),vmax=np.max(data[:]),clip=False)
    # 	elif len(clim) == 2:
    # 		cmap = banas_hsv_cm(clim[0],clim[0],clim[1],clim[1],N=20)
    # 		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
    # 	elif len(clim) == 4:
    # 		cmap = banas_hsv_cm(clim[0],clim[1],clim[2],clim[3])
    #		norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)

    pcm1 = m1.pcolormesh(x1, y1, data, cmap=cmap, norm=norm)
    #	m1.drawcoastlines(linewidth=0.5)
    regional_coast_lon, regional_coast_lat = m1(
        *(utils.get_coastline('regional')))
    m1.plot(regional_coast_lon, regional_coast_lat, 'k', linewidth=0.5)

    pcm2 = m2.pcolormesh(x2, y2, data, cmap=cmap, norm=norm)
    #	m2.drawcoastlines(linewidth=0.5)
    detailed_coast_lon, detailed_coast_lat = m2(
        *(utils.get_coastline('detailed')))
    m2.plot(detailed_coast_lon, detailed_coast_lat, 'k', linewidth=0.5)

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

    if not title == None:
        ax1.set_title(title)

    FigureCanvas(fig).print_png(filename)
Exemple #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)
Exemple #5
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)