示例#1
0
def plotframeset(axes, gbox, bbox, frameset, options=""):
    r"""Plot an annotated coordinate grid in a matplotlib axes area.

       plot = starlink.Atl.plotframeset( axes, gbox, bbox, frameset,
                                         options="" )

       Parameters:
          axes: A matplotlib "Axes" object. The annotated axes normally
             produced by matplotlib will be removed, and axes will
             instead be drawn by the AST Plot class.
          gbox: A list of four values giving the bounds of the new
             annotated axes within the matplotlib Axes object. The supplied
             values should be in the order (xleft,ybottom,xright,ytop) and
             should be given in the matplotlib "axes" coordinate system.
          bbox: A list of four values giving the bounds of the new
             annotated axes within the coordinate system represented by the
             base Frame of the supplied FrameSet. The supplied values should
             be in the order (xleft,ybottom,xright,ytop).
          frameset: An AST FrameSet such as returned by the Atl.readfitswcs
             function. Its base Frame should be 2-dimensional.
          options: An optional string holding a comma-separated list of Plot
             attribute settings. These control the appearance of the
             annotated axes.
          plot: A reference to the Ast.Plot that was used to draw the axes.

       Example:
          >>> import pyfits
          >>> import starlink.Atl as Atl
          >>> import matplotlib.pyplot
          >>>
          >>> hdulist = pyfits.open( 'test.fit' )
          >>> (frameset,encoding) = starlink.Atl.readfitswcs( hdulist[0] )
          >>> if frameset != None:
          >>>    naxis1 = hdulist[0].header['NAXIS1']
          >>>    naxis2 = hdulist[0].header['NAXIS2']
          >>>    Atl.plotframeset( matplotlib.pyplot.figure().add_subplot(111),
          >>>                      [ 0.1, 0.1, 0.9, 0.9 ],
          >>>                      [ 0.5, 0.5, naxis1+0.5, naxis2+0.5 ], frameset )
          >>>    matplotlib.pyplot.show()
    """

    import starlink.Grf as Grf

    axes.xaxis.set_visible(False)
    axes.yaxis.set_visible(False)

    plot = Ast.Plot(frameset, gbox, bbox, Grf.grf_matplotlib(axes), options)
    plot.grid()
    return plot
示例#2
0
def plotframeset(axes, gbox, bbox, frameset, options=""):
    r"""Plot an annotated coordinate grid in a matplotlib axes area.

       plot = starlink.Atl.plotframeset( axes, gbox, bbox, frameset,
                                         options="" )

       Parameters:
          axes: A matplotlib "Axes" object. The annotated axes normally
             produced by matplotlib will be removed, and axes will
             instead be drawn by the AST Plot class.
          gbox: A list of four values giving the bounds of the new
             annotated axes within the matplotlib Axes object. The supplied
             values should be in the order (xleft,ybottom,xright,ytop) and
             should be given in the matplotlib "axes" coordinate system.
          bbox: A list of four values giving the bounds of the new
             annotated axes within the coordinate system represented by the
             base Frame of the supplied FrameSet. The supplied values should
             be in the order (xleft,ybottom,xright,ytop).
          frameset: An AST FrameSet such as returned by the Atl.readfitswcs
             function. Its base Frame should be 2-dimensional.
          options: An optional string holding a comma-separated list of Plot
             attribute settings. These control the appearance of the
             annotated axes.
          plot: A reference to the Ast.Plot that was used to draw the axes.

       Example:
          >>> import pyfits
          >>> import starlink.Atl as Atl
          >>> import matplotlib.pyplot
          >>>
          >>> hdulist = pyfits.open( 'test.fit' )
          >>> (frameset,encoding) = starlink.Atl.readfitswcs( hdulist[0] )
          >>> if frameset != None:
          >>>    naxis1 = hdulist[0].header['NAXIS1']
          >>>    naxis2 = hdulist[0].header['NAXIS2']
          >>>    Atl.plotframeset( matplotlib.pyplot.figure().add_subplot(111),
          >>>                      [ 0.1, 0.1, 0.9, 0.9 ],
          >>>                      [ 0.5, 0.5, naxis1+0.5, naxis2+0.5 ], frameset )
          >>>    matplotlib.pyplot.show()
    """

    import starlink.Grf as Grf

    axes.xaxis.set_visible(False)
    axes.yaxis.set_visible(False)

    plot = Ast.Plot(frameset, gbox, bbox, Grf.grf_matplotlib(axes), options)
    plot.grid()
    return plot
示例#3
0
if grf_aspect_ratio > fits_aspect_ratio:
    hx = 0.5
    hy = 0.5 * fits_aspect_ratio / grf_aspect_ratio
else:
    hx = 0.5 * grf_aspect_ratio / fits_aspect_ratio
    hy = 0.5

#  Shrink the box to leave room for axis annotation.
hx *= 0.7
hy *= 0.7

gbox = (0.5 - hx, 0.5 - hy, 0.5 + hx, 0.5 + hy)

#  Create a drawing object that knows how to draw primitives (lines,
#  marks and strings) into the matplotlib plotting region.
grf = Grf.grf_matplotlib(ax)

