astsource
, and the sink object
should be an instance of a class that provides a method called
astsink
. The read()
method of the Channel class
calls the astsource
method repeatedly with no arguments, and
expects it to return a string holding the next line of text input to store in the Channel.
Likewise, write()
method of the Channel class will call the
astsink
method repeatedly with a single argument, the text of
the next line to store in the external data sink, and will ignore anything
returned by astsink
.
astsource
and astsink
. Note, the
starlink.Atl
module contains a class,
PyFITSAdapter
, that
can be used to provide such methods for the specific case where the
external data source is a
PyFITS
header.
read
method to read an object from a
FitsChan, the FitsChan's "Card" attribute will be cleared automatically
before the read is performed. This means it is not necessary to clear
"Card" explicitly before calling the read
method (as is
required in C and Fortran).
>>> for card in fc:
>>> print(card)
However, this is achieved by incrementing the Card attribute of the FitsChan. So the looping will be affected by any other operation that changes the Card attribute of the FitsChan during the loop.
>>> fc["NAXIS1"] = 1200
If a card for the keyword already exists in the FitsChan, the value of the card will be changed. If the FitsChan does not contain a card for the named keyword, a new card will be appended to the end of the FitsChan. You can retrieve the value of the a keyword in a similar way: for instance,
>>> crval1 = fc["CRVAL1"]
Note, if a keyword occurs more than once in a FitsChan, the the retrieved value will be a tuple containing all the individual keyword values.
>>> print( frame.ActiveUnit )
>>> frame.ActiveUnit = True
>>> import starlink.Ast as Ast
>>> km = Ast.KeyMap()
>>> km['fred'] = 1.2
Note, only strings and integers should be used as keys with a KeyMap. If
a string is used, the returned value is the value of the KeyMap entry
with the specified key. If an integer is used, the returned value is a
tuple containing the key and value of the corresponding entry in the
KeyMap (the order in which entries are returned is specified by the
SortBy attribute of the KeyMap). When setting a value, a
starlink.Ast.MPIND
exception is reported if the specified zero-based
integer index is greater than or equal to the number of entries in the
KeyMap.
>>> for (k,v) in km:
>>> print(k)
>>> print(v)
starlink.Grf.grf_matplotlib
class, that uses the facilities of the matplotlib library to plot
the required primitives. So, the following code will create an annotated
coordinate grid covering a square in a simple default 2D Frame:
import matplotlib.pyplot as plt
import starlink.Ast as Ast
import starlink.Grf as Grf
# Create a matplotlib figure covering the whole work space
fig = plt.figure()
# Create a matplotlib "Axes" (i.e. the plotting region) covering the whole
# Figure. Ensure that the matplotlib axis annotations are not drawn.
ax = fig.add_subplot(111)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
# Create a grf module that knows how to draw into the matplotlib plotting
# region.
grf = Grf.grf_matplotlib( ax )
# Store the required bounds of the Plot within the plotting region.
gbox = ( 0.1, 0.1, 0.9, 0.9 )
# Store the required bounds of the Plot within the simple default Frame.
bbox = ( -1.0, -1.0, 1.0, 1.0 )
# Create the Plot, using the above grf object, and using a default Frame.
plot = Ast.Plot( None, gbox, bbox, grf )
# Set some niceattributes for the plot. Note, colours can be supplied in any
# form that is acceptable to matplotlib.
plot.Colour_Border = "lime"
plot.Colour_Ticks = "lime"
plot.MajTickLen = 0.02
plot.Width_TextLab = 2
plot.Width_NumLab = 2
plot.Width_Title = 2
# Draw a coordinate grid.
plot.grid()
# Display everything.
plt.show()
Other such classes could be written based on other graphics libraries,
following the pattern of the grf_matplotlib
class (for more
detailed documentation on the required methods, see also the grf_pgplot.c
file in the AST source distribution).