0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PyAtomDB を google Colab で簡単に動かす方法

Last updated at Posted at 2021-06-27

はじめに

PyAtomDB とは、AtomDB という宇宙物理向けの原子物理データベースです。これはとっても便利なツールなのですが、パソコンが変わるたびに環境を構築するのが面倒、という人向けに、google Colab で、PyAtomDB example scripts を動かす例を紹介します。

コードを読めばわかる人は、

PyAtomDB を google Colab で動かした例のColabのページ

を参照ください。出力結果は、

をご覧ください。

セットアップの概要解説

環境変数の設定

自分のgoogle Drive、google Colab 上では、/content/drive/MyDrive/ としてマウントされている。自分のgoogle Drive に atomdb というディレクトリを作成する。 その場所(/content/drive/MyDrive/atomdb)を環境変数ATOMDBが参照するように設定する。

Colabのマウントって何?という方は、ColaboratoryでのGoogle Driveへのマウントが簡単になっていたお話 を一読ください。

!export ATOMDB=/content/drive/MyDrive/atomdb

google Colab は、bashが動いているが、shコマンドで変数などを設定するときは、!を初めにつける必要がある。(ちなみに、移動するときは、%cd のように %が先頭に着くことには注意。)

データのダウンロード

PyAtomDB example scripts は、Chandra衛星の
cycle22 の CALDB を使う例になっているが、これを持ってない場合は、

!wget https://cxc.cfa.harvard.edu/caldb/prop_plan/grating/CY23/aciss_meg1_cy23.grmf
!wget https://cxc.cfa.harvard.edu/caldb/prop_plan/grating/CY23/aciss_meg1_cy23.garf

を実行して、cycle23のデータをダウンロードしておこう(2021.6.28の話)。以下、rmf (検出器応答の行列成分) と arf (有効面積のベクトル成分) は、これらのファイルを使う設定とする。

データベースのファイルのダウンロード

一番最初にexampleを動かす時に、ファイルをダウンロードする。

ATOMDB environment variable not set. Set up AtomDB files now? (yes/no/info) [yes]yes
Location to install AtomDB files [/root/atomdb] :/content/drive/MyDrive/atomdb
Allow reporting of anonymous usage statistics (yes/no/info) [yes]no
You are about to install:
AtomDB installation location: /content/drive/MyDrive/atomdb
Transmit anonymous user data: no
Randomly generated userid: 00000000
Is this ok? (y/n) [y]y
Temporarily setting $ATOMDB environment variable to /content/drive/MyDrive/atomdb.  It is *strongly* recommended that you add this to your environment   permanently.
creating directory /content/drive/MyDrive/atomdb ...done
creating user data file /content/drive/MyDrive/atomdb/userdata ...done
finding current version of AtomDB.  Latest version is 3.0.9
Do you wish to download the emissivity data for these files (recommended)? (y/n) [y]y
making directory /content/drive/MyDrive/atomdb/installtmp

Uncompressing ...  Uncompressed
...

「AtomDB installation location: /content/drive/MyDrive/atomdb」 のように、自分のgoogle drive 上の atomdb ディレクトリが設定されていることを確認しよう。

図の出力

colab上では、plt.show(), plot.draw() のタイミングが、ローカルと違う場合があるので、図がでない??と思ったら、show のタイミングや、ax, plt.figure の初期化などを微調節しよう。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?