Interpolation of stellar spectra and templates¶
Within ASTRA, the individual Frame's and the Stellar templates have a common parent class:
from ASTRA.Components.Modelling import Spectral_Modelling
Due to the nature of ASTRA internals, the configurations from this parent class are not see through the config_help function when called on either of those two objects.
In [11]:
Copied!
from ASTRA.Components.Modelling import Spectral_Modelling
Spectral_Modelling.config_help()
from ASTRA.Components.Modelling import Spectral_Modelling
Spectral_Modelling.config_help()
Configurations: Name:: SAVE_DISK_SPACE Description:: Save disk space in the outputs if different than None Mandatory:: False Default value:: DISK_SAVE_MODE.DISABLED Constraints:: Value from list <<enum 'DISK_SAVE_MODE'>> Name:: WORKING_MODE Description:: How to store the output files. If one-shot, overwrites all files, otherwise updates products Mandatory:: False Default value:: WORKING_MODE.ONE_SHOT Constraints:: Value from list <<enum 'WORKING_MODE'>> Name:: INTERPOL_MODE Description:: None Mandatory:: False Default value:: SPECTRA_INTERPOL_MODE.SPLINES Constraints:: Value from list <<enum 'SPECTRA_INTERPOL_MODE'>> Name:: SPLINE_TYPE Description:: None Mandatory:: False Default value:: SPLINE_INTERPOL_MODE.CUBIC_SPLINE Constraints:: Value from list <<enum 'SPLINE_INTERPOL_MODE'>> Name:: INTERPOLATION_ERR_PROP Description:: None Mandatory:: False Default value:: INTERPOLATION_ERR_PROP.interpolation Constraints:: Value from list <<enum 'INTERPOLATION_ERR_PROP'>> Name:: NUMBER_WORKERS Description:: None Mandatory:: False Default value:: 1 Constraints:: Value inside interval <(0, inf)>; Edges: True Name:: FLUX_SMOOTH_CONFIGS Description:: Configure a possible flux smoothing before template construction Mandatory:: False Default value:: FLUX_SMOOTH_CONFIGS.NONE Constraints:: Value from list <<enum 'FLUX_SMOOTH_CONFIGS'>> Name:: FLUX_SMOOTH_WINDOW_SIZE Description:: Number of points that will be used for the filter to smooth the spectra Mandatory:: False Default value:: 15 Constraints:: Value inside interval <(0, inf)>; Edges: True Name:: FLUX_SMOOTH_DEG Description:: Degree of the polynomial that will be used for the filter to smooth the spectra Mandatory:: False Default value:: 2 Constraints:: Value inside interval <(0, inf)>; Edges: True Name:: FLUX_SMOOTH_ORDER Description:: Order in which we smooth the flux (before, after or both) Mandatory:: False Default value:: FLUX_SMOOTH_ORDER.AFTER Constraints:: Value from list <<enum 'FLUX_SMOOTH_ORDER'>>
This parent class unlocks a common API for the interpolation of spectra (either in the form of a single observation or in the form of a stellar template).
This interface will run a serial set of operations:
- If configured to do so, smooth the stellar spectra before the interpolation
- Apply/remove a given RV shift to the wavelengths
- Interpolate the spectra and compute new flux uncertainties (based on configuration)
- If configured to do so, smooth the stellar spectra after the interpolation
This function does not compute the limits of interpolation (i.e., it will extrapolate if the new_wavelengths are outside the valid ranges of the underlying data)
In [19]:
Copied!
import matplotlib.pyplot as plt
from ASTRA.Instruments import ESPRESSO
from ASTRA.utils import choices
frame = ESPRESSO(file_path="/home/amiguel/spectra_collection/ESPRESSO/proxima/r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits",
user_configs={"INTERPOL_MODE": choices.SPECTRA_INTERPOL_MODE.SPLINES,
"SPLINE_INTERPOL_MODE": choices.SPLINE_INTERPOL_MODE.CUBIC_SPLINE
}
)
frame.generate_root_path("tmp")
spectral_order = 50
wave, flux, err, mask = frame.get_data_from_spectral_order(order=spectral_order)
fig, axis = plt.subplots()
axis.scatter(wave[~mask], flux[~mask], color="black")
waves_to_interpol = wave[~mask][1000:1500]
for spline_mode in [choices.SPLINE_INTERPOL_MODE.CUBIC_SPLINE, choices.SPLINE_INTERPOL_MODE.QUADRATIC_SPLINE]:
new_flux, new_err = frame.interpolate_spectrum_to_wavelength(order = 50,
new_wavelengths=waves_to_interpol,
shift_RV_by=10,
RV_shift_mode="apply",)
axis.scatter(waves_to_interpol, new_flux, label=spline_mode.name, s=6)
axis.legend(ncol=3, loc=4, bbox_to_anchor=(1,1))
axis.set_xlim([waves_to_interpol[0], waves_to_interpol[-1]])
import matplotlib.pyplot as plt
from ASTRA.Instruments import ESPRESSO
from ASTRA.utils import choices
frame = ESPRESSO(file_path="/home/amiguel/spectra_collection/ESPRESSO/proxima/r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits",
user_configs={"INTERPOL_MODE": choices.SPECTRA_INTERPOL_MODE.SPLINES,
"SPLINE_INTERPOL_MODE": choices.SPLINE_INTERPOL_MODE.CUBIC_SPLINE
}
)
frame.generate_root_path("tmp")
spectral_order = 50
wave, flux, err, mask = frame.get_data_from_spectral_order(order=spectral_order)
fig, axis = plt.subplots()
axis.scatter(wave[~mask], flux[~mask], color="black")
waves_to_interpol = wave[~mask][1000:1500]
for spline_mode in [choices.SPLINE_INTERPOL_MODE.CUBIC_SPLINE, choices.SPLINE_INTERPOL_MODE.QUADRATIC_SPLINE]:
new_flux, new_err = frame.interpolate_spectrum_to_wavelength(order = 50,
new_wavelengths=waves_to_interpol,
shift_RV_by=10,
RV_shift_mode="apply",)
axis.scatter(waves_to_interpol, new_flux, label=spline_mode.name, s=6)
axis.legend(ncol=3, loc=4, bbox_to_anchor=(1,1))
axis.set_xlim([waves_to_interpol[0], waves_to_interpol[-1]])
2025-04-14 22:44:47.206 | INFO | ASTRA.base_models.Frame:__init__:252 - Creating frame from: /home/amiguel/spectra_collection/ESPRESSO/proxima/r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits 2025-04-14 22:44:47.208 | WARNING | ASTRA.Components.SpectrumComponent:regenerate_order_status:96 - Resetting order status of Frame - ESPRESSO 2025-04-14 22:44:47.224 | DEBUG | ASTRA.base_models.Frame:assess_bad_orders:710 - Rejecting spectral orders 2025-04-14 22:44:47.227 | INFO | ASTRA.base_models.Frame:assess_bad_orders:740 - Frame None rejected 37 orders for having SNR smaller than 5: 0-36 2025-04-14 22:44:47.229 | DEBUG | ASTRA.base_models.Frame:load_S2D_data:861 - Opening the S2D arrays from r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits 2025-04-14 22:44:47.248 | WARNING | ASTRA.Instruments.ESO_PIPELINE:load_ESO_DRS_S2D_data:327 - Not applying correction to blue-red flux balance! 2025-04-14 22:44:47.319 | DEBUG | ASTRA.base_models.Frame:build_mask:627 - Cleaning wavelength regions from [] 2025-04-14 22:44:47.320 | DEBUG | ASTRA.base_models.Frame:build_mask:645 - Removed 0 regions () 2025-04-14 22:44:47.321 | DEBUG | ASTRA.base_models.Frame:build_mask:671 - Ensuring that we have increasing wavelengths 2025-04-14 22:44:47.333 | DEBUG | ASTRA.base_models.Frame:build_mask:677 - Took 0 seconds () 2025-04-14 22:44:47.335 | DEBUG | ASTRA.base_models.Frame:assess_bad_orders:710 - Rejecting spectral orders 2025-04-14 22:44:47.359 | DEBUG | ASTRA.base_models.Frame:assess_bad_orders:723 - Frame None rejected 37 orders due for having less than 0.25 valid pixels: 0-36 2025-04-14 22:44:47.361 | INFO | ASTRA.base_models.Frame:assess_bad_orders:740 - Frame None rejected 37 orders for having SNR smaller than 5: 0-36
Out[19]:
(4486.688103074458, 4490.840682985041)