Class CompressedImageHDU
- All Implemented Interfaces:
FitsElement
A header-data unit (HDU) containing a compressed image. A compressed image is a normal binary table with some additional constraints. The original image is divided into 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 or quantization options for each tile (i.e. compressed table row) individually. Table keywords, which conflict with those in the original image are 'saved' under standard alternative names, so they may be restored with the image as appropriate.
Compressing an image HDU is typically a multi-step process:
- Create a
CompressedImageHDU, e.g. withfromImageHDU(ImageHDU, int...). - Set up the compression algorithm, including quantization (if desired) via
setCompressAlgorithm(String)andsetQuantAlgorithm(String), and optionally the compressiomn method used for preserving the blank values viapreserveNulls(String). - Set compression (and quantization) options, via calling on
getCompressOption(Class) - Perform the compression via
compress()
For example to compress an image HDU:
ImageHDU image = ...
// 1. Create compressed HDU
CompressedImageHDU compressed = CompressedImageHDU.fromImageHDU(image, 60, 40);
// 2. Set compression (and optional qunatizaiton) algorithm(s)
compressed.setCompressAlgorithm(Compression.ZCMPTYPE_RICE_1)
.setQuantAlgorithm(Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1)
.preserveNulls(Compression.ZCMPTYPE_HCOMPRESS_1);
// 3. Set compression (and quantizaiton) options
compressed.getCompressOption(RiceCompressOption.class).setBlockSize(32);
compressed.getCompressOption(QuantizeOption.class).setBZero(3.0).setBScale(0.1).setBNull(-999);
// 4. Perform the compression.
compressed.compress();
After the compression, the compressed image 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 asImageHDU() method. E.g.:
CompressedImageHDU compressed = ... ImageHDU image = compressed.asImageHDU();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of table columns FITS supportsFields 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
ConstructorsConstructorDescriptionCompressedImageHDU(Header hdr, CompressedImageData datum) Creates an new compressed image HDU with the specified header and compressed data. -
Method Summary
Modifier and TypeMethodDescriptionRestores the original image HDU by decompressing the data contained in this compresed image HDU.voidcompress()Performs the actual compression with the selected algorithm(s) and options.forceNoLoss(int x, int y, int width, int heigth) Specify an area within the image that will not undergo a lossy compression.static CompressedImageHDUfromImageHDU(ImageHDU imageHDU, int... tileAxis) Prepare a compressed image hdu for the specified image. the tile axis that are specified with -1 default to tiling by rows.<T extends ICompressOption>
TgetCompressOption(Class<T> clazz) Returns the compression (or quantization) options for a selected compression option class.getData()Returns the data component of this HDU.int[]Given this compressed HDU, get the original (decompressed) axes.Obtain a header representative of a decompressed ImageHDU.getTileHDU(int[] corners, int[] lengths) Returns anImageHDU, with the specified decompressed image area.Deprecated.(for internal use) There is no reason why this should be exposed to users.booleanisHeader()Deprecated.static booleanDeprecated.(for internal use) Will reduce visibility in the futurestatic CompressedImageDatamanufactureData(Header hdr) Deprecated.(for internal use) Will reduce visibility in the futurepreserveNulls(String compressionAlgorithm) Sets the compression algorithm used for preserving the blank values in the original image even if the compression is lossy.setCompressAlgorithm(String compressAlgorithm) Sets the compression algorithm to use, by its standard FITS name.setQuantAlgorithm(String quantAlgorithm) Sets the quantization algorithm to use, by its standard FITS name.Methods inherited from class BinaryTableHDU
addColumn, convertToBits, encapsulate, getColumnDescriptor, info, isData, 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 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.
-
Field Details
-
MAX_NAXIS_ALLOWED
public static final int MAX_NAXIS_ALLOWEDThe maximum number of table columns FITS supports- See Also:
-
-
Constructor Details
-
CompressedImageHDU
Creates an new compressed image HDU with the specified header and compressed data.- Parameters:
hdr- the headerdatum- the compressed image 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
-
fromImageHDU
public static CompressedImageHDU fromImageHDU(ImageHDU imageHDU, int... tileAxis) throws FitsException Prepare a compressed image hdu for the specified image. the tile axis that are specified with -1 default to tiling by rows. To actually perform the compression, you will next have to select the compression algorithm (and optinally a quantization algorithm), then configure options for these, and finally callcompress()to perform the compression. See the description of this class for more details.- Parameters:
imageHDU- the image to compresstileAxis- the requested tile sizes in pixels in x, y, z... order (i.e. opposite of the Java array indexing order!). The actual tile sizes that are set might be different, e.g. to fit within the image bounds and/or to conform to tiling conventions (esp. in more than 2 dimensions).- Returns:
- the prepared compressed image hdu.
- Throws:
FitsException- if the image could not be used to create a compressed image.- 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 futureReturns an empty compressed image data object based on its description in a FITS header.- Parameters:
hdr- the FITS header containing a description of the compressed image- Returns:
- an empty compressed image data corresponding to the header description.
- Throws:
FitsException- if the header does not sufficiently describe a compressed image
-
asImageHDU
Restores the original image HDU by decompressing the data contained in this compresed image HDU.- Returns:
- The uncompressed Image HDU.
- Throws:
FitsException- If there was an issue with the decompression.- See Also:
-
getTileHDU
public ImageHDU getTileHDU(int[] corners, int[] lengths) throws IOException, FitsException, IllegalArgumentException Returns anImageHDU, with the specified decompressed image area. The HDU's header will be adjusted as necessary to reflect the correct size and coordinate system of the image cutout.- Parameters:
corners- the location in pixels where the tile begins in the full (uncompressed) image. The number of elements in the array must match the image dimnesion.lengths- the size of the tile in pixels. The number of elements in the array must match the image dimnesion.- Returns:
- a new image HDU containing the selected area of the uncompresed image, including the adjusted header for the selected area,
- Throws:
IOException- If the tiling operation itself could not be performedFitsException- If the compressed image itself if invalid or imcompleteIllegalArgumentException- if the tile area is not fully contained inside the uncompressed image or if the lengths are not positive definite.- Since:
- 1.18
- See Also:
-
getImageAxes
Given this compressed HDU, get the original (decompressed) axes.- Returns:
- the dimensions of the axis.
- Throws:
FitsException- if the axis are configured wrong.- Since:
- 1.18
-
getImageHeader
Obtain a header representative of a decompressed ImageHDU.- Returns:
- Header with decompressed cards.
- Throws:
HeaderCardException- if the card could not be copied- Since:
- 1.18
-
compress
Performs the actual compression with the selected algorithm(s) and options. When creating a compressed image HDU, e.g using thefromImageHDU(ImageHDU, int...)method, the HDU is merely prepared but without actually performing the compression to allow the user to configure the algorithm(S) to be used as well as any specific compression (or quantization) options. See details in the class description.- Throws:
FitsException- if the compression could not be performed- See Also:
-
forceNoLoss
Specify an area within the image that will not undergo a lossy compression. This will only have affect it the selected compression (including the options) is a lossy compression. All tiles touched by this region will be handled so that there is no loss of any data, the reconstruction will be exact.- Parameters:
x- the x position in the imagey- the y position in the imagewidth- the width of the areaheigth- the height of the area- Returns:
- this
-
getCompressOption
Returns the compression (or quantization) options for a selected compression option class. It is presumed that the requested options are appropriate for the compression and/or quantization algorithm that was selected. E.g., if you calledsetCompressionAlgorithm(, then you can retrieve options for it with this method asCompression.ZCMPTYPE_RICE_1)getCompressOption(.RiceCompressOption.class)- Type Parameters:
T- The generic type of the compression class- Parameters:
clazz- the compression class- Returns:
- The current set of options for the requested type, or
nullif there are no options or if the requested type does not match the algorithm(s) selected. - See Also:
-
getData
Description copied from class:BasicHDUReturns the data component of this HDU.- Overrides:
getDatain classBasicHDU<BinaryTable>- Returns:
- the associated Data object
-
getUncompressedData
Deprecated.(for internal use) There is no reason why this should be exposed to users. UseasImageHDU()instead. Future release may restrict the visibility to private.Returns the uncompressed image in serialized form, as it would appear in a stream.- Returns:
- the buffer containing the serialized form of the uncompressed image.
- Throws:
FitsException- if the decompression could not be performed.- See Also:
-
isHeader
Deprecated.Description copied from class:BinaryTableHDUCheck that this HDU has a valid header.- Overrides:
isHeaderin classBinaryTableHDU- Returns:
trueif this HDU has a valid header.
-
preserveNulls
Sets the compression algorithm used for preserving the blank values in the original image even if the compression is lossy. When compression an integer image, a BLANK header should be defined in its header. You should typically use one of the enum values defined inCompression.- Parameters:
compressionAlgorithm- compression algorithm to use for the null pixel mask, seeCompressionfor recognized names.- Returns:
- itself
- See Also:
-
setCompressAlgorithm
Sets the compression algorithm to use, by its standard FITS name. You should typically use one of the enum values defined inCompression.- Parameters:
compressAlgorithm- compression algorithm to use, seeCompressionfor recognized names.- Returns:
- itself
- Throws:
FitsException- if no algorithm is available by the specified name- See Also:
-
setQuantAlgorithm
Sets the quantization algorithm to use, by its standard FITS name. You should typically use one of the enum values defined inCompression.- Parameters:
quantAlgorithm- quantization algorithm to use, seeCompressionfor recognized names.- Returns:
- itself
- Throws:
FitsException- if no algorithm is available by the specified name- See Also:
-
Bitpix.VALUE_FOR_BYTEinstead.