Introduction
specutils
is a Python package for representing, loading, manipulating, and analyzing astronomical spectroscopic data. The generic data containers and accompanying modules provide a toolbox that the astronomical community can use to build more domain-specific packages. For more details about the underlying principles, see APE13, the guiding document for spectroscopic development in the Astropy Project.
Install
conda install
环境:
linux-64 v0.4
win-32 v0.2.2
noarch v1.5.0
osx-64 v0.4
win-64 v0.4
To install this package with conda run one of the following:
conda install -c astropy specutils
conda install -c astropy/label/openastronomy specutils
Documents
https://specutils.readthedocs.io/en/stable/index.html
Examples
包络线拟合 continuum fitting
import numpy as np
import matplotlib.pyplot as plt
from astropy.modeling import models
from astropy import units as u
from specutils.spectra import Spectrum1D, SpectralRegion
from specutils.fitting import fit_generic_continuum
#
np.random.seed(0)
x = np.linspace(0., 10., 200)
y = 3 * np.exp(-0.5 * (x - 6.3)**2 / 0.1**2)
y += np.random.normal(0., 0.2, x.shape)
#
y_continuum = 3.2 * np.exp(-0.5 * (x - 5.6)**2 / 4.8**2)
y += y_continuum
#
spectrum = Spectrum1D(flux=y*u.Jy, spectral_axis=x*u.um)
#
g1_fit = fit_generic_continuum(spectrum)
#
y_continuum_fitted = g1_fit(x*u.um)
#
f, ax = plt.subplots() # doctest: +IGNORE_OUTPUT
ax.plot(x, y) # doctest: +IGNORE_OUTPUT
ax.plot(x, y_continuum_fitted) # doctest: +IGNORE_OUTPUT
ax.set_title("Continuum Fitting") # doctest: +IGNORE_OUTPUT
ax.grid(True) # doctest: +IGNORE_OUTPUT
The normalized spectrum is simply the old spectrum devided by the fitted continuum, which returns a new object:
# The normalized spectrum is simply the old spectrum devided by the
# fitted continuum, which returns a new object:
#
spec_normalized = spectrum / y_continuum_fitted
#
f, ax = plt.subplots() # doctest: +IGNORE_OUTPUT
ax.plot(spec_normalized.spectral_axis, spec_normalized.flux) # doctest: +IGNORE_OUTPUT
ax.set_title("Continuum normalized spectrum") # doctest: +IGNORE_OUTPUT
ax.grid(True) # doctest: +IGNORE_OUTPUT