GridSpectra#
- class GridPolator.GridSpectra(native_wl: Array | ndarray, params: OrderedDict[str, Array | ndarray], spectra: Array | ndarray, impl: str = 'scipy')#
Bases:
objectStore, recall, and interpolate a grid of spectra
- Parameters:
native_wl (jax.numpy.ndarray or numpy.ndarray) – The native wavelength axis of the grid.
params (OrderedDict of str and jax.numpy.ndarray or numpy.ndarray) – The other axes of the grid. The order is the same as the order of axes in spectra.
spectra (jax.numpy.ndarray or numpy.ndarray) – The flux values to place in the grid. The last dimension should be wavelength.
impl (str, Optional) – The interpolater implementation to use. Either ‘scipy’ or ‘jax’. Defaults to ‘scipy’.
Notes
A major question a user might ask is how to chose the implementation. It comes down to balancing overhead and performance. The JAX implementation can be noticably faster than Scipy if you plan to evaluate many thousands of times. For instances that will probably be evaluated less than that (e.g. you are making a phase curve with ~100 epochs) Scipy’s lack of overhead is likely preferable.
Warning
If you use the JAX implementation you must make sure all you input arrays are jax.numpy.ndarray.
Examples
>>> spectra = jnp.array([spec1,spec2,spec3] >>> params = {'teff': jnp.array([3000,3100,3200])} >>> wl = jnp.linspace(0,10,20) >>> GridSpectra(wl,params,spectra)
>>> spectra = jnp.array([ [spec11,spec12], [spec21,spec22], [spec31,spec32] ]) >>> params = { 'teff': jnp.array([3000,3100,3200]), 'metalicity': jnp.array([-1,1]) } >>> GridSpectra(wl,params,spectra)
Methods
evaluate(params[, wl])Evaluate the grid.
from_st(w1, w2, resolving_power, teffs, ...)Load the Grid of Phoenix models from STScI.
from_vspec(w1, w2, resolving_power, teffs[, ...])Load the default VSPEC PHOENIX grid.
Methods Summary
evaluate(params[, wl])Evaluate the grid.
from_st(w1, w2, resolving_power, teffs, ...)Load the Grid of Phoenix models from STScI.
from_vspec(w1, w2, resolving_power, teffs[, ...])Load the default VSPEC PHOENIX grid.
Methods Documentation
- evaluate(params: Tuple[Array | ndarray], wl: Array | ndarray = None) Array | ndarray#
Evaluate the grid. args has the same order as params in the __init__ method.
- Parameters:
params (tuple of jax.numpy.ndarray or numpy.ndarray) – The parameter values to evaluate the grid at. They must be in array form, even if they are scalars.
wl (jax.numpy.ndarray or numpy.ndarray, optional) – The wavelength axis to evaluate the grid at. If not provided, the native wavelength axis is used.
- Returns:
The flux of the grid at the evaluated points.
- Return type:
jax.numpy.ndarray or numpy.ndarray
Examples
>>> grid = GridSpectra(native_wl, params, spectra) >>> new_params = (jnp.array([3050, 3100]), jnp.array([0.5, 1])) # Will return two sets of spectra >>> grid.evaluate(new_params)
-
classmethod from_st(w1:
astropy.units.Quantity, w2:astropy.units.Quantity, resolving_power: float, teffs: List[int], metalicities: List[float], loggs: List[float], impl_bin: str = 'rust', impl_interp: str = 'scipy', fail_on_missing: bool = False)# Load the Grid of Phoenix models from STScI.
- Parameters:
w1 (astropy.units.Quantity) – The blue wavelength limit.
w2 (astropy.units.Quantity) – The red wavelength limit.
metalicities (list of float) – The metallicity coordinates to load.
impl_bin (str, Optional) – The binning implementation to use. Defaults to ‘rust’.
impl_interp (str, Optional) – The interpolation implementation to use. Defaults to ‘scipy’.
fail_on_missing (bool, Optional) – Whether to raise an exception if the grid needs to be downloaded. Defaults to false.
-
classmethod from_vspec(w1:
astropy.units.Quantity, w2:astropy.units.Quantity, resolving_power: float, teffs: List[int], impl_bin: str = 'rust', impl_interp: str = 'scipy', fail_on_missing: bool = False)# Load the default VSPEC PHOENIX grid.
- Parameters:
w1 (astropy.units.Quantity) – The blue wavelength limit.
w2 (astropy.units.Quantity) – The red wavelength limit.
resolving_power (float) – The resolving power to use.
impl_bin (str, Optional) – The binning implementation to use. Defaults to ‘rust’.
impl_interp (str, Optional) – The interpolation implementation to use. Defaults to ‘scipy’.
fail_on_missing (bool, Optional) – Whether to raise an exception if the grid needs to be downloaded. Defaults to False.