2012/05/06

多段sshを介したMacの画面共有

gateway-Aの下にあるlocal-Aの画面を、gateway-Bの下にあるlocal-B (=目の前の端末)で画面共有したいとき。多段sshをつかいましょう。

参考: SSH多段トンネリング接続でMacを画面共有する

gateway-Bへのsshを介す必要がなければ、上記の参考ページの方法そのままでいけます。 僕の環境では目の前の端末から外に直接出られないので、もう1段sshが必要ですが、基本的にはおなじ方法で大丈夫です。

具体的には以下のようになります。
ssh -t -L 10000:127.0.0.1:5900 \
username@gateway-B "ssh -t -L 5900:127.0.0.1:5900 \
username@gateway-A "ssh  -L 5900:127.0.0.1:5900 username@local-A""
あとは画面共有.appを起動してlocalhost:10000を叩けばokです。 もちろんserver (local-A)での画面共有の許可、sshごとのpassword/passphraseの入力が必要ですのでお気をつけを。

2012/01/02

D論お役立ち?スクリプト

○Labelのチェックをおこなう

Thesis全体で使用されている\labelコマンドを列挙し、chapter間の重複をしらべる。
\label{labtype:labname}という形式を仮定。labels.txtにchapter, labtype, labname, 重複の有無を列記。重複がなければ最後のcolumnは'ok'、あれば該当するchapter名がcsvで書かれる。重複がある場合も、初出時は'ok'になる仕様。

#!/usr/bin/env python

skipnames = [] #List tex filenames which should be excluded label search.
outfile = 'labels.txt'
maintex = 'ms.tex' #The main tex filename in which your articles are included.

def add_elem(elem,key,dic):

    if dic.has_key(key):

        dic[key].append(elem)

    else:
        
        dic[key] = [elem]

    return(0)

texnames = []
labels = {}

for line in open(maintex,'r'):

    if line.startswith('\include{') or line.startswith('%\include{'):
        texname = line.replace('\include{','').replace('}\n','').replace('%','')
        if not texname in skipnames:
            texnames.append(texname)

f = open(outfile,'w')

for texname in texnames:

    texfile = texname+'.tex'

    for line in open(texfile,'r'):

        if line.find('\label{') != -1:

            templine = line[line.find('\label{')+len('\label{'):]
            label = templine[:templine.find('}')]
            labtype, labname = label.split(':')
            add_elem(label,texname,labels)
            dupflag = 'ok'
            for texkey in labels.keys():
                if texkey == texname:
                    continue
                lablist = labels[texkey]
                if label in lablist:
                    if dupflag == 'ok':
                        dupflag = texkey
                    else:
                        dupflag += ','+texkey
                else:
                    pass
            f.write('%10s %10s %15s %20s\n' % (texname, labtype, labname, dupflag))
f.close()

○Referenceをsortする

reference.texに記述したreference listをアルファベット順にsortする。
コメントアウトしたものは消されます。Archiveは残すので間違えて消したりしても安心のはず。

#!/usr/bin/env python

import os,datetime

archive = 'ref_archives'
if not os.path.exists(archive):
    os.mkdir(archive)
else:
    pass

reffile = 'reference.tex'
date  = datetime.date.today().isoformat().replace('-','')
biblist = []

i = 0
row = 0
for line in open(reffile,'r'):

    if line.startswith('%') or line.startswith('\\begin') or line.startswith('\\end') or line == '\n':
        pass
    elif line.startswith('\\bibitem'):
        try:
            biblist.append(line.replace('\n',''))
        except:
            print(line)
            exit()
        i += 1
    else:
        try:
            biblist[i-1] = biblist[i-1]+line.replace('\n','')
        except:
            print(line)
            exit()
        pass
    row += 1

os.system('mv '+reffile+' '+archive+'/'+reffile.replace('.tex','_'+date+'.tex'))

f = open(reffile,'w')

bibdoc = {}

for bib in biblist:

    title = bib.replace(']','[').split('[')[1]
    citekey = bib.replace(']','[').split('[')[-1].replace('}','{').split('{')[1]
    content = bib.replace('\\bibitem[','').replace(title,'').replace(']{','').replace(citekey+'} ','')
    author = title.split('(')[0]
    year = title.replace(')','(').split('(')[1]

    bibdoc[title] = bib

keys = bibdoc.keys()

keys.sort()

