Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added spec_res parameter to ReadCalibration.resample_spectrum #37

Merged
merged 1 commit into from Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 23 additions & 10 deletions species/read/read_calibration.py
Expand Up @@ -2,17 +2,17 @@
Module with reading functionalities for calibration spectra.
"""

import os
import configparser
import os

from typing import Optional, Dict, Tuple
from typing import Dict, Optional, Tuple

import h5py
import spectres
import numpy as np
import spectres

from typeguard import typechecked
from scipy.optimize import curve_fit
from typeguard import typechecked

from species.analysis import photometry
from species.core import box
Expand All @@ -35,8 +35,8 @@ def __init__(self,
tag : str
Database tag of the calibration spectrum.
filter_name : str, None
Filter name that is used for the wavelength range. Full spectrum is used if set to
``None``.
Filter that is used for the wavelength range. The full spectrum is read if the argument
is set to ``None``.

Returns
-------
Expand Down Expand Up @@ -65,18 +65,26 @@ def __init__(self,
def resample_spectrum(self,
wavel_points: np.ndarray,
model_param: Optional[Dict[str, float]] = None,
spec_res: Optional[float] = None,
apply_mask: bool = False) -> box.SpectrumBox:
"""
Function for resampling of a spectrum and uncertainties onto a new wavelength grid.
Function for resampling the spectrum and optional uncertainties onto a new wavelength grid.

Parameters
----------
wavel_points : np.ndarray
Wavelength points (um).
Wavelengths (um).
model_param : dict, None
Model parameters. Should contain the 'scaling' value. Not used if set to ``None``.
Dictionary with the model parameters, which should only contain the ``'scaling'``
keyword. No scaling is applied if the argument of ``model_param`` is set to ``None``.
spec_res : float, None
Spectral resolution that is used for smoothing the spectrum before resampling the
wavelengths. No smoothing is applied if the argument is set to ``None``. The smoothing
can only be applied ti spectra with a constant spectral resolution (which is the case
for all model spectra that are compatible with ``species``) or a constant wavelength
spacing. The first smoothing approach is fastest.
apply_mask : bool
Exclude negative values and NaN values.
Exclude negative values and NaNs.

Returns
-------
Expand All @@ -86,6 +94,11 @@ def resample_spectrum(self,

calibbox = self.get_spectrum()

if spec_res is not None:
calibbox.flux = read_util.smooth_spectrum(wavelength=calibbox.wavelength,
flux=calibbox.flux,
spec_res=spec_res)

if apply_mask:
indices = np.where(calibbox.flux > 0.)[0]

Expand Down