Package nom.tam.fits
Class BasicHDU<DataClass extends Data>
java.lang.Object
nom.tam.fits.BasicHDU<DataClass>
- Type Parameters:
DataClass
- the generic type of data contained in this HDU instance.
- All Implemented Interfaces:
FitsElement
- Direct Known Subclasses:
ImageHDU
,RandomGroupsHDU
,TableHDU
,UndefinedHDU
Abstract base class for all header-data unit (HDU) types. A HDU is a self-contained building block of the FITS files,
which encapsulates information on a particular data object such as an image or table. As the name implies, HDUs
constitute of a header and data entities, which can be accessed separately (via the
getHeader()
and
getData()
methods respectively). The Header
class provides many functions to add, delete and read
header keywords in HDUs in a variety of formats. The Data
class, and its concrete subclassses provide access
to the specific data object that the HDU encapsulates. It provides basic functionality for an HDU.-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Deprecated.static final int
Deprecated.UseBitpix.VALUE_FOR_DOUBLE
instead.static final int
Deprecated.UseBitpix.VALUE_FOR_FLOAT
instead.static final int
Deprecated.UseBitpix.VALUE_FOR_INT
instead.static final int
Deprecated.UseBitpix.VALUE_FOR_LONG
instead.static final int
Deprecated.UseBitpix.VALUE_FOR_SHORT
instead. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add information to the header.void
Add information to the header.void
Add information to the header.void
Add information to the header.void
addValue
(IFitsHeader key, boolean val) Add information to the header.void
addValue
(IFitsHeader key, double val) Add information to the header.void
addValue
(IFitsHeader key, int val) Add information to the header.void
addValue
(IFitsHeader key, String val) Add information to the header.long
Deprecated.UseverifyIntegrity()
instead when appropriate.card
(IFitsHeader key) Returns a header card builder for filling the header cards using the builder pattern.Return the name of the person who compiled the information in the data associated with this header.int[]
getAxes()
In FITS files the index represented by NAXIS1 is the index that changes most rapidly.Return the Bitpix enum type for this HDU.final int
Deprecated.(for internal use) Will reduce visibility or remove entirely in the future.long
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.double
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.getBUnit()
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
and not for other HDU or data types.double
getBZero()
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.Get the FITS file creation date as aDate
object.getData()
Returns the data component of this HDU.static NullDataHDU
Deprecated.UseNullDataHDU
instead.double
getEpoch()
Deprecated.usegetEquinox()
insteaddouble
Get the equinox in years for the celestial coordinate system in which positions given in either the header or data are expressed.long
Returns the byte offset at which this element starts ina file.int
Deprecated.Should not be exposed outside ofRandomGroupsHDU
-- will reduce visibility in the future/Returns the FITS header component of this HDUGet the name of the instrument which was used to acquire the data in this FITS file.final Object
Returns the underlying Java object (usually an array of some type) that stores the data internally.double
Return the minimum valid value in the array.double
Return the minimum valid value in the array.Get the name of the observed object in this FITS file.Get the FITS file observation date as aDate
object.Get the name of the person who acquired the data in this FITS file.Get the name of the organization which created this FITS file.int
Deprecated.Should not be exposed outside ofRandomGroupsHDU
-- will reduce visibility in the future.Return the citation of a reference where the data associated with this header are published.long
getSize()
Returns the size of this elements in the FITS representation.long
Deprecated.Not very useful, since it has no meaning other than ensuring that the checksum of the HDU yields(int) -1
(that is0xffffffff
) after including this value for the CHECKSUM keyword in the header.long
Returns the FITS checksum for the HDU's data that is stored in the header of this HDU under theDATASUM
keyword.Get the name of the telescope which was used to acquire the data in this FITS file.getTrimmedString
(String keyword) Deprecated.(for internal use) Will reduced visibility in the future.getTrimmedString
(IFitsHeader keyword) Deprecated.(for internal use) Will reduced visibility in the future.abstract void
info
(PrintStream stream) Print out some information about this HDU.static boolean
Deprecated.(for internal use) Will be removed as it serves no purpose.static boolean
Deprecated.(for internal use) Will be removed as it serves no purpose.void
read
(ArrayDataInput stream) Read a FITS element from the input, starting at the current position.boolean
reset()
Reset the input stream to point to the beginning of this elementvoid
rewrite()
Rewrite the contents of the element in place.boolean
Checks if we can write this element back to its source.void
Computes the checksums for this HDU and stores theCHECKSUM
andDATASUM
values in the header.boolean
Checks that the HDUs data checksum is correct.boolean
Checks the HDU's integrity, using the recorded CHECKSUM and/or DATASUM keywords if present.void
write
(ArrayDataOutput stream) Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.
-
Field Details
-
BITPIX_BYTE
Deprecated.UseBitpix.VALUE_FOR_BYTE
instead.- See Also:
-
BITPIX_SHORT
Deprecated.UseBitpix.VALUE_FOR_SHORT
instead.- See Also:
-
BITPIX_INT
Deprecated.UseBitpix.VALUE_FOR_INT
instead.- See Also:
-
BITPIX_LONG
Deprecated.UseBitpix.VALUE_FOR_LONG
instead.- See Also:
-
BITPIX_FLOAT
Deprecated.UseBitpix.VALUE_FOR_FLOAT
instead.- See Also:
-
BITPIX_DOUBLE
Deprecated.UseBitpix.VALUE_FOR_DOUBLE
instead.- See Also:
-
-
Method Details
-
getDummyHDU
Deprecated.UseNullDataHDU
instead. Gets a HDU with no data, only header.- Returns:
- an HDU without content
-
isHeader
Deprecated.(for internal use) Will be removed as it serves no purpose.Checks that this is a valid header for the HDU. This method is static but should be implemented by all subclasses.- Parameters:
header
- to validate.- Returns:
true
if this is a valid header.
-
isData
Deprecated.(for internal use) Will be removed as it serves no purpose.- Parameters:
o
- The Object being tested.- Returns:
- if this object can be described as a FITS image. This method is static but should be implemented by all subclasses.
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to add- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to add- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to add- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to add- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to addcomment
- comment for the key/value pair- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to addcomment
- comment for the key/value pair- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to addcomment
- comment for the key/value pair- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
addValue
Add information to the header.- Parameters:
key
- key to add to the headerval
- value for the key to addcomment
- comment for the key/value pair- Throws:
HeaderCardException
- if the card does not follow the specification- See Also:
-
getAuthor
Return the name of the person who compiled the information in the data associated with this header.- Returns:
- either
null
or a String object
-
getAxes
In FITS files the index represented by NAXIS1 is the index that changes most rapidly. This reflectsf the behavior of Fortran where there are true multidimensional arrays. In Java in a multidimensional array is an array of arrays and the first index is the index that changes slowest. So at some point a client of the library is going to have to invert the order. E.g., if I have a FITS file willBITPIX=16 NAXIS1=10 NAXIS2=20 NAXIS3=30
this will be read into a Java array short[30][20][10] so it makes sense to me at least that the returned dimensions are 30,20,10- Returns:
- the dimensions of the axis.
- Throws:
FitsException
- if the axis are configured wrong.
-
getBitpix
Return the Bitpix enum type for this HDU.- Returns:
- The Bitpix enum object for this HDU.
- Throws:
FitsException
- if the BITPIX value in the header is absent or invalid.- Since:
- 1.16
- See Also:
-
getBitPix
Deprecated.(for internal use) Will reduce visibility or remove entirely in the future.Return the BITPIX integer value as stored in the FIS header.- Returns:
- The BITPIX integer values for this HDU as it appears in the header.
- Throws:
FitsException
- if the BITPIX value in the header is absent or invalid.- See Also:
-
getBUnit
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
and not for other HDU or data types.Returns the name of the physical unit in which images are represented.- Returns:
- the standard name of the physical unit in which the image is expressed, e.g.
"Jy beam^{-1}"
.
-
getBlankValue
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.Returns the integer value that signifies blank (missing ornull
) data in an integer image.- Returns:
- the integer value used for identifying blank / missing data in integer images.
- Throws:
FitsException
- if the header does not specify a blanking value.
-
getBScale
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.Returns the floating-point increment between adjacent integer values in the image.- Returns:
- the floating-point quantum that corresponds to the increment of 1 in the integer data representation.
- See Also:
-
getBZero
Deprecated.This is only applicable toImageHDU
orRandomGroupsHDU
with integer type data and not for other HDU or data types.Returns the floating-point value that corresponds to an 0 integer value in the image.- Returns:
- the floating point value that correspond to the integer 0 in the image data.
- See Also:
-
getCreationDate
Get the FITS file creation date as aDate
object.- Returns:
- either
null
or a Date object
-
getData
Returns the data component of this HDU.- Returns:
- the associated Data object
-
getEpoch
Deprecated.usegetEquinox()
insteadGet the equinox in years for the celestial coordinate system in which positions given in either the header or data are expressed.- Returns:
- either
null
or a String object
-
getEquinox
public double getEquinox()Get the equinox in years for the celestial coordinate system in which positions given in either the header or data are expressed.- Returns:
- either
null
or a String object
-
getFileOffset
public long getFileOffset()Description copied from interface:FitsElement
Returns the byte offset at which this element starts ina file. If the element was not obtained from an input, then 0 is returned.- Specified by:
getFileOffset
in interfaceFitsElement
- Returns:
- the byte at which this element begins. This is only available if the data is originally read from a random access medium. Otherwise 0 is returned.
-
getGroupCount
public int getGroupCount()Deprecated.Should not be exposed outside ofRandomGroupsHDU
-- will reduce visibility in the future/Returns the number of data objects (of identical shape and size) that are group together in this HDUs data segment. For most data types this would be simply 1, except forRandomGroupsData
, where other values are possible.- Returns:
- the number of data objects (of identical shape and size) that are grouped together in the data segment.
- See Also:
-
getStoredChecksum
Deprecated.Not very useful, since it has no meaning other than ensuring that the checksum of the HDU yields(int) -1
(that is0xffffffff
) after including this value for the CHECKSUM keyword in the header. It will be removed in the future. UseverifyIntegrity()
instead when appropriate.Returns the decoded checksum that is stored in the header of this HDU under theCHECKSUM
keyword. It does not have much use, and is not needed for integrity verification since the purpose of the CHECKSUM value is merely to ensure that the checksum of the HDU is always(int) -1
.- Returns:
- the decoded FITS checksum value recorded in the HDU
- Throws:
FitsException
- if the HDU's header does not contain aCHECKSUM
keyword.- Since:
- 1.17
- See Also:
-
getStoredDatasum
Returns the FITS checksum for the HDU's data that is stored in the header of this HDU under theDATASUM
keyword. This may be useful to compare against the checksum calculated from data in memory (e.g. viaData.calcChecksum()
) to check changes / corruption of the in-memory data vs what was stored in the file. Note however, that this type of checkum test will fail if the file used non-standard padding at the end of the data segment, even if the data themselves are identical. Hence, for verifying data contained in a fileverifyDataIntegrity()
orverifyIntegrity()
should be preferred.- Returns:
- the FITS
DATASUM
value recorded in the HDU - Throws:
FitsException
- if the HDU's header does not contain aDATASUM
keyword.- Since:
- 1.17
- See Also:
-
setChecksum
Computes the checksums for this HDU and stores the
CHECKSUM
andDATASUM
values in the header. This should be the last modification to the HDU before writing it.Note, that this method will always calculate the checksum in memory. As a result it will load data in deferred read mode into RAM for performaing the calculation. If you prefer to keep deferred read mode data unloaded, you should use
Fits.setChecksum(int)
instead.- Throws:
FitsException
- if there was an error serializing the HDU for the checksum computation.- Since:
- 1.17
- See Also:
-
verifyIntegrity
Checks the HDU's integrity, using the recorded CHECKSUM and/or DATASUM keywords if present. In addition of performing the same checks asverifyDataIntegrity()
, it also checks the overall checksum of the HDU if possible. When the header has a CHECKSUM keyword stored, the overall checksum of the HDU must be0xffffffff
, that is -1 in 32-bit representation.- Returns:
true
if the HDU has a CHECKSUM and/or DATASUM record to check against, otherwisefalse
- Throws:
FitsException
- if the HDU fails the integrity test.IOException
- if there was an I/O error accessing the input.- Since:
- 1.18.1
- See Also:
-
verifyDataIntegrity
Checks that the HDUs data checksum is correct. The recorded DATASUM will be used, if available, to check the integrity of the data segment.- Returns:
true
if the HDU has DATASUM record to check against, otherwisefalse
- Throws:
FitsException
- if the HDU fails the integrity test.IOException
- if there was an I/O error accessing the input.- Since:
- 1.18.1
- See Also:
-
calcChecksum
Deprecated.UseverifyIntegrity()
instead when appropriate. It's not particularly useful since integrity checking does not use or require knowledge of this sum. May be removed from future releases.Computes and returns the FITS checksum for this HDU, e.g. to compare agains the storedCHECKSUM
in the FITS header. This method always computes the checksum from data fully loaded in memory. As such it will load deferred read mode data into RAM to perform the calculation. If you prefer to leave the data in deferred read mode, you can useFits.calcChecksum(int)
instead.- Returns:
- the computed HDU checksum (in memory).
- Throws:
FitsException
- if there was an error while calculating the checksum- Since:
- 1.17
- See Also:
-
getHeader
Returns the FITS header component of this HDU- Returns:
- the associated header
- See Also:
-
card
Returns a header card builder for filling the header cards using the builder pattern.- Parameters:
key
- the key for the first card.- Returns:
- the builder for header cards.
-
getInstrument
Get the name of the instrument which was used to acquire the data in this FITS file.- Returns:
- either
null
or a String object
-
getKernel
Returns the underlying Java object (usually an array of some type) that stores the data internally.- Returns:
- the non-FITS data object. Same as
getData()
.getKernel()
.
-
getMaximumValue
public double getMaximumValue()Return the minimum valid value in the array.- Returns:
- minimum value.
-
getMinimumValue
public double getMinimumValue()Return the minimum valid value in the array.- Returns:
- minimum value.
-
getObject
Get the name of the observed object in this FITS file.- Returns:
- either
null
or a String object
-
getObservationDate
Get the FITS file observation date as aDate
object.- Returns:
- either
null
or a Date object
-
getObserver
Get the name of the person who acquired the data in this FITS file.- Returns:
- either
null
or a String object
-
getOrigin
Get the name of the organization which created this FITS file.- Returns:
- either
null
or a String object
-
getParameterCount
public int getParameterCount()Deprecated.Should not be exposed outside ofRandomGroupsHDU
-- will reduce visibility in the future.Returns the number of parameter bytes (per data group) accompanying each data object in the group.- Returns:
- the number of bytes used for arbitrary extra parameters accompanying each data object in the group.
- See Also:
-
getReference
Return the citation of a reference where the data associated with this header are published.- Returns:
- either
null
or a String object
-
getSize
public long getSize()Description copied from interface:FitsElement
Returns the size of this elements in the FITS representation. This may include padding if the element (such as a header or data segment) is expected to complete a FITS block of 2880 bytes.- Specified by:
getSize
in interfaceFitsElement
- Returns:
- The size of this element in bytes, or 0 if the element is empty or invalid.
-
getTelescope
Get the name of the telescope which was used to acquire the data in this FITS file.- Returns:
- either
null
or a String object
-
getTrimmedString
Deprecated.(for internal use) Will reduced visibility in the future. UseHeader.getStringValue(IFitsHeader)
or similar instead followed byString.trim()
if necessary.Get the String value associated with the headerkeyword
. Trailing spaces are not significant in FITS headers and are automatically omitted during parsing. Leading spaces are however considered significant, and are retained otherwise.- Parameters:
keyword
- the FITS keyword- Returns:
- either
null
or a String with leading/trailing blanks stripped.
-
getTrimmedString
Deprecated.(for internal use) Will reduced visibility in the future. UseHeader.getStringValue(String)
or similar instead followed byString.trim()
if necessary.Get the String value associated with the headerkeyword
.with leading spaces removed. Trailing spaces are not significant in FITS headers and are automatically omitted during parsing. Leading spaces are however considered significant, and are retained otherwise.- Parameters:
keyword
- the FITS keyword- Returns:
- either
null
or a String with leading/trailing blanks stripped.
-
info
Print out some information about this HDU.- Parameters:
stream
- the printstream to write the info on- Throws:
FitsException
- if the HDU is malformed
-
read
Description copied from interface:FitsElement
Read a FITS element from the input, starting at the current position. Ater the read, the implementations should leave the input position aligned to the start of the next FITS block.- Specified by:
read
in interfaceFitsElement
- Parameters:
stream
- The input data stream- Throws:
FitsException
- if the read was unsuccessful.IOException
- if the read was unsuccessful.
-
reset
public boolean reset()Description copied from interface:FitsElement
Reset the input stream to point to the beginning of this element- Specified by:
reset
in interfaceFitsElement
- Returns:
- True if the reset succeeded.
-
rewrite
Description copied from interface:FitsElement
Rewrite the contents of the element in place. The data must have been originally read from a random access device, and the size of the element may not have changed.- Specified by:
rewrite
in interfaceFitsElement
- Throws:
FitsException
- if the rewrite was unsuccessful.IOException
- if the rewrite was unsuccessful.
-
rewriteable
public boolean rewriteable()Description copied from interface:FitsElement
Checks if we can write this element back to its source. An element can only be written back if it is associated to a random accessible input and the current size FITS within the old block size.- Specified by:
rewriteable
in interfaceFitsElement
- Returns:
true
if this element can be rewritten?
-
write
Description copied from interface:FitsElement
Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.- Specified by:
write
in interfaceFitsElement
- Parameters:
stream
- The data sink.- Throws:
FitsException
- if the write was unsuccessful.
-
Bitpix.VALUE_FOR_BYTE
instead.