public class FitsChan extends Channel
While a FitsChan is active, it represents a buffer which may contain zero or more 80-character "header cards" conforming to FITS conventions. Any sequence of FITS-conforming header cards may be stored, apart from the "END" card whose existence is merely implied. The cards may be accessed in any order by using the FitsChan's integer Card attribute, which identifies a "current" card, to which subsequent operations apply. Searches based on keyword may be performed (using astFindFits), new cards may be inserted (astPutFits, astPutCards, astSetFits<X>) and existing ones may be deleted (astDelFits), extracted (astGetFits<X>), or changed (astSetFits<X>).
When you create a FitsChan, you have the option of specifying "source" and "sink" functions which connect it to external data stores by reading and writing FITS header cards. If you provide a source function, it is used to fill the FitsChan with header cards when it is accessed for the first time. If you do not provide a source function, the FitsChan remains empty until you explicitly enter data into it (e.g. using astPutFits, astPutCards, astWrite or by using the SourceFile attribute to specifying a text file from which headers should be read). When the FitsChan is deleted, any remaining header cards in the FitsChan can be saved in either of two ways: 1) by specifying a value for the SinkFile attribute (the name of a text file to which header cards should be written), or 2) by providing a sink function (used to to deliver header cards to an external data store). If you do not provide a sink function or a value for SinkFile, any header cards remaining when the FitsChan is deleted will be lost, so you should arrange to extract them first if necessary (e.g. using astFindFits or astRead).
Coordinate system information may be described using FITS header cards using several different conventions, termed "encodings". When an AST Object is written to (or read from) a FitsChan, the value of the FitsChan's Encoding attribute determines how the Object is converted to (or from) a description involving FITS header cards. In general, different encodings will result in different sets of header cards to describe the same Object. Examples of encodings include the DSS encoding (based on conventions used by the STScI Digitised Sky Survey data), the FITS-WCS encoding (based on a proposed FITS standard) and the NATIVE encoding (a near loss-less way of storing AST Objects in FITS headers).
The available encodings differ in the range of Objects they can represent, in the number of Object descriptions that can coexist in the same FitsChan, and in their accessibility to other (external) astronomy applications (see the Encoding attribute for details). Encodings are not necessarily mutually exclusive and it may sometimes be possible to describe the same Object in several ways within a particular set of FITS header cards by using several different encodings.
The detailed behaviour of astRead and astWrite, when used with a FitsChan, depends on the encoding in use. In general, however, all successful use of astRead is destructive, so that FITS header cards are consumed in the process of reading an Object, and are removed from the FitsChan (this deletion can be prevented for specific cards by calling the astRetainFits function). An unsuccessful call of astRead (for instance, caused by the FitsChan not containing the necessary FITS headers cards needed to create an Object) results in the contents of the FitsChan being left unchanged.
If the encoding in use allows only a single Object description to be stored in a FitsChan (e.g. the DSS, FITS-WCS and FITS-IRAF encodings), then write operations using astWrite will over-write any existing Object description using that encoding. Otherwise (e.g. the NATIVE encoding), multiple Object descriptions are written sequentially and may later be read back in the same sequence.
This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more details.
You should have received a copy of the GNU General Public Licence along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA 02110-1301, USA
source
and/or sink
methods. Note that output is only guaranteed to get written
if the close
method is explicitly called.
The close
method should be explicitly called to ensure
cleanup, but the finalizer will call it if it has not previously been
called at finalization time.AST__BAD, AST__TUNULL, pointer
Constructor and Description |
---|
FitsChan()
Creates a new FitsChan which can be used as a buffer for
FITS objects, but will not read or write header cards.
|
FitsChan(Iterator cardIt)
Creates a new FitsChan whose initial contents will be a sequence of
FITS header cards obtained from an Iterator.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Must be called to dispose of the object and ensure that any
writes are performed.
|
void |
delFits()
Delete the current FITS card in a FitsChan.
|
protected void |
finalize()
Finalizes the object.
|
String |
findFits(String name,
boolean inc)
Find a FITS card in a FitsChan by keyword.
|
String |
getAllWarnings()
Get
a list of all currently available condition names.
|
int |
getCard()
Get
index of current FITS card in a FitsChan.
|
boolean |
getCarLin()
Get
ignore spherical rotations on CAR projections.
|
boolean |
getCDMatrix()
Get
use CDi_j keywords to represent pixel scaling, rotation, etc.
|
boolean |
getDefB1950()
Get
use FK4 B1950 as defaults.
|
String |
getEncoding()
Get
system for encoding Objects as FITS headers.
|
int |
getFitsDigits()
Get
digits of precision for floating point FITS values.
|
boolean |
getIwc()
Get
include a Frame representing FITS-WCS intermediate world coordinates.
|
int |
getNcard()
Get
number of FITS header cards in a FitsChan.
|
String |
getWarnings()
Get
controls the issuing of warnings about various conditions.
|
Iterator |
iterator()
Returns an iterator over the header cards currently in this FitsChan.
|
void |
purgeWCS()
Delete all cards in the FitsChan describing WCS information.
|
void |
putCards(String cards)
Store a set of FITS header cards in a FitsChan.
|
void |
putFits(String card,
boolean overwrite)
Store a FITS header card in a FitsChan.
|
AstObject |
read()
Reads an AST object from this FitsChan.
|
void |
retainFits()
Indicate that the current card in a FitsChan should be retained.
|
void |
setCard(int card)
Set
index of current FITS card in a FitsChan.
|
void |
setCarLin(boolean carLin)
Set
ignore spherical rotations on CAR projections.
|
void |
setCDMatrix(boolean CDMatrix)
Set
use CDi_j keywords to represent pixel scaling, rotation, etc.
|
void |
setDefB1950(boolean defB1950)
Set
use FK4 B1950 as defaults.
|
void |
setEncoding(String encoding)
Set
system for encoding Objects as FITS headers.
|
void |
setFits(String name,
boolean value,
String comment,
boolean overwrite)
Stores a boolean value for a named keyword within this
FitsChan at the current card position.
|
void |
setFits(String name,
double rval,
double ival,
String comment,
boolean overwrite)
Stores a double complex value for a named keyword within this
FitsChan at the current card position.
|
void |
setFits(String name,
double value,
String comment,
boolean overwrite)
Stores a double value for a named keyword within this
FitsChan at the current card position.
|
void |
setFits(String name,
int rval,
int ival,
String comment,
boolean overwrite)
Stores an integer complex value for a named keyword within this
FitsChan at the current card position.
|
void |
setFits(String name,
int value,
String comment,
boolean overwrite)
Stores an integer value for a named keyword within this
FitsChan at the current card position.
|
void |
setFits(String name,
String value,
String comment,
boolean overwrite)
Stores a String value for a named keyword within this
FitsChan at the current card position.
|
void |
setFitsContinue(String name,
String value,
String comment,
boolean overwrite)
Stores a CONTINUE type value for a named keyword
FitsChan at the current card position.
|
void |
setFitsDigits(int fitsDigits)
Set
digits of precision for floating point FITS values.
|
void |
setIwc(boolean iwc)
Set
include a Frame representing FITS-WCS intermediate world coordinates.
|
void |
setWarnings(String warnings)
Set
controls the issuing of warnings about various conditions.
|
protected void |
sink(String line)
Disposes of a line of output.
|
protected String |
source()
Obtains a line of input.
|
boolean |
testFits(String name)
See if a named keyword has a defined value in a FitsChan.
|
int |
write(AstObject obj)
Writes an AST object to this channel.
|
copy, getComment, getFull, getReportLevel, getSkip, getStrict, setComment, setFull, setReportLevel, setSkip, setStrict, warnings
annul, clear, delete, equals, getAstConstantI, getB, getC, getD, getF, getI, getID, getIdent, getL, getNobject, getObjSize, getRefCount, hashCode, isThreaded, reportVersions, sameObject, set, setB, setC, setD, setF, setI, setID, setIdent, setL, show, test, tune
public FitsChan(Iterator cardIt)
cardIt
- an Iterator which should supply Strings giving the
channel's initial content. Only the first 80
characters of each supplied string are significant.
This parameter may be supplied null in the case of
no initial content.public FitsChan()
public Iterator iterator()
next
method
will be an 80-character String. The Iterator's remove
method can be used to delete cards from the underlying channel.
The iterator should not be used while the FitsChan is being
written to.
This method is a convenience wrapper which uses findFits
and delFits
to do the work.
protected void sink(String line) throws IOException
close
method of this FitsChan is called
(either explicitly or under control of the garbage collector)
to dispose of each FITS header card currently in the channel.
The FitsChan
implementation simply discards each
line, but it may be overridden by subclasses to output the header
cards in a useful way. The method may throw an IOException in case
of error.sink
in class Channel
line
- an 80-character string giving the contents of one
FITS header card. This method discards it.IOException
- if a write error is encounteredprotected final String source()
null
if there are no more.
The FitsChan
implementation uses the Iterator
supplied in the constructor to obtain the lines of text.
It is declared final to prevent subclasses overriding it -
algthough in principle it could work, this practice would be
fraught with difficulty since the method is called by the
FitsChan constructor before the subclassed object has been
properly constucted, so it is likely to be in an inconsistent state.protected void finalize() throws Throwable
Channel
public void close()
sink
method will be invoked to write out any content of this
FitsChan
.public AstObject read()
read
in class Channel
AstObject
which has been read.
null
is returned, without error, if no
further objects remain to be read on the streamAstException
- if an error occurs in the AST librarypublic int write(AstObject obj)
write
in class Channel
obj
- an AstObject
to be writtenAstException
- if an error occurs in the AST librarypublic void setFits(String name, double rval, double ival, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readrval
- real part of the valueival
- imaginary part of the valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFits(String name, int rval, int ival, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readrval
- real part of the valueival
- imaginary part of the valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFits(String name, double value, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readvalue
- valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFits(String name, int value, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readvalue
- valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFits(String name, boolean value, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readvalue
- valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFits(String name, String value, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readvalue
- valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void setFitsContinue(String name, String value, String comment, boolean overwrite)
name
- FITS keyword name - may be a complete FITS header card,
in which case the keyword is extracted from it.
No more than 80 characters are readvalue
- valuecomment
- comment associated with the keyword.
If null or a blank string is supplied,
then any comment present in name is used.
If name
contains no comment, then
any existing coment in the card being overwritten
is retained. Otherwise, no comment is stored.overwrite
- If true, the new card overwrites the current card,
and the Card
attribute is incremented.
If false, then new card is inserted in front of the
current card, and the current card is left unchanged.
In either case, if the current card on entry
points to end-of-file, the new card is appended
to the end of the list.public void delFits()
After deletion, the following card becomes the current card.
AstException
- if an error occurred in the AST librarypublic String findFits(String name, boolean inc)
If the search is successful (i.e. a card is found which matches the template), the contents of the card are (optionally) returned and the Card attribute is adjusted to identify the card found or, if required, the one following it. If the search is not successful, the function returns zero and the Card attribute is set to the "end-of-file".
A field specifier starts with a "%" character. This is followed by an optional single digit (0 to 9) specifying a field width. Finally, there is a single character which specifies the
type of character to be matched, as follows:
- "c": matches all upper case letters,
- "d": matches all decimal digits,
- "f": matches all characters which are permitted within a FITS
keyword (upper case letters, digits, underscores and hyphens).
If the field width is omitted, the field specifier matches one or more characters. If the field width is zero, it matches zero or more characters. Otherwise, it matches exactly the number of
characters specified. In addition to this:
- The template "%f" will match a blank FITS keyword consisting
of 8 spaces (as well as matching all other keywords).
- A template consisting of 8 spaces will match a blank keyword
(only).
For example:
- The template "BitPix" will match the keyword "BITPIX" only.
- The template "crpix%1d" will match keywords consisting of
"CRPIX" followed by one decimal digit.
- The template "P%c" will match any keyword starting with "P"
and followed by one or more letters.
- The template "E%0f" will match any keyword beginning with "E".
- The template "%f" will match any keyword at all (including a
blank one).
name
- Pointer to a null-terminated character string containing a
template for the keyword to be found. In the simplest case,
this should simply be the keyword name (the search is case
insensitive and trailing spaces are ignored). However, this
template may also contain "field specifiers" which are
capable of matching a range of characters (see the "Keyword
Templates" section for details). In this case, the first card
with a keyword which matches the template will be found. To
find the next FITS card regardless of its keyword, you should
use the template "%f".inc
- If this value is zero (and the search is successful), the
FitsChan's Card attribute will be set to the index of the card
that was found. If it is non-zero, however, the Card
attribute will be incremented to identify the card which
follows the one found.AstException
- if an error occurred in the AST librarypublic boolean testFits(String name)
name
- Pointer to a null-terminated character string
containing the FITS keyword name. This may be a complete FITS
header card, in which case the keyword to use is extracted from
it. No more than 80 characters are read from this string.AstException
- if an error occurred in the AST librarypublic void putFits(String card, boolean overwrite)
card
- Pointer to a possibly null-terminated character string
containing the FITS card to be stored. No more than 80
characters will be used from this string (or fewer if a null
occurs earlier).overwrite
- If this value is zero, the new card is inserted in front of
the current card in the FitsChan (as identified by the
initial value of the Card attribute). If it is non-zero, the
new card replaces the current card. In either case, the Card
attribute is then incremented by one so that it subsequently
identifies the card following the one stored.AstException
- if an error occurred in the AST librarypublic void retainFits()
Cards that have not been flagged in this way are removed when a read operation completes succesfully, but only if the card was used in the process of creating the returned AST Object. Any cards that are irrelevant to the creation of the AST Object are retained whether or not they are flagged.
AstException
- if an error occurred in the AST librarypublic void purgeWCS()
AstException
- if an error occurred in the AST librarypublic void putCards(String cards)
cards
- Pointer to a null-terminated character string
containing the FITS cards to be stored. Each individual card
should occupy 80 characters in this string, and there should be
no delimiters, new lines, etc, between adjacent cards. The final
card may be less than 80 characters long.
This is the format produced by the fits_hdr2str function in the
CFITSIO library.AstException
- if an error occurred in the AST librarypublic int getCard()
A value assigned to Card will position the FitsChan at any desired point, so that a particular card within it can be accessed. Alternatively, the value of Card may be enquired in order to determine the current position of a FitsChan.
The default value of Card is 1. This means that clearing this attribute (using astClear) effectively "rewinds" the FitsChan, so that the first card is accessed next. If Card is set to a value which exceeds the total number of cards in the FitsChan (as given by its Ncard attribute), it is regarded as pointing at the "end-of-file". In this case, the value returned in response to an enquiry is always one more than the number of cards in the FitsChan.
public void setCard(int card)
A value assigned to Card will position the FitsChan at any desired point, so that a particular card within it can be accessed. Alternatively, the value of Card may be enquired in order to determine the current position of a FitsChan.
The default value of Card is 1. This means that clearing this attribute (using astClear) effectively "rewinds" the FitsChan, so that the first card is accessed next. If Card is set to a value which exceeds the total number of cards in the FitsChan (as given by its Ncard attribute), it is regarded as pointing at the "end-of-file". In this case, the value returned in response to an enquiry is always one more than the number of cards in the FitsChan.
card
- the Card attribute of this objectpublic boolean getCarLin()
The FITS-WCS paper specifies that headers which include a CAR projection represent a linear mapping from pixel coordinates to "native spherical coordinates", NOT celestial coordinates. An extra mapping is then required from native spherical to celestial. This mapping is a 3D rotation and so the overall Mapping from pixel to celestial coordinates is NOT linear. See the FITS-WCS papers for further details.
public void setCarLin(boolean carLin)
The FITS-WCS paper specifies that headers which include a CAR projection represent a linear mapping from pixel coordinates to "native spherical coordinates", NOT celestial coordinates. An extra mapping is then required from native spherical to celestial. This mapping is a 3D rotation and so the overall Mapping from pixel to celestial coordinates is NOT linear. See the FITS-WCS papers for further details.
carLin
- the CarLin attribute of this objectpublic boolean getCDMatrix()
If the attribute has a non-zero value then the transformation is represented by a set of CDi_j keywords representing a square matrix (where "i" is the index of an intermediate world coordinate axis and "j" is the index of a pixel axis). If the attribute has a zero value the transformation is represented by a set of PCi_j keywords (which also represent a square matrix) together with a corresponding set of CDELTi keywords representing the axis scalings. See FITS-WCS paper II "Representation of Celestial Coordinates in FITS" by M. Calabretta & E.W. Greisen, for a complete description of these two schemes.
The default value of the CDMatrix attribute is determined by the contents of the FitsChan at the time the attribute is accessed. If the FitsChan contains any CDi_j keywords then the default value is non-zero. Otherwise it is zero. Note, reading a FrameSet from a FitsChan will in general consume any CDi_j keywords present in the FitsChan. Thus the default value for CDMatrix following a read will usually be zero, even if the FitsChan originally contained some CDi_j keywords. This behaviour is similar to that of the Encoding attribute, the default value for which is determined by the contents of the FitsChan at the time the attribute is accessed. If you wish to retain the original value of the CDMatrix attribute (that is, the value before reading the FrameSet) then you should enquire the default value before doing the read, and then set that value explicitly.
public void setCDMatrix(boolean CDMatrix)
If the attribute has a non-zero value then the transformation is represented by a set of CDi_j keywords representing a square matrix (where "i" is the index of an intermediate world coordinate axis and "j" is the index of a pixel axis). If the attribute has a zero value the transformation is represented by a set of PCi_j keywords (which also represent a square matrix) together with a corresponding set of CDELTi keywords representing the axis scalings. See FITS-WCS paper II "Representation of Celestial Coordinates in FITS" by M. Calabretta & E.W. Greisen, for a complete description of these two schemes.
The default value of the CDMatrix attribute is determined by the contents of the FitsChan at the time the attribute is accessed. If the FitsChan contains any CDi_j keywords then the default value is non-zero. Otherwise it is zero. Note, reading a FrameSet from a FitsChan will in general consume any CDi_j keywords present in the FitsChan. Thus the default value for CDMatrix following a read will usually be zero, even if the FitsChan originally contained some CDi_j keywords. This behaviour is similar to that of the Encoding attribute, the default value for which is determined by the contents of the FitsChan at the time the attribute is accessed. If you wish to retain the original value of the CDMatrix attribute (that is, the value before reading the FrameSet) then you should enquire the default value before doing the read, and then set that value explicitly.
CDMatrix
- the CDMatrix attribute of this objectpublic boolean getDefB1950()
public void setDefB1950(boolean defB1950)
defB1950
- the DefB1950 attribute of this objectpublic String getEncoding()
There are several ways (conventions) by which coordinate system information may be represented in the form of FITS headers and the Encoding attribute is used to specify which of these should be used. The encoding options available are outlined in the "Encodings Available" section below, and in more detail in the sections which follow.
Encoding systems differ in the range of possible Objects (e.g. classes) they can represent, in the restrictions they place on these Objects (e.g. compatibility with some externally-defined coordinate system model) and in the number of Objects that can be stored together in any particular set of FITS header cards (e.g. multiple Objects, or only a single Object). The choice of encoding also affects the range of external applications which can potentially read and interpret the FITS header cards produced.
The encoding options available are not necessarily mutually exclusive, and it may sometimes be possible to store multiple Objects (or the same Object several times) using different encodings within the same set of FITS header cards. This possibility increases the likelihood of other applications being able to read and interpret the information.
By default, a FitsChan will attempt to determine which encoding system is already in use, and will set the default Encoding value accordingly (so that subsequent I/O operations adopt the same conventions). It does this by looking for certain critical FITS keywords which only occur in particular encodings. For details of how this works, see the "Choice of Default Encoding" section below. If you wish to ensure that a particular encoding system is used, independently of any FITS cards already present, you should set an explicit Encoding value yourself.
system:
- "DSS": Encodes coordinate system information in FITS header
cards using the convention developed at the Space Telescope
Science Institute (STScI) for the Digitised Sky Survey (DSS)
astrometric plate calibrations. The main advantages of this
encoding are that FITS images which use it are widely available
and it is understood by a number of important and
well-established astronomy applications. For further details,
see the section "The DSS Encoding" below.
- "FITS-WCS": Encodes coordinate system information in FITS
header cards using the conventions described in the FITS
world coordinate system (FITS-WCS) papers by E.W. Greisen,
M. Calabretta, et al. The main advantages of this encoding are that
it should be understood by any FITS-WCS compliant application and
is likely to be adopted widely for FITS data in future. For further
details, see the section "The FITS-WCS Encoding" below.
- "FITS-PC": Encodes coordinate system information in FITS
header cards using the conventions described in an earlier draft
of the FITS world coordinate system papers by E.W. Greisen and
M. Calabretta. This encoding uses a combination of CDELTi and
PCiiijjj keywords to describe the scale and rotation of the pixel
axes. This encoding is included to support existing data and
software which uses these now superceded conventions. In general,
the "FITS-WCS" encoding (which uses CDi_j or PCi_j keywords to
describe the scale and rotation) should be used in preference to
"FITS-PC".
- "FITS-IRAF": Encodes coordinate system information in FITS
header cards using the conventions described in the document
"World Coordinate Systems Representations Within the FITS
Format" by R.J. Hanisch and D.G. Wells, 1988. This encoding is
currently employed by the IRAF data analysis facility, so its
use will facilitate data exchange with IRAF. Its main advantages
are that it is a stable convention which approximates to a
subset of the propsed FITS-WCS encoding (above). This makes it
suitable as an interim method for storing coordinate system
information in FITS headers until the FITS-WCS encoding becomes
stable. Since many datasets currently use the FITS-IRAF
encoding, conversion of data from FITS-IRAF to the final form of
FITS-WCS is likely to be well supported.
- "FITS-AIPS": Encodes coordinate system information in FITS
header cards using the conventions originally introduced by the
AIPS data analysis facility. This is base on the use of CDELTi and
CROTAi keuwords to desribe the scale and rotation of each axis.
These conventions have been superceded but are still widely used.
- "FITS-AIPS++": Encodes coordinate system information in FITS
header cards using the conventions used by the AIPS++ project.
This is an extension of FITS-AIPS which includes some of the
features of FITS-IRAF and FITS-PC.
- "FITS-CLASS": Encodes coordinate system information in FITS
header cards using the conventions used by the CLASS project.
CLASS is a software package for reducing single-dish radio and
sub-mm spectroscopic data. See the section "CLASS FITS format" at
http://www.iram.fr/IRAMFR/GILDAS/doc/html/class-html/.
- "NATIVE": Encodes AST Objects in FITS header cards using a
convention which is private to the AST library (but adheres to
the general FITS standard) and which uses FITS keywords that
will not clash with other encoding systems. The main advantages
of this are that any class of AST Object may be encoded, and any
(reasonable) number of Objects may be stored sequentially in the
same FITS header. This makes FITS headers an almost loss-less
communication path for passing AST Objects between applications
(although all such applications must, of course, make use of the
AST library to interpret the information). For further details,
see the section "The NATIVE Encoding" below.
used to arrive at the default value is as follows:
- If the FitsChan contains any keywords beginning with the
string "BEGAST", then NATIVE encoding is used,
- Otherwise, FITS-CLASS is used if the FitsChan contains a DELTAV
keyword and a keyword of the form VELO-xxx, where xxx indicates one
of the rest frames used by class (e.g. "VELO-LSR").
- Otherwise, if the FitsChan contains a CTYPE keyword which
represents a spectral axis using the conventions of the AIPS and
AIPS++ projects (e.g. "FELO-LSR", etc), then one of FITS-AIPS or
FITS-AIPS++ encoding is used. FITS-AIPS++ is used if any of the
keywords CDi_j, PROJP, LONPOLE or LATPOLE are
found in the FitsChan. Otherwise FITS-AIPS is used.
- Otherwise, if the FitsChan contains a keyword of the form
"PCiiijjj", where "i" and "j" are single digits, then
FITS-PC encoding is used,
- Otherwise, if the FitsChan contains a keyword of the form
"CDiiijjj", where "i" and "j" are single digits, then
FITS-IRAF encoding is used,
- Otherwise, if the FitsChan contains a keyword of the form
"CDi_j", and at least one of RADECSYS, PROJPi, or CjVALi
where "i" and "j" are single digits, then FITS-IRAF encoding is
used.
- Otherwise, if the FitsChan contains any keywords of the form
PROJPi, CjVALi or RADECSYS, where "i" and "j" are single digits,
then FITS-PC encoding is used.
- Otherwise, if the FitsChan contains a keyword of the form
CROTAi, where "i" is a single digit, then FITS-AIPS encoding is
used.
- Otherwise, if the FitsChan contains a keyword of the form
CRVALi, where "i" is a single digit, then FITS-WCS encoding is
used.
- Otherwise, if the FitsChan contains the "PLTRAH" keyword, then
DSS encoding is used,
- Otherwise, if none of these conditions is met (as would be the
case when using an empty FitsChan), then NATIVE encoding is
used.
Except for the NATIVE and DSS encodings, all the above checks also require that the header contains at least one CTYPE, CRPIX and CRVAL keyword (otherwise the checking process continues to the next case).
Setting an explicit value for the Encoding attribute always over-rides this default behaviour.
Note that when writing information to a FitsChan, the choice of encoding will depend greatly on the type of application you expect to be reading the information in future. If you do not know this, there may sometimes be an advantage in writing the information several times, using a different encoding on each occasion.
When reading a DSS encoded Object (using astRead), the FitsChan concerned must initially be positioned at the first card (its Card attribute must equal 1) and the result of the read, if successful, will always be a pointer to a FrameSet. The base Frame of this FrameSet represents DSS pixel coordinates, and the current Frame represents DSS celestial coordinates. Such a read is always destructive and causes the FITS header cards required for the construction of the FrameSet to be removed from the FitsChan, which is then left positioned at the "end-of-file". A subsequent read using the same encoding will therefore not return another FrameSet, even if the FitsChan is rewound.
When astWrite is used to store a FrameSet using DSS encoding, an attempt is first made to simplify the FrameSet to see if it conforms to the DSS model. Specifically, the current Frame must be a FK5 SkyFrame; the projection must be a tangent plane (gnomonic) projection with polynomial corrections conforming to DSS requirements, and north must be parallel to the second base Frame axis.
If the simplification process succeeds, a description of the FrameSet is written to the FitsChan using appropriate DSS FITS header cards. The base Frame of the FrameSet is used to form the DSS pixel coordinate system and the current Frame gives the DSS celestial coordinate system. A successful write operation will over-write any existing DSS encoded data in the FitsChan, but will not affect other (non-DSS) header cards. If a destructive read of a DSS encoded Object has previously occurred, then an attempt will be made to store the FITS header cards back in their original locations.
If an attempt to simplify a FrameSet to conform to the DSS model fails (or if the Object supplied is not a FrameSet), then no data will be written to the FitsChan and astWrite will return zero. No error will result.
When reading a NATIVE encoded object from a FitsChan (using astRead), FITS header cards are read, starting at the current card (as determined by the Card attribute), until the start of the next Object description is found. This description is then read and converted into an AST Object, for which a pointer is returned. Such a read is always destructive and causes all the FITS header cards involved in the Object description to be removed from the FitsChan, which is left positioned at the following card.
The Object returned may be of any class, depending on the description that was read, and other AST routines may be used to validate it (for example, by examining its Class or ID attribute using astGetC). If further NATIVE encoded Object descriptions exist in the FitsChan, subsequent calls to astRead will return the Objects they describe in sequence (and destroy their descriptions) until no more remain between the current card and the "end-of-file".
When astWrite is used to write an Object using NATIVE encoding, a description of the Object is inserted immediately before the current card (as determined by the Card attribute). Multiple Object descriptions may be written in this way and are stored separately (and sequentially if the Card attribute is not modified between the writes). A write operation using the NATIVE encoding does not over-write previously written Object descriptions. Note, however, that subsequent behaviour is undefined if an Object description is written inside a previously-written description, so this should be avoided.
When an Object is written to a FitsChan using NATIVE encoding, astWrite should (barring errors) always transfer data and return a value of 1.
public void setEncoding(String encoding)
There are several ways (conventions) by which coordinate system information may be represented in the form of FITS headers and the Encoding attribute is used to specify which of these should be used. The encoding options available are outlined in the "Encodings Available" section below, and in more detail in the sections which follow.
Encoding systems differ in the range of possible Objects (e.g. classes) they can represent, in the restrictions they place on these Objects (e.g. compatibility with some externally-defined coordinate system model) and in the number of Objects that can be stored together in any particular set of FITS header cards (e.g. multiple Objects, or only a single Object). The choice of encoding also affects the range of external applications which can potentially read and interpret the FITS header cards produced.
The encoding options available are not necessarily mutually exclusive, and it may sometimes be possible to store multiple Objects (or the same Object several times) using different encodings within the same set of FITS header cards. This possibility increases the likelihood of other applications being able to read and interpret the information.
By default, a FitsChan will attempt to determine which encoding system is already in use, and will set the default Encoding value accordingly (so that subsequent I/O operations adopt the same conventions). It does this by looking for certain critical FITS keywords which only occur in particular encodings. For details of how this works, see the "Choice of Default Encoding" section below. If you wish to ensure that a particular encoding system is used, independently of any FITS cards already present, you should set an explicit Encoding value yourself.
system:
- "DSS": Encodes coordinate system information in FITS header
cards using the convention developed at the Space Telescope
Science Institute (STScI) for the Digitised Sky Survey (DSS)
astrometric plate calibrations. The main advantages of this
encoding are that FITS images which use it are widely available
and it is understood by a number of important and
well-established astronomy applications. For further details,
see the section "The DSS Encoding" below.
- "FITS-WCS": Encodes coordinate system information in FITS
header cards using the conventions described in the FITS
world coordinate system (FITS-WCS) papers by E.W. Greisen,
M. Calabretta, et al. The main advantages of this encoding are that
it should be understood by any FITS-WCS compliant application and
is likely to be adopted widely for FITS data in future. For further
details, see the section "The FITS-WCS Encoding" below.
- "FITS-PC": Encodes coordinate system information in FITS
header cards using the conventions described in an earlier draft
of the FITS world coordinate system papers by E.W. Greisen and
M. Calabretta. This encoding uses a combination of CDELTi and
PCiiijjj keywords to describe the scale and rotation of the pixel
axes. This encoding is included to support existing data and
software which uses these now superceded conventions. In general,
the "FITS-WCS" encoding (which uses CDi_j or PCi_j keywords to
describe the scale and rotation) should be used in preference to
"FITS-PC".
- "FITS-IRAF": Encodes coordinate system information in FITS
header cards using the conventions described in the document
"World Coordinate Systems Representations Within the FITS
Format" by R.J. Hanisch and D.G. Wells, 1988. This encoding is
currently employed by the IRAF data analysis facility, so its
use will facilitate data exchange with IRAF. Its main advantages
are that it is a stable convention which approximates to a
subset of the propsed FITS-WCS encoding (above). This makes it
suitable as an interim method for storing coordinate system
information in FITS headers until the FITS-WCS encoding becomes
stable. Since many datasets currently use the FITS-IRAF
encoding, conversion of data from FITS-IRAF to the final form of
FITS-WCS is likely to be well supported.
- "FITS-AIPS": Encodes coordinate system information in FITS
header cards using the conventions originally introduced by the
AIPS data analysis facility. This is base on the use of CDELTi and
CROTAi keuwords to desribe the scale and rotation of each axis.
These conventions have been superceded but are still widely used.
- "FITS-AIPS++": Encodes coordinate system information in FITS
header cards using the conventions used by the AIPS++ project.
This is an extension of FITS-AIPS which includes some of the
features of FITS-IRAF and FITS-PC.
- "FITS-CLASS": Encodes coordinate system information in FITS
header cards using the conventions used by the CLASS project.
CLASS is a software package for reducing single-dish radio and
sub-mm spectroscopic data. See the section "CLASS FITS format" at
http://www.iram.fr/IRAMFR/GILDAS/doc/html/class-html/.
- "NATIVE": Encodes AST Objects in FITS header cards using a
convention which is private to the AST library (but adheres to
the general FITS standard) and which uses FITS keywords that
will not clash with other encoding systems. The main advantages
of this are that any class of AST Object may be encoded, and any
(reasonable) number of Objects may be stored sequentially in the
same FITS header. This makes FITS headers an almost loss-less
communication path for passing AST Objects between applications
(although all such applications must, of course, make use of the
AST library to interpret the information). For further details,
see the section "The NATIVE Encoding" below.
used to arrive at the default value is as follows:
- If the FitsChan contains any keywords beginning with the
string "BEGAST", then NATIVE encoding is used,
- Otherwise, FITS-CLASS is used if the FitsChan contains a DELTAV
keyword and a keyword of the form VELO-xxx, where xxx indicates one
of the rest frames used by class (e.g. "VELO-LSR").
- Otherwise, if the FitsChan contains a CTYPE keyword which
represents a spectral axis using the conventions of the AIPS and
AIPS++ projects (e.g. "FELO-LSR", etc), then one of FITS-AIPS or
FITS-AIPS++ encoding is used. FITS-AIPS++ is used if any of the
keywords CDi_j, PROJP, LONPOLE or LATPOLE are
found in the FitsChan. Otherwise FITS-AIPS is used.
- Otherwise, if the FitsChan contains a keyword of the form
"PCiiijjj", where "i" and "j" are single digits, then
FITS-PC encoding is used,
- Otherwise, if the FitsChan contains a keyword of the form
"CDiiijjj", where "i" and "j" are single digits, then
FITS-IRAF encoding is used,
- Otherwise, if the FitsChan contains a keyword of the form
"CDi_j", and at least one of RADECSYS, PROJPi, or CjVALi
where "i" and "j" are single digits, then FITS-IRAF encoding is
used.
- Otherwise, if the FitsChan contains any keywords of the form
PROJPi, CjVALi or RADECSYS, where "i" and "j" are single digits,
then FITS-PC encoding is used.
- Otherwise, if the FitsChan contains a keyword of the form
CROTAi, where "i" is a single digit, then FITS-AIPS encoding is
used.
- Otherwise, if the FitsChan contains a keyword of the form
CRVALi, where "i" is a single digit, then FITS-WCS encoding is
used.
- Otherwise, if the FitsChan contains the "PLTRAH" keyword, then
DSS encoding is used,
- Otherwise, if none of these conditions is met (as would be the
case when using an empty FitsChan), then NATIVE encoding is
used.
Except for the NATIVE and DSS encodings, all the above checks also require that the header contains at least one CTYPE, CRPIX and CRVAL keyword (otherwise the checking process continues to the next case).
Setting an explicit value for the Encoding attribute always over-rides this default behaviour.
Note that when writing information to a FitsChan, the choice of encoding will depend greatly on the type of application you expect to be reading the information in future. If you do not know this, there may sometimes be an advantage in writing the information several times, using a different encoding on each occasion.
When reading a DSS encoded Object (using astRead), the FitsChan concerned must initially be positioned at the first card (its Card attribute must equal 1) and the result of the read, if successful, will always be a pointer to a FrameSet. The base Frame of this FrameSet represents DSS pixel coordinates, and the current Frame represents DSS celestial coordinates. Such a read is always destructive and causes the FITS header cards required for the construction of the FrameSet to be removed from the FitsChan, which is then left positioned at the "end-of-file". A subsequent read using the same encoding will therefore not return another FrameSet, even if the FitsChan is rewound.
When astWrite is used to store a FrameSet using DSS encoding, an attempt is first made to simplify the FrameSet to see if it conforms to the DSS model. Specifically, the current Frame must be a FK5 SkyFrame; the projection must be a tangent plane (gnomonic) projection with polynomial corrections conforming to DSS requirements, and north must be parallel to the second base Frame axis.
If the simplification process succeeds, a description of the FrameSet is written to the FitsChan using appropriate DSS FITS header cards. The base Frame of the FrameSet is used to form the DSS pixel coordinate system and the current Frame gives the DSS celestial coordinate system. A successful write operation will over-write any existing DSS encoded data in the FitsChan, but will not affect other (non-DSS) header cards. If a destructive read of a DSS encoded Object has previously occurred, then an attempt will be made to store the FITS header cards back in their original locations.
If an attempt to simplify a FrameSet to conform to the DSS model fails (or if the Object supplied is not a FrameSet), then no data will be written to the FitsChan and astWrite will return zero. No error will result.
When reading a NATIVE encoded object from a FitsChan (using astRead), FITS header cards are read, starting at the current card (as determined by the Card attribute), until the start of the next Object description is found. This description is then read and converted into an AST Object, for which a pointer is returned. Such a read is always destructive and causes all the FITS header cards involved in the Object description to be removed from the FitsChan, which is left positioned at the following card.
The Object returned may be of any class, depending on the description that was read, and other AST routines may be used to validate it (for example, by examining its Class or ID attribute using astGetC). If further NATIVE encoded Object descriptions exist in the FitsChan, subsequent calls to astRead will return the Objects they describe in sequence (and destroy their descriptions) until no more remain between the current card and the "end-of-file".
When astWrite is used to write an Object using NATIVE encoding, a description of the Object is inserted immediately before the current card (as determined by the Card attribute). Multiple Object descriptions may be written in this way and are stored separately (and sequentially if the Card attribute is not modified between the writes). A write operation using the NATIVE encoding does not over-write previously written Object descriptions. Note, however, that subsequent behaviour is undefined if an Object description is written inside a previously-written description, so this should be avoided.
When an Object is written to a FitsChan using NATIVE encoding, astWrite should (barring errors) always transfer data and return a value of 1.
encoding
- the Encoding attribute of this objectpublic int getFitsDigits()
By default, a positive value is used which results in no loss of information, assuming that the value's precision is double. Usually, this causes no problems.
However, to adhere strictly to the recommendations of the FITS standard, the width of the formatted value (including sign, decimal point and exponent) ought not to be more than 20 characters. If you are concerned about this, you should set FitsDigits to a negative value, such as -15. In this case, the absolute value (+15) indicates the maximum number of significant digits to use, but the actual number used may be fewer than this to ensure that the FITS recommendations are satisfied. When using this approach, the resulting number of significant digits may depend on the value being formatted and on the presence of any sign, decimal point or exponent.
The value of this attribute is effective when FITS header cards are output, either using astFindFits or by the action of the FitsChan's sink function when it is finally deleted.
public void setFitsDigits(int fitsDigits)
By default, a positive value is used which results in no loss of information, assuming that the value's precision is double. Usually, this causes no problems.
However, to adhere strictly to the recommendations of the FITS standard, the width of the formatted value (including sign, decimal point and exponent) ought not to be more than 20 characters. If you are concerned about this, you should set FitsDigits to a negative value, such as -15. In this case, the absolute value (+15) indicates the maximum number of significant digits to use, but the actual number used may be fewer than this to ensure that the FITS recommendations are satisfied. When using this approach, the resulting number of significant digits may depend on the value being formatted and on the presence of any sign, decimal point or exponent.
The value of this attribute is effective when FITS header cards are output, either using astFindFits or by the action of the FitsChan's sink function when it is finally deleted.
fitsDigits
- the FitsDigits attribute of this objectpublic int getNcard()
public String getWarnings()
The text of any warning will be stored within the FitsChan in the form of one or more new header cards with keyword ASTWARN. If required, applications can check the FitsChan for ASTWARN cards (using astFindFits) after the call to astRead or astWrite has been performed, and report the text of any such cards to the user. ASTWARN cards will be propagated to any output header unless they are deleted from the FitsChan using astDelFits.
public void setWarnings(String warnings)
The text of any warning will be stored within the FitsChan in the form of one or more new header cards with keyword ASTWARN. If required, applications can check the FitsChan for ASTWARN cards (using astFindFits) after the call to astRead or astWrite has been performed, and report the text of any such cards to the user. ASTWARN cards will be propagated to any output header unless they are deleted from the FitsChan using astDelFits.
warnings
- the Warnings attribute of this objectpublic String getAllWarnings()
case-insensitive):
- "BadCel": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan if an unknown celestial co-ordinate
system is specified by the CTYPE keywords.
- "BadCTYPE": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan if an illegal algorithm code is specified
by a CTYPE keyword, and the illegal code can be converted to an
equivalent legal code.
- "BadLat": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan if the latitude of the reference point
has an absolute value greater than 90 degrees. The actual absolute
value used is set to exactly 90 degrees in these cases.
- "BadMat": This condition arises if the matrix describing the
transformation from pixel offsets to intermediate world coordinates
cannot be inverted. This matrix describes the scaling, rotation, shear,
etc., applied to the pixel axes, and is specified by keywords such as
PCi_j, CDi_j, CROTA, etc. For example, the matrix will not be invertable
if any rows or columns consist entirely of zeros. The FITS-WCS Paper I
"Representation of World Coordinates in FITS" by Greisen & Calabretta
requires that this matrix be invertable. Many operations (such as
grid plotting) will not be possible if the matrix cannot be inverted.
- "BadPV": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan. It is issued if a PVi_m header is found
that refers to a projection parameter that is not used by the
projection type specified by CTYPE.
- "BadVal": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan if it is not possible to convert the
value of a FITS keywords to the expected type. For instance, this
can occur if the FITS header contains a string value for a keyword
which should have a floating point value, or if the keyword has no
value at all (i.e. is a comment card).
- "Distortion": This condition arises when reading a FrameSet from a
non-Native encoded FitsChan if any of the CTYPE keywords specify an
unsupported distortion code using the "4-3-3" format specified in
FITS-WCS paper IV. Such distortion codes are ignored.
- "NoCTYPE": This condition arises if a default CTYPE value is used
within astRead, due to no value being present in the supplied FitsChan.
This condition is only tested for when using non-Native encodings.
- "NoEquinox": This condition arises if a default equinox value is used
within astRead, due to no value being present in the supplied FitsChan.
This condition is only tested for when using non-Native encodings.
- "NoRadesys": This condition arises if a default reference frame is
used for an equatorial co-ordinate system within astRead, due to no
value being present in the supplied FitsChan. This condition is only
tested for when using non-Native encodings.
- "NoLonpole": This condition arises if a default value is used for
the LONPOLE keyword within astRead, due to no value being present
in the supplied FitsChan. This condition is only tested for when
using non-Native encodings.
- "NoLatpole": This condition arises if a default value is used for
the LATPOLE keyword within astRead, due to no value being present
in the supplied FitsChan. This condition is only tested for when
using non-Native encodings.
- "NoMjd-obs": This condition arises if a default value is used for
the date of observation within astRead, due to no value being present
in the supplied FitsChan. This condition is only tested for when using
non-Native encodings.
- "Tnx": This condition arises if a FrameSet is read from a FITS
header containing an IRAF "TNX" projection which includes terms
not supproted by AST. Such terms are ignored and so the resulting
FrameSet may be inaccurate.
- "Zpx": This condition arises if a FrameSet is read from a FITS
header containing an IRAF "ZPX" projection which includes "lngcor"
or "latcor" correction terms. These terms are not supported by AST
and are ignored. The resulting FrameSet may therefore be inaccurate.
public boolean getIwc()
FITS-WCS paper 1 defines IWC as a Cartesian coordinate system with one axis for each WCS axis, and is the coordinate system produced by the rotation matrix (represented by FITS keyword PCi_j, CDi_j, etc). For instance, for a 2-D FITS-WCS header describing projected celestial longitude and latitude, the intermediate world coordinates represent offsets in degrees from the reference point within the plane of projection.
public void setIwc(boolean iwc)
FITS-WCS paper 1 defines IWC as a Cartesian coordinate system with one axis for each WCS axis, and is the coordinate system produced by the rotation matrix (represented by FITS keyword PCi_j, CDi_j, etc). For instance, for a 2-D FITS-WCS header describing projected celestial longitude and latitude, the intermediate world coordinates represent offsets in degrees from the reference point within the plane of projection.
iwc
- the Iwc attribute of this objectCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.