xp-extinction-toolkit

A Python library designed for astronomy researchers. It provides a set of extinction correction tools for spectroscopic and photometric data, based on the median extinction curve calculated from about 370,000 high-quality samples in Gaia DR3 and LAMOST DR7.

https://github.com/vnohhf/xp_extinction_toolkit

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: iop.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (5.9%) to scientific vocabulary

Keywords

astronomy dust
Last synced: 6 months ago · JSON representation ·

Repository

A Python library designed for astronomy researchers. It provides a set of extinction correction tools for spectroscopic and photometric data, based on the median extinction curve calculated from about 370,000 high-quality samples in Gaia DR3 and LAMOST DR7.

Basic Info
  • Host: GitHub
  • Owner: vnohhf
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 1.47 MB
Statistics
  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • Open Issues: 1
  • Releases: 1
Topics
astronomy dust
Created about 2 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README-zh.md

XPExtinctionToolkit

English | 中文

XP_Extinction_Toolkit 是一个为天文研究者设计的 Python 库。它基于 Gaia DR3 和 LAMOST DR7 中大约37万个高质量样本计算得到的中值消光曲线,提供了一组适用于光谱和测光数据的消光改正工具。这些工具可以在已知消光的情况下提供对天体光谱和任意波段测光数据的消光改正,同时也可以通过光谱模拟用于探究尘埃的一些基本的观测性质。更多信息见我们的文章 (Zhang et al., 2024)。 包含以下功能(后附使用说明):

  1. 函数 ext_curve

    获取银河系的高精度中值消光曲线。

  2. 函数 deredden

    对输入光谱进行消光改正,适用范围是 2900 - 53414 Å。

  3. 函数 Cal_E4455

    将 E(B-V) 或 E(B-V)_SFD 通过经验公式转换成 E(440-550)。

  4. 函数 star_ext

    可以计算给定 Teff、logg 和红化时,输入波段的精确消光有效波长。输入红化可以是E(440-550)、E(B-V) 或者 E(B-V)SFD(指取自SFD全天二维尘埃红化图 Schlegel et al. (1998))。本函数可使用 XP 消光曲线(默认)或`dustextinction` 包提供的各类 Rv 依赖的消光曲线模型。

  5. 函数 star_reddening

    可以计算给定 Teff、logg 和红化时,输入颜色的精确红化,使用 XP 消光曲线(默认)或其他消光模型。输入红化可以是E(440-550)、E(B-V) 或者 E(B-V)_SFD。

  6. 函数 model_extinction

    计算给定输入波段的模拟消光。使用 XP 消光曲线(默认)或其他消光模型。返回一个不同 Teff、E(B-V)、logg 时的各波段模拟消光值的 DataFrame。

其中函数4、5、6对于测光波段(颜色)的消光(红化)估计是基于BOSZ光谱库,滤光片通带和实测消光曲线的,属于理论与实测结合的计算,可能会和纯实测结果有所不同。当需要计算 GALEX,PS1,SDSS,Gaia,2MASS 和 WISE 波段的消光(或红化)时,我们推荐使用另一个基于实测的消光系数包extinction_coefficient 来进行消光改正。该包在 0 - 0.5 mag 的E(B-V)范围和 4000 - 10000 K 的温度范围内大多有效。

如何安装

使用 pip

~~~

PyPI (推荐)

pip install XPExtinctionToolkit

从本 github 库

pip install git+https://github.com/vnohhf/XPExtinctionToolkit.git ~~~

从源代码安装

