Utilities¶
Collection of utility functions for eniric.
-
eniric.utilities.
band_limits
(band: str) → Tuple[float, float][source]¶ Get wavelength limits of band in microns.
Parameters: band (str) – Band letter to get wavelength range for. Returns: - wav_min (float) – Lower wavelength bound of band in microns
- wav_max (float) – Upper wavelength bound of band in microns
-
eniric.utilities.
band_middle
(band: str) → float[source]¶ Calculate band mid-point.
- band: str
- Band label
Returns: middle – Wavelength at middle band. Return type: float
-
eniric.utilities.
band_selector
(wav: numpy.ndarray, flux: numpy.ndarray, band: str) → Tuple[numpy.ndarray, numpy.ndarray][source]¶ Select a specific wavelength band.
Parameters: - wav (array-like) – Wavelength values.
- flux (array-like) – Flux values.
- band (str) – Band letter to select, upper or lower case is supported. Options are (“ALL” or “”), “VIS”, “GAP”, “Z”, “Y”, “J”, “H”, “K”.
-
eniric.utilities.
cpu_minus_one
() → int[source]¶ Get one less than number of CPUs available.
Returns: num_cpu_minus_1 – One less than number of CPUs, or one. Return type: int
-
eniric.utilities.
doppler_limits
(rvmax, wmin, wmax)[source]¶ Calculate wavelength limits to apply if preforming doppler shift.
To avoid any edge effects within wmin and wmax after doppler shift.
Parameters: Returns: - new_wmin (float) – Lower wavelength bound shifted by -rvmax
- new_wmax (float) – Lower wavelength bound shifted by +rvmax
-
eniric.utilities.
doppler_shift_flux
(wavelength: numpy.ndarray, flux: numpy.ndarray, vel: float, new_wav: Optional[numpy.ndarray] = None)[source]¶ Doppler shift flux by a given velocity, return it at the original wavelengths (non-relativistic).
Apply Doppler shift to the wavelength values of the spectrum using the velocity value provided and the relation (Deltalambda / lambda = v / c)
Then linearly interpolate the flux with the new wavelength to the old wavelengths.
Parameters: - wavelength (ndarray) – Wavelength vector
- flux (ndarray) – Flux vector
- vel (float) – Velocity to Doppler shift by in km/s.
- new_wav (Optional[ndarray]) – New wavelength array to evaluate the doppler shifted flux at. If None then defaults to new_wav=wavelength.
Returns: new_flux – Doppler-shifted flux evaluated at new_wav.
Return type: ndarray
-
eniric.utilities.
doppler_shift_wav
(wavelength: numpy.ndarray, vel: float)[source]¶ Doppler shift wavelength by a given velocity (non-relativistic).
Apply Doppler shift to the wavelength values of the spectrum using the velocity value provided and the relation (Deltalambda / lambda = v / c)
Parameters: - wavelength (ndarray) – Wavelength vector
- vel (float) – Velocity to Doppler shift by in km/s.
Notes
- The Doppler shift is calculated using the relation
- [ Deltalambda / lambda = v / c ]
Where RV is the radial velocity (in km/s), (lambda_0)` is the rest wavelength and (Deltalambda) is the wavelength shift, (lambda_{shift} - lambda_0)
-
eniric.utilities.
load_aces_spectrum
(params: Union[numpy.ndarray, List[float]], photons: bool = True, air: bool = False, wl_range: Union[List[float], Tuple[float, float]] = (3000, 54000))[source]¶ Load a Phoenix spectrum from the phoenix library using STARFISH.
Parameters: Returns: - wav_micron (ndarray) – Wavelength in microns
- flux_micron (ndarray) – Photon counts per (cm**2 s) or SED/micron (within a multiplicative constant 1/(h*c)).
- Spectra available from http (//phoenix.astro.physik.uni-goettingen.de)
-
eniric.utilities.
load_btsettl_spectrum
(params: Union[numpy.ndarray, List[float]], photons: bool = True, air: bool = False, wl_range: Union[List[float], Tuple[float, float]] = (3000, 30000))[source]¶ Load a BT-Settl spectrum from the CIFIST2011 library using STARFISH.
Parameters: Returns: - wav_micron (ndarray) – Wavelength in microns
- flux_micron (ndarray) – Photon counts per (cm**2 s) or SED/micron. (within a multiplicative constant 1/(h*c))
Notes
- From BT-SETTL readme:
CIFIST2011_2015: published version of the BT-Settl grid (Baraffe et al. 2015, Allard et al. 2015. This grid will be the most complete of the CIFIST2011 grids above, but currently: Teff = 1200 - 7000K, logg = 2.5 - 5.5, [M/H] = 0.0.
Available from https://phoenix.ens-lyon.fr/Grids/BT-Settl/CIFIST2011_2015/FITS/
The BT-Settl models are Sampled at a higher rate than PHOENIX-ACES (>10 X). Therefore we cut it by factor of 10 during loading to give them similar number of points. This makes the convolutions go 10X faster.
-
eniric.utilities.
mask_between
(x: numpy.ndarray, xmin: float, xmax: float) → numpy.ndarray[source]¶ Create boolean mask of x between xmin and xmax.
-
eniric.utilities.
moving_average
(x: numpy.ndarray, window_size: Union[int, float]) → numpy.ndarray[source]¶ Moving average.
-
eniric.utilities.
resolutions2ints
(resolution: Sequence[Any]) → List[int][source]¶ List of resolutions to list of integer resolutions.
Convert from [“100k”, “30000”] to [100000, 30000].
-
eniric.utilities.
resolutions2strs
(resolution: Sequence[Any]) → List[str][source]¶ List of resolutions to list of string resolutions.
Convert from [“100000”, 10000] to [“100k”, “10k”].
-
eniric.utilities.
rv_cumulative
(rv_vector: Union[List, numpy.ndarray], single: bool = False) → List[float][source]¶ Function that calculates the cumulative RV vector weighted_error.
-
eniric.utilities.
rv_cumulative_full
(rv_vector: Union[List, numpy.ndarray]) → numpy.ndarray[source]¶ Function that calculates the cumulative RV vector weighted_error. In both directions.
-
eniric.utilities.
silent_remove
(filename: str) → None[source]¶ Remove file without failing when it doesn’t exist.
-
eniric.utilities.
wav_selector
(wav: Union[numpy.ndarray, List[float]], flux: Union[numpy.ndarray, List[float]], wav_min: float, wav_max: float) → Tuple[numpy.ndarray, numpy.ndarray][source]¶ function that returns wavelength and flux within a giving range
Parameters: Returns: - wav_sel (array) – New wavelength array within bounds wav_min, wav_max
- flux_sel (array) – New wavelength array within bounds wav_min, wav_max