Bases: pyfits.hdu.image._ImageBaseHDU, pyfits.hdu.base.ExtensionHDU
FITS image extension HDU class.
Construct an image HDU.
Parameters: | |
---|---|
data : array
header : Header instance name : str, optional
do_not_scale_image_data : bool, optional
uint : bool, optional
|
Add the CHECKSUM and DATASUM cards to this HDU with the values set to the checksum calculated for the HDU and the data respectively. The addition of the DATASUM card may be overridden.
Parameters: | |
---|---|
when : str, optional
override_datasum : bool, optional
blocking: str, optional :
|
Notes
For testing purposes, first call add_datasum with a when argument, then call add_checksum with a when argument and override_datasum set to True. This will provide consistent comments for both cards and enable the generation of a CHECKSUM card with a consistent value.
Add the DATASUM card to this HDU with the value set to the checksum calculated for the data.
Parameters: | |
---|---|
when : str, optional
blocking: str, optional :
|
|
Returns: | |
checksum : int
|
Notes
For testing purposes, provide a when argument to enable the comment value in the card to remain consistent. This will enable the generation of a CHECKSUM card with a consistent value.
Make a copy of the HDU, both header and data are copied.
Calculates and returns the number of bytes that this HDU will write to a file.
Parameters: | |
---|---|
None : | |
Returns: | |
Number of bytes : |
Returns a dictionary detailing information about the locations of this HDU within any associated file. The values are only valid after a read or write of the associated file with no intervening changes to the HDUList.
Parameters: | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
None : |
|||||||||||||
Returns: | |||||||||||||
dictionary or None :
|
Creates a new HDU object of the appropriate type from a string containing the HDU’s entire header and, optionally, its data.
Parameters: | |
---|---|
data : str
fileobj : file, optional
offset : int, optional
checksum : bool optional
ignore_missing_end : bool, optional
kwargs : optional
|
Read the HDU from a file. Normally an HDU should be opened with fitsopen() which reads the entire HDU list in a FITS file. But this method is still provided for symmetry with writeto().
Parameters: | |
---|---|
fileobj : file object or file-like object
checksum : bool
ignore_missing_end : bool
|
Check the existence, location, and value of a required Card.
TODO: Write about parameters
If pos = None, it can be anywhere. If the card does not exist, the new card will have the fix_value as its value when created. Also check the card’s value by using the test argument.
Execute the verification with selected option.
Scale image data by using BSCALE/BZERO.
Call to this method will scale data and update the keywords of BSCALE and BZERO in _header. This method should only be used right before writing to the output file, as the data will be scaled and is therefore not very usable after the call.
Parameters: | |
---|---|
type : str, optional
option : str
bscale, bzero : int, optional
|
Size (in bytes) of the data portion of the HDU.
Update the extension name associated with the HDU.
If the keyword already exists in the Header, it’s value and/or comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.
Parameters: | |
---|---|
value : str
comment : str, optional
before : str or int, optional
after : str or int, optional
savecomment : bool, optional
|
Update the extension version associated with the HDU.
If the keyword already exists in the Header, it’s value and/or comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.
Parameters: | |
---|---|
value : str
comment : str, optional
before : str or int, optional
after : str or int, optional
savecomment : bool, optional
|
Update the header keywords to agree with the data.
Verify all values in the instance.
Parameters: | |
---|---|
option : str
|
Verify that the value in the CHECKSUM keyword matches the value calculated for the current HDU CHECKSUM.
Returns: | |
---|---|
valid : int
|
Verify that the value in the DATASUM keyword matches the value calculated for the DATASUM of the current HDU data.
Returns: | |
---|---|
valid : int
|
Works similarly to the normal writeto(), but prepends a default PrimaryHDU are required by extension HDUs (which cannot stand on their own).
Works similarly to property(), but computes the value only once.
Adapted from the recipe at http://code.activestate.com/recipes/363602-lazy-property-evaluation
Access a section of the image array without loading the entire array into memory. The Section object returned by this attribute is not meant to be used directly by itself. Rather, slices of the section return the appropriate slice of the data, and loads only that section into memory.
Sections are mostly obsoleted by memmap support, but should still be used to deal with very large scaled images. See the Data Sections section of the PyFITS documentation for more details.
Shape of the image array–should be equivalent to self.data.shape.
Bases: pyfits.hdu.table.BinTableHDU
Compressed Image HDU class.
Parameters: | |
---|---|
data : array, optional
header : Header instance, optional
name : str, optional
compressionType : str, optional
tileSize : int, optional
hcompScale : float, optional
hcompSmooth : float, optional
quantizeLevel : float, optional
|
Notes
The pyfits module supports 2 methods of image compression.
- The entire FITS file may be externally compressed with the gzip or pkzip utility programs, producing a *.gz or *.zip file, respectively. When reading compressed files of this type, pyfits first uncompresses the entire file into a temporary file before performing the requested read operations. The pyfits module does not support writing to these types of compressed files. This type of compression is supported in the _File class, not in the CompImageHDU class. The file compression type is recognized by the .gz or .zip file name extension.
- The CompImageHDU class supports the FITS tiled image compression convention in which the image is subdivided into a grid of rectangular tiles, and each tile of pixels is individually compressed. The details of this FITS compression convention are described at the FITS Support Office web site. Basically, the compressed image tiles are stored in rows of a variable length arrray column in a FITS binary table. The pyfits module recognizes that this binary table extension contains an image and treats it as if it were an image extension. Under this tile-compression format, FITS header keywords remain uncompressed. At this time, pyfits does not support the ability to extract and uncompress sections of the image without having to uncompress the entire image.
The pyfits module supports 3 general-purpose compression algorithms plus one other special-purpose compression technique that is designed for data masks with positive integer pixel values. The 3 general purpose algorithms are GZIP, Rice, and HCOMPRESS, and the special-purpose technique is the IRAF pixel list compression technique (PLIO). The compressionType parameter defines the compression algorithm to be used.
The FITS image can be subdivided into any desired rectangular grid of compression tiles. With the GZIP, Rice, and PLIO algorithms, the default is to take each row of the image as a tile. The HCOMPRESS algorithm is inherently 2-dimensional in nature, so the default in this case is to take 16 rows of the image per tile. In most cases, it makes little difference what tiling pattern is used, so the default tiles are usually adequate. In the case of very small images, it could be more efficient to compress the whole image as a single tile. Note that the image dimensions are not required to be an integer multiple of the tile dimensions; if not, then the tiles at the edges of the image will be smaller than the other tiles. The tileSize parameter may be provided as a list of tile sizes, one for each dimension in the image. For example a tileSize value of [100,100] would divide a 300 X 300 image into 9 100 X 100 tiles.
The 4 supported image compression algorithms are all ‘loss-less’ when applied to integer FITS images; the pixel values are preserved exactly with no loss of information during the compression and uncompression process. In addition, the HCOMPRESS algorithm supports a ‘lossy’ compression mode that will produce larger amount of image compression. This is achieved by specifying a non-zero value for the hcompScale parameter. Since the amount of compression that is achieved depends directly on the RMS noise in the image, it is usually more convenient to specify the hcompScale factor relative to the RMS noise. Setting hcompScale = 2.5 means use a scale factor that is 2.5 times the calculated RMS noise in the image tile. In some cases it may be desirable to specify the exact scaling to be used, instead of specifying it relative to the calculated noise value. This may be done by specifying the negative of the desired scale value (typically in the range -2 to -100).
Very high compression factors (of 100 or more) can be achieved by using large hcompScale values, however, this can produce undesireable ‘blocky’ artifacts in the compressed image. A variation of the HCOMPRESS algorithm (called HSCOMPRESS) can be used in this case to apply a small amount of smoothing of the image when it is uncompressed to help cover up these artifacts. This smoothing is purely cosmetic and does not cause any significant change to the image pixel values. Setting the hcompSmooth parameter to 1 will engage the smoothing algorithm.
Floating point FITS images (which have BITPIX = -32 or -64) usually contain too much ‘noise’ in the least significant bits of the mantissa of the pixel values to be effectively compressed with any lossless algorithm. Consequently, floating point images are first quantized into scaled integer pixel values (and thus throwing away much of the noise) before being compressed with the specified algorithm (either GZIP, RICE, or HCOMPRESS). This technique produces much higher compression factors than simply using the GZIP utility to externally compress the whole FITS file, but it also means that the original floating point value pixel values are not exactly perserved. When done properly, this integer scaling technique will only discard the insignificant noise while still preserving all the real imformation in the image. The amount of precision that is retained in the pixel values is controlled by the quantizeLevel parameter. Larger values will result in compressed images whose pixels more closely match the floating point pixel values, but at the same time the amount of compression that is achieved will be reduced. Users should experiment with different values for this parameter to determine the optimal value that preserves all the useful information in the image, without needlessly preserving all the ‘noise’ which will hurt the compression efficiency.
The default value for the quantizeLevel scale factor is 16, which means that scaled integer pixel values will be quantized such that the difference between adjacent integer values will be 1/16th of the noise level in the image background. An optimized algorithm is used to accurately estimate the noise in the image. As an example, if the RMS noise in the background pixels of an image = 32.0, then the spacing between adjacent scaled integer pixel values will equal 2.0 by default. Note that the RMS noise is independently calculated for each tile of the image, so the resulting integer scaling factor may fluctuate slightly for each tile. In some cases, it may be desireable to specify the exact quantization level to be used, instead of specifying it relative to the calculated noise value. This may be done by specifying the negative of desired quantization level for the value of quantizeLevel. In the previous example, one could specify quantizeLevel`=-2.0 so that the quantized integer levels differ by 2.0. Larger negative values for `quantizeLevel means that the levels are more coarsely-spaced, and will produce higher compression factors.
Add the CHECKSUM and DATASUM cards to this HDU with the values set to the checksum calculated for the HDU and the data respectively. The addition of the DATASUM card may be overridden.
Parameters: | |
---|---|
when : str, optional
override_datasum : bool, optional
blocking: str, optional :
|
Notes
For testing purposes, first call add_datasum with a when argument, then call add_checksum with a when argument and override_datasum set to True. This will provide consistent comments for both cards and enable the generation of a CHECKSUM card with a consistent value.
Add the DATASUM card to this HDU with the value set to the checksum calculated for the data.
Parameters: | |
---|---|
when : str, optional
blocking: str, optional :
|
|
Returns: | |
checksum : int
|
Notes
For testing purposes, provide a when argument to enable the comment value in the card to remain consistent. This will enable the generation of a CHECKSUM card with a consistent value.
Make a copy of the table HDU, both header and data are copied.
Calculates and returns the number of bytes that this HDU will write to a file.
Parameters: | |
---|---|
None : | |
Returns: | |
Number of bytes : |
Returns a dictionary detailing information about the locations of this HDU within any associated file. The values are only valid after a read or write of the associated file with no intervening changes to the HDUList.
Parameters: | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
None : |
|||||||||||||
Returns: | |||||||||||||
dictionary or None :
|
Creates a new HDU object of the appropriate type from a string containing the HDU’s entire header and, optionally, its data.
Parameters: | |
---|---|
data : str
fileobj : file, optional
offset : int, optional
checksum : bool optional
ignore_missing_end : bool, optional
kwargs : optional
|
[Deprecated] Returns the table’s column definitions.
Read the HDU from a file. Normally an HDU should be opened with fitsopen() which reads the entire HDU list in a FITS file. But this method is still provided for symmetry with writeto().
Parameters: | |
---|---|
fileobj : file object or file-like object
checksum : bool
ignore_missing_end : bool
|
Check the existence, location, and value of a required Card.
TODO: Write about parameters
If pos = None, it can be anywhere. If the card does not exist, the new card will have the fix_value as its value when created. Also check the card’s value by using the test argument.
Execute the verification with selected option.
Scale image data by using BSCALE and BZERO.
Calling this method will scale self.data and update the keywords of BSCALE and BZERO in self._header and self._image_header. This method should only be used right before writing to the output file, as the data will be scaled and is therefore not very usable after the call.
Parameters: | |
---|---|
type : str, optional
option : str, optional
bscale, bzero : int, optional
|
Size (in bytes) of the data portion of the HDU.
Create a table from the input ASCII files. The input is from up to three separate files, one containing column definitions, one containing header parameters, and one containing column data. The column definition and header parameters files are not required. When absent the column definitions and/or header parameters are taken from the current values in this HDU.
Parameters: | |
---|---|
datafile : file path, file object or file-like object
cdfile : file path, file object, file-like object, optional
hfile : file path, file object, file-like object, optional
replace : bool
|
Notes
The primary use for the tcreate method is to allow the input of ASCII data that was edited in a standard text editor of the table data and parameters. The tdump method can be used to create the initial ASCII files.
datafile: Each line of the data file represents one row of table data. The data is output one column at a time in column order. If a column contains an array, each element of the column array in the current row is output before moving on to the next column. Each row ends with a new line.
Integer data is output right-justified in a 21-character field followed by a blank. Floating point data is output right justified using ‘g’ format in a 21-character field with 15 digits of precision, followed by a blank. String data that does not contain whitespace is output left-justified in a field whose width matches the width specified in the TFORM header parameter for the column, followed by a blank. When the string data contains whitespace characters, the string is enclosed in quotation marks (""). For the last data element in a row, the trailing blank in the field is replaced by a new line character.
For column data containing variable length arrays (‘P’ format), the array data is preceded by the string 'VLA_Length= ' and the integer length of the array for that row, left-justified in a 21-character field, followed by a blank.
For column data representing a bit field (‘X’ format), each bit value in the field is output right-justified in a 21-character field as 1 (for true) or 0 (for false).
cdfile: Each line of the column definitions file provides the definitions for one column in the table. The line is broken up into 8, sixteen-character fields. The first field provides the column name (TTYPEn). The second field provides the column format (TFORMn). The third field provides the display format (TDISPn). The fourth field provides the physical units (TUNITn). The fifth field provides the dimensions for a multidimensional array (TDIMn). The sixth field provides the value that signifies an undefined value (TNULLn). The seventh field provides the scale factor (TSCALn). The eighth field provides the offset value (TZEROn). A field value of "" is used to represent the case where no value is provided.
hfile: Each line of the header parameters file provides the definition of a single HDU header card as represented by the card image.
Dump the table HDU to a file in ASCII format. The table may be dumped in three separate files, one containing column definitions, one containing header parameters, and one for table data.
Parameters: | |
---|---|
datafile : file path, file object or file-like object, optional
cdfile : file path, file object or file-like object, optional
hfile : file path, file object or file-like object, optional
clobber : bool
|
Notes
The primary use for the tdump method is to allow editing in a standard text editor of the table data and parameters. The tcreate method can be used to reassemble the table from the three ASCII files.
datafile: Each line of the data file represents one row of table data. The data is output one column at a time in column order. If a column contains an array, each element of the column array in the current row is output before moving on to the next column. Each row ends with a new line.
Integer data is output right-justified in a 21-character field followed by a blank. Floating point data is output right justified using ‘g’ format in a 21-character field with 15 digits of precision, followed by a blank. String data that does not contain whitespace is output left-justified in a field whose width matches the width specified in the TFORM header parameter for the column, followed by a blank. When the string data contains whitespace characters, the string is enclosed in quotation marks (""). For the last data element in a row, the trailing blank in the field is replaced by a new line character.
For column data containing variable length arrays (‘P’ format), the array data is preceded by the string 'VLA_Length= ' and the integer length of the array for that row, left-justified in a 21-character field, followed by a blank.
For column data representing a bit field (‘X’ format), each bit value in the field is output right-justified in a 21-character field as 1 (for true) or 0 (for false).
cdfile: Each line of the column definitions file provides the definitions for one column in the table. The line is broken up into 8, sixteen-character fields. The first field provides the column name (TTYPEn). The second field provides the column format (TFORMn). The third field provides the display format (TDISPn). The fourth field provides the physical units (TUNITn). The fifth field provides the dimensions for a multidimensional array (TDIMn). The sixth field provides the value that signifies an undefined value (TNULLn). The seventh field provides the scale factor (TSCALn). The eighth field provides the offset value (TZEROn). A field value of "" is used to represent the case where no value is provided.
hfile: Each line of the header parameters file provides the definition of a single HDU header card as represented by the card image.
Update header keywords to reflect recent changes of columns.
Compress the image data so that it may be written to a file.
Update the table header cards to match the compressed data.
Update the table header (_header) to the compressed image format and to match the input data (if any). Create the image header (_image_header) from the input image header (if any) and ensure it matches the input data. Create the initially-empty table data array to hold the compressed data.
This method is mainly called internally, but a user may wish to call this method after assigning new data to the CompImageHDU object that is of a different type.
Parameters: | |
---|---|
image_header : Header instance
name : str, optional
compressionType : str, optional
tileSize : sequence of int, optional
hcompScale : float, optional
hcompSmooth : float, optional
quantizeLevel : float, optional
|
Update the extension name associated with the HDU.
If the keyword already exists in the Header, it’s value and/or comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.
Parameters: | |
---|---|
value : str
comment : str, optional
before : str or int, optional
after : str or int, optional
savecomment : bool, optional
|
Update the extension version associated with the HDU.
If the keyword already exists in the Header, it’s value and/or comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.
Parameters: | |
---|---|
value : str
comment : str, optional
before : str or int, optional
after : str or int, optional
savecomment : bool, optional
|
Verify all values in the instance.
Parameters: | |
---|---|
option : str
|
Verify that the value in the CHECKSUM keyword matches the value calculated for the current HDU CHECKSUM.
Returns: | |
---|---|
valid : int
|
Verify that the value in the DATASUM keyword matches the value calculated for the DATASUM of the current HDU data.
Returns: | |
---|---|
valid : int
|
Works similarly to the normal writeto(), but prepends a default PrimaryHDU are required by extension HDUs (which cannot stand on their own).
Works similarly to property(), but computes the value only once.
Adapted from the recipe at http://code.activestate.com/recipes/363602-lazy-property-evaluation
Works similarly to property(), but computes the value only once.
Adapted from the recipe at http://code.activestate.com/recipes/363602-lazy-property-evaluation
Works similarly to property(), but computes the value only once.
Adapted from the recipe at http://code.activestate.com/recipes/363602-lazy-property-evaluation
Works similarly to property(), but computes the value only once.
Adapted from the recipe at http://code.activestate.com/recipes/363602-lazy-property-evaluation
Shape of the image array–should be equivalent to self.data.shape.
Bases: object
Image section.
Slices of this object load the corresponding section of an image array from the underlying FITS file on disk, and applies any BSCALE/BZERO factors.
Section slices cannot be assigned to, and modifications to a section are not saved back to the underlying file.
See the Data Sections section of the PyFITS documentation for more details.