specex.sources module
SPECEX - SPECtra EXtractor.
This module provides utility to identify sources directly from datacubes.
Copyright (C) 2022-2023 Maurizio D’Addona <mauritiusdadd@gmail.com>
- specex.sources.detect_from_cube(options=None)[source]
Run the main program of this module.
Parameters
- optionslist, optional
List of arguments to pass to argparse. The default is None.
Returns
None.
- specex.sources.get_dilation_maxima(image, box_sizes=[3, 5], threshold=0, smoothing_factor=1)[source]
Find local peaks in an image using a dilation morphological filter.
Parameters
- image2D numpy.ndarray
The image data.
- box_sizeint, optional
The size of the dilation box. The default is 3. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.maximum_filter.html
- thresholdfloat, optional
Peaks with value lower or equal than this value will be discarded.
- smoothing_factorfloat, optional
Std. Dev. of the gaussian kernel used to smooth the input image.
Returns
- peakslist
list of 2-tuples containing the positions of the local maxima.
- specex.sources.get_local_maxima(image, threshold=0, smoothing_factor=1)[source]
Find local peaks in an image comparing pixels with their neighbours.
Parameters
- image2D numpy.ndarray
The image data.
- thresholdfloat, optional
Peaks with value lower or equal than this value will be discarded.
- smoothing_factorfloat, optional
Std. Dev. of the gaussian kernel used to smooth the input image.
Returns
- peakslist
list of 2-tuples containing the positions of the local maxima.
- specex.sources.get_sn_single_slice(cube_slice, cube_slice_var=None, rebin_size=2, kernel_width=1)[source]
Get Signal to Noise ratio of an image.
Identify spotential ources from a single 2D array (image) considering the signal to noise ratio of each pixel. If a pixel has a SN greather than the given threshold then it is considered to belong to a source.
NOTE
This function is very memory intensive and will probably never be actually used since I wrote more memory-wise functions. I leave it here just as an example.
Parameters
- cube_slice2D np.ndarray
A single slice of the datacube.
- cube_slice_var2D np.ndarray, optional
The variance map for the input slice. If this is not provided, noise will be approximately estimated directly from the input slice.
- noise_rebin_sizeint, optional
Both imput slice and cube_slice_var (if provided) are rebinned combining NxN pixel into one pixel, where N = 2*rebin_size + 1.
- kernel_widthfloat:
The std. dev. to be passed to the smoothing gaussian kernel. (For more info see astropy.convolution.Gaussian2DKernel)
Returns
None.
- specex.sources.get_snr_spaxels(data_hdu, var_hdu=None, mask_hdu=None, inverse_mask=False, snr_function=<function get_spectrum_snr>)[source]
Get the SNR map of a spectral datacube.
Parameters
- data_hduastropy.fits.ImageHDU
The HDU containing spectral data.
- mask_hduastropy.fits.ImageHDU, optional
The HDU containing data qaulity mask. The default is None.
- inverse_maskbool, optional
Wether. The default is False.
Returns
- snr_mapTYPE
DESCRIPTION.
- specex.sources.get_spectrum(flux_spaxels, var_spaxels=None, weights=None, average=False)[source]
Get spectrum from a list of spaxels.
Parameters
- flux_spaxels2D numpy.ndarray
The set of spectralspaxels used to compute the spectrum, in the form of a 2D numpy array where the first axis represents the wavelength and the second axis moves trough the different spaxels.
- var_spaxels2D numpy.ndarray, optional
Same format of flux_spaxels but for variace data. The default is None. If none, the variance is computed using the spectra lspaxels.
- weights1D numpy.ndarray or list of float, optional
Optional weights for each spaxel. The default is None.
- averageTYPE, optional
Wether to average the spaxels or to sum them. The default is False.
Returns
- spectrum1D numpy.ndarray
The spectrum.
- spectrum_var1D numpy.ndarray
The variance of the spectrum.
- specex.sources.rebin_slice_2d(data, bin_size_x, bin_size_y=None, rebin_function=<function mean>)[source]
Rebin a 2D image.
Parameters
- data2D np.ndarray
The input array.
- bin_size_xint
Number of pixels to combine along x axis.
- bin_size_yint, optional
Number of pixels to combine along x axis. If none, use the same value as bin_size_x The default is None.
- rebin_functionfunction, optional
The function used to combine pixels. The default is np.mean.
Returns
- rebinned2D np.ndarray
The rebinned array.