A common requirement when displaying image data is to plot an associated coordinate grid over the displayed image (e.g. the following Figure):
The use of AST in such circumstances is independent of the underlying graphics system, so starting up the graphics system, setting up a coordinate system, displaying the image, and closing down afterwards can all be done using the graphics routines you would normally use.
However, displaying an image at a precise location can be a little
fiddly with some graphics systems, and obviously the grid drawn by AST
will not be accurately registered with the image unless this is done
correctly. In the following template, we therefore illustrate both
steps, basing the image display on the PGPLOT graphics
package. Plotting a
coordinate grid with AST then becomes a relatively minor part of what
is almost a complete graphics program.
Once again, we assume that a pointer, WCSINFO, to a suitable FrameSet
associated with the image has already been obtained
().
DOUBLE PRECISION BBOX( 4 )
INTEGER NX, NY, PGBEG, PLOT
REAL DATA( NX, NY ), GBOX( 4 ), HI, LO, SCALE, TR( 6 )
REAL X1, X2, XLEFT, XRIGHT, Y1, Y2, YBOTTOM, YTOP
...
* Access the image data, which we assume will be stored in the real
* 2-dimensional array DATA with dimension sizes NX and NY. Also
* derive limits for scaling it, which we assign to the variables HI
* and LO.
<this stage depends on your data system, so is not shown>
* Open PGPLOT using the device given by environment variable
* PGPLOT_DEV and check for success.
IF ( PGBEG( 0, ' ', 1, 1 ) .EQ. 1 ) THEN
* Clear the screen and ensure equal scales on both axes.
CALL PGPAGE
CALL PGWNAD( 0.0, 1.0, 0.0, 1.0 )
* Obtain the extent of the plotting area (not strictly necessary for
* PGPLOT, but possibly for other graphics systems). From this, derive
* the display scale in graphics units per pixel so that the image
* will fit within the display area.
CALL PGQWIN( X1, X2, Y1, Y2 )
SCALE = MIN( ( X2 - X1 ) / NX, ( Y2 - Y1 ) / NY )
* Calculate the extent of the area in graphics units that the image
* will occupy, so as to centre it within the display area.
XLEFT = 0.5 * ( X1 + X2 - NX * SCALE )
XRIGHT = 0.5 * ( X1 + X2 + NX * SCALE )
YBOTTOM = 0.5 * ( Y1 + Y2 - NY * SCALE )
YTOP = 0.5 * ( Y1 + Y2 + NY * SCALE )
* Set up a PGPLOT coordinate transformation matrix and display the
* image data as a grey scale map (these details are specific to
* PGPLOT).
TR( 1 ) = XLEFT - 0.5 * SCALE
TR( 2 ) = SCALE
TR( 3 ) = 0.0
TR( 4 ) = YBOTTOM - 0.5 * SCALE
TR( 5 ) = 0.0
TR( 6 ) = SCALE
CALL PGGRAY( DATA, NX, NY, 1, NX, 1, NY, HI, LO, TR )
* BEGINNING OF AST BIT
* ====================
* Store the locations of the bottom left and top right corners of the
* region used to display the image, in graphics coordinates.
GBOX( 1 ) = XLEFT
GBOX( 2 ) = YBOTTOM
GBOX( 3 ) = XRIGHT
GBOX( 4 ) = YTOP
* Similarly, store the locations of the image's bottom left and top
* right corners, in pixel coordinates -- with the first pixel centred
* at (1,1).
BBOX( 1 ) = 0.5D0
BBOX( 2 ) = 0.5D0
BBOX( 3 ) = NX + 0.5D0
BBOX( 4 ) = NY + 0.5D0
* Create a Plot, based on the FrameSet associated with the
* image. This attaches the Plot to the graphics surface so that it
* matches the displayed image. Specify that a complete set of grid
* lines should be drawn (rather than just coordinate axes).
PLOT = AST_PLOT( WCSINFO, GBOX, BBOX, 'Grid=1', STATUS )
* Optionally, we can now set other Plot attributes to control the
* appearance of the grid. The values assigned here use the
* colour/font indices defined by the underlying graphics system.
CALL AST_SET( PLOT, 'Colour(grid)=2, Font(textlab)=3', STATUS )
* Use the Plot to draw the coordinate grid.
CALL AST_GRID( PLOT, STATUS )
<maybe some more AST graphics here>
* Annul the Plot when finished (or use the AST_BEGIN/AST_END
* technique shown earlier).
CALL AST_ANNUL( PLOT, STATUS )
* END OF AST BIT
* ==============
* Close down the graphics system.
CALL PGEND
END IF
Note that once you have set up a Plot which is aligned with a
displayed image, you may also use it to generate further graphical
output of your own, specified in the image's world coordinate system
(such as markers to represent astronomical objects, annotation,
etc.). There is also a range of Plot attributes which gives
control over most aspects of the output's appearance. For details of
the facilities available, see and the description of
the Plot class in
.
For details of how to build a graphics program which uses PGPLOT, see
and the description of the ast_link command in
.
AST A Library for Handling World Coordinate Systems in Astronomy