从 git 仓库中下载 extinctioncoefficient 后,可以从源代码中安装 (https://github.com/vnohhf/extinctioncoeffcient/): ~~~ python setup.py install ~~~

使用指南

1. 获取 XP 消光曲线并绘图

~~~python import numpy as np import matplotlib.pyplot as plt from xpextinctiontoolkit import ExtinctionToolkit

初始化 ExtinctionToolkit

ExtTool = ExtinctionToolkit()

获取 XP 消光曲线

λ, kx55 = ExtTool.ext_curve()

绘图

fig,ax = plt.subplots(2,1, figsize=(5,6), tightlayout=True, dpi=300) ax[0].plot(λ[λ<10200], kx55[λ<10200], lw=1) ax[1].plot(1e4/λ, kx55, lw=1) ax[0].set(title='XP extinction curve (optical part)', ylabel='E(λ-55)/E(44-55)', xlabel='Wavelength [Å]') ax[1].set(title='XP extinction curve (optical and infrared)', ylabel='E(λ-55)/E(44-55)', xlabel='Wavelength number [1/μm]') for axi in ax: axi.minortickson() axi.grid(True, ls=':', color='dimgray', lw=0.2, which='major', zorder=1) ~~~

2. 对输入光谱进行消光改正

2.1 单个光谱

~~~python ExtTool = ExtinctionToolkit()

获取 BOSZ 光谱

BOSZ = np.load(ExtTool.startpath+'/BOSZspectra.npy', allow_pickle=1)

获取波长,已修改为匹配 XP 消光曲线。

λ, _ = ExtTool.ext_curve()

随机选择一个作为示例,获取原始光谱及其 Teff

ind = np.random.choice(range(len(BOSZ))) originalspec = BOSZ[ind] teff = ExtTool.tefflist[ind]

以 E(B-V) 为 0.1 对原始光谱进行红化。

输入的 ebv 转换为 E4455 需要温度信息

reddenedspec = originalspec / ExtTool.deredden(ebv=0.1, Teff=teff, wave=λ)

对红化的光谱进行去红化

(这里 intrinsicspec 即等于 originalspec,仅展示去红化的用法)

intrinsicspec = reddenedspec * ExtTool.deredden(ebv=0.1, Teff=teff, wave=λ)

绘图

fig, ax = plt.subplots(1, 1, figsize=(8, 4), tightlayout=True, dpi=300) ax.plot(λ, intrinsicspec, lw=0.9, label='本征光谱') ax.plot(λ, reddenedspec, lw=0.9, label='红化光谱') ax.set(title=f'Teff = {teff} [K]', ylabel='Flux [$cm^{-2} s^{-1} Å^{-1}$]', xlabel='波长 [Å]') ax.minortickson() ax.legend() ~~~

2.2 多光谱的红化/去红化

~~~python ebvlist = np.random.uniform(low=0, high=2, size=len(BOSZ)) reddenedspecmatrix = 1 / ExtTool.deredden(ebv=ebvlist, Teff=ExtTool.teff_list, wave=λ) * BOSZ ~~~

3. 将 E(B-V) 或 E(B-V)_SFD 转换为 E(440-550)

3.1 输入 E(B-V)

~~~python from xpextinctiontoolkit import ExtinctionToolkit ebv = [0.1, 0.3, 0.5] Teff = [4000, 6000, 8000] E4455 = ExtTool.Cal_E4455(ebv=ebv, Teff=Teff) ~~~

3.2 输入 E(B-V)_SFD

~~~python sfdebv = 0.2 E4455 = ExtTool.Cal_E4455(sfdebv=sfdebv) ~~~

4. 计算 1000 颗恒星的四个波段的消光

~~~python import numpy as np from xpextinctiontoolkit import ExtinctionToolkit

ExtTool = ExtinctionToolkit()

检查内置滤光片通带

print(ExtTool.Filters.keys())

生成 Teff 和 E(440-550) 的随机值

Band = ['2MASS.Ks', 'PS1.i', 'SDSS.g', 'WISE.W2'] Teff = np.random.uniform(low=4000, high=10000, size=1000) E4455 = np.random.uniform(low=0, high=2, size=1000)

计算定义波段的消光

Extinction = ExtTool.star_ext(Band, E4455=E4455, Teff=Teff) ~~~

5. 根据 Teff 和 E(B-V),计算恒星的红化

5.1 使用内置滤光片

本程序包内置了 GCPD_Johnson、GALEX、PS1、SDSS、Gaia3、2MASS 和 WISE 的通带。 ~~~python

定义 E(B-V)_SFD 和 Teff(这里也可以使用array、tuple等)

sfdebv = [0.3, 0.7, 1, 1.3] Teff = [6542, 6000, 3900, 7659]

定义色指数

Color = ['Johnson.B-Johnson.V', 'GAIA3.G-GAIA3.Grp']

计算红化

Reddening = ExtTool.star_reddening(Color, sfdebv=sfdebv, Teff=Teff) ~~~

5.2 使用外部输入滤光片

请将 '/path/to/new/filters/' 替换为实际的滤光片存放的绝对路径。 ~~~python ExtTool = ExtinctionToolkit(filterdir='/path/to/new/filters/') Band = ['NewBand'] Extinction = ExtTool.star_ext(Band, E4455=0.1, Teff=5000) ~~~

6. 计算不同 SED 时的模拟消光

6.1 使用 XP 消光曲线

~~~python ExtTool_XP = ExtinctionToolkit(model='XP') Band = ['GALEX.NUV', 'PS1.z', 'SDSS.u', 'WISE.W4']

计算模拟消光

ModelExt, _ = ExtToolXP.modelextinction(Band, callamb=False, energy=False) ~~~

6.2 获取有效波长

设置 'cal_lamb' 为 True 以计算有效波长(单位:埃(Å))。

~~~python

计算模拟消光和相应的有效波长

ModelExt, Modelλeff = ExtToolXP.modelextinction(['GALEX.NUV', 'PS1.z', 'SDSS.u'], cal_lamb=True, energy=False) ~~~

部分项目滤光片类型为光子计数(如 Gaia、GALEX、PAN-STARRS、SDSS),部分为能量计数(如 2MASS、WISE)。使用能量计数类型的滤光片时,将 'energy' 设置为 True 以获取正确的有效波长。

~~~python ModelExt, Modelλeff = ExtToolXP.modelextinction(['2MASS.H', 'WISE.W3'], cal_lamb=True, energy=True) ~~~

6.3 使用 dust_extinction 提供的 Rv 依赖消光曲线

~~~python from dustextinction.parameteraverages import CCM89, F99, F19, G23

使用 F19 消光曲线

ExtToolF19 = ExtinctionToolkit(model=F19) ModelExt, Modelλeff = ExtToolF19.modelextinction(['PS1.z', 'SDSS.u'], callamb=True, energy=False)

使用不同 Rv 值(默认值为 3.1)的 G23 模型

ExtToolG23 = ExtinctionToolkit(model=G23, Rv=2.5) ModelExt, Modelλeff = ExtToolG23.modelextinction(['2MASS.H', 'WISE.W4'], callamb=True, energy=True) ~~~

Owner

  • Login: vnohhf
  • Kind: user
  • Location: Beijing, China
  • Company: Beijing Normal University

A Ph.D student major in astronomy. I enjoy listening to music, especially postrock and pure music. I'm good at Chinese calligraphy and maybe biology.

Citation (CITATION.cff)

cff-version: 1.0
message: "If you use this software, please cite it as below."
authors:
- family-names: Ruoyi
  given-names: Zhang
orcid: https://orcid.org/0000-0003-1863-1268
- family-names: Haibo
  given-names: Yuan
orcid: https://orcid.org/0000-0003-2471-2363
- family-names: Bowen
  given-names: Huang
orcid: https://orcid.org/0000-0002-1259-0517
- family-names: Tao
  given-names: Wang
orcid: https://orcid.org/0000-0002-4878-1227
- family-names: Lin
  given-names: Yang
orcid: https://orcid.org/0000-0002-9824-0461
- family-names: Gregory
  given-names: Green
- family-names: Xiangyu
  given-names: Zhang
orcid: https://orcid.org/0000-0003-3112-3305

title: An Empirical Extinction Curve Revealed by Gaia XP Spectra and LAMOST
version: v1.0
date-released: 2024-07-02
                           

GitHub Events

Total
  • Issues event: 1
  • Watch event: 4
  • Push event: 3
Last Year
  • Issues event: 1
  • Watch event: 4
  • Push event: 3

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Cooper-J2000 (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 10 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
pypi.org: xp-extinction-toolkit

Extinction correction package using extinction curves derived from XP spectra

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 10 Last month
Rankings
Dependent packages count: 10.7%
Average: 35.6%
Dependent repos count: 60.5%
Maintainers (1)
Last synced: 6 months ago

Dependencies

XP_Extinction_Toolkit.egg-info/requires.txt pypi
  • astropy *
  • numpy *
  • pandas *
  • scipy *
  • tqdm *
setup.py pypi
  • astropy *
  • numpy *
  • pandas *
  • scipy *
  • tqdm *