Package nom.tam.fits
Class BasicHDU<DataClass extends Data>
- java.lang.Object
-
- nom.tam.fits.BasicHDU<DataClass>
-
- All Implemented Interfaces:
FitsElement
- Direct Known Subclasses:
ImageHDU
,RandomGroupsHDU
,TableHDU
,UndefinedHDU
public abstract class BasicHDU<DataClass extends Data> extends java.lang.Object implements FitsElement
This abstract class is the parent of all HDU types. It provides basic functionality for an HDU.
-
-
Field Summary
Fields Modifier and Type Field Description static int
BITPIX_BYTE
static int
BITPIX_DOUBLE
static int
BITPIX_FLOAT
static int
BITPIX_INT
static int
BITPIX_LONG
static int
BITPIX_SHORT
protected boolean
isPrimary
Is this the first HDU in a FITS file?private static java.util.logging.Logger
LOG
private static int
MAX_NAXIS_ALLOWED
protected DataClass
myData
The associated data unit.protected Header
myHeader
The associated header.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addValue(java.lang.String key, boolean val, java.lang.String comment)
Add information to the header.void
addValue(java.lang.String key, double val, java.lang.String comment)
void
addValue(java.lang.String key, int val, java.lang.String comment)
void
addValue(java.lang.String key, java.lang.String val, java.lang.String comment)
void
addValue(IFitsHeader key, boolean val)
void
addValue(IFitsHeader key, double val)
void
addValue(IFitsHeader key, int val)
void
addValue(IFitsHeader key, java.lang.String val)
(package private) boolean
canBePrimary()
HeaderCardBuilder
card(IFitsHeader key)
get a builder for filling the header cards using the builder pattern.java.lang.String
getAuthor()
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.int
getBitPix()
long
getBlankValue()
double
getBScale()
java.lang.String
getBUnit()
double
getBZero()
java.util.Date
getCreationDate()
Get the FITS file creation date as aDate
object.DataClass
getData()
static BasicHDU<?>
getDummyHDU()
double
getEpoch()
Deprecated.usegetEquinox()
insteaddouble
getEquinox()
Get the equinox in years for the celestial coordinate system in which positions given in either the header or data are expressed.long
getFileOffset()
Get the starting offset of the HDUint
getGroupCount()
Header
getHeader()
java.lang.String
getInstrument()
Get the name of the instrument which was used to acquire the data in this FITS file.java.lang.Object
getKernel()
double
getMaximumValue()
Return the minimum valid value in the array.double
getMinimumValue()
Return the minimum valid value in the array.java.lang.String
getObject()
Get the name of the observed object in this FITS file.java.util.Date
getObservationDate()
Get the FITS file observation date as aDate
object.java.lang.String
getObserver()
Get the name of the person who acquired the data in this FITS file.java.lang.String
getOrigin()
Get the name of the organization which created this FITS file.int
getParameterCount()
java.lang.String
getReference()
Return the citation of a reference where the data associated with this header are published.long
getSize()
java.lang.String
getTelescope()
Get the name of the telescope which was used to acquire the data in this FITS file.java.lang.String
getTrimmedString(java.lang.String keyword)
Get the String value associated withkeyword
.java.lang.String
getTrimmedString(IFitsHeader keyword)
Get the String value associated withkeyword
.abstract void
info(java.io.PrintStream stream)
Print out some information about this HDU.static boolean
isData(java.lang.Object o)
static boolean
isHeader(Header header)
Check that this is a valid header for the HDU.void
read(ArrayDataInput stream)
Read a data array into the current object and if needed position to the beginning of the next FITS block.boolean
reset()
Reset the input stream to point to the beginning of this elementvoid
rewrite()
Rewrite the contents of the element in place.boolean
rewriteable()
protected void
saveReplaceCard(java.lang.String key, boolean isString, java.lang.String value)
Safely replace a card in the header, knowing that no exception will occur.(package private) void
setPrimaryHDU(boolean newPrimary)
Indicate that an HDU is the first element of a FITS file.void
write(ArrayDataOutput stream)
Write the contents of the element to a data sink.
-
-
-
Field Detail
-
MAX_NAXIS_ALLOWED
private static final int MAX_NAXIS_ALLOWED
- See Also:
- Constant Field Values
-
LOG
private static final java.util.logging.Logger LOG
-
BITPIX_BYTE
public static final int BITPIX_BYTE
- See Also:
- Constant Field Values
-
BITPIX_SHORT
public static final int BITPIX_SHORT
- See Also:
- Constant Field Values
-
BITPIX_INT
public static final int BITPIX_INT
- See Also:
- Constant Field Values
-
BITPIX_LONG
public static final int BITPIX_LONG
- See Also:
- Constant Field Values
-
BITPIX_FLOAT
public static final int BITPIX_FLOAT
- See Also:
- Constant Field Values
-
BITPIX_DOUBLE
public static final int BITPIX_DOUBLE
- See Also:
- Constant Field Values
-
myHeader
protected Header myHeader
The associated header.
-
isPrimary
protected boolean isPrimary
Is this the first HDU in a FITS file?
-
-
Method Detail
-
getDummyHDU
public static BasicHDU<?> getDummyHDU()
- Returns:
- an HDU without content
-
isHeader
public static boolean isHeader(Header header)
Check that this is a valid header for the HDU. This method is static but should be implemented by all subclasses. TODO: refactor this to be in a meta object so it can inherit normally also seeisData(Object)
- Parameters:
header
- to validate.- Returns:
true
if this is a valid header.
-
isData
public static boolean isData(java.lang.Object o)
- 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. TODO:
refactor this to be in a meta object so it can inherit normally
also see
isHeader(Header)
-
saveReplaceCard
protected void saveReplaceCard(java.lang.String key, boolean isString, java.lang.String value)
Safely replace a card in the header, knowing that no exception will occur. Only for internal use!- Parameters:
key
- the key of the cardisString
- is the value a Stringvalue
- the String representation of the value
-
addValue
public void addValue(IFitsHeader key, boolean val) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(IFitsHeader key, double val) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(IFitsHeader key, int val) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(IFitsHeader key, java.lang.String val) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(java.lang.String key, boolean val, java.lang.String comment) throws HeaderCardException
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
-
addValue
public void addValue(java.lang.String key, double val, java.lang.String comment) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(java.lang.String key, int val, java.lang.String comment) throws HeaderCardException
- Throws:
HeaderCardException
-
addValue
public void addValue(java.lang.String key, java.lang.String val, java.lang.String comment) throws HeaderCardException
- Throws:
HeaderCardException
-
canBePrimary
boolean canBePrimary()
- Returns:
- Indicate whether HDU can be primary HDU. This method must be overriden in HDU types which can appear at the beginning of a FITS file.
-
getAuthor
public java.lang.String 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
public int[] getAxes() throws FitsException
In FITS files the index represented by NAXIS1 is the index that changes most rapidly. This reflects 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
public int getBitPix() throws FitsException
- Throws:
FitsException
-
getBlankValue
public long getBlankValue() throws FitsException
- Throws:
FitsException
-
getBScale
public double getBScale()
-
getBUnit
public java.lang.String getBUnit()
-
getBZero
public double getBZero()
-
getCreationDate
public java.util.Date getCreationDate()
Get the FITS file creation date as aDate
object.- Returns:
- either
null
or a Date object
-
getData
public DataClass getData()
- Returns:
- the associated Data object
-
getEpoch
@Deprecated public double 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()
Get the starting offset of the HDU- 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.
-
getGroupCount
public int getGroupCount()
-
getHeader
public Header getHeader()
- Returns:
- the associated header
-
card
public HeaderCardBuilder card(IFitsHeader key)
get a 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
public java.lang.String 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
public java.lang.Object getKernel()
- Returns:
- the non-FITS data object
-
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
public java.lang.String getObject()
Get the name of the observed object in this FITS file.- Returns:
- either
null
or a String object
-
getObservationDate
public java.util.Date getObservationDate()
Get the FITS file observation date as aDate
object.- Returns:
- either
null
or a Date object
-
getObserver
public java.lang.String getObserver()
Get the name of the person who acquired the data in this FITS file.- Returns:
- either
null
or a String object
-
getOrigin
public java.lang.String getOrigin()
Get the name of the organization which created this FITS file.- Returns:
- either
null
or a String object
-
getParameterCount
public int getParameterCount()
-
getReference
public java.lang.String 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()
- Specified by:
getSize
in interfaceFitsElement
- Returns:
- The size of this element in bytes
-
getTelescope
public java.lang.String 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
public java.lang.String getTrimmedString(java.lang.String keyword)
Get the String value associated withkeyword
.- Parameters:
keyword
- the FITS keyword- Returns:
- either
null
or a String with leading/trailing blanks stripped.
-
getTrimmedString
public java.lang.String getTrimmedString(IFitsHeader keyword)
Get the String value associated withkeyword
.- Parameters:
keyword
- the FITS keyword- Returns:
- either
null
or a String with leading/trailing blanks stripped.
-
info
public abstract void info(java.io.PrintStream stream)
Print out some information about this HDU.- Parameters:
stream
- the printstream to write the info on
-
read
public void read(ArrayDataInput stream) throws FitsException, java.io.IOException
Description copied from interface:FitsElement
Read a data array into the current object and if needed position to the beginning of the next FITS block.- Specified by:
read
in interfaceFitsElement
- Parameters:
stream
- The input data stream- Throws:
FitsException
- if the read was unsuccessful.java.io.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
public void rewrite() throws FitsException, java.io.IOException
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.java.io.IOException
- if the rewrite was unsuccessful.
-
rewriteable
public boolean rewriteable()
- Specified by:
rewriteable
in interfaceFitsElement
- Returns:
true
if this element can be rewritten?
-
setPrimaryHDU
void setPrimaryHDU(boolean newPrimary) throws FitsException
Indicate that an HDU is the first element of a FITS file.- Parameters:
newPrimary
- value to set- Throws:
FitsException
- if the operation failed
-
write
public void write(ArrayDataOutput stream) throws FitsException
Description copied from interface:FitsElement
Write the contents of the element to a data sink.- Specified by:
write
in interfaceFitsElement
- Parameters:
stream
- The data sink.- Throws:
FitsException
- if the write was unsuccessful.
-
-