specex.specex module

SPECEX - SPECtra EXtractor.

Extract spectra from spectral data cubes.

Copyright (C) 2022-2023 Maurizio D’Addona <mauritiusdadd@gmail.com>

specex.cubex.get_spplate_fits(cube_header, spec_header, obj_ids, spec_data, var_data=None, and_mask_data=None, or_mask_data=None, wdisp_data=None, sky_data=None)[source]

Generate a plate fits file similar to the ones used in SDSS.

Parameters

cube_headerTYPE

DESCRIPTION.

spec_headerTYPE

DESCRIPTION.

obj_idsTYPE

DESCRIPTION.

spec_dataTYPE

DESCRIPTION.

var_dataTYPE, optional

DESCRIPTION. The default is None.

and_mask_dataTYPE, optional

DESCRIPTION. The default is None.

or_mask_dataTYPE, optional

DESCRIPTION. The default is None.

wdisp_dataTYPE, optional

DESCRIPTION. The default is None.

sky_dataTYPE, optional

DESCRIPTION. The default is None.

Returns

hdulTYPE

DESCRIPTION.

specex.cubex.get_spsingle_fits(main_header, spec_wcs_header, obj_spectrum, spec_hdu_header, obj_spectrum_var=None, no_nans=False)[source]

Generate a fits containing the spectral data.

Parameters

main_headerdict

Dictionary containing the base information of the spectrum extraction. The keys of the dictionaries are the names of the fits CARDS that will be written, while the values can be either strings or tuples in the form of (cadr value, card comment).

spec_wcs_headerastropy.io.fits.Header object

Header containing the WCS information of the spectrum.

obj_spectrumnumpy.ndarray

The actual spectral data.

spec_hdu_headerastropy.io.fits.Header object

Header of the HDU of the original cube containing the spectral data.

obj_spectrum_varnumpy.ndarray (default=None)

The variance of the spectral data.

no_nansbool, optional

If true, nan values in the spectrum are replaced by a linear interpolation. In this case an additional extension is added to the fits file, containing a mask for identifying the previously bax pixels.

Returns

hdulastropy.io.fits.HDUList object

The fits HDUL containing the extracted spectra.

specex.cubex.load_specex_file(filename, spec_hdu_index=None, var_hdu_index=None, wd_hdu_index=None, mask_hdu_index=None, smoothing=0)[source]

Load a spectrum file generated by specex (or any compatible file).

Parameters

filenamestr

The path of the fits file containing the spectrum.

spec_hdu_indexint or str, optional

The index or name of the HDU containing the flux. The default is None.

var_hdu_indexint or str, optional

The index or name of the HDU containing the variance. The default is None.

wd_hdu_indexint or str, optional

The index or name of the HDU containing the resolution curve. The default is None.

mask_hdu_indexint or str, optional

The index or name of the HDU containing the flux nan mask. The default is None.

smoothingint, optional

If greather than zero, the the spectrum is smoothed with a window of this size. The default is 0.

Raises

ValueError

When flux and variance have different shape.

Returns

dict

A dict containing the following keys:

  • ‘id’: the ID of the spectrum,

  • ‘main_header’: the FITS header of the primary HDU,

  • ‘wavelength’: the wavelengths of the dispersion grid,

  • ‘flux’: the fluxes,

  • ‘variance’: the variance of the fluxes,

  • ‘r_curve’: the resolution curve,

  • ‘nan_mask’: a mask indicating invalid fluxes,

  • ‘flux_units’: the units of the fluxes,

  • ‘wavelength_units’: the units of the wavelengths

specex.cubex.specex(options=None)[source]

Run the main program.

Returns

None.

specex.cubex.speclist2ez(spec_files, spec_hdu_name='SPECTRUM', var_hdu_name='VARIANCE')[source]

Generate a list of spectra that can be imported into pandora EZ.

Parameters

spec_fileslist of str

List of file paths.

spec_hdu_namestr, optional

The name of the HDU containing the spectral data. The default is ‘SPECTRUM’.

var_hdu_namestr, optional

The name of the HDU containing the variance data. The default is ‘VARIANCE’.

Returns

txt_dataTYPE

DESCRIPTION.