Simple pipeline

A simple pipeline expliciting with

  • reading some spectral data

  • plotting the data

  • plotting data with additional informative vertical band

  • fitting the data’s continuum

  • extracting a band from that data

  • running a simple fit on the extracted spectral band

import numpy as np
from specmodels.specmodels_base import SpecModel
import specmodels.specmodels_functions as sf
# Plot 67P data
data = SpecModel(
    data="./../../data/raponi_2020_67p_virtis_mir.txt",
    label="67P (Raponi+2020)",
    ylabel="RADF",
    interpolation_order=5,
)
# Regular plot
_ = data.base_plot()
../../_images/8d88ed8128cc85d6d846e3ffb7e78e25788f7a56d19ca03fc862f50100265422.png
# Define rectangle parameters
rect_params = [
    dict(
        xy=(2.80, 0.0),
        width=0.90,
        height=5.0,
        edgecolor="grey",
        facecolor="grey",
        alpha=0.7,
    ),
]

_ = data.base_plot_norm(wl_ref=1.2, rects=rect_params)
../../_images/0af9a6184ca9727e4a6d1d7c8a0bacb3b8e52e7514bf7c3c7e9e647c0065bb48.png
# Define a set of spectral features to ignore in the fitting
# 1.05 -> 1.10
# 2.80 -> 3.70
mask = np.array([[1.05, 1.10], [2.8, 3.7]], dtype=np.float64)
# Reset the initial continuum fit with the added information
data.continuum_update_fits(order_max=4, mask=mask)
# Re-plot
_ = data.continuum_plt_fit(mask=mask)
../../_images/964f8fca59ae551390968a3faa65ea34d21f1849bc15a30cd493c962171d9702.png ../../_images/35d1cb818ed57d093c055f61fa20e7b23da89132f84e5eac68dce4f17e39d062.png ../../_images/612fce8ba22918f8e697e1287c30b72cb079ae6b4a0d99345df8da9cdd02f2ff.png ../../_images/20996382954a4bcef99e5a4b63f2a6377e0904a1c06b1900528bb1cfcfa213c0.png
band_3 = data.rectify_extract_band(
    wrange=np.array([2.75, 3.7]),
    dlt=np.array([[0.05, 0.05], [0.05, 0.05]]),
    label="band 3 µm",
)
../../_images/523855bea1111a8f380d854cd33d97dadf84f6e7c1107d302e016ad007ca33de.png
_ = band_3.base_plot()
../../_images/58f03cc6460b8637cbbe720bfc3de36cee1d818f23686c9f075ae2c558030477.png
# Simple gaussian fit
rd, _, _ = band_3.fit_simple(sf.gaussian, area=True)
../../_images/9d4eca8262eafc3833da1c526d57e7be9dfe08ef15bbdf36c42f1d4ab0ad9a19.png
# Run fits with multiple gaussians
mgauss_dvals = band_3.mgauss_nfits(ngaussians=list(range(2, 7)))
# Plot multifit results with individual gaussians
for dfit in mgauss_dvals:
    _, _ = band_3.mgaussfit_plot(dfit)
../../_images/b0a758dcc9367720f8a2f16bdcd3f995e76bcccc6f2564b2c17fcf65e9d12527.png ../../_images/805e18718d3fa3f3ca6edd9badb45dcf4f2a44cda3798b6832eadf0bc7ddf655.png ../../_images/42d39106c7559fdb5891f6c56ce556a099207741fa7f14ea667b1c94a9659b55.png ../../_images/2f47a649605257f530b36f0e096b8241d100ac5d9da3dc618b556712c1b0626a.png ../../_images/2e8daadcaac1a204404edc240dcf0d1c357e4f1ca1c87883f17d230cc523178b.png

#EOF