f.write('\\begin{thebibliography}{}\n')
for key in keys:
    f.write(bibdoc[key]+'\n')
f.write('\end{thebibliography}\n')
f.close()

print('Done.')

○Abbreviationの各章での引用回数をcheckする

description環境で書かれたabbreviation listに各章での略語および元の用語の引用回数をコメントで追記します。
元の用語に関しては複数行にまたがるものは数え落とします。先頭の語のcapitalizeの有無はどっちでも拾います。

#!/usr/bin/env python

import os,datetime

skipnames = [
    'abbreviations',
    'reference',
    'acknowledgement',
    ] #List tex filenames which should be excluded label search.

maintex = 'ms.tex' #The main tex filename in which your articles are included.

texnames = []

for line in open(maintex,'r'):

    if line.startswith('\include{') or line.startswith('%\include{'):
        texname = line.replace('\include{','').replace('}\n','').replace('%','')
        if not texname in skipnames:
            texnames.append(texname)

archive = 'abb_archives'
if not os.path.exists(archive):
    os.mkdir(archive)
else:
    pass

def find_keyinchaps(key):

    chaplab = ''
    ch = 1
    for texname in texnames:
        if texname in skipnames:
            continue
        count = 0
        texfile = texname+'.tex'
        for line in open(texfile,'r'):
            if line.find(key+' ') != -1 or line.find(key+'s ') != -1 or line.find(key+')') != -1:
                count += 1
        if count != 0:
            chaplab += str(ch)+' x'+str(count)+', '
        ch += 1
    return(chaplab[:-2])

def find_continchaps(content):

    content = content.replace('-',' ').lower()

    chaplab = ''
    ch = 1
    for texname in texnames:
        if texname in skipnames:
            continue
        count = 0
        texfile = texname+'.tex'
        for line in open(texfile,'r'):
            line = line.replace('-',' ').lower()
            if line.find(content) != -1:
                count += 1
        if count != 0:
            chaplab += str(ch)+' x'+str(count)+', '
        ch += 1
    return(chaplab[:-2])

abbfile = 'abbreviations.tex'
date  = datetime.date.today().isoformat().replace('-','')
abblist = []

i = 0
row = 0
for line in open(abbfile,'r'):

    if line.startswith('\\chapter') or line.startswith('\\begin') or line.startswith('\\end') or line == '\n':
        pass
    elif line.startswith('\\item'):
        try:
            abblist.append(line.replace('\n',''))
        except:
            print(line)
            exit()
        i += 1
    else:
        try:
            abblist[i-1] = abblist[i-1]+line.replace('\n','')
        except:
            print(line)
            exit()
        pass
    row += 1

os.system('mv '+abbfile+' '+archive+'/'+abbfile.replace('.tex','_'+date+'.tex'))

f = open(abbfile,'w')

abbdoc = {}

for abb in abblist:

    abbkey = abb[abb.find('[')+1:abb.find(']')]
    maxnum = abb.find('%')
    if maxnum == -1:
        maxnum = len(abb)
    content = abb[abb.find('$\\ldots$')+len('$\\ldots$'):maxnum].strip(' ')

    abbdoc[abbkey] = content

keys = abbdoc.keys()

keys.sort()

f.write('\\chapter{Abbreviation}\n')
f.write('\\begin{description}\n')
for key in keys:
    usedchaps = find_keyinchaps(key)
    usedchaps2 = find_continchaps(abbdoc[key])

    f.write('\\item [%s] $\\ldots$ %s %s\n' % (key, abbdoc[key], '% '+usedchaps+' ; '+usedchaps2))

f.write('\\end{description}\n')
f.close()

print('Done.')

2011/12/05

Surface brightness of the Galactic diffuse X-ray emission

系内、特に銀河面付近のソースを扱うX線屋さんが避けて通れない背景拡散放射 (GDXE)。
その輝度の見積もりがむずかしくbackground estimationで苦労することもしばしば。

すざくの良質なスペクトルを元にH. Uchiyamaさんがその表面輝度をモデル化しています。
H. Uchiyama PhD (2010) PDFはこちら

Sgr A*を中心とする2つの2-D exponentialの和を用いたモデル (eq.4.2) は特に便利なので、
銀河座標を放り込むと表面輝度を表示するかんたんなスクリプトを書きました。
座標を2セットいれると2領域間での輝度の比を表示します。
無駄にnumpyつかってるのはご愛嬌。。

