python - 使用 Python - 在 Simbad 中进行坐标查询后,如何提取 Aladin 生成的图像(使用网站上的 Simbad 绘图按钮打开)?
问题描述
基本目标:给定一组天空坐标 (ra, dec),此 Python 函数应返回以这些坐标为中心的天空 FITS 图像。
详细目标:该函数将使用 astroquery 和 simbad 执行坐标查询。理想情况下,它将能够访问以 (ra, dec) 为中心的给定区域内的对象数据库。因此,还将输入一些尺寸参数(FoV 或半径)。但主要是,当通过浏览器在 simbad 上完成查询时,有一个选项可以绘制以输入坐标为中心的星区,由 AladinLite 制作,并且该函数应返回此图像(希望作为 FITS 图像)。
我所尝试的:我所尝试的一切都是发现 astroquery 和 simbad 的使用。但是我在文档中找不到任何关于如何通过 astroquery 获取来自 AladinLite 的图像的信息。找到一种使用 Python 直接从 Aladin 获取图像的方法似乎也不可能。
问题:是否可以使用 Python 和 astroquery 在浏览器版本的 simbad 坐标查询上获取 AladinLite 生成的图像?如果是这样,我该怎么做?
我附上了 Web 浏览器的屏幕截图,显示了 AladinLite 生成的图像。要清楚 - 我想要星域的图像,而不是带有圆圈物体的图像等等。
一些伪代码:
def generate_starfield(ra, dec, FoV):
# define the sky coords
coords = SkyCoord(ra=ra, dec=dec)
# do an astroquery.simbad query using above coords
query = perform_query(coords)
# extract the image from the query generated by AladinLite
image = get_aladinlite_image(query, FoV)
return image
解决方案
警告:我不是天文学研究人员,虽然我是 Astropy 开发人员,但我并不是真正的用户,所以如果有更多经验/了解该问题的人想要加入,可能会有一些更好的方法来做到这一点。
但是 AladinLite 不是图像目录。它只是一个用于图像查看和绘图的基于 Web 的 UI。但是,由 U. Strasbourg 托管的AladinLite示例服务从他们的HiPS 调查服务中获取数据。他们通过hips2fits基于 Web 的 API 提供这些数据。我不认为 AladinLite 提供了一个界面来将其所有显示的图块收集到 FITS 图像中以供下载。这就是 hips2fits 服务的用途。顺便说一句,它在网站上指出:
我们将从 astroquery.cds 开发对 hips2fits 的访问。同时,这个笔记本应该让你开始从 Python 脚本中查询 hips2fits。
因此,您的工作流程的第一部分是正确的:您将使用astroquery
查询 Simbad。但随后您需要查询图像数据。目前还没有 Python 特定的 API,但是 Web API 有很好的文档记录,所以主要是构建正确的 URL 的问题。这是一个示例工作流程,我使用您提供的屏幕截图中的相同坐标提出:
>>> from astroquery.simbad import Simbad
>>> from astropy.coordinates import SkyCoord
>>> coord = SkyCoord('16 14 20.30000000 -19 06 48.1000000', unit=(u.hourangle, u.deg), frame='fk5')
>>> query_results = Simbad.query_region(coord)
>>> query_results
<Table length=3>
MAIN_ID RA DEC ... COO_QUAL COO_WAVELENGTH COO_BIBCODE
"h:m:s" "d:m:s" ...
object str13 str13 ... str1 str1 object
----------------------- ------------- ------------- ... -------- -------------- -------------------
[T64] 7 16 14 20.2881 -19 06 48.062 ... A O 2018yCat.1345....0G
IRAS 16114-1858 16 14 22.1 -19 06 14 ... E M 1988IRASP.C......0J
2MASS J16142091-1906051 16 14 20.9018 -19 06 05.195 ... A O 2018A&A...616A...1G
现在假设我想要一个以结果中的第一个对象为中心的图像(类似于 Web UI 上显示的 AladinLite 预览):
>>> from urllib.parse import urlencode
>>> from astropy.io import fits
>>> object_main_id = query_results[0]['MAIN_ID'].decode('ascii')
>>> object_coords = SkyCoord(ra=query_results['RA'], dec=query_results['DEC'],
... unit=(u.hourangle, u.deg), frame='icrs')
>>> query_params = {
... 'hips': 'DSS',
... 'object': object_main_id,
... 'ra': object_coords[0].ra.value,
... 'dec': object_coords[0].dec.value,
... 'fov': (2 * u.arcmin).to(u.deg).value,
... 'width': 500,
... 'height': 500
... }
>>> url = f'http://alasky.u-strasbg.fr/hips-image-services/hips2fits?{urlencode(query_params)}'
>>> hdul = fits.open(url)
Downloading http://alasky.u-strasbg.fr/hips-image-services/hips2fits?hips=DSS&object=%5BT64%5D++7&ra=243.58457533549102&dec=-19.113364937196987&fov=0.03333333333333333&width=500&height=500
|==============================================================| 504k/504k (100.00%) 0s
>>> hdul.info()
>>> hdul.info()
Filename: /path/to/.astropy/cache/download/py3/ef660443b43c65e573ab96af03510e19
No. Name Ver Type Cards Dimensions Format
0 PRIMARY 1 PrimaryHDU 22 (500, 500) int16
>>> hdul[0].header
SIMPLE = T / conforms to FITS standard
BITPIX = 16 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 500
NAXIS2 = 500
WCSAXES = 2 / Number of coordinate axes
CRPIX1 = 250.0 / Pixel coordinate of reference point
CRPIX2 = 250.0 / Pixel coordinate of reference point
CDELT1 = -6.6666668547014E-05 / [deg] Coordinate increment at reference point
CDELT2 = 6.6666668547014E-05 / [deg] Coordinate increment at reference point
CUNIT1 = 'deg' / Units of coordinate increment and value
CUNIT2 = 'deg' / Units of coordinate increment and value
CTYPE1 = 'RA---TAN' / Right ascension, gnomonic projection
CTYPE2 = 'DEC--TAN' / Declination, gnomonic projection
CRVAL1 = 243.584534 / [deg] Coordinate value at reference point
CRVAL2 = -19.11335065 / [deg] Coordinate value at reference point
LONPOLE = 180.0 / [deg] Native longitude of celestial pole
LATPOLE = -19.11335065 / [deg] Native latitude of celestial pole
RADESYS = 'ICRS' / Equatorial coordinate system
HISTORY Generated by CDS hips2fits service - See http://alasky.u-strasbg.fr/hips
HISTORY -image-services/hips2fits for details
HISTORY From HiPS CDS/P/DSS2/NIR (DSS2 NIR (XI+IS))
现在进行绘图。在 AladinLite 预览中看到的各种标记和刻度是由 AladinLite 查看器本身生成的,因此使用基于 Python 的工作流程,您现在可以提供自己的绘图。有很多方法可以解决这个问题。您现在可以保存 FITS 图像并使用您已有的任何绘图工具。虽然对于纯 Python 工作流程,aplpy包是专门为天文图设计的。这是我对这张图片所做的,只是作为一个例子:
>>> import aplpy
>>> gc = aplpy.FITSFigure(hdul)
>>> gc.show_grayscale()
INFO: Auto-setting vmin to 2.560e+03 [aplpy.core]
INFO: Auto-setting vmax to 1.513e+04 [aplpy.core]
>>> gc.show_markers(object_coords.ra, object_coords.dec, edgecolor='red',
... marker='s', s=50**2)
>>> gc.save('plot.png')
结果:
推荐阅读
- javascript - 当我尝试增加一件商品的数量时,购物车中的其他商品数量也会增加
- palantir-foundry - Palantir Foundry 中轮廓结果的快照
- ios - 是否可以让用户在 iOS 应用上“预订”订阅,然后在以后“开启”订阅?
- python - ImportError:无法从“PIL”(/usr/lib/python3/dist-packages/PIL/__init__.py)导入名称“_imaging”
- reactjs - 带有反应路由器的WordPress不会显示页面?
- javascript - 使用 SSJS 计算数据扩展中的 id 和 Upsert 到另一个数据扩展
- php - 在数据库中创建一个新表
- jquery - 通过JQUERY中另一个页面的链接取消隐藏div
- flutter - Flutter Sum 列表中的值
- python - PCA 反向给出错误数据