mangadap.proc.util module¶
Provides a set of processing utility functions for the MaNGA DAP.
- License:
- Copyright (c) 2015, SDSS-IV/MaNGA Pipeline Group
- Licensed under BSD 3-clause license - see LICENSE.rst
- Source location:
- $MANGADAP_DIR/python/mangadap/proc/util.py
- Imports and python version compliance:
from __future__ import division from __future__ import print_function from __future__ import absolute_import from __future__ import unicode_literals import sys if sys.version > '3': long = int import numpy import astropy.constants
- Revision history:
- 01 Feb 2016: Original implementation by K. Westfall (KBW)
-
mangadap.proc.util.
HDUList_mask_wavelengths
(hdu, bitmask, bitmask_flag, wave_limits, wave_ext='WAVE', mask_ext='MASK', invert=False)[source]¶ Mask pixels in a specified wavelength range by turning on the bit value in the specified extention in a provided HDUList object.
Parameters: - hdu (astropy.io.fits.hdu.hdulist.HDUList) – HDUList to alter
- (class (bitmask) – BitMask): Bit mask object used to turn on the named bit mask.
- bitmask_flag (str) – Name of the bit to turn on.
- wave_limits (list or numpy.ndarray) – Two-element array with the low and high wavelength limits.
- wave_ext (str) – (Optional) Name of the wavelength extension in hdu.
- mask_ext (str) – (Optional) Name of the mask extension in hdu.
- invert (bool) – (Optional) Invert the sense of the masking. Instead of masking pixel in the wavelength interval, mask all pixels outside it.
Returns: The modified HDUList object.
Return type: Raises: Exception
– Raised if wave_limits does not have a length of two.
-
mangadap.proc.util.
flux_to_fnu
(wave, flambda, unit_norm=1e-17)[source]¶ Convert a spectrum with flux per unit wavelength to flux per unit frequency; i.e., calculate
\[F_{\nu} = F_{\lambda} \frac{d\lambda}{d\nu} = F_{\lambda} \frac{\lambda^2}{c},\]where the first two arguments of the function are \(\lambda\) and \(F_{\lambda}\). The input wavelength units are expected to be angstroms, and the input flux units are expected to be \(n\ {\rm erg\ s}^{-1}\ {\rm cm}^{-2}\ {\rm A}^{-1}\), where \(n\) is the value of unit_norm. The output flux units are microjanskys, \(10^{-29} {\rm erg\ s}^{-1}\ {\rm cm}^{-2}\ {\rm Hz}^{-1}\).
Parameters: - wave (numpy.ndarray, list) – The vector with the wavelengths in angstroms.
- flambda (numpy.ndarray, list) – The vector with the flux per unit wavelength (angstroms).
- unit_norm (float) – (Optional) The unit normalization of the flux. For example, this is \(10^{-17}\) when the flux units are \(10^{-17} {\rm erg\ s}^{-1}\ {\rm cm}^{-2}\ {\rm A}^{-1}\).
Returns: The flux in units of microjanskys.
Return type: float,numpy.ndarray
Raises: ValueError
– Raised if the arguments do not have the same shape.
-
mangadap.proc.util.
growth_lim
(a, lim, fac=1.0, midpoint=None, default=[0.0, 1.0])[source]¶ Set the plots limits of an array based on two growth limits.
Parameters: - a (array-like) – Array for which to determine limits.
- lim (float) – Percentage of the array values to cover.
- fac (float) – (Optional) Factor to increase the range based on the growth limits. Default is no increase.
- midpoint (float) – (Optional) Force the midpoint of the range to be centered on this value. Default is to middle of growth range.
- default (list) – (Optional) Default range to return if a has no data. Default is 0 to 1.
Returns: Lower and upper limits for the range of a plot of the data in a.
Return type: list
-
mangadap.proc.util.
optimal_scale
(dat, mod, wgt=None)[source]¶ Calculate the optimal scaling of an input model that minimizes the weighted root-mean-square difference between a set of data and a model. When defining the weighted RMS as:
\[{\rm RMS}^2 = \frac{1}{N} \sum_i w_i^2(d_i - f m_i)^2\]The optimal renormalization factor that minimizes the RMS is:
\[f = \frac{\mathbf{d}^\prime \dot \mathbf{m}^\prime}{||\mathbf{m}^\prime||^2}\]where \(d^\prime_i = w_i d_i\) and \(m^\prime_i = w_i m_i\).
Parameters: - dat (array-like) – Array of data.
- mod (array-like) – Model to renormalize.
- wgt (array-like) – (Optional) Array of weights to apply to each residual.
Returns: The optimal scaling that minimizes the weighted root-mean-square difference betwen the data and the model.
Return type: float
Raises: ValueError
– Raised if the array sizes do not match.
-
mangadap.proc.util.
replace_with_data_from_nearest_coo
(coo, data, replace)[source]¶ Replace data in array with the spatially nearest neighbor.
Parameters: - coo (numpy.ndarray) – A 2D array with the x and y coordinates of all the data. Shape must be (NDATA, 2).
- data (numpy.ndarray) – A 1D or 2D array with data to replace. The length of the first (or only) axis must be NDATA.
- replace (numpy.ndarray) – Boolean array that is True for elements that should be replaced on output. Shape must be (NDATA,).
Returns: The data array with the selected rows replaced with the nearest data set.
Return type: numpy.ndarray
Raises: ValueError
– Raised if the array sizes are inappropriate.
-
mangadap.proc.util.
select_proc_method
(method_key, method_type, method_list=None, available_func=None, dapsrc=None)[source]¶ Select a method from a list. One of method_list or available_func must be provided.
Parameters: - method_key (str) – Keyword used to select the method.
- method_type (object) – Object type to check method_list against.
- method_list (list) – (Optional) List of methods from which to find the selection keyword. If none is provided, available_func must be provided.
- available_func (callable) – (Optional) Callable function that
returns a list of default methods in place of method_list.
For example, see
mangadap.proc.templatelibrary.available_template_libraries()
. - dapsrc (str) – (Optional) Root path to the DAP source
directory. If not provided, the default is defined by
mangadap.config.defaults.dap_source_dir()
.
Returns: An object with base class
mangadap.par.ParSet
, containing a set of parameters used to define a method or database.Return type: object
Raises: KeyError
– Raised if the selected keyword is not among the provided list or if the provided list has more than one identical keyword.TypeError
– Raised if the input method_list object is not a list or method_type, or if available function is not a callable function.