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
import os

print(os.getcwd())
print(os.path.dirname(os.path.realpath("./raponi_2020_67p_virtis_mir.txt")))
/workspace/cxlfeller/specmodels/pipelines/simple
/workspace/cxlfeller/specmodels/pipelines/simple
# Plot 67P data
data = SpecModel(
    data="./raponi_2020_67p_virtis_mir.txt",
    label="67P (Raponi+2020)",
    ylabel="RADF",
    interpolation_order=5,
)
# Regular plot
_ = data.base_plot()
../../_images/e7b4d31fcc07f1965dd39edb56b58b963755ca0c9969e2f51126066980a5ed7c.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/d08ef2cadddd73c440fec7d9d8e12369d0e70fc468c30891be79310cb07a60f1.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/9884ef760663b17fe32c8f1ed6fcdacddbfcf7c56b64f21170d00ef304aa45c8.png ../../_images/c12d72cddf2b5c2f9e984fd42271159265a1d673479fbf90970f96363c31a86f.png ../../_images/5023695a01ef339fe3052861355cdd5fbca16233285f8043f9cd146e1636f9e2.png ../../_images/2002fbf248b1f1c4dbf6cc2c67946341beb08985edd3f5452949307087fdea7f.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/9c8b08baf10a449b5f13dfe9e52fe064a2df6c77c3b1de027af0281c3bdb7e8f.png
_ = band_3.base_plot()
../../_images/94b98fc1600f7d5c36a86a38465f8f7a9a03e641746e8ce39774bbead3b0226c.png
# Simple gaussian fit
rd, _, _ = band_3.fit_simple(sf.gaussian, area=True)
../../_images/377bd3686879bf80bc5177869c95d587a6eb9609b4bd3018be3e133b1df77cc1.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/46abd3540078c65dc609edc7ae36101283172cef7e356d2c82f51aba35ea7ef6.png ../../_images/ff4f387f396b60117168a66f508fa91dc03d5a9e6fbd7736220463706ce46de6.png ../../_images/af0b333a633d9d65f855773b2cddf3e0f9ac8e1899bff441da5775db77d684cd.png ../../_images/0f749b64beaa120981ae44c376c81f679bb842c9924fba3f1f9fe3d182ca9c68.png ../../_images/403c9a760739224c4bd2dfa956ff8bff52b74ea84b033619a21ac07e5049b6ad.png

#EOF