Class CompressedTableHDU
java.lang.Object
nom.tam.fits.BasicHDU<BinaryTable>
nom.tam.fits.TableHDU<BinaryTable>
nom.tam.fits.BinaryTableHDU
nom.tam.image.compression.hdu.CompressedTableHDU
- All Implemented Interfaces:
FitsElement
A header-data unit (HDU) containing a compressed binary table. A compressed table is still a binary table but with
some additional constraints. The original table is divided into groups of rows (tiles) and each tile is compressed on
its own. The compressed data is then stored in the 3 data columns of this binary table (compressed, gzipped and
uncompressed) depending on the compression type used in the tile. Additional data columns may contain specific
compression options for each tile (i.e. compressed table row) individually. Table keywords, which conflict with those
in the original table are 'saved' under standard alternative names, so they may be restored with the original table
as appropriate.
Compressing a table HDU is typically a two-step process:
- Create a
CompressedTableHDU, e.g. withfromBinaryTableHDU(BinaryTableHDU, int, String...), using the specified number of table rows per compressed block, and compression algorithm(s) - Perform the compression via
compress()
For example to compress a binary table:
BinaryTableHDU table = ... // 1. Create compressed HDU with the CompressedTableHDU compressed = CompressedTableHDU.fromBinaryTableHDU(table, 4, Compression.ZCMPTYPE_RICE_1); // 2. Perform the compression. compressed.compress();
which of course you can compact into a single line as:
CompressedTableHDU compressed = CompressedTableHDU.fromBinaryTableHDU(table, 4, Compression.ZCMPTYPE_RICE_1).compress();
The two step process (as opposed to a single-step one) was probably chosen because it mimics that of
CompressedImageHDU, where further configuration steps may be inserted in-between. After the compression, the
compressed table HDU can be handled just like any other HDU, and written to a file or stream, for example.
The reverse process is simply via the asBinaryTableHDU() method. E.g.:
CompressedTableHDU compressed = ... BinaryTableHDU table = compressed.asBinaryTableHDU();
- See Also:
-
Field Summary
Fields inherited from class BasicHDU
BITPIX_BYTE, BITPIX_DOUBLE, BITPIX_FLOAT, BITPIX_INT, BITPIX_LONG, BITPIX_SHORTModifier and TypeFieldDescriptionstatic final intDeprecated.static final intDeprecated.UseBitpix.VALUE_FOR_DOUBLEinstead.static final intDeprecated.UseBitpix.VALUE_FOR_FLOATinstead.static final intDeprecated.UseBitpix.VALUE_FOR_INTinstead.static final intDeprecated.UseBitpix.VALUE_FOR_LONGinstead.static final intDeprecated.UseBitpix.VALUE_FOR_SHORTinstead. -
Constructor Summary
ConstructorsConstructorDescriptionCompressedTableHDU(Header hdr, CompressedTableData datum) Creates an new compressed table HDU with the specified header and compressed data. -
Method Summary
Modifier and TypeMethodDescriptionRestores the original binary table HDU by decompressing the data contained in this compresed table HDU.final BinaryTableHDUasBinaryTableHDU(int tile) Restores a section of the original binary table HDU by decompressing a single compressed table tile.asBinaryTableHDU(int fromTile, int toTile) Restores a section of the original binary table HDU by decompressing a selected range of compressed table tiles.compress()Performs the actual compression with the selected algorithm(s) and options.static CompressedTableHDUfromBinaryTableHDU(BinaryTableHDU binaryTableHDU, int tileRows, String... columnCompressionAlgorithms) Prepare a compressed binary table HDU for the specified binary table.getColumnData(int col) Returns a particular section of a decompressed data column.getColumnData(int col, int fromTile, int toTile) Returns a particular section of a decompressed data column.getData()Returns the data component of this HDU.Obtain a header representative of a decompressed TableHDU.intReturns the number of compressed tiles contained in this HDU.intReturns the number of table rows that are compressed in each table tile.static booleanChecks if we should use reversed compressed/uncompressed heap indices for when decompressing variable-length arrays (VLAs).static booleanDeprecated.(for internal use) Will reduce visibility in the futurestatic CompressedTableDatamanufactureData(Header hdr) Deprecated.(for internal use) Will reduce visibility in the futurestatic voiduseOldStandardVLAIndexing(boolean value) Enables or disables using reversed compressed/uncompressed heap indices for when decompressing variable-length arrays (VLAs), as was prescribed by the original FITS 4.0 standard and the Pence et al. 2013 convention.Methods inherited from class BinaryTableHDU
addColumn, convertToBits, encapsulate, getColumnDescriptor, info, isData, isHeader, manufactureHeader, setColumnName, setComplexColumn, wrap, writeModifier and TypeMethodDescriptionintAdd a column to the table without any associated header information.final booleanconvertToBits(int col) Converts a column from FITS logical values to bits.static BinaryTableDeprecated.(for internal use) UseBinaryTable.fromColumnMajor(Object[])orBinaryTable.fromRowMajor(Object[][])instead.getColumnDescriptor(int col) Returns a copy of the column descriptor of a given column in this tablevoidinfo(PrintStream stream) Print out some information about this HDU.static booleanDeprecated.(for internal use) Will reduce visibility in the futurebooleanisHeader()Deprecated.(for internal use) Will reduce visibility in the futurestatic HeadermanufactureHeader(Data data) Deprecated.(for internal use) Will reduce visibility in the futurevoidsetColumnName(int index, String name, String comment) Sets the name / ID of a specific column in this table.booleansetComplexColumn(int index) Convert a column in the table to complex.static BinaryTableHDUwrap(BinaryTable tab) Wraps the specified table in an HDU, creating a header for it with the essential table description.voidwrite(ArrayDataOutput out) 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.Methods inherited from class TableHDU
addRow, deleteColumnsIndexOne, deleteColumnsIndexOne, deleteColumnsIndexZero, deleteColumnsIndexZero, deleteRows, deleteRows, findColumn, getColumn, getColumn, getColumnFormat, getColumnMeta, getColumnMeta, getColumnName, getColumns, getDefaultColumnName, getElement, getNCols, getNRows, getRow, setColumn, setColumn, setColumnMeta, setColumnMeta, setColumnMeta, setColumnMeta, setColumnMeta, setColumnMeta, setColumnMeta, setCurrentColumn, setCurrentColumn, setElement, setRowModifier and TypeMethodDescriptionintAdd a row to the end of the table.voiddeleteColumnsIndexOne(int column, int len) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteColumns(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.voiddeleteColumnsIndexOne(int column, int len, String[] fields) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteColumns(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.voiddeleteColumnsIndexZero(int column, int len) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteColumns(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.voiddeleteColumnsIndexZero(int column, int len, IFitsHeader[] fields) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteColumns(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.voiddeleteRows(int row) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteRows(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.voiddeleteRows(int firstRow, int nRow) Deprecated.It is not entirely foolproof for keeping the header in sync -- it is better to useTableData.deleteRows(int, int)to edit tables before wrapping them in an HDU and editing the header as necessary to incorporate custom entries.intfindColumn(String colName) Find the 0-based column index corresponding to a particular column name.getColumn(int col) Returns the data for a particular column in as an array of elements.Returns the data for a particular column in as an array of elements.getColumnFormat(int index0) Get the FITS type of a column in the table.getColumnMeta(int index0, String keyBase) Convenience method for getting column metadata, as a string.getColumnMeta(int index0, IFitsHeader keyBase) Convenience method for getting column metadata, as a string.getColumnName(int index0) Gets the name of a column in the table, as it appears in this HDU's header.Object[]Returns the data for all columns in as an array.static StringgetDefaultColumnName(int col) Returns the default name for a columns with the specified index, to use if no column name was explicitly definedgetElement(int row, int col) Returns a specific element from this tableintgetNCols()Get the number of columns for this tableintgetNRows()Get the number of rows for this tableObject[]getRow(int row) Returns a specific row from this tablevoidUpdate a column within a table.voidUpdate a column within a table.voidsetColumnMeta(int index0, String key, Boolean value, String comment, boolean after) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetColumnMeta(int index0, String key, Number value, int precision, String comment, boolean after) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetColumnMeta(int index0, String key, Number value, String comment, boolean after) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetColumnMeta(int index0, String key, String value, String comment) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetColumnMeta(int index0, String key, String value, String comment, boolean after) voidsetColumnMeta(int index0, IFitsHeader key, Number value, String comment, boolean after) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetColumnMeta(int index0, IFitsHeader key, String value, String comment, boolean after) Specify column metadata for a given column in a way that allows all of the column metadata for a given column to be organized together.voidsetCurrentColumn(int col) Deprecated.(for internal use) Will be removed int the future (no longer used).voidsetCurrentColumn(int col0, boolean after) Deprecated.(for internal use) Will have private access in the future.voidsetElement(int row, int col, Object element) Update a single element within the table.voidUpdate a row within a table.Methods inherited from class BasicHDU
addValue, addValue, addValue, addValue, addValue, addValue, addValue, addValue, calcChecksum, card, getAuthor, getAxes, getBitpix, getBitPix, getBlankValue, getBScale, getBUnit, getBZero, getCreationDate, getDummyHDU, getEpoch, getEquinox, getFileOffset, getGroupCount, getHeader, getInstrument, getKernel, getMaximumValue, getMinimumValue, getObject, getObservationDate, getObserver, getOrigin, getParameterCount, getReference, getSize, getStoredChecksum, getStoredDatasum, getTelescope, getTrimmedString, getTrimmedString, read, reset, rewrite, rewriteable, setChecksum, verifyDataIntegrity, verifyIntegrityModifier and TypeMethodDescriptionvoidAdd information to the header.voidAdd information to the header.voidAdd information to the header.voidAdd information to the header.voidaddValue(IFitsHeader key, boolean val) Add information to the header.voidaddValue(IFitsHeader key, double val) Add information to the header.voidaddValue(IFitsHeader key, int val) Add information to the header.voidaddValue(IFitsHeader key, String val) Add information to the header.longDeprecated.UseBasicHDU.verifyIntegrity()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 intDeprecated.(for internal use) Will reduce visibility or remove entirely in the future.longDeprecated.This is only applicable toImageHDUorRandomGroupsHDUwith integer type data and not for other HDU or data types.doubleDeprecated.This is only applicable toImageHDUorRandomGroupsHDUwith integer type data and not for other HDU or data types.getBUnit()Deprecated.This is only applicable toImageHDUorRandomGroupsHDUand not for other HDU or data types.doublegetBZero()Deprecated.This is only applicable toImageHDUorRandomGroupsHDUwith integer type data and not for other HDU or data types.Get the FITS file creation date as aDateobject.static NullDataHDUDeprecated.UseNullDataHDUinstead.doublegetEpoch()Deprecated.useBasicHDU.getEquinox()insteaddoubleGet the equinox in years for the celestial coordinate system in which positions given in either the header or data are expressed.longReturns the byte offset at which this element starts ina file.intDeprecated.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 ObjectReturns the underlying Java object (usually an array of some type) that stores the data internally.doubleReturn the minimum valid value in the array.doubleReturn 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 aDateobject.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.intDeprecated.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.longgetSize()Returns the size of this elements in the FITS representation.longDeprecated.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.longReturns the FITS checksum for the HDU's data that is stored in the header of this HDU under theDATASUMkeyword.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.voidread(ArrayDataInput stream) Read a FITS element from the input, starting at the current position.booleanreset()Reset the input stream to point to the beginning of this elementvoidrewrite()Rewrite the contents of the element in place.booleanChecks if we can write this element back to its source.voidComputes the checksums for this HDU and stores theCHECKSUMandDATASUMvalues in the header.booleanChecks that the HDUs data checksum is correct.booleanChecks the HDU's integrity, using the recorded CHECKSUM and/or DATASUM keywords if present.
-
Constructor Details
-
CompressedTableHDU
Creates an new compressed table HDU with the specified header and compressed data.- Parameters:
hdr- the headerdatum- the compressed table data. The data may not be actually compressed at this point, int which case you may need to callcompress()before writing the new compressed HDU to a stream.- See Also:
-
-
Method Details
-
useOldStandardVLAIndexing
public static void useOldStandardVLAIndexing(boolean value) Enables or disables using reversed compressed/uncompressed heap indices for when decompressing variable-length arrays (VLAs), as was prescribed by the original FITS 4.0 standard and the Pence et al. 2013 convention.The FITS 4.0 standard defines the convention of compressing variable-length columns in binary tables. On page 50 it writes:
2. Append the VLA descriptors from the uncompressed table (which may be either Q-type or P-type) to the temporary array of VLA descriptors for the compressed table.
And the original Tiled-table convention by W. Pence et al. also writes:
[...] we concatenate the array of descriptors from the uncompressed table onto the end of the temporary array of descriptors (to the compressed VLAs in the compressed table) before the 2 combined arrays of descriptors are compressed and written into the heap in the compressed table.
However, it appears that the commonly used toolsfpack/funpackprovided in CFITSIO do just the reverse of this presciption. They store the uncopressed pointer before the compressed pointers. Because these tools are widely used we want to support files created or consumed by these tools. As such we allow to deviate from the FITS standard, and swap the order of the stored VLA indices inside compressed tables.- Parameters:
value-trueif we should use VLA indices in compressed tables that follow the format described in the original Pence et al. 2013 convention, and also the FITS 4.0 standard as of 2024 Mar 1; otherwisefalse. These original prescriptions define the reverse of what is actually implemented by CFITSIO and its toolsfpackandfunpack. (Our default is to conform to CFITSIO, and the expected revision of the standard to match).- Since:
- 1.19.1
- See Also:
-
hasOldStandardVLAIndexing
public static boolean hasOldStandardVLAIndexing()Checks if we should use reversed compressed/uncompressed heap indices for when decompressing variable-length arrays (VLAs).- Returns:
- value
trueif we will assime VLA indices in compressed tables that follow the format described in the original Pence et al. 2013 convention, and also the FITS 4.0 standard as of 2024 Mar 1; otherwisefalse. These original prescriptions define the reverse of what is actually implemented by CFITSIO and its toolsfpackandfunpack. (Our default is to conform to CFITSIO, and the expcted revision of the standard to match). - Since:
- 1.19.1
- See Also:
-
fromBinaryTableHDU
public static CompressedTableHDU fromBinaryTableHDU(BinaryTableHDU binaryTableHDU, int tileRows, String... columnCompressionAlgorithms) throws FitsException Prepare a compressed binary table HDU for the specified binary table. When the tile row size is specified with -1, the value will be set ti the number of rows in the table. The table will be compressed in "rows" that are defined by the tile size. Next step would be to set the compression options into the HDU and then compress it.- Parameters:
binaryTableHDU- the binary table to compresstileRows- the number of rows that should be compressed per tile.columnCompressionAlgorithms- the compression algorithms to use for the columns (optional default compression will be used if a column has no compression specified). You should typically use one or more of the enum values defined inCompression. The FITS standard currently allows only the lossless GZIP_1, GZIP_2, RICE_1, or NOCOMPRESS (e.g.Compression.ZCMPTYPE_GZIP_1orCompression.ZCMPTYPE_NOCOMPRESS.)- Returns:
- the prepared compressed binary table HDU.
- Throws:
IllegalArgumentException- if any of the listed compression algorithms are not approved for use with tables.FitsException- if the binary table could not be used to create a compressed binary table.- See Also:
-
isHeader
Deprecated.(for internal use) Will reduce visibility in the futureCheck that this HDU has a valid header for this type.- Parameters:
hdr- header to check- Returns:
trueif this HDU has a valid header.
-
manufactureData
Deprecated.(for internal use) Will reduce visibility in the future- Parameters:
hdr- the header that describes the compressed HDU- Returns:
- a new blank data object created from the header description
- Throws:
FitsException
-
asBinaryTableHDU
Restores the original binary table HDU by decompressing the data contained in this compresed table HDU.- Returns:
- The uncompressed binary table HDU.
- Throws:
FitsException- If there was an issue with the decompression.- See Also:
-
getTileRows
Returns the number of table rows that are compressed in each table tile. This may be useful for figuring out what tiles to decompress, e.g. viaasBinaryTableHDU(int, int), when wanting to access select table rows only. This value is stored under the FITS keyword ZTILELEN in the compressed header. Thus, this method simply provides a user-friendly way to access it. Note that the last tile may contain fewer rows than the value indicated by this- Returns:
- the number of table rows that are compressed into a tile.
- Throws:
FitsException- if the compressed header does not contain the required ZTILELEN keyword, or it is <= 0.- Since:
- 1.19
- See Also:
-
getTileCount
public int getTileCount()Returns the number of compressed tiles contained in this HDU.- Returns:
- the number of compressed tiles in this table. It is the same as the NAXIS2 value of the header, which is
also returned by
TableHDU.getNRows()for this compressed table. - Since:
- 1.19
- See Also:
-
asBinaryTableHDU
public BinaryTableHDU asBinaryTableHDU(int fromTile, int toTile) throws FitsException, IllegalArgumentException Restores a section of the original binary table HDU by decompressing a selected range of compressed table tiles. The returned section will start at row indexfromTile * getTileRows()of the full table.- Parameters:
fromTile- Java index of first tile to decompresstoTile- Java index of last tile to decompress- Returns:
- The uncompressed binary table HDU from the selected compressed tiles.
- Throws:
IllegalArgumentException- If the tile range is out of boundsFitsException- If there was an issue with the decompression.- See Also:
-
asBinaryTableHDU
public final BinaryTableHDU asBinaryTableHDU(int tile) throws FitsException, IllegalArgumentException Restores a section of the original binary table HDU by decompressing a single compressed table tile. The returned section will start at row indextile * getTileRows()of the full table.- Parameters:
tile- Java index of the table tile to decompress- Returns:
- The uncompressed binary table HDU from the selected compressed tile.
- Throws:
IllegalArgumentException- If the tile index is out of boundsFitsException- If there was an issue with the decompression.- See Also:
-
getColumnData
Returns a particular section of a decompressed data column.- Parameters:
col- the Java column index- Returns:
- The uncompressed column data as an array.
- Throws:
IllegalArgumentException- If the tile range is out of boundsFitsException- If there was an issue with the decompression.- See Also:
-
getColumnData
public Object getColumnData(int col, int fromTile, int toTile) throws FitsException, IllegalArgumentException Returns a particular section of a decompressed data column.- Parameters:
col- the Java column indexfromTile- the Java index of first tile to decompresstoTile- the Java index of last tile to decompress- Returns:
- The uncompressed column data segment as an array.
- Throws:
IllegalArgumentException- If the tile range is out of boundsFitsException- If there was an issue with the decompression.- See Also:
-
compress
Performs the actual compression with the selected algorithm(s) and options. When creating a compressed table HDU, e.g using thefromBinaryTableHDU(BinaryTableHDU, int, String...)method, the HDU is merely prepared but without actually performing the compression, and this method will have to be called to actually perform the compression. The design would allow for setting options between creation and compressing, but in this case there is really nothing of the sort.- Returns:
- itself
- Throws:
FitsException- if the compression could not be performed- See Also:
-
getTableHeader
Obtain a header representative of a decompressed TableHDU.- Returns:
- Header with decompressed cards.
- Throws:
HeaderCardException- if the card could not be copied- Since:
- 1.18
-
getData
Description copied from class:BasicHDUReturns the data component of this HDU.- Overrides:
getDatain classBasicHDU<BinaryTable>- Returns:
- the associated Data object
-
Bitpix.VALUE_FOR_BYTEinstead.