#  Create the AST Plot, using the above object to draw the primitives. The
#  Plot is based on the FrameSet that describes the WCS read from the FITS
#  headers, so the plot knows how to convert from WCS coords to pixel
#  coords, and then to matplotlib data coords. Specify the plotting
#  attributes read from the "attr" file.
plot = Ast.Plot(fs, gbox, bbox, grf, plot_atts)

#  And finally, draw the annotated WCS axes and any coordinate grid
#  requested in the plotting attributes.
plot.grid()

#  Make the matplotlib plotting area visible
plt.show()
示例#4
0
	def __init__(self, circle_extent=None, figsize=(12.0, 12.0)):
		
		self.ast_plot = None # type: Ast.Plot
		
		# -------------------------------------------------------
		# Create frame set that will map the position in the plot
		# (i.e. pixel coordinates) to the sky (i.e. WCS)
		fits_chan = ASTFITSChannel()
		
		naxis1 = 100
		naxis2 = 100

		# The NAXIS values are arbitrary; this object is used for mapping.
		cards = {
			"CRVAL1":circle_extent.center[0], # reference point (image center) in sky coords
			"CRVAL2":circle_extent.center[1],
			"CTYPE1":"RA---TAN", #"GLON-TAN", # projection type
			"CTYPE2":"DEC--TAN", #"GLAT-TAN",
			"CRPIX1":50.5, # reference point (image center) point in pixel coords
			"CRPIX2":50.5,
			"CDELT1":2.1*circle_extent.radius/100,
			"CDELT2":2.1*circle_extent.radius/100,
			"NAXIS1":naxis1,
			"NAXIS2":naxis2,
			"NAXES":2,
		}
		naxis1 = cards['NAXIS1']
		naxis2 = cards['NAXIS2']
		pix2sky_mapping = ASTFrameSet.fromFITSHeader(fits_header=cards)
		# -------------------------------------------------------
		
		#  Create a matplotlib figure, 12x12 inches in size.
		dx = figsize[0] # 12.0
		dy = figsize[1] # 12.0
		fig = plt.figure( figsize=(dx,dy) )
		fig_aspect_ratio = dy/dx
		
		#  Set up the bounding box of the image in pixel coordinates, and get
		#  the aspect ratio of the image.
		bbox = (0.5, 0.5, naxis1 + 0.5, naxis2 + 0.5)
		fits_aspect_ratio = ( bbox[3] - bbox[1] )/( bbox[2] - bbox[0] )
		
		#  Set up the bounding box of the image as fractional offsets within the
		#  figure. The hx and hy variables hold the horizontal and vertical half
		#  widths of the image, as fractions of the width and height of the figure.
		#  Shrink the image area by a factor of 0.7 to leave room for annotated axes.
		if fig_aspect_ratio > fits_aspect_ratio :
		  hx = 0.5
		  hy = 0.5*fits_aspect_ratio/fig_aspect_ratio
		else:
		  hx = 0.5*fig_aspect_ratio/fits_aspect_ratio
		  hy = 0.5
		
		hx *= 0.7
		hy *= 0.7
		gbox = ( 0.5 - hx, 0.5 - hy, 0.5 + hx, 0.5 + hy )
		
		#  Add an Axes structure to the figure and display the image within it,
		#  scaled between data values zero and 100. Suppress the axes as we will
		#  be using AST to create axes.
		ax_image = fig.add_axes( [ gbox[0], gbox[1], gbox[2] - gbox[0],
								  gbox[3] - gbox[1] ], zorder=1 )
		ax_image.xaxis.set_visible( False )
		ax_image.yaxis.set_visible( False )
		#ax_image.imshow( hdu_list[0].data, vmin=0, vmax=200, cmap=plt.cm.gist_heat,
		#				origin='lower', aspect='auto')
		
		#  Add another Axes structure to the figure to hold the annotated axes
		#  produced by AST. It is displayed on top of the previous Axes
		#  structure. Make it transparent so that the image will show through.
		ax_plot = fig.add_axes( [ 0, 0, 1, 1 ], zorder=2 )
		ax_plot.xaxis.set_visible(False)
		ax_plot.yaxis.set_visible(False)
		ax_plot.patch.set_alpha(0.0)
		
		#  Create a drawing object that knows how to draw primitives (lines,
		#  marks and strings) into this second Axes structure.
		grf = Grf.grf_matplotlib( ax_plot )
		
		#print(f"gbox: {gbox}")
		#print(f"bbox: {bbox}")
		
		# box in graphics coordinates (area to draw on, dim of plot)
		#plot = Ast.Plot( frameset.astObject, gbox, bbox, grf )
		self.ast_plot = Ast.Plot( pix2sky_mapping.astObject, gbox, bbox, grf, options="Uni1=ddd:mm:ss" )
		 #, options="Grid=1" )
		#plot.set( "Colour(border)=2, Font(textlab)=3" );
		
		self.ast_plot.Grid = True # can change the line properties
		self.ast_plot.Format_1 = "dms"
		
		# colors:
		# 1 = black
		# 2 = red
		# 3 = lime
		# 4 = blue
		# 5 = 
		# 6 = pink
		
		self.ast_plot.grid()
		self.ast_plot.Width_Border = 2