specutils Python天文光谱库 使用笔记

Introduction

specutilsis 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

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值