Bases: astropy.io.fits.hdu.image._ImageBaseHDU, astropy.io.fits.hdu.base.ExtensionHDU
FITS image extension HDU class.
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
checksum_keyword: str, optional :
datasum_keyword: 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
datasum_keyword: 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.
Image/array data as a ndarray.
Please remember that the order of axes on an Numpy array are opposite of the order specified in the FITS file. For example for a 2D image the “rows” or y-axis are the first dimension, and the “columns” or x-axis are the second dimension.
If the data is scaled using the BZERO and BSCALE parameters, this attribute returns the data scaled to its physical values unless the file was opened with do_not_scale_image_data=True.
Calculates and returns the number of bytes that this HDU will write to a file.
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.
Returns : | dict or None :
|
---|
Creates a new HDU object of the appropriate type from a string containing the HDU’s entire header and, optionally, its data.
Note: When creating a new HDU from a string without a backing file object, the data of that HDU may be read-only. It depends on whether the underlying string was an immutable Python str/bytes object, or some kind of read-write memory buffer such as a memoryview.
Parameters : | data : str, bytearray, memoryview, ndarray
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 pyfits.open 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.
Parameters : | keyword : str
pos : int, callable
test : callable
fix_value : str, int, float, complex, bool, None
option : str
errlist : list
|
---|
Notes
If pos=None, the card can be anywhere in the header. 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 the HDU’s 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
|
---|
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.
Size (in bytes) of the data portion of the HDU.
Deprecated since version 0.3: Use the .name attribute or Header.set instead.
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
|
---|
Deprecated since version 0.3: Use the .ver attribute or Header.set instead.
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).
Bases: astropy.io.fits.hdu.table.BinTableHDU
Compressed Image HDU class.
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
checksum_keyword: str, optional :
datasum_keyword: 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
datasum_keyword: 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.
Deprecated since version 0.3: Use the compressed_data attribute instead.
Make a copy of the table HDU, both header and data are copied.
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 dump method is to allow viewing and editing the table data and parameters in a standard text editor. The load method can be used to create a new table from the three plain text (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.
Note
This format does not support variable length arrays using the (‘Q’ format) due to difficult to overcome ambiguities. What this means is that this file format cannot support VLA columns in tables stored in files that are over 2 GB in size.
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.
Calculates and returns the number of bytes that this HDU will write to a file.
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.
Returns : | dict or None :
|
---|
Creates a new HDU object of the appropriate type from a string containing the HDU’s entire header and, optionally, its data.
Note: When creating a new HDU from a string without a backing file object, the data of that HDU may be read-only. It depends on whether the underlying string was an immutable Python str/bytes object, or some kind of read-write memory buffer such as a memoryview.
Parameters : | data : str, bytearray, memoryview, ndarray
fileobj : file, optional
offset : int, optional
checksum : bool, optional
ignore_missing_end : bool, optional
kwargs : optional
|
---|
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 header object given in the header argument; otherwise sensible defaults are inferred (though this mode is not recommended).
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
header : Header object
|
---|
Notes
The primary use for the load method is to allow the input of ASCII data that was edited in a standard text editor of the table data and parameters. The dump 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.
Note
This format does not support variable length arrays using the (‘Q’ format) due to difficult to overcome ambiguities. What this means is that this file format cannot support VLA columns in tables stored in files that are over 2 GB in size.
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.
Read the HDU from a file. Normally an HDU should be opened with pyfits.open 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.
Parameters : | keyword : str
pos : int, callable
test : callable
fix_value : str, int, float, complex, bool, None
option : str
errlist : list
|
---|
Notes
If pos=None, the card can be anywhere in the header. 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
|
---|
Shape of the image array–should be equivalent to self.data.shape.
Size (in bytes) of the data portion of the HDU.
Deprecated since version 0.1: Use load() instead.
Deprecated since version 0.1: Use dump() instead.
Update header keywords to reflect recent changes of columns.
Deprecated since version 0.3: Use (refactor your code) instead.
Deprecated since version 0.3: Use (refactor your code) instead.
Deprecated since version 0.3: Use (refactor your code) instead.
Deprecated since version 0.3: Use the .name attribute or Header.set instead.
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
|
---|
Deprecated since version 0.3: Use the .ver attribute or Header.set instead.
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).
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.