使用 Python - 在 Simbad 中进行坐标查询后,如何提取 Aladin 生成的图像(使用网站上的 Simbad 绘图按钮打开)?
Using Python - After a coordinate query in Simbad, how do I extract the image generated by Aladin (opened with the Simbad plot button on the website)?
基本目标:给定一组天空坐标 (ra, dec),此 Python 函数应该 return 以这些坐标为中心的天空的 FITS 图像。
详细目标:该函数将使用astroquery 和simbad 执行坐标查询。理想情况下,它将能够访问以 (ra, dec) 为中心的给定区域内的对象数据库。因此,一些尺寸参数也将被输入(FoV,或半径)。但主要是,当通过浏览器在 simbad 上进行查询时,有一个选项可以绘制以输入坐标为中心的星形区域,由 AladinLite 制作,并且函数应该 return 此图像(希望作为 FITS 图像).
我的尝试:我在这里所做的一切都是为了发现 astroquery 和 simbad 的使用。但是我在文档中找不到任何关于如何通过 astroquery 获取 AladinLite 图像的信息。使用 Python 寻找直接从 Aladin 获取图像的方法似乎也不可能。
问题:是否可以使用 Python 和 astroquery 在浏览器版本的 simbad 坐标查询中获取 AladinLite 生成的图像?如果是这样,我该怎么做呢?
I attached a screenshot of the web browser showing the image generated by AladinLite. To be clear - I want the image of the star field, not the image with the circled objects and so on.
一些伪代码:
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 开发人员,但我并不是真正的用户,所以如果有人拥有更多 experience/understanding问题想一起来。
但 AladinLite 不是图像目录。它只是一个基于网络的 UI 图像查看和绘图。但是,AladinLite sample service hosted by U. Strasbourg takes its data from their HiPS Survey services. They provide this data through a hips2fits 基于 Web API。我不认为 AladinLite 提供了一个界面来将其所有显示的图块收集到 FITS 图像中以供下载。这就是 hips2fits 服务的用途。顺便说一句,它在网站上注明:
We will develop an access to hips2fits from astroquery.cds. In the meantime, this notebook should get you started to query hips2fits from Python scripts.
因此您的工作流程的第一部分是正确的:您将使用 astroquery
来查询 Simbad。但是随后您需要查询图像数据。目前还没有 Python-specific API,但是网络 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
现在假设我想要一个以结果中的第一个对象为中心的图像(类似于网络上显示的 AladinLite 预览 UI):
>>> 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')
结果:
基本目标:给定一组天空坐标 (ra, dec),此 Python 函数应该 return 以这些坐标为中心的天空的 FITS 图像。
详细目标:该函数将使用astroquery 和simbad 执行坐标查询。理想情况下,它将能够访问以 (ra, dec) 为中心的给定区域内的对象数据库。因此,一些尺寸参数也将被输入(FoV,或半径)。但主要是,当通过浏览器在 simbad 上进行查询时,有一个选项可以绘制以输入坐标为中心的星形区域,由 AladinLite 制作,并且函数应该 return 此图像(希望作为 FITS 图像).
我的尝试:我在这里所做的一切都是为了发现 astroquery 和 simbad 的使用。但是我在文档中找不到任何关于如何通过 astroquery 获取 AladinLite 图像的信息。使用 Python 寻找直接从 Aladin 获取图像的方法似乎也不可能。
问题:是否可以使用 Python 和 astroquery 在浏览器版本的 simbad 坐标查询中获取 AladinLite 生成的图像?如果是这样,我该怎么做呢?
I attached a screenshot of the web browser showing the image generated by AladinLite. To be clear - I want the image of the star field, not the image with the circled objects and so on.
一些伪代码:
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 开发人员,但我并不是真正的用户,所以如果有人拥有更多 experience/understanding问题想一起来。
但 AladinLite 不是图像目录。它只是一个基于网络的 UI 图像查看和绘图。但是,AladinLite sample service hosted by U. Strasbourg takes its data from their HiPS Survey services. They provide this data through a hips2fits 基于 Web API。我不认为 AladinLite 提供了一个界面来将其所有显示的图块收集到 FITS 图像中以供下载。这就是 hips2fits 服务的用途。顺便说一句,它在网站上注明:
We will develop an access to hips2fits from astroquery.cds. In the meantime, this notebook should get you started to query hips2fits from Python scripts.
因此您的工作流程的第一部分是正确的:您将使用 astroquery
来查询 Simbad。但是随后您需要查询图像数据。目前还没有 Python-specific API,但是网络 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
现在假设我想要一个以结果中的第一个对象为中心的图像(类似于网络上显示的 AladinLite 预览 UI):
>>> 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')
结果: