Fit module¶
ORCS (Outils de Réduction de Cubes Spectraux) provides tools to extract data from ORBS spectral cubes.
This module contains the fitting classes
-
class
orcs.fit.
SpectralCube
(*args: Any, **kwargs: Any)¶ Bases:
orb.cube.
Extension of
orcs.core.SpectralCube
Gives access to an HDF5 cube with extended fit functionalities.
The child class
SpectralCube
may be prefered in general for its broader functionality.See also
orb.core.SpectralCube
-
_get_estimated_frame_path
(param, comp)¶ Return path to the estimated parameter frame
-
_get_integrated_spectrum_fit_path
(region_name)¶ Return the path to an integrated spectrum fit
- Parameters
region_name – Name of the region
-
_get_integrated_spectrum_path
(region_name)¶ Return the path to an integrated spectrum
- Parameters
region_name – Name of the region
-
estimate_parameters_in_region
(region, lines, vel_range, subtract_spectrum=None, binning=3, precision=10, max_comps=1, threshold=1, prod=True)¶ - Parameters
lines – Emission lines to fit (must be in cm-1 if the cube is in wavenumber. must be in nm otherwise).
region – Region to fit. Multiple regions can be used to define the fitted region. They do not need to be contiguous.
threshold – Detection threshold as a factor of the std of the calculated score.
-
fit_integrated_spectra
(regions_file_path, lines, fmodel='sinc', nofilter=True, subtract_spectrum=None, plot=True, verbose=True, max_iter=None, **kwargs)¶ Fit integrated spectra and their emission lines parameters.
- Parameters
regions_file_path – Path to a ds9 reg file giving the positions of the regions. Each region is considered as a different region.
subtract – Spectrum to subtract (must be a spline)
plot – (Optional) If True, plot each intergrated spectrum along with the its fit (default True).
verbose – (Optional) If True print the fit results (default True).
max_iter – (Optional) Maximum number of iterations (default None)
-
fit_lines_in_integrated_region
(*args, **kwargs)¶ Fit lines of a spectrum integrated over a given region (can be a list of pixels as returned by the function
numpy.nonzero()
or a ds9 region file).- Parameters
region – Region to integrate (can be a list of pixel coordinates as returned by the function
numpy.nonzero()
or the path to a ds9 region file). If it is a ds9 region file, multiple regions can be defined and all will be integrated into one spectrum.lines – Emission lines to fit (must be in cm-1 if the cube is in wavenumber. must be in nm otherwise).
nofilter – (Optional) If True, Filter model is not added and the fit is made with a single range set to the filter bandpass.
subtract_spectrum – (Optional) Remove the given spectrum from the extracted spectrum before fitting parameters. Useful to remove sky spectrum. Both spectra must have the same size.
max_iter – (Optional) Maximum number of iterations (default None)
mean_flux – (Optional) If True the flux of the spectrum is the mean flux of the extracted region (default False).
kwargs – Keyword arguments of the function
_fit_lines_in_spectrum()
.
- Returns
a tuple (axis, spectrum, fit_dict). fit_dict is a dictionary containing the fit results (same output as
_fit_lines_in_spectrum()
)
-
fit_lines_in_region
(region, lines, fmodel='sinc', binning=1, nofilter=True, subtract_spectrum=None, max_iter=None, timeout=None, **kwargs)¶ Fit lines in a given region of the cube. All the pixels in the defined region are fitted one by one and a set of maps containing the fitted paramaters are written. Note that the pixels can be binned.
- Parameters
region – Region to fit. Can be a path to a ds9 file, a string defining the region in ds9 format or a boolean map (i.e. a mask) of the same dimension as the cube field of view where 1s stand for pixels that should be fitted. If a ds9 file, multiple regions can be used to define the fitted region. They do not need to be contiguous.
lines – Emission lines to fit (must be in cm-1 if the cube is in wavenumber. must be in nm otherwise).
binning – Binning of the extracted spectra.
nofilter – (Optional) If True, Filter model is not added and the fit is made with a single range set to the filter bandpass (default True).
subtract_spectrum – (Optional) Remove the given spectrum from the extracted spectrum before fitting parameters. Useful to remove sky spectrum. Both spectra must have the same size.
max_iter – (Optional) Maximum number of iterations (default None)
kwargs – Keyword arguments of the function
_fit_lines_in_spectrum()
.
- Timeout
(Optional) max processing time per pixel. If reached, the given pixel is passed (default None).
Note
You can pass the fitting parameters (e.g. pos_cov, sigma_cov etc.) as maps (a 2d numpy.ndarray instance or a path to a map). But you have to append the suffix ‘_map’ to the parameter you want to map. Any nan or inf in the map will be replaced by the median of the map. This mode is best used once the velocity parameter has been estimated with estimate_parameters_in_region().
-
fit_lines_in_spectrum
(*args, **kwargs)¶ Fit lines of a spectrum extracted from a circular region of a given radius.
- Parameters
x – X position of the center
y – Y position of the center
r – Radius. If 0, only the central pixel is extracted.
lines – Emission lines to fit (must be in cm-1 if the cube is in wavenumber. must be in nm otherwise).
nofilter – (Optional) If True, Filter model is not added and the fit is made with a single range set to the filter bandpass.
subtract_spectrum – (Optional) Remove the given spectrum from the extracted spectrum before fitting parameters. Useful to remove sky spectrum. Both spectra must have the same size.
max_iter – (Optional) Maximum number of iterations (default None)
mean_flux – (Optional) If True the flux of the spectrum is the mean flux of the extracted region (default False).
kwargs – Keyword arguments of the function
_fit_lines_in_spectrum()
.
- Returns
a tuple (axis, spectrum, fit_dict). fit_dict is a dictionary containing the fit results (same output as
orb.fit.fit_lines_in_spectrum()
)
-
fit_lines_in_spectrum_bin
(*args, **kwargs)¶ Fit lines of a spectrum extracted from a squared region of a given size.
- Parameters
x – X position of the bottom-left pixel
y – Y position of the bottom-left pixel
b – Binning. If 0, only the central pixel is extracted.
lines – Emission lines to fit (must be in cm-1 if the cube is in wavenumber. must be in nm otherwise).
nofilter – (Optional) If True, Filter model is not added and the fit is made with a single range set to the filter bandpass.
subtract_spectrum – (Optional) Remove the given spectrum from the extracted spectrum before fitting parameters. Useful to remove sky spectrum. Both spectra must have the same size.
max_iter – (Optional) Maximum number of iterations (default None)
mean_flux – (Optional) If True the flux of the spectrum is the mean flux of the extracted region (default False).
kwargs – Keyword arguments of the function
orb.fit.fit_lines_in_spectrum()
.
- Returns
a tuple (axis, spectrum, fit_dict). fit_dict is a dictionary containing the fit results (same output as
orb.fit.fit_lines_in_spectrum()
)
-
get_amp_ratio_from_flux_ratio
(line0, line1, flux_ratio)¶ Return the amplitude ratio (amp(line0) / amp(line1)) to define from the flux ratio (at constant fwhm and broadening).
- Parameters
line0 – Wavenumber of the line 0 (in cm-1).
line1 – Wavenumber of the line 1 (in cm-1).
flux_ratio – Flux ratio: flux(line0) / flux(line1).
-