※初期版にひどいバグ:
l0, b0で絶対値とるの忘れてました!
12/5に参照した方は修正した下記をご覧下さい。

#!/usr/bin/env python

'''
The model expression and the parameters are respectively 
taken from eq.4.2 and table 4.11 of H. Uchiyama 2010, PhD Thesis
http://repository.tksc.jaxa.jp/pl/dr/IS8000028000/en
The parameters were measured with the K-alpha lines from FeXXV 
and FeXXVI and the 5-10 keV continuum bands.
The unit of surface brightness is 1e-7 ph/s/cm2/am2 for 
Fe Ka lines and 1e-13 erg/s/cm2/am2 for 5-10keV continuum.
'''

import numpy as np

gpos_SgrAs = np.array([-0.056, -0.046])

a1 = (26.3, 10.0, 3.4)
a2 = (1.6, 0.25, 0.20)

hl1 = (0.47, 0.51, 0.48)
hb1 = (0.22, 0.22, 0.19)

hl2 = (30, 47, 55)
hb2 = (1.7, 17, 2.5)

band2colnum = {
    'FeXXV':0,
    'FeXXVI':1,
    'hard':2
    }

def calc_sb(l, b, band):

    i = band2colnum[band]

    l0, b0 = np.abs(np.array([l, b]) - gpos_SgrAs)
    sb1 = a1[i] * np.exp(-l0/hl1[i]) * np.exp(-b0/hb1[i])
    sb2 = a2[i] * np.exp(-l0/hl2[i]) * np.exp(-b0/hb2[i])
    sb = sb1 + sb2

    return(sb)

def calc_ratio(l1,b1, l2,b2, band):

    sb1 = calc_sb(l1, b1, band)
    sb2 = calc_sb(l2, b2, band)
    ratio = sb1 / sb2

    return(ratio)

if __name__ == '__main__':

    import sys

    argvs = sys.argv

    try:
        l, b, band = argvs[1:4]
        cnum = band2colnum[band]
        sb = calc_sb(float(l), float(b), band)
        print(sb)
    except:
        try:
            l1, b1, l2, b2, band = argvs[1:6]
            cnum = band2colnum[band]
            rt = calc_ratio(float(l1), float(b1), float(l2), float(b2), band)
            print(rt)
        except:
            print('Usage1 calc sb : calcgdxe.py l b band')
            print('Usage2 calc sb ratio : calcgdxe.py l1 b1 l2 b2 band')
            print('band should be selected from FeXXV, FeXXVI, or hard')
            exit()


追記。

標準で入ってないないnumpyというライブラリを使っているので、
import numpyでこける場合は以下の3点を修正すれば動くと思います。
めんどくさいので動作みかくにん。

1)
import numpy as np
gpos_SgrAs = np.array([-0.056, -0.046])
↓
import math
l_SgrAs = -0.056
b_SgrAs = -0.046

2)
l0, b0 = np.abs(np.array([l, b]) - gpos_SgrAs)
↓
l0 = abs(l - l_SgrAs)
b0 = abs(b - b_SgrAs)

3)
np.exp()
↓
math.exp()

2011/11/17

All sky map in various wavelengths

  • Longer wavelengths: LAMBDA Foreground
    • FITS images http://lambda.gsfc.nasa.gov/product/foreground/f_products.cfm
    • PNG images http://lambda.gsfc.nasa.gov/product/foreground/f_images.cfm
    • Contents: 
      • Composite H-alpha 
      • Haslam 408MHz
      • N(HI) 
      • LAB HI survey
      • Predicted dust emission at 94GHz
      • Derived E(B-V)
      • W(CO) at 115GHz
      • IRAS/ISSA at 12, 25, 60, and 100um
  • X-rays
    • ROSAT All Sky Survey 
      • Ref: http://iopscience.iop.org/0004-637X/485/1/125/35274.text.html
    • MAXI
  • Fermi LAT map http://astrometry.fas.harvard.edu/skymaps/fermi/


Plotting All-Sky Map with matplotlib+pywcsgrid2
http://leejjoon.github.com/matplotlib_astronomy_gallery/allsky/allsky.html

2011/09/09

理研 基礎科学特別研究員 選考結果

採用内定いただきました。正直、非常に精神的に楽になりました。
書類や面接の指導をしてくださった方々(面接練習には実に3回も
つきあって頂きました。。)、twitterなどで応援の言葉をかけて
くださった方々に、深くお礼申し上げます。

