suncasa.io.ndfits
Attributes
Functions
|
Function to check if the FITS file contains compressed data |
|
this code fixes the header problem of fits out from CASA 5.4+ which leads to a streched solar image. |
|
get axis index of polarization |
|
Squeezes single-dimensional entries from an n-dimensional FITS image data array and updates the FITS header accordingly. |
|
get band information from center frequencies and band widths. |
|
Read a fits file. |
|
Take a data header pair and write a compressed FITS file. |
|
|
|
|
|
wrap single frequency fits files into a multiple frequencies fits file |
|
Updates a FITS file by optionally replacing its primary or compressed image data, adding new columns to the |
Module Contents
- suncasa.io.ndfits.is_compressed_fits(fitsfile)[source]
Function to check if the FITS file contains compressed data
- suncasa.io.ndfits.headerfix(header, PC_coor=True)[source]
this code fixes the header problem of fits out from CASA 5.4+ which leads to a streched solar image.
Setting PC_coor equal to True will reset the rotation matrix.
- suncasa.io.ndfits.headersqueeze(header, data)[source]
Squeezes single-dimensional entries from an n-dimensional FITS image data array and updates the FITS header accordingly.
This function is useful for preparing image data for astropy fits compression, which only supports 1D, 2D, or 3D images. It removes any single-dimensional entries from the shape of the data array and updates the corresponding FITS header keys to reflect the new dimensions.
- Parameters:
header (astropy.io.fits.Header) – FITS header object containing the metadata of the image.
data (numpy.ndarray) – n-dimensional image data array.
- Returns:
A tuple of the updated header object and the squeezed data array.
- Return type:
(astropy.io.fits.Header, numpy.ndarray)
Note
This function only updates the header keys related to dimensions, coordinate types, values, increments, reference pixels, and units. Any specific header keys related to coordinate transformations (e.g., PC matrix) for dimensions higher than the third are also updated if necessary. The function does not handle higher-order WCS transformations beyond simple axis permutations and squeezes.
- suncasa.io.ndfits.get_bdinfo(freq, bw)[source]
get band information from center frequencies and band widths.
- Parameters:
freq (array_like) – an array of the center frequencies of all frequency bands in Hz
bw (array_like) – an array of the band widths of all frequency bands in Hz
- Returns:
fbounds – A dict of band information
- Return type:
dict
- suncasa.io.ndfits.read(filepath, hdus=None, verbose=False, **kwargs)[source]
Read a fits file.
- Parameters:
filepath (str) – The fits file to be read.
hdus (int or iterable) – The HDU indexes to read from the file.
verbose (bool) – if verbose
- Returns:
pairs – A list of (data, header) tuples
- Return type:
list
Notes
This routine reads all the HDU’s in a fits file and returns a list of the data and a FileHeader instance for each one.
Also all comments in the original file are concatenated into a single “comment” key in the returned FileHeader.
- suncasa.io.ndfits.write(fname, data, header, mask=None, fix_invalid=True, filled_value=0.0, overwrite=True, **kwargs)[source]
Take a data header pair and write a compressed FITS file. Caveat: only 1D, 2D, or 3D images are currently supported by Astropy fits compression. To be compressed, the image data array (n-dimensional) must have at least n-3 single-dimensional entries.
- Parameters:
fname (str) – File name, with extension.
data (numpy.ndarray) – n-dimensional data array.
header (dict) – A header dictionary.
compression_type (str, optional) – Compression algorithm: one of ‘RICE_1’, ‘RICE_ONE’, ‘PLIO_1’, ‘GZIP_1’, ‘GZIP_2’, ‘HCOMPRESS_1’
hcomp_scale (float, optional) – HCOMPRESS scale parameter
- suncasa.io.ndfits.wrap(fitsfiles, outfitsfile=None, docompress=False, mask=None, fix_invalid=True, filled_value=0.0, observatory=None, imres=None, verbose=False, **kwargs)[source]
wrap single frequency fits files into a multiple frequencies fits file
- suncasa.io.ndfits.update(fitsfile, new_data=None, new_columns=None, new_header_entries=None)[source]
Updates a FITS file by optionally replacing its primary or compressed image data, adding new columns to the first binary table (BinTableHDU), and/or updating header entries in the first image HDU (PrimaryHDU for uncompressed or CompImageHDU for compressed FITS files).
Parameters: - fitsfile (str): Path to the FITS file to be updated. - new_data (np.ndarray, optional): New data array to replace the existing data in the first image HDU.
Defaults to None, which means the data will not be updated.
new_columns (list of astropy.io.fits.Column, optional): New columns to be added to the first BinTableHDU. Defaults to None, which means no columns will be added.
new_header_entries (dict, optional): Header entries to update or add in the first image HDU. Each key-value pair represents a header keyword and its new value. Defaults to None, which means no header updates will be made.
Returns: - bool: True if any of the specified updates were successfully applied, False otherwise.
The function determines whether the FITS file is compressed to properly handle the image HDU type. It attempts to update the image HDU’s data, the BinTableHDU’s columns, and the image HDU’s header based on the provided arguments. If all input parameters are None, indicating no updates are specified, the function will print a message and return False.