天体名と距離を表示する アノテーション

アノテーション

これは、天体名や銀河名、距離を画像に表示させる”GalaxyAnnotator”を、”Ubuntu 24.04.2 LTS” で使う案内です。

R.Nanbaさんが作成されたスクリプト”GalaxyAnnotator”(2025年3月現在ver0.9.4)
https://github.com/rnanba/GalaxyAnnotator
こちらを使い天体画像に、天体名や銀河名、距離などを表示します。

Ubuntu 24 でアノテーションを表示させます

”GalaxyAnnotator”スクリプトの使い方は、
https://snct-astro.hatenadiary.jp/entry/2021/05/29/010041
こちらに詳しく解りやすく、案内されています。有り難うございます。

”GalaxyAnnotator” をLinux / Ubuntu で使うには、
Pythonと、pythonモジュールの astropy、svgwrite が必要です。Inkscapeも必要になります。

ここでは、システム全体にPythonパッケージをインストールします。

$ sudo apt install python3-astropy
$ sudo apt install python3-svgwrite

銀河名を表示させたい画像の位置情報を得るために、
http://nova.astrometry.net/
その画像をアップロードします。

しばらくして、”Go to results page” を見ると、Calibrationの項目に “wcs.fits” があるので、ダウンロードし、”GalaxyAnnotator-x.x”のディレクトリに保存します。

“GalaxyAnnotator-x.x” ディレクトリには、アップロードした画像と、 “wcs.fits”ファイルを置きます。例えば、[Abell1656.png]と、[wcs.fits]です。下の画像が、[Abell1656.png]です。

Date: 2025-02-22
Optics: Takahashi TS-160, HEUIB-II
Camera: ASI533MC Pro, gain 100, offset 20, EAF
Exposure: 180s x 19 (total 57m)
Mount: 160jp, Althiba3, off-axis guide, INDI Library
Processing: Siril 1.3.6, GraXpert 3.1.0rc2, StarNet2, Galaxy Annotator v0.9.4

次に、votable.xmlを作ります。

$ python3 leda-get-votable.py wcs.fits votable.xml

次に、天体情報などが入ったファイルを作ります。
『leda-get-votable.pyを使って wcs.fits から画像の写野を読み取ってその範囲に存在する銀河のデータを HyperLeda から取得する。』
— https://github.com/rnanba/GalaxyAnnotator#readmeより

leda-votable-to-galaxy.pyを使って、上で作った votable.xml から天体情報ファイルを生成します。
そのファイル名をここでは、[Abell1656.json]にします。

$ python3 leda-votable-to-galaxy.py -m 13 -s -d -j -p 4 votable.xml Abell1656.json

オプションの意味は、
https://github.com/rnanba/GalaxyAnnotator#readmeより、
-m 13 : 指定された等級より明るい銀河のみを銀河情報ファイルに出力する。”-m 13″は13等星より明るい銀河
-s : 等級データのない天体をスキップする場合
-d : 距離情報(Gly (ギガ光年)表記の光路距離)を説明文として付加した銀河情報ファイルに出力します。
-j : 距離情報を日本語表記(光年)で出力する。
-p : 距離情報は有効桁数(デフォルトで3桁)の一つ下の桁を四捨五入した値で出力します。”-p 4″ は4桁にする例です。
-i : 等級データのない天体を出力に含める場合

ここに表示される「距離情報」は、今現在の地球から天体までの距離ではなく、「光路距離」です。
『光路距離は、天体から発した光が X 年かかって現在の地球に届いた場合の距離を X 光年とするもの』
『光が届くまでの間に宇宙そのものが膨張を続けているため、天体から光が発した時点での天体と地球の間の距離や、今現在の時点での天体と地球の間の距離とは異なる値になることに注意してください。』
https://github.com/rnanba/GalaxyAnnotator#readmeより

