Dataclass module¶
The dataclass module defines a Data class which is very similar to astropy CCDData and uses much of the astropy code, but defines a class that can also include wavelength, response, and sky attributes. We also add a bitmask attribute that is an integer rather than a boolean to allow it to be used as a bitmask (see bitmask module). We also remove the requirement of including units. Finally, the name CCDData is not used, since we may be using digital data that may not come from a CCD!
Unfortunately, without redoing nddata, the methods provided by nddata, such as slicing and arithmetic, drop the new attributes. So beware using those! Internally in pyvista, uncertainties are propagated in the code rather than using the nddata functions.
The Data class includes a write() method to write all of the different attributes to different extentsions in a FITS file. The read() method will read FITS files with these multiple extensions and populate the attributes of a Data object.
dataclass functions¶
- class pyvista.dataclass.Data(*args, **kwd)[source]¶
Class to include a wavelength array on top of CCDData
- add_wave(wave)[source]¶
Add a wavelength attribute to Data object
- Parameters
wave (float, array-like) – Wavelength array to add
- add_bitmask(bitmask)[source]¶
Add a bitmask attribute to Data object
- Parameters
bitmask (int, array-like) – Bitmask array to add
- add_response(response)[source]¶
Add a response attribute to Data object
- Parameters
response (float, array-like) – Response array to add
- add_sky(sky)[source]¶
Add a sky attribute to Data object
- Parameters
sky (flat, array-like) – Sky array to add
- add_skyerr(skyerr)[source]¶
Add a skyerr attribute to Data object
- Parameters
skyerr (flat, array-like) – Sky error array to add
- to_hdu(hdu_data='FLUX', hdu_bitmask='BITMASK', hdu_uncertainty='UNCERT', hdu_wave='WAVE', hdu_response='RESPONSE', hdu_sky='SKY', hdu_skyerr='SKYERR', wcs_relax=True, key_uncertainty_type='UTYPE', as_image_hdu=True)[source]¶
Creates an HDUList object from a CCDData object.
- Parameters
hdu_bitmask (str or None, optional) – If it is a string append this attribute to the HDUList as ~astropy.io.fits.ImageHDU with the string as extension name. Flags are not supported at this time. If
Nonethis attribute is not appended. Default is'BITMASK'for mask,'UNCERT'for uncertaintyhdu_uncertainty (str or None, optional) – If it is a string append this attribute to the HDUList as ~astropy.io.fits.ImageHDU with the string as extension name. Flags are not supported at this time. If
Nonethis attribute is not appended. Default is'BITMASK'for mask,'UNCERT'for uncertaintyhdu_flags (str or None, optional) – If it is a string append this attribute to the HDUList as ~astropy.io.fits.ImageHDU with the string as extension name. Flags are not supported at this time. If
Nonethis attribute is not appended. Default is'BITMASK'for mask,'UNCERT'for uncertaintywcs_relax (bool) – Value of the
relaxparameter to use in converting the WCS to a FITS header using ~astropy.wcs.WCS.to_header. The commonCTYPERA---TAN-SIPandDEC--TAN-SIPrequiresrelax=Truefor the-SIPpart of theCTYPEto be preserved.key_uncertainty_type (str, optional) – The header key name for the class name of the uncertainty (if any) that is used to store the uncertainty type in the uncertainty hdu. Default is
UTYPE.as_image_hdu (bool) – If this option is True, the first item of the returned ~astropy.io.fits.HDUList is a ~astropy.io.fits.ImageHDU, instead of the default ~astropy.io.fits.PrimaryHDU.
- Raises
ValueError –
If
self.maskis set but not a numpy.ndarray. - Ifself.uncertaintyis set but not a astropy uncertainty type. - Ifself.uncertaintyis set but has another unit thenself.data.
NotImplementedError – Saving flags is not supported.
- Returns
hdulist
- Return type
~astropy.io.fits.HDUList
- pyvista.dataclass.fits_data_reader(filename, hdu=0, unit=None, hdu_uncertainty='UNCERT', hdu_bitmask='BITMASK', hdu_wave='WAVE', hdu_response='RESPONSE', hdu_sky='SKY', hdu_skyerr='SKYERR', key_uncertainty_type='UTYPE', **kwd)[source]¶
Generate a Data object from a FITS file. Modified from astropy fits_ccddata_reader
- Parameters
filename (str) – Name of fits file.
hdu (int, str, tuple of (str, int), optional) – Index or other identifier of the Header Data Unit of the FITS file from which CCDData should be initialized. If zero and no data in the primary HDU, it will search for the first extension HDU with data. The header will be added to the primary HDU. Default is
0.unit (~astropy.units.Unit, optional) – Units of the image data. If this argument is provided and there is a unit for the image in the FITS header (the keyword
BUNITis used as the unit, if present), this argument is used for the unit. Default isNone.hdu_uncertainty (str or None, optional) – FITS extension from which the uncertainty should be initialized. If the extension does not exist the uncertainty of the CCDData is
None. Default is'UNCERT'.hdu_bitmask (str or None, optional) – FITS extension from which the bitmask should be initialized. If the extension does not exist the bitmask of the CCDData is
None. Default is'BITMASK'.hdu_flags (str or None, optional) – Currently not implemented. Default is
None.key_uncertainty_type (str, optional) – The header key name where the class name of the uncertainty is stored in the hdu of the uncertainty (if any). Default is
UTYPE.kwd – Any additional keyword parameters are passed through to the FITS reader in
astropy.io.fits; see Notes for additional discussion.
Notes
FITS files that contained scaled data (e.g. unsigned integer images) will be scaled and the keywords used to manage scaled data in
astropy.io.fitsare disabled.
- pyvista.dataclass.minmax(data, mask=None, low=3, high=10)[source]¶
Return min,max scaling factors for input data using median, and MAD
- Parameters
img – input CCDData
low – number of MADs below median to return
high – number of MADs above median to retunr
- Returns
low and high scaling factors
- Return type
min,max