軌道計算アニメーション


ネット上の例にあったもの
0.1sec x 10 = 1secごとにパラパラアニメ
$ convert -delay 10 ./Pic/*.png test.gif

-----

[基本]

自分の場合
$ convert -delay 1 1with_bar/*.png 1snapshot_with_bar.gif

例えば

1with_bar

というフォルダに複数pngファイルがあったとき、それらをファイルの名前順につなげてくれるようである。

 

- google chromeなどのブラウザで見ると動いてくれる。

- Macのpreviewで見ると、combineされた(100枚の画像なら100ページの)画像として見れる。

gifはストップ・再生ができないので(ブラウザの更新ボタンで最初からなら再生できる)、snapshotを見る上ではpreviewがいい。

 

-----

[少し応用]

$ convert -delay 20 -resize 50% omega_m*Gyr/0*/fig*Lz/*png reduced50_delay20.gif

などとすると、もとのpngファイルのサイズを50%にしたもののgifファイルを作れる。gifが重すぎるときに便利。

-delay 20 ::: 20/100 secごと

-resize 50% ::: 画像サイズが50%

 

Python いろいろなパッケージのインストール

(1) fitsio

$pip install fitsio

 

(2) esutil  [ https://github.com/esheldon/esutil ]

$ pip install esutil

 

(3) isodist [  ]

$ python setup.py build
$ python setup.py install

 

(4) periodictable-1.4.1 [ https://pypi.python.org/pypi/periodictable ] 

$ sudo python setup.py install

lambda式

Pythonの「ラムダ文」が難しいww

 

import scipy.optimize as op

def lnprob(theta, ell_data, bee_data):

    lp = lnprior(theta)

    if not np.isfinite(lp):

        return -np.inf

    return lp + lnlike(theta, ell_data, bee_data)

 

    theta=[5.05, 250., -200., 1.1] #探索するパラメータの初期値。

    minus_lnprob = lambda theta,*args: -lnprob(theta,*args)

    result = op.minimize(minus_lnprob, theta, args=(ell_data, bee_data), method='TNC', bounds=bnds,  options={'maxiter': 10000,'xtol': 1e-6, 'ftol':1e-6})

    print(result)

    print(result["x"])

 

試行錯誤の末、上記に辿り着き、なんとかうまく行ったが、理解できないww

    minus_lnprob = lambda theta,*args: -lnprob(theta,*args)

の部分は

def minus_lnprob(theta, ell_data, bee_data):

    return -lnprob(theta, ell_data, bee_data)

と同値のようである。

galpy事始め

(1)自分の座標系

太陽:(xGC,yGC,zGC)=(-R0, 0, 0)

LSR: (vxGC,vyGC,vzGC)=(0, LSR, 0)

 

(2)galpyの座標系

太陽:(xGC_B,yGC_B,zGC_B)=(R0, 0, 0)

LSR: (vxGC_B,vyGC_B,vzGC_B)=(0, -LSR, 0)

 

(3)近いうちに、座標系をもう一度確認しよう

x_galpy = -xGC

vx_galpy = -vxGC

とすれば、自分の座標系と一致する。

galpyは、y=0平面で鏡像対称の世界を計算していると理解すればよい。

orbitの各時刻の値にアクセスするときにだけ注意をすればよい。

[galpyのメソッドで(ell, bee)などの計算は正しい。]

 

MCMCのPythonライブラリ

macbook air

(1)emcee
(2)emcee test
(3)nose
(4)Cython
(5)triangle_plot
(6)astropy
(7)scikit-learn
(8)astroML
(9)healpy
(10)pymc


(1)emcee install

#air の場合、 pip ではうまくいかなかった。
#mini はpipでOK

$ easy_install emcee

Searching for emcee
Reading http://pypi.python.org/simple/emcee/
Best match: emcee 2.1.0
Downloading https://pypi.python.org/packages/source/e/emcee/emcee-2.1.0.tar.gz#md5=c6b6fad05c824d40671d4a4fc58dfff7
Processing emcee-2.1.0.tar.gz
Writing /var/folders/rp/pl6_r3nd4jx77n_41w_wxv_c0000gn/T/easy_install-7Pi0Us/emcee-2.1.0/setup.cfg
Running emcee-2.1.0/setup.py -q bdist_egg --dist-dir /var/folders/rp/pl6_r3nd4jx77n_41w_wxv_c0000gn/T/easy_install-7Pi0Us/emcee-2.1.0/egg-dist-tmp-z_yyFt
zip_safe flag not set; analyzing archive contents...
Adding emcee 2.1.0 to easy-install.pth file

Installed /Users/user_name_of_this_mac/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/emcee-2.1.0-py2.7.egg
Processing dependencies for emcee
Finished processing dependencies for emcee

(2) test installation

$ python -c 'import emcee; emcee.test()'
Starting tests...
test_blobs ...
Passed.
test_ensemble ...
Passed.
test_inf_nan_params ...
Passed.
test_mh ...
Passed.
test_nan_lnprob ...
Passed.
test_parallel ...
Passed.
test_pt_sampler ...
[[ 4.28078961 9.65907666 12.04358703 2.87660849 7.82525845]
[ 3.2170057 4.24150198 5.38886129 2.57120086 3.5628032 ]
[ 3.34190318 3.93665869 0.82218183 2.12615653 2.49409284]
[ 2.96794288 4.44072437 3.32023843 1.41856222 2.0569162 ]
[ 3.61527134 5.3512537 4.55853738 2.75207078 3.02549049]
[ 3.95276797 6.1557117 4.38194265 3.01447094 3.24526784]
[ 3.96019439 6.18795309 4.57944292 3.06475761 3.37076447]
[ 4.11819964 5.7659697 4.8562809 3.0359267 3.32589204]
[ 3.85603363 5.8957338 4.66856969 2.73020252 3.26294585]
[ 3.99426772 5.59603551 4.77616469 2.71490972 3.06735538]
[ 3.84855889 5.30711848 4.39331468 2.63502553 3.03036884]
[ 3.72773645 5.31566673 4.29787118 2.68011324 3.30029418]
[ 3.70281773 5.21921852 4.31161499 2.54182746 3.18707777]
[ 3.51953548 5.44804836 4.34200003 2.43029784 3.21089521]
[ 3.52115997 5.57011287 4.22717807 2.33530092 3.01453834]
[ 3.53066543 5.59681081 4.16195481 2.32190219 2.96314379]
[ 3.61405652 5.67793786 4.54752642 2.36962106 2.96819806]
[ 3.73036245 5.69646144 4.49372029 2.44394668 2.91694628]
[ 3.51842425 5.69187972 4.84872206 2.24377814 3.20128908]
[ 3.55529756 6.06242817 4.92321959 2.36286834 3.41771155]]
Passed.
0 tests failed


(3)ついでにnose

$ easy_install nose

 

(4)Cython
$ easy_install cython

(5)triangle_plot
$ pip install triangle_plot

(6)astropy
$ pip install --no-deps astropy


(7)scikit-learn
$ pip install -U numpy scipy scikit-learn

(8)astroML
$ pip install astroML
$ pip install astroML_addons

(9)healpy
$ sudo port install py27-healpy

(10)
・まず、githubからインストールを試みる
・zip解凍して
$ cd pymc-master/
$ python setup.py config_fc --fcompiler gfortran build
$ python setup.py install

うまくいっているか調べるためにDesktopにpymc_test.pyを作り走らせる:
$ cd ../Desktop/
$ python pymc_test.txt
Running unit tests for pymc.tests
NumPy version 1.7.1
NumPy is installed in /Users/user_name_of_this_mac/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy
Python version 2.7.3 | 64-bit | (default, Aug 8 2013, 05:37:06) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
nose version 1.2.1

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

全然OKじゃない。笑

・この一連の操作をやったあとに、
$ easy_install pymc
$ python pymc_test.txt

Running unit tests for pymc.tests
NumPy version 1.7.1
NumPy is installed in /Users/user_name_of_this_mac/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy
Python version 2.7.3 | 64-bit | (default, Aug 8 2013, 05:37:06) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
nose version 1.2.1
...............S..S.............S.......................................................................................................0 x
1 (x_pow_2)
dtype: object
.....SS....................[-----------------51% ] 517 of 1000 complete in 0.5 sec
[-----------------91%-------------- ] 912 of 1000 complete in 1.0 sec
[-----------------100%-----------------] 1000 of 1000 complete in 1.1 sec
.[-----------------100%-----------------] 1000 of 1000 complete in 0.4 sec
............
----------------------------------------------------------------------
Ran 175 tests in 27.616s

OK (SKIP=5)

これでようやくうまくいった。