結果として内定をいただきましたが、反省点は山のようにあります。
ところで学振とちがって、評点などは教えてもらえないみたい??
参考にしたかったのだけれど。

いずれにしても、、

つぎはD論!

さわだ

Troubleshooting the installation of AtomDB in the HEASoft 6.11 source-code package [updated]

※revised on 2011/09/09 10:00 pm (JST)
※日本語版が下にあります。

I met a trouble on the installation of HEASoft-6.11. The trouble is related to apec/AtomDB data loaded in Xspec and divided into two different factors:
  • AtomDB v.2.0.0 has a serious bug. (http://www.atomdb.org/bug_201.php)
  • The corrected version of AtomDB (v.2.0.1) is not included in the source-code package of HEASoft until yesterday (2011/09/08 JST).

I've discussed with Bryan K. Irby, the HEASoft developer.
The problem and solution seem to be different depending on the download date of the package.

  • 2011/06/29 -- 2011/09/08 (yesterday)
    • The package does not include the corrected version of AtomDB (2.0.1) thus you will see an error message when you load apec in Xspec. 
    • Download a patch file and install it from http://heasarc.nasa.gov/docs/software/lheasoft/bugs.html . 
    • Never use the older AtomDB v.2.0.0 files included in the package (at ${HEADAS}/Xspec/src/spectral/modelData ) because it has a serious bug. See http://www.atomdb.org/bug_201.phpfor for detail.
      • NOTE: Until now (2011/09/09 JST), the HEASoft bug list page does not have any information of the lacking AtomDB v.2.0.1 in the source-code package downloaded during 2011/06/29--2011/09/08. 
      • Thanks to Bryan's quick response, we are now able to get sufficient information to deal with the problem on this version of the HEASoft source-code distribution. 
      • The updated information is available at http://heasarc.nasa.gov/docs/software/lheasoft/bugs.html .
  • 2011/09/09 (today) --
    • Bryan has revised the source-code package.
    • The package correctly includes the latest AtomDB (v.2.0.1) and users can load it in Xspec without installing any patch. (I confirmed this by downloading/installing the source-code package for the MacOSX 10.6.)
---

HEASoft-6.11に入っているAtomDB v.2とそのインストールが少し面倒なことになっているのでまとめます。

問題は以下の2点。

  • v.2.0.0にバグがある
  • v.2.0.1が最近まで出回ってたsource-code packageに含まれてない

Bryan K. Irbyとやりとりをした結果、状況が整理できました。
Packageをdownloadした時期によって問題と取るべき対応が異なります。

  • -- 2011/06/28
    • バグがある2.0.0が入ってた。パッチをあてましょう。
  • 2011/06/29 -- 2011/09/08 (昨日)
    • バグがある2.0.0はのぞいた。でも、修正版2.0.1を入れるの忘れた。
    • よって、やっぱりパッチをあてましょう (上のリンク参照) 。
      • ** これに関する情報がいま現在もHeasoftの頁に無いせいでだいぶ混乱。
      • ** 実際京都だけじゃなくて多くの人が状況を理解できなくて
      • ** わざわざv.2.0.0をひっぱってきて使ってた模様。
      • ** Bryanにwebpageの修正を要求中。
      • その後Bryanがそっこーでwebpageを修正してくれました。
      • http://heasarc.nasa.gov/docs/software/lheasoft/bugs.html を参照ください。
  • 2011/09/09 (今日) --
    • Bryanが直してくれました。
    • ちゃんと2.0.1が入ってます。ふつうにインストールすれば
    • そのままつかえます。(さわだcheck済み)
--- 

さわだ%言ってみるもんだ



2011/08/28

海外学振結果

不採用Aでした。

項目別評価は、
①研究業績 3.67
②研究計画 3.50
③外国の機関で研究することの意義 3.67
④総合評価 3.34
総合評価のTスコアは3.156。

特別な弱点も長所もなく、全体的に点が足りないということですね。
個人的には、乏しい研究業績(*)よりも研究計画の評価が低かったのは意外だったので、見直して今後に活かさなければなりません。といっても今年度の主だった書類はすでに申請ずみなのですが。

(*)=主著3報(PASJ×2, NIM A×1)+共著2報(ApJ 2nd×1, PASJ 3rd×1)+国際会議口頭×1+その他