Class Fits
- All Implemented Interfaces:
Closeable
,AutoCloseable
Handling of FITS files and streams. This class is a container of HDUs (header-data units), which together constitute a complete FITS file. Users of this library are strongly encouraged to study the FITS Standard documentation before using this library, as the library typically requires a level of familiarity with FITS and its capabilities. When constructing FITS files, users will typically want to populate their headers with as much of the standard information as possible to provide a full and accurate description of the data they wish to represent way beyond the bare essentials that are handled automatically by this library.
Fits
objects can be built-up HDU-by-HDU, and then written to a file (or stream), e.g.:
// Create a new empty Fits containe Fits fits = new Fits(); // Create an image HDU, e.g. from a 2D array we have prepared earlier float[][] image = ... BasicHDU<?> imageHDU = Fits.makeHDU(image); // ... we can of course add data to the HDU's header as we like... // Make this image the first HDU... fits.addHDU(imageHDU); // Write the FITS to a file... fits.write("myimage.fits");
Or, we may read a Fits
object from the input, e.g. as:
// Create and empty Fits assigned to an input file Fits f = new Fits(new File("myimage.fits"); // Read the entire FITS (skipping over the data for now...) f.read(); // Get the image data from the first HDU (will actually read the image now) float[][] image = (float[][]) f.getHDU(0).getKernel();
When reading FITS from random-accessible files (like in the example above), the read()
call will parse the
header for each HDU but will defer reading of actual data to a later time when it's actually accessed. This makes
Fits
objects fast, frugal, and lean, especially when one is interested in certain parts of the data
contained in the FITS file. (When reading from streams, deferred reading is not an option, so read()
will
load all HDUs into memory each time).
Fits
objects also allow reading HDUs sequentially one at a time using the readHDU()
, or even
when using getHDU(int)
or getHDU(String)
methods, even if read()
was not called
previously, e.g.:
// Create and empty Fits assigned to an input Fits f = new Fits(new File("myimage.fits"); // Get HDU index 2 (0-based, i.e. 3rd HDU) FITS. It will read (stream) or skim (file) the FITS up to the 3rd // HDU, returning it. If the FITS file or stream contains further HDUs they will not be accessed until we // need them later (if at all). BasucHDU<?> hdu = f.getHDU(2);
When building Fits
from local Java data objects, it's best to use makeHDU(Object)
to create
HDUs, which will chose the most appropriate type of HDU for the given data object (taking into some of the static
preferences set in FitsFactory
prior). makeHDU(Object)
will return one of the following HDU
objects:
all of which derive from BasicHDU
.
Since HDU literally means 'header-data unit', they constitute of a header and data entities, which can be accessed
separately. 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.
- Version:
- 1.20
- See Also:
-
Constructor Summary
ConstructorDescriptionFits()
Creates an empty Fits object which is not associated with an input stream.Creates a new (empty) FITS container associated with a file input.Deprecated.Fits
(InputStream str) Creates a new (empty) FITS container associated with the given input stream.Fits
(InputStream str, boolean compressed) Deprecated.UseFits(InputStream)
instead (compression is auto detected).Creates a new (empty) FITS container with a file or URL as its input.Deprecated.UseFits(String)
instead (compression is auto detected).Creates a new (empty) FITS container with a given URL as its input.Deprecated.UseFits(URL)
instead (compression is auto detected).Creates a new (empty) FITS container associated withFitsFile
input.Fits
(RandomAccessFileIO src) Creates a new (empty) FITS container associated with an input that supports generalized random access. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an HDU to the Fits object.long
calcChecksum
(int hduIndex) Deprecated.UseBasicHDU.verifyIntegrity()
instead when appropriate.long
calcDatasum
(int hduIndex) Calculates the data checksum for a given HDU in the Fits.static long
checksum
(byte[] data) Deprecated.void
close()
int
Deprecated.usegetNumberOfHDUs()
insteadvoid
deleteHDU
(int n) Delete an HDU from the HDU list.getCompleteHeader
(int n) Returns the 'complete' header of the nth HDU in this FITS file/object.getCompleteHeader
(String name) Returns the complete header of the first HDU by the specified name in this FITS file/object.getCompleteHeader
(String name, int version) Returns the complete header of the first HDU by the specified name and version in this FITS file/object.BasicHDU<?>
getHDU
(int n) Returns the n'th HDU.BasicHDU<?>
Returns the HDU by the given extension name (defined byEXTNAME
header keyword).BasicHDU<?>
Returns the HDU by the given extension name and version (defined byEXTNAME
andEXTVER
keywords).int
Get the number of HDUs currently available in memory.Returns the primary header of this FITS file, that is the header of the primary HDU in this Fits object.Returns the input from which thisFits
is associated to (if any)..void
Insert a FITS object into the list of HDUs.makeHDU
(DataClass data) Creates a new empty HDU for the given data type.static BasicHDU<?>
Creates an HDU that wraps around the specified data object.static BasicHDU<?>
Creates a new empty HDU based on the header description of the dataBasicHDU<?>[]
read()
Return all HDUs for the Fits object.void
read
(InputStream is) Deprecated.UseFits(InputStream)
constructor instead.BasicHDU<?>
readHDU()
Read the next HDU on the default input stream.void
rewrite()
Re-writes all HDUs that have been loaded (and possibly modified) to the disk, if possible -- or else does nothing.static void
saveClose
(InputStream in) Deprecated.Use try-with-resources constructs in Java 8+ instead.void
Add or modify the CHECKSUM keyword in all headers.void
setChecksum
(int hduIndex) Computes theCHECKSUM
andDATASUM
values for the specified HDU index and stores them in the HUS's header.static void
setChecksum
(BasicHDU<?> hdu) Deprecated.void
setStream
(ArrayDataInput stream) Deprecated.This method is poorly conceived as we cannot really read FITS from just anyArrayDataInput
but only those, which utilizeFitsDecoder
to convert Java types to FITS binary format, such asFitsInputStream
orFitsFile
(or else a wrappedDataInputStream
).int
size()
Deprecated.The meaning of size of ambiguous.void
skipHDU()
Skip the next HDU on the default input stream.void
skipHDU
(int n) Skip HDUs on the associate input stream.void
Checks the integrity of all HDUs.static String
version()
Returns the version sting of this FITS libraryvoid
write
(DataOutput os) Deprecated.This method is poorly conceived as we cannot really write FITS to just anyDataOutput
but only to specificArrayDataOutput
, which utilizeFitsEncoder
to convert Java types to FITS binary format, such asFitsOutputStream
orFitsFile
(or else a wrappedDataOutputStream
).void
Writes the contents to a new file.void
Writes the contents to the specified file.void
Writes the contents to a designated FITS file.void
write
(FitsOutputStream out) Writes the contents to a designated FITS output stream.
-
Constructor Details
-
Fits
public Fits()Creates an empty Fits object which is not associated with an input stream. -
Fits
Creates a new (empty) FITS container associated with a file input. If the file is compressed a stream will be used, otherwise random access will be supported.
While the FITS object is associated with the specified file, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
myFile
- The File object. The content of this file will not be read into the Fits object until the user makes some explicit request. * @throws FitsException if the operation failed- Throws:
FitsException
- if the operation failed- See Also:
-
Fits
Deprecated.UseFits(File)
instead (compression is auto detected). Will remove in the future.Creates a new (empty) FITS container associated with a file input.
While the FITS object is associated with the specified file, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
myFile
- The File object. The content of this file will not be read into the Fits object until the user makes some explicit request.compressed
- Is the data compressed?- Throws:
FitsException
- if the operation failed- See Also:
-
Fits
Creates a new (empty) FITS container associated with an input that supports generalized random access.
While the FITS object is associated with the specified input, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
src
- the random access input. The content of this input will not be read into the Fits object until the user makes some explicit request.- Throws:
FitsException
- if the operation failed- See Also:
-
Fits
Creates a new (empty) FITS container associated with
FitsFile
input.While the FITS object is associated with the specified file input, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
src
- the random access input. The content of this input will not be read into the Fits object until the user makes some explicit request.- Throws:
FitsException
- if the input could not bew repositions to its beginning- Since:
- 1.18
- See Also:
-
Fits
Creates a new (empty) FITS container associated with the given input stream. Compression is determined from the first few bytes of the stream.
While the FITS object is associated with the specified input stream, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
str
- The data stream. The content of this stream will not be read into the Fits object until the user makes some explicit request.- Throws:
FitsException
- if the operation failed- See Also:
-
Fits
Deprecated.UseFits(InputStream)
instead (compression is auto detected). Will remove in the future.Creates a new (empty) FITS container associated with an input stream.
While the FITS object is associated with the specified input stream, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
str
- The data stream. The content of this stream will not be read into the Fits object until the user makes some explicit request.compressed
- Is the stream compressed? This is currently ignored. Compression is determined from the first two bytes in the stream.- Throws:
FitsException
- if the operation failed- See Also:
-
Fits
Creates a new (empty) FITS container with a file or URL as its input. The string is assumed to be a URL if it begins one of the protocol strings. If the string ends in .gz it is assumed that the data is in a compressed format. All string comparisons are case insensitive.
While the FITS object is associated with the specified file, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
filename
- The name of the file or URL to be processed. The content of this file will not be read into the Fits object until the user makes some explicit request.- Throws:
FitsException
- Thrown if unable to find or open a file or URL from the string given.- See Also:
-
Fits
Deprecated.UseFits(String)
instead (compression is auto detected). Will be a private method in the future.Creates a new (empty) FITS container associated with a file or URL as its input. The string is assumed to be a URL if it begins one of the protocol strings. If the string ends in .gz it is assumed that the data is in a compressed format. All string comparisons are case insensitive.
While the FITS object is associated with the specified file, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
filename
- The name of the file or URL to be processed. The content of this file will not be read into the Fits object until the user makes some explicit request.compressed
- is the file compressed?- Throws:
FitsException
- Thrown if unable to find or open a file or URL from the string given.- See Also:
-
Fits
Creates a new (empty) FITS container with a given URL as its input.
While the FITS object is associated with the resource, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
myURL
- The URL to be read. The content of this URL will not be read into the Fits object until the user makes some explicit request.- Throws:
FitsException
- Thrown if unable to find or open a file or URL from the string given.- See Also:
-
Fits
Deprecated.UseFits(URL)
instead (compression is auto detected). Will remove in the future.Creates a new (empty) FITS container associated with a given uncompressed URL as its input.
While the FITS object is associated with the resource, it is initialized as an empty container with no data loaded from the input automatically. You may want to call
read()
to load all data from the input and/orreadHDU()
/getHDU(int)
for select HDUs, which you can then add viaaddHDU(BasicHDU)
to the container.- Parameters:
myURL
- The URL to be associated with the FITS file. The content of this URL will not be read into the Fits object until the user makes some explicit request.compressed
- Compression flag, ignored.- Throws:
FitsException
- Thrown if unable to use the specified URL.- See Also:
-
-
Method Details
-
makeHDU
public static <DataClass extends Data> BasicHDU<DataClass> makeHDU(DataClass data) throws FitsException Creates a new empty HDU for the given data type.- Type Parameters:
DataClass
- the class of the HDU- Parameters:
data
- The data to be described in this HDU.- Returns:
- a newly created HDU from the given Data.
- Throws:
FitsException
- if the operation failed
-
makeHDU
Creates a new empty HDU based on the header description of the data- Parameters:
h
- The header which describes the FITS extension- Returns:
- a newly created HDU from the given header (and including the header).
- Throws:
FitsException
- if the header could not be converted to a HDU.
-
makeHDU
Creates an HDU that wraps around the specified data object. The HDUs header will be created and populated with the essential description of the data. The following HDU types may be returned depending on the nature of the argument:
NullDataHDU
-- if the argument isnull
ImageHDU
-- if the argument is a regular numerical array, such as adouble[]
,float[][]
, orshort[][][]
BinaryTableHDU
-- the the argument is anObject[rows][cols]
type array with a regular structure and supported column data types, provided that it cannot be represented by an ASCII table OR ifFitsFactory.getUseAsciiTables()
isfalse
AsciiTableHDU
-- Like above, but only when the data can be represented by an ASCII table ANDFitsFactory.getUseAsciiTables()
istrue
As of 1.18, this metohd will not create and return random group HDUs for
Object[][2]
style data. Instead, it will return an appropriate binary or ASCII table, since the FITS standard recommends against using random groups going forward, except for reading some old data from certain radio telescopes. If the need ever arises to create new random groups HDUs with this library, you may useRandomGroupsHDU.createFrom(Object[][])
instead.- Parameters:
o
- The data to be described in this HDU.- Returns:
- a newly created HDU from the given data kernel.
- Throws:
FitsException
- if the parameter could not be converted to a HDU.- See Also:
-
version
Returns the version sting of this FITS library- Returns:
- the version of the library.
-
saveClose
Deprecated.Use try-with-resources constructs in Java 8+ instead.close the input stream, and ignore eventual errors.- Parameters:
in
- the input stream to close.
-
addHDU
Add an HDU to the Fits object. Users may intermix calls to functions which read HDUs from an associated input stream with the addHDU and insertHDU calls, but should be careful to understand the consequences.- Parameters:
myHDU
- The HDU to be added to the end of the FITS object.- Throws:
FitsException
- if the HDU could not be inserted.- See Also:
-
currentSize
Deprecated.usegetNumberOfHDUs()
insteadGet the current number of HDUs in the Fits object.- Returns:
- The number of HDU's in the object.
-
deleteHDU
Delete an HDU from the HDU list.- Parameters:
n
- The index of the HDU to be deleted. If n is 0 and there is more than one HDU present, then the next HDU will be converted from an image to primary HDU if possible. If not a dummy header HDU will then be inserted.- Throws:
FitsException
- if the HDU could not be deleted.
-
getHDU
Returns the n'th HDU. If the HDU is already read simply return a pointer to the cached data. Otherwise read the associated stream until the n'th HDU is read.- Parameters:
n
- The index of the HDU to be read. The primary HDU is index 0.- Returns:
- The n'th HDU or null if it could not be found.
- Throws:
FitsException
- if the header could not be readIOException
- if the underlying buffer threw an errorIndexOutOfBoundsException
- if the Fits contains no HDU by the given index.- See Also:
-
getPrimaryHeader
Returns the primary header of this FITS file, that is the header of the primary HDU in this Fits object. This method differs fromgetHDU(0).getHeader()
, int that the primary header this way will be properly configured as the primary HDU with all mandatory keywords, even if the HDU's header did not contain these entries originally. (Subsequent calls togetHDU(0).getHeader()
will also contain the populated mandatory keywords).- Returns:
- The primary header of this FITS file/object.
- Throws:
FitsException
- If the Fits is empty (does not contain a primary HDU)IOException
- if there was a problem accessing the FITS from the input- Since:
- 1.19
- See Also:
-
getCompleteHeader
Returns the 'complete' header of the nth HDU in this FITS file/object. This differs fromgetHDU(int)
.getHeader()
in two important ways:- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
getHDU(n).getHeader()
will also include the populated mandatory keywords.) - If the header contains the
Standard.INHERIT
keyword, a new header object is returned, which merges the non-conflicting primary header keys on top of the keywords explicitly defined in the HDU already.
- Parameters:
n
- The zero-based index of the HDU.- Returns:
- The completed header of the HDU. If the HDU contains the INHERIT key this header will be a new header object constructed by this call to include also all non-conflicting primary header keywords. Otherwise it will simply return the HDUs header (after adding the mandatory keywords).
- Throws:
FitsException
- If the FITS is emptyIOException
- If the HDU is not accessible from its sourceIndexOutOfBoundsException
- If the FITS does not contain a HDU by the specified index- Since:
- 1.19
- See Also:
- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
-
getCompleteHeader
public Header getCompleteHeader(String name) throws FitsException, IOException, NoSuchElementException Returns the complete header of the first HDU by the specified name in this FITS file/object. This differs fromgetHDU(String)
.getHeader()
in two important ways:- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
getHDU(n).getHeader()
will also include the populated mandatory keywords.) - If the header contains the
Standard.INHERIT
keyword, a new header object is returned, which merges the non-conflicting primary header keys on top of the keywords explicitly defined in the HDU already.
- Parameters:
name
- The HDU name- Returns:
- The completed header of the HDU. If the HDU contains the INHERIT key this header will be a new header object constructed by this call to include also all non-conflicting primary header keywords. Otherwise it will simply return the HDUs header (after adding the mandatory keywords).
- Throws:
FitsException
- If the FITS is emptyIOException
- If the HDU is not accessible from its sourceNoSuchElementException
- If the FITS does not contain a HDU by the specified name- Since:
- 1.19
- See Also:
- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
-
getCompleteHeader
public Header getCompleteHeader(String name, int version) throws FitsException, IOException, NoSuchElementException Returns the complete header of the first HDU by the specified name and version in this FITS file/object. This differs fromgetHDU(String)
.getHeader()
in two important ways:- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
getHDU(n).getHeader()
will also include the populated mandatory keywords.) - If the header contains the
Standard.INHERIT
keyword, a new header object is returned, which merges the non-conflicting primary header keys on top of the keywords explicitly defined in the HDU already.
- Parameters:
name
- The HDU nameversion
- The HDU version- Returns:
- The completed header of the HDU. If the HDU contains the INHERIT key this header will be a new header object constructed by this call to include also all non-conflicting primary header keywords. Otherwise it will simply return the HDUs header (after adding the mandatory keywords).
- Throws:
FitsException
- If the FITS is emptyIOException
- If the HDU is not accessible from its sourceNoSuchElementException
- If the FITS does not contain a HDU by the specified name and version- Since:
- 1.19
- See Also:
- The header will be populated with the mandatory FITS keywords based on whether it is that of a primary or
extension HDU in this Fits, and the type of HDU it is. (Subsequent calls to
-
getHDU
Returns the HDU by the given extension name (defined byEXTNAME
header keyword). This method checks only for EXTNAME but will ignore the version (defined byEXTVER
). If multiple HDUs have the same matchingEXTNAME
, this method will return the first match only.- Parameters:
name
- The name of the HDU as defined byEXTNAME
(case sensitive)- Returns:
- The first HDU that matches the specified extension name and version, or
null
if the FITS does not contain a matching HDU. - Throws:
FitsException
- if the header could not be readIOException
- if the underlying buffer threw an error- Since:
- 1.17.0
- See Also:
-
getHDU
Returns the HDU by the given extension name and version (defined byEXTNAME
andEXTVER
keywords). If multiple HDUs have the same matching name and version, this method will return the first match only.- Parameters:
name
- The name of the HDU as defined byEXTNAME
(case sensitive)version
- The extension version as defined byEXTVER
in the matching HDU.- Returns:
- The first HDU that matches the specified extension name and version, or
null
if the FITS does not contain a matching HDU. - Throws:
FitsException
- if the header could not be readIOException
- if the underlying buffer threw an error- Since:
- 1.17.0
- See Also:
-
getNumberOfHDUs
public int getNumberOfHDUs()Get the number of HDUs currently available in memory. For FITS objects associated with an input this method returns only the number of HDUs that have already been read / scanned, e.g. viareadHDU()
orread()
methods. Thus, if you want to know how many HDUs a FITS file might actually contain, you should callread()
to register them all before calling this method. -
getStream
Returns the input from which thisFits
is associated to (if any)..- Returns:
- The associated data input, or
null
if thisFits
container was not read from an input. Users may wish to call this function after opening a Fits object when they want low-level rea/wrte access to the FITS resource directly.
-
insertHDU
Insert a FITS object into the list of HDUs.- Parameters:
myHDU
- The HDU to be inserted into the list of HDUs.position
- The location at which the HDU is to be inserted.- Throws:
FitsException
- if the HDU could not be inserted.
-
read
Return all HDUs for the Fits object. If the FITS file is associated with an external stream make sure that we have exhausted the stream.- Returns:
- an array of all HDUs in the Fits object. Returns null if there are no HDUs associated with this object.
- Throws:
FitsException
- if the reading failed.
-
read
Deprecated.UseFits(InputStream)
constructor instead. We will remove this method in the future.Read a FITS file from an InputStream object.- Parameters:
is
- The InputStream stream whence the FITS information is found.- Throws:
FitsException
- if the data read could not be interpreted
-
readHDU
Read the next HDU on the default input stream. This call may return any concrete subclass ofBasicHDU
, including compressed HDU types.- Returns:
- The HDU read, or null if an EOF was detected. Note that null is only returned when the EOF is detected immediately at the beginning of reading the HDU.
- Throws:
FitsException
- if the header could not be readIOException
- if the underlying buffer threw an error- See Also:
-
setChecksum
Computes the
CHECKSUM
andDATASUM
values for the specified HDU index and stores them in the HUS's header. For deferred data the data sum is calculated directly from the file (if possible), without loading the entire (potentially huge) data into RAM for the calculation.- Parameters:
hduIndex
- The index of the HDU for which to compute and set theCHECKSUM
andDATASUM
header values.- Throws:
FitsException
- if there was a problem computing the checksum for the HDUIOException
- if there was an I/O error while accessing the data from the input- Since:
- 1.17
- See Also:
-
setChecksum
Add or modify the CHECKSUM keyword in all headers. As of 1.17 the checksum for deferred data is calculated directly from the file (if possible), without loading the entire (potentially huge) data into RAM for the calculation.
As of 1.17, the routine calculates checksums both for HDUs that are in RAM, as well as HDUs that were not yet loaded from the input (if any). Any HDUs not in RAM at the time of the call will stay in deferred mode (if the HDU itself supports it). After setting (new) checksums, you may want to call #rewrite()
- Throws:
FitsException
- if there was an error during the checksumming operationIOException
- if there was an I/O error while accessing the data from the input- See Also:
-
calcDatasum
Calculates the data checksum for a given HDU in the Fits. If the HDU does not currently have data loaded from disk (in deferred read mode), the method will calculate the checksum directly from disk. Otherwise, it will calculate the datasum from the data in memory.
- Parameters:
hduIndex
- The index of the HDU for which to calculate the data checksum- Returns:
- The data checksum. This may differ from the datasum or the original FITS input due to differences in padding used at the end of the data record by this library vs the library that was used to generate the FITS.
- Throws:
FitsException
- if there was an error processing the HDU.IOException
- if there was an I/O error accessing the input.- Since:
- 1.17
- See Also:
-
calcChecksum
Deprecated.UseBasicHDU.verifyIntegrity()
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.Calculates the FITS checksum for a given HDU in the Fits. If the HDU does not currently have data loaded from disk (i.e. in deferred read mode), the method will compute the checksum directly from disk. Otherwise, it will calculate the checksum from the data in memory and using the standard padding after it.- Parameters:
hduIndex
- The index of the HDU for which to calculate the HDU checksum- Returns:
- The checksum value that would appear in the header if this HDU was written to an output. This may differ from the checksum recorded in the input, due to different formating conventions used by this library vs the one that was used to generate the input.
- Throws:
FitsException
- if there was an error processing the HDU.IOException
- if there was an I/O error accessing the input.- Since:
- 1.17
- See Also:
-
verifyIntegrity
Checks the integrity of all HDUs. HDUs that do not specify either CHECKSUM or DATASUM keyword will be ignored.- Throws:
FitsIntegrityException
- if the FITS is corrupted, the message will inform about which HDU failed the integrity test first.FitsException
- if the header or HDU is invalid or garbled.IOException
- if the Fits object is not associated to a random-accessible input, or if there was an I/O error accessing the input.- Since:
- 1.18.1
- See Also:
-
setStream
Deprecated.This method is poorly conceived as we cannot really read FITS from just anyArrayDataInput
but only those, which utilizeFitsDecoder
to convert Java types to FITS binary format, such asFitsInputStream
orFitsFile
(or else a wrappedDataInputStream
). As such, this method is inherently unsafe as it can be used to parse FITS content iscorrectly. It will be removed from the public API in a future major release. Set the data stream to be used for future input.- Parameters:
stream
- The data stream to be used.
-
size
Deprecated.The meaning of size of ambiguous. UsegetNumberOfHDUs()
instead. Note size() will read the input file/stream to the EOF before returning the number of HDUs whichgetNumberOfHDUs()
does not. If you wish to duplicate this behavior and ensure that the input has been exhausted before getting the number of HDUs then use the sequence:read(); getNumberOfHDUs();
Return the number of HDUs in the Fits object. If the FITS file is associated with an external stream make sure that we have exhausted the stream.- Returns:
- number of HDUs.
- Throws:
FitsException
- if the file could not be read.
-
skipHDU
Skip the next HDU on the default input stream.- Throws:
FitsException
- if the HDU could not be skippedIOException
- if the underlying stream failed- See Also:
-
skipHDU
Skip HDUs on the associate input stream.- Parameters:
n
- The number of HDUs to be skipped.- Throws:
FitsException
- if the HDU could not be skippedIOException
- if the underlying stream failed- See Also:
-
write
Writes the contents to a designated FITS file. It is up to the caller to close the file as appropriate after writing to it.- Parameters:
file
- a file that support FITS encoding- Throws:
FitsException
- if there were any errors writing the contents themselves.IOException
- if the underlying file could not be trimmed or closed.- Since:
- 1.16
- See Also:
-
write
Writes the contents to a designated FITS output stream. It is up to the caller to close the stream as appropriate after writing to it.- Parameters:
out
- an output stream that supports FITS encoding.- Throws:
FitsException
- if there were any errors writing the contents themselves.IOException
- if the underlying file could not be flushed or closed.- Since:
- 1.16
- See Also:
-
write
Writes the contents to a new file.- Parameters:
file
- a file to which the FITS is to be written.- Throws:
FitsException
- if there were any errors writing the contents themselves.IOException
- if the underlying output stream could not be created or closed.- See Also:
-
rewrite
Re-writes all HDUs that have been loaded (and possibly modified) to the disk, if possible -- or else does nothing. For HDUs that are in deferred mode (data unloaded and unchanged), only the header is re-written to disk. Otherwise, both header and data is re-written. Of course, rewriting is possible only if the sizes of all headers and data segments remain the same as before.- Throws:
FitsException
- If one or more of the HDUs cannot be re-written, or if there was some other error serializing the HDUs to disk.IOException
- If there was an I/O error accessing the output file.- Since:
- 1.17
- See Also:
-
write
Writes the contents to the specified file. It simply wrapswrite(File)
for convenience.- Parameters:
fileName
- the file name/path- Throws:
FitsException
- if there were any errors writing the contents themselves.IOException
- if the underlying stream could not be created or closed.- Since:
- 1.16
- See Also:
-
write
Deprecated.This method is poorly conceived as we cannot really write FITS to just anyDataOutput
but only to specificArrayDataOutput
, which utilizeFitsEncoder
to convert Java types to FITS binary format, such asFitsOutputStream
orFitsFile
(or else a wrappedDataOutputStream
). As such, this method is inherently unsafe as it can be used to create unreadable FITS files. It will be removed from a future major release. Use one of the more appropriate otherwrite()
methods instead. Writes the contents to an external file or stream. The file or stream remains open and it is up to the caller to close it as appropriate.- Parameters:
os
- ADataOutput
stream.- Throws:
FitsException
- if the operation failed- See Also:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
setChecksum
Deprecated.set the checksum of a HDU.- Parameters:
hdu
- the HDU to add a checksum- Throws:
FitsException
- the checksum could not be added to the header
-
checksum
Deprecated.calculate the checksum for the block of data- Parameters:
data
- the data to create the checksum for- Returns:
- the checksum
-
Fits(File)
instead (compression is auto detected).