概要
題名にある通り、宇宙物理の便利なモジュールastropyと、天文関連のデータを勝手に引っ張ってきてくれるastroqueryを使って、SDSS(Sloan Digital Sky Survey)のデータを描画してみたいと思います。
astroqueryのインストール
pip install
PyPIに登録されているので、簡単に以下のコマンドでインストールできます。
pip install astroquery
スクリプト
スクリプト
以下にスクリプトとその描画結果を示します。
#!/usr/bin/env python
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astroquery.sdss import SDSS
from matplotlib import pyplot as plt
objCoord = SkyCoord('00h39m34.8s +00d51m36.0s', frame='icrs')
# Get SDSS images
xObj = SDSS.query_region(objCoord, spectro=True)
imgObj = SDSS.get_images(matches=xObj)
image_i = imgObj[0][0]
data_i = image_i.data
# Plot the image
fig = plt.figure()
# ax = fig.add_subplot(111, projection=wcs_cut)
ax = fig.add_subplot(111)
imgRegion = ax.imshow(data_i.data, origin='lower', vmin=-0.64, vmax=0.45)
plt.show()
結果
左下に棒渦巻き銀河のようなものが見えますね。
スクリプト詳細
SkyCoord
objCoord = SkyCoord('00h39m34.8s +00d51m36.0s', frame='icrs')
ここで描画したい座標を指定しています。試しに
objCoord = SkyCoord('0h8m05.63s +14d50m23.3s', frame='icrs')
としてみると描画結果は以下のようになり、違う領域が図示されることがわかります。
SDSS.query_region
xObj = SDSS.query_region(objCoord, spectro=True)
この行でobjCoord
で指定した座標あたりの領域を取るためのクエリを作成します。
SDSS.get_images
imgObj = SDSS.get_images(matches=xObj)
この行で先ほど作成したクエリのデータを取得しています。試しにこのget_imagesデータをprintしてみましょう。すると
[[<astropy.io.fits.hdu.image.PrimaryHDU object at 0x108db8438>, <astropy.io.fits.hdu.image.ImageHDU object at 0x108dbd940>, <astropy.io.fits.hdu.table.BinTableHDU object at 0x108da0240>, <astropy.io.fits.hdu.table.BinTableHDU object at 0x108da4b38>]]
のようにfitsデータであることがわかります。そしてその[0][0]
番目を以下のように書き出してみましょう。
print(dir(imgObj[0][0]))
すると
['_EXCLUDE', '_MASK', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_axes', '_bitpix', '_blank', '_bscale', '_buffer', '_bzero', '_calculate_checksum', '_calculate_datasum', '_char_encode', '_checksum', '_checksum_valid', '_close', '_compute_checksum', '_compute_hdu_checksum', '_convert_pseudo_unsigned', '_data_loaded', '_data_needs_rescale', '_data_offset', '_data_replaced', '_data_size', '_datasum', '_datasum_valid', '_default_name', '_do_not_scale_image_data', '_dtype_for_bitpix', '_encode_byte', '_file', '_gcount', '_get_raw_data', '_get_scaled_image_data', '_get_timestamp', '_has_data', '_hdu_registry', '_header', '_header_offset', '_modified', '_new', '_orig_bitpix', '_orig_blank', '_orig_bscale', '_orig_bzero', '_output_checksum', '_padding_byte', '_pcount', '_postwriteto', '_prewriteto', '_readfrom_internal', '_scale_back', '_scale_internal', '_standard', '_summary', '_uint', '_update_checksum', '_update_header_scale_info', '_update_uint_scale_keywords', '_verify', '_verify_blank', '_verify_checksum_datasum', '_writedata', '_writedata_direct_copy', '_writedata_internal', '_writeheader', '_writeto', '_writeto_internal', 'add_checksum', 'add_datasum', 'copy', 'data', 'filebytes', 'fileinfo', 'fromstring', 'header', 'is_image', 'level', 'match_header', 'name', 'readfrom', 'register_hdu', 'req_cards', 'run_option', 'scale', 'section', 'shape', 'size', 'standard_keyword_comments', 'unregister_hdu', 'update_header', 'ver', 'verify', 'verify_checksum', 'verify_datasum', 'writeto']
のようにこの中にdata
が入っていることがわかります。あとはこれをプロットするだけです。
結言
今回はSDSSを使用しましたが、他にもALMA
やGAIA
のデータを気軽に触ることができます。皆様もぜひお試しください。