元画像[Abell1656.png]に天体名や銀河名、距離が入った画像を作ります。ここでは[Abell1656.svg]です。
“sample-style.json”には色やフォントの指定があります。
これを使い、アノテーションされたsvgファイルを作ります。

$ python3 galaxy-annotator.py Abell1656.json sample-style.json wcs.fits Abell1656.png Abell1656.svg

アノテーションが施されたsvgファイルを、Inkscapeで編集します。
もしくは、Inkscapeを用いて、png や jpg などへ変換します。

一目で、名前と距離が判って嬉しい。
このアノテーションスクリプトを使って、見たことがない距離を表示させるのが、楽しい。
R.Nanbaさん、有難うございます。

leda-votable-to-galaxy.py -m 17
“-m 17″と指定して、17等級以上の銀河名を表示させると、折り重なり。。。

アノテーションの為に、Python環境を Ubuntu 24 に整えます

Pythonの仕様の変更とOSのバージョンにより、Ubuntu で pip コマンドが使えなくなりました。
Python は venv の仮想環境下でのみ実行できるようです。
cowsayをインストールしようとすると、次のエラー表示となりました。

$ pip install cowsay
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

hint: See PEP 668 for the detailed specification.
とあるので、
https://peps.python.org/pep-0668/
を見てみます。

“Abstract”にある3段落目、最後には、

This PEP proposes a mechanism for a Python installation to communicate to tools like pip that its global package installation context is managed by some means external to Python, such as an OS package manager. It specifies that Python-specific package management tools should neither install nor remove packages into the interpreter’s global context, by default, and should instead guide the end user towards using a virtual environment.

“Python のパッケージ管理は、仮想環境を使ってね” と読めます。

$ sudo apt install python3-venv python3-pip
$ python3 -m venv ~/siril_py
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
$ update-alternatives --config python

pipやpipxを使って、モジュールを入れたのですが、そのモジュールが働いてくれません

“GalaxyAnnotator-x.x” ディレクトリで以下のコマンド操作

$ python leda-get-votable.py wcs.fits votable.xml

初めて行うと、次の表示が表示されました。
ModuleNotFoundError: No module named ‘astropy’
「モジュールが無いから、追加してね」とあるので、インストールします。
自身のディレクトリにモジュールを入れるので、pipを使います。
が、pipやpipxを使って、モジュールを入れたのですが、そのモジュールが働きません。

モジュールが動かないのは、以下の様な作業でした。

$ pip install astropy

しかし、pipでモジュールをインストールしようとしらならば、次のメッセージ

“If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.”

「Debian でパッケージ化されていない Python アプリケーションをインストールしたい場合は、pipx install xyz を使うのが一番簡単でしょう。pipx がインストールされていることを確認してください。」

$ sudo apt remove python3-pip <- pipを削除
$ sudo apt install pipx
$ pipx install astropy

installed package astropy 7.0.1, installed using Python 3.12.3
These apps are now globally available
– fits2bitmap
– fitscheck
– fitsdiff
– fitsheader
– fitsinfo
– samp_hub
– showtable
– volint
⚠️ Note: ‘/home/minmin/.local/bin’ is not on your PATH environment variable.
These apps will not be globally accessible until your PATH is updated.
Run pipx ensurepath to automatically add it,
or manually modify your PATH in your shell’s config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨

$ pipx ensurepath
$ python leda-get-votable.py wcs.fits votable.xml

ここでエラー表示がありました
こちらの”Ubuntu 24.04.2 LTS”では、pip や pipxを使って入れたモジュールが、リンクを張っても、パスを通しても、動かないので、もう一つの方法を行います。
“To install Python packages system-wide, try apt install python3-xyz,where xyz is the package you are trying to install.”
「システム全体にPythonパッケージをインストールするには、apt install python3-xyz を試してください。」

$ sudo apt install python3-astropy

『pipやpipxを使って、モジュールを入れたのですが、そのモジュールが働きません』は、以上になります。

コメント