- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
长话短说:我想用 Python 将 Gaia 天体测量数据绘制成 TESS 图像。怎么可能?
详细版本见下文。
我有 64x64 像素 TESS盖亚 ID 为 4687500098271761792 的恒星图像。苔丝天文台指南的第 8 页说 1 像素是 ~21 弧秒。使用 Gaia Archive ,我搜索这颗星星(在顶部特征下方,单击“搜索”。)并提交查询以查看 1000 弧秒内的星星,大致是我们需要的半径。我用于搜索的名称是 Gaia DR2 4687500098271761792
,如下图:
提交查询,我得到了一个包含 500 颗星的列表,带有 RA
和 DEC
坐标。选择 CSV
和 Download results
, 我得到了 4687500098271761792 周围的星星列表。这个结果文件也可以在 here 中找到。 .这是来自 Gaia 的输入我们想使用。
从苔丝,我们有 4687500098271761792_med.fits , 图像文件。我们使用以下方法绘制它:
from astropy.io import fits
from astropy.wcs import WCS
import matplotlib.pyplot as plt
hdul = fits.open("4687500098271761792_med.fits")[0]
wcs = WCS(hdul.header)
fig = plt.figure(figsize=(12,12))
fig.add_subplot(111, projection=wcs)
plt.imshow(hdul.data)
hdul.data
中的数据不关心投影:
plt.imshow(hdul.data)
DEC
和
RA
第一个图中的值分别约为 -72° 和 16°,这很好,因为盖亚目录为我们提供了 4687500098271761792 附近的恒星,大致具有这些坐标。所以投影似乎还可以。
imshow()
上方的盖亚星。情节。我们阅读了
CSV
我们之前下载的文件并解压缩
RA
和
DEC
来自它的对象的值:
import pandas as pd
df=pd.read_csv("4687500098271761792_within_1000arcsec.csv")
ralist=df['ra'].tolist()
declist=df['dec'].tolist()
plt.scatter(ralist,declist,marker='+')
RA
和
DEC
值为
WCS
,并以这种方式绘制它们:
for index, each in enumerate(ralist):
ra, dec = wcs.all_world2pix([each], [declist[index]], 1)
plt.scatter(ra, dec, marker='+', c='k')
all_world2pix
来自
here .
1
参数只是设置原点的位置。
all_world2pix
的说明说:
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
hdul = fits.open("4687500098271761792_med.fits")[0]
wcs = WCS(hdul.header)
fig = plt.figure(figsize=(12,12))
fig.add_subplot(111, projection=wcs)
plt.imshow(hdul.data)
for index, each in enumerate(ralist):
ra, dec = wcs.all_world2pix([each], [declist[index]], 1)
plt.scatter(ra, dec, marker='+', c='k')
imshow()
上面有许多标记的图片,标记应该是 TESS 图像上星星所在的位置。我工作的 Jupyter Notebook 可用
here .
transform
plotting in world coordintes 的论据.用一些示例点(下图中的弯曲十字)进行了尝试。还把盖亚数据绘制在地块上,没有处理它,它们最终集中在一个非常狭窄的空间。应用于他们
transform
方法,得到了一个看似与以前非常相似的结果。代码(还有
here):
import pandas as pd
df=pd.read_csv("4687500098271761792_within_1000arcsec.csv")
ralist=df['ra'].tolist()
declist=df['dec'].tolist()
from astropy.io import fits
from astropy.wcs import WCS
import matplotlib.pyplot as plt
hdul = fits.open("4687500098271761792_med.fits")[0]
wcs = WCS(hdul.header)
fig = plt.figure(figsize=(12,12))
fig.add_subplot(111, projection=wcs)
plt.imshow(hdul.data)
ax = fig.gca()
ax.scatter([16], [-72], transform=ax.get_transform('world'))
ax.scatter([16], [-72.2], transform=ax.get_transform('world'))
ax.scatter([16], [-72.4], transform=ax.get_transform('world'))
ax.scatter([16], [-72.6], transform=ax.get_transform('world'))
ax.scatter([16], [-72.8], transform=ax.get_transform('world'))
ax.scatter([16], [-73], transform=ax.get_transform('world'))
ax.scatter([15], [-72.5], transform=ax.get_transform('world'))
ax.scatter([15.4], [-72.5], transform=ax.get_transform('world'))
ax.scatter([15.8], [-72.5], transform=ax.get_transform('world'))
ax.scatter([16.2], [-72.5], transform=ax.get_transform('world'))
ax.scatter([16.6], [-72.5], transform=ax.get_transform('world'))
ax.scatter([17], [-72.5], transform=ax.get_transform('world'))
for index, each in enumerate(ralist):
ax.scatter([each], [declist[index]], transform=ax.get_transform('world'),c='k',marker='+')
for index, each in enumerate(ralist):
ax.scatter([each], [declist[index]],c='b',marker='+')
imshow()
绘制)。现在让我们尝试绘制恒定的 RA 和 DEC 线(或者说恒定的纬度和经度线),以更好地理解 Gaia 数据点错位的原因。将上面的代码扩展几行:
ax.coords.grid(True, color='green', ls='solid')
overlay = ax.get_coords_overlay('icrs')
overlay.grid(color='red', ls='dotted')
最佳答案
首先我要说,好问题!非常详细和可复制。我仔细研究了您的问题,并尝试从您的 git 存储库开始重做练习,并从 GAIA 存档中下载目录。
编辑
以编程方式您的代码很好(请参阅下面的 旧部分 以了解略有不同的方法)。缺失点的问题是从 GAIA 存档下载 csv 文件时只能获得 500 个数据点。因此看起来好像查询中的所有点都塞进了一个奇怪的形状。但是,如果您将搜索半径限制为较小的值,您可以看到 TESS 图像内有一些点:
请与旧部分中显示的版本进行比较。代码与下面相同,只是下载的 csv 文件适用于较小的半径。因此,在导出到 csv 时,您似乎只是从 GAIA 存档下载了所有可用数据的一部分。避免这种情况的方法是像您一样进行搜索。然后,在结果页面上点击 Show query in ADQL form
在底部和查询中,您以 SQL 格式更改显示:
Select Top 500
Select
aplpy
- 在后台使用 matplotlib - 最后得到以下代码:
from astropy.io import fits
from astropy.wcs import WCS
import aplpy
import matplotlib.pyplot as plt
import pandas as pd
from astropy.coordinates import SkyCoord
import astropy.units as u
from astropy.io import fits
fits_file = fits.open("4687500098271761792_med.fits")
central_coordinate = SkyCoord(fits_file[0].header["CRVAL1"],
fits_file[0].header["CRVAL2"], unit="deg")
figure = plt.figure(figsize=(10, 10))
fig = aplpy.FITSFigure("4687500098271761792_med.fits", figure=figure)
cmap = "gist_heat"
stretch = "log"
fig.show_colorscale(cmap=cmap, stretch=stretch)
fig.show_colorbar()
df = pd.read_csv("4687500098271761792_within_1000arcsec.csv")
# the epoch found in the dataset is J2015.5
df['coord'] = SkyCoord(df["ra"], df["dec"], unit="deg", frame="icrs",
equinox="J2015.5")
coords = df["coord"].tolist()
coords_degrees = [[coord.ra.degree, coord.dec.value] for coord in df["coord"]]
ra_values = [coord[0] for coord in coords_degrees]
dec_values = [coord[1] for coord in coords_degrees]
width = (40*u.arcmin).to(u.degree).value
height = (40*u.arcmin).to(u.degree).value
fig.recenter(x=central_coordinate.ra.degree, y=central_coordinate.dec.degree,
width=width, height=height)
fig.show_markers(central_coordinate.ra.degree,central_coordinate.dec.degree,
marker="o", c="white", s=15, lw=1)
fig.show_markers(ra_values, dec_values, marker="o", c="blue", s=15, lw=1)
fig.show_circles(central_coordinate.ra.degree,central_coordinate.dec.degree,
radius=(1000*u.arcsec).to(u.degree).value, edgecolor="black")
fig.save("GAIA_TESS_test.png")
关于python - 如何使用 Python 将 Gaia 天体测量数据绘制为 TESS 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54116787/
我正在尝试使用 astropy 将 WCS 转换为像素,但是当我尝试读取图像时: from astropy import wcs w = wcs.WCS('image_file.fits') 我收到以
我是一名优秀的程序员,十分优秀!