Notes on installation of TiRiFiC on MacOS

Here is a small note on installing the package TiRiFiC on MacOS 10.12.6. 

Here is a short introduction from its official webpage:

Tilted Ring Fitting Code (TiRiFiC) is a computer program to construct simulated (high-resolution) astronomical spectroscopic 3d-observations (data cubes) of simple kinematical- and morphological models of rotating (galactic) disks. It is possible to automatically optimise the parametrisations of constructed model disks to fit spectroscopic (3d-) observations via a χ2 minimisation. TiRiFiC depends on several free non-standard libraries, but is a standalone routine (after compilation). In former development stages, TiRiFiC has been implemented as a task in the Groningen Image Processing System (GIPSY) software package. From version 2.2.0 on, the GIPSY implementation is not longer supported and will not be installed. The source code of TiRiFiC can be downloaded from this web page.

The original installation guide can be found here: Installation_Guide. However, I notice that this guide was written for Linux specifically. On Ubuntu, things are quite easy. But under MacOS/MacOSX, the situation can be a bit different. Because the official website does not provide a detailed guide for Mac users. I put a small note here for general (to be honest, mostly my personal note) interests.

As said on their installation guide page, some dependencies are needed before installation: fftw-3, wcs, gsl, gcc, libreadline, pgplot, openmp, doxygen. For Mac users, the aforementioned packages can be easily installed using MacPorts. Since I am using MacPorts, I will just show the cases for that below. Taking fftw-3 for example, what you need to do is just to use 

sudo port search fftw-3

And the results will pop-up, just copy the names of the packages, and then use

sudo port install fftw-3

to install the package. It’s the same for all the rest packages.

After installation of all the dependencies, one will need to download the latest version of the package TiRiFiC from the GitHub page Then unzip the file if you downloaded the zip from GitHub. On the official installation guide page of TiRiFiC, it’s said you need to compile qfits first, but that seems only valid for older versions. So the proper step now is to edit the settings file. This file is the core for a successful compilation of the entire package.
Unfortunately, the template is not MacOS/MacOSX friendly. After several times experiment, I found the right way of editing it. If you are using Macports, the file should be like this:

# This part has to be edited by the user. tirific depends on the
# existence of several external libraries, which have to be provided
# by the user. Those libraries are non-standard, but quite common,
# such that you can easily install them. We leave it to you to install
# the libraries in a convenient form.
# Default number of disks, can be changed at runtime by the user
# Compile with possibility to do a primary beam correction (YES/NO)
# CC is the compiler to use
CC = gcc
# CFLAGS is the flags to use the compiler with
CFLAGS = -Wall -pedantic -O4 -I/opt/local/include/malloc
# The operating system (At the moment chose between MAC_OS_X and LINUX
# Compile with open mp (YES/NO)? Note that this means that fftw is optimally compiled with the --enable-openmp option (personally I used the Ubuntu synaptic version, which seems to work)
# Opem MP compiler options
OPENMPCOMP = -fopenmp
# Open MP linker options
OPENMPLIB = -fopenmp
# external directories containing include files
# This is the standard include 
STDDIR = /opt/local/include/
# This is the math library include file and most probably at this location
MATHDIR = /usr/include/
# This is the fftw include directory. It should contain the file fftw3.h
FFTWDIR = /opt/local/include/
# This is the position of the parent directory of the gsl directory
GSLDIR = /opt/local/include/gsl/
# This is the directory in which the wcs include files reside
WCSDIR = /opt/local/include/wcslib
# Pgplot directory
PGPDIR = /opt/local/include/
# X11 Lib
X11LIB = /opt/local/lib/
# external libraries
# The math library
# The fftw3f library, alternatively
# -Ldirectory_in_which_the_file_libfftw3f.a_is -lfftw3f
FFTWLIB = -L/opt/local/lib/ -lfftw3f -lfftw3
# laquaterm
AQUATERMLIB = -L/opt/local/lib/ -lfftw3f -lfftw3
# The gsl library linker flags-, alternatively
GSLLIB = -L$(GSLDIR) -lgsl -lgslcblas
# The wcs library
WCSLIB = -L$(WCSDIR) -lwcs
# Pgplot linker flags, for Mac OS, maybe -L$(PGPDIR) -lcpgplot -lpgplot $(X11LIB) -lpng -laquaterm -Wl,-framework -Wl,Foundation  -W1,-AppKit 
PGPLIB = -L$(PGPDIR) -lcpgplot -lpgplot -L$(X11LIB) -lpng -Wl,-framework -Wl,Foundation  
# Readline library
READLINELIB= -lreadline

After editing this file, you can now type “make” to compile the packages. It will first compile qfits and then the tirific packages. In the end, you will see a binary file named “tirific” under the bin directory. Now you can use this binary to run the modelling. See an example here:

Now you would like to make your binary executable everywhere. This can be done simply by putting the binary path in your ~/.profile file, namely adding

export PATH=$PATH:/Users/your_path_of_the_binray/tirific-master/bin

That’s it.


Start to learn Julia

With the speed comparable to C/FORTRAN and the learning curve as Python, I think Julia may have a very bright future. Currently, the visualisation packages are not so rich but on can always try matplotlib since using python in Julia is not hard.

A bit part of the AstroLib is still under progress in Julia. I am surprised that there are only three main contributors that are translating IDL/Python packages to Julia. I would like to also contribute a little once I have learned more about this language.


Astronomy Feeling



    昨夜看了一部关于Aaron Swartz的纪录片,心理乱糟糟的。脑子里不停地浮现Mark说的“connect the world”,以及Aaron说的“public domain”。有时候,我们随心所欲的使用着互联网,理所应当的认为它应该是怎样的体现着自由和共享,然而我们并未意识到,这种自由实际上也是由一些人付出了生命的代价捍卫而来的。仔细想想,科学家的论文被出版者拿来当商品买卖这一点本来就很令人惊讶。科学家的经费出自政府/个人机构的基金资助,而政府的钱又来源于税收,那么最终(受资助的)科学家研究的成果都是要让每个民众同等的享受到的(理想的情况下)。然而,在科学家往期刊投稿需要交版面费的前提下,这些期刊仍旧向读者收取高额的阅读费用,这无疑是在阻碍科学更广泛的传播。知识的权利似乎被集权在少数的几个大的出版机构手里,他们凭借着对阻断知识的自由传播而赚取利润。








    宇宙中最剧烈的“爆炸”当属伽玛暴(Gamma-Ray Burst,天文学中常将其简称为GRB)。我们知道光本质上就是电磁波,而实际上它具有一个很宽的波长范围,不同的波长对应不同类型的辐射。不同类型的辐射对应的能量也大不相同(如图1)。波长越短的电磁波携带的能量越多。在实际的研究当中,天文学家也主要依靠天体在各种波段发出的电磁波来研究这些遥远且触不可及的天体。图1中最右端,波长最短的电磁波即为伽玛射线,它主要产生于原子核内的物理作用,即原子核衰变和核反应。不难想象,如果有氢弹(或原子弹)爆炸,那么将会有大量的伽玛射线在短时间被释放出,即伽玛射线爆发。因此伽玛射线可以用于检测地球上的核试验。这也是伽玛射线探测的早期应用之一。

Screen Shot 2014-09-05 at 14.56.02


Screen Shot 2014-09-05 at 14.56.59但因为设备的限制,美军无法确认伽玛射线来自哪个方向,因此不能排除这些伽玛光子来自于地球的可能。后来他们经过谨慎的分析,排除了伽玛射线爆发来自地球的可能性,这是人们第一次观测到来自宇宙的伽玛射线爆发(如图2)。从此以后人们开始了对伽玛暴的详细研究,同时,人们对伽玛暴的起源众说纷纭,有人认为伽玛暴来自于彗星的相互碰撞、有人说其来自银河系内的中子星,还有人认为它和河外的超新星爆发有关。所有的这一切在1997年取得了突破性的进展,人们首次在伽玛暴之后的同一位置处探测到了X射线的辐射,称之为伽玛暴X射线余辉,之后又在光学甚至是射电波段探测到了类似的余辉现象。这些余辉的能量逐级递减,总体呈现出一个对数衰减的趋势。借助这些在伽玛射线以外的波段上发射出的余辉,人们对伽玛暴的物理模型有了更加精准的物理模型限制,同时也确认了伽玛暴的银河系外星系(河外星系)的起源。

Screen Shot 2014-09-05 at 14.58.45

    此外,1991年发射的康普顿伽玛射线望远镜(Compton Gamma Ray Observatory,CGRO)上搭载了一个灵敏度非常高的仪器——BATSE(Burst and Transient Source Explorer,瞬时爆发源探测器)。科学家通过BATSE对伽玛暴来源的统计发现,伽玛暴在全天均匀分布(如图3),这个观测结果与银河系的盘状结构并不符合,这也印证了伽玛暴的银河系外起源,也与之后1997年天文学家建立的伽玛暴余辉的物理模型限制相符合。

    天文学家通过观测发现,根据爆发的持续时间,伽玛暴大致可以分为两类。如图4所示,伽玛暴的持续时间分布呈现出2个峰值。处于红线左边的一类伽玛暴的持续时间短于2秒,我们将其称为短暴;而红线右边那部分所对应的伽玛暴持续时间长于2秒,称为长暴,占所有伽玛暴总数的70%左右。不过尽管天文学家将其称之为长暴,其持续时间也不过千秒的量级,最长也长不过一个小时,相比于其他的天文现象,可以说是“瞬息万变”。通过对这两种伽玛暴的研究,天文学家发现,短暴主要发生在椭圆星系当中(我们称其所在星系为“宿主星系”),它很可能来自于中子星的相互并和或者中子星和黑洞的并和。Screen Shot 2014-09-05 at 14.59.44而长伽玛暴主要存在于恒星形成活动比较剧烈的盘状星系当中,常常伴随着大量超星新爆发的活动。天文学家们普遍认为伽玛暴是一类大质量恒星死亡时爆发产生的现象,所以长暴所处的星系应该是年轻的,正在进行着大量恒星形成活动的星系。因为恒星形成于分子云中,分子云包含了大量气体和尘埃,因此如果我们观测伽玛暴的宿主星系,应该能够看到大量的气体和尘埃。


    今年6月的《自然》(Nature)杂志上刊载了日本国立天文台的廿日出文洋(Hatsukade)研究员领导的研究小组关于伽玛暴的新发现。他们运用了目前世界上最强大的射电望远镜干涉阵列——阿塔卡玛(亚)毫米波射电望远镜干涉阵(Atacama Large Milimeter/submillimter Array,简称为ALMA)第一次观测到了长伽玛暴所在的宿主星系的尘埃和气体(因为气体和尘埃的辐射波段主要在毫米波和亚毫米波的辐射波段),而且得到了高分辨率的气体和尘埃辐射的图像。

Screen Shot 2014-09-05 at 15.00.52

    其实廿日出文洋研究员带领的研究小组从2003年开始起就一直试图探测到伽玛暴宿主星系里的气体和尘埃,但他们得到的观测结果一直不理想。因为观测设备灵敏度的限制,使他们探测伽玛暴宿主星系内气体和尘埃的愿望屡屡落空。然而,借助于处于火力尚未全开的ALMA(在ALMA射电干涉阵运行初期,望远镜阵列中的66面天线只有一部分被使用),在只有24到27面天线参与观测的情况下,他们依旧只用了不到1小时的观测时间就探测到了伽玛暴宿主星系里气体和尘埃。可以想象,当ALMA的66面天线全部运行起来时,它将是如何的强大!为了详细了解和分析长暴的性质,特别是暗长暴,也就是前面提到的,其光学波段余辉不可见的那一类长暴的性质,作者选取了两个暗伽玛长暴(GRB 020819B和GRB 051022,前两位数字02和05代表年,中间两位代表月,后两位代表日,后面的字母代表序号)的宿主星系作为观测对象,利用ALMA对这两个星系进行观测。

    图5显示了《自然》杂志刊出的论文里所发表的ALMA观测结果。这两个伽玛暴中GRB 020819B 的宿主星系引起了科学家们极大的兴趣。可以看到图中用红色十字叉丝标出的位置就是伽玛暴发生的位置,而在这个位置处,作者几乎没有看到任何的分子气体的辐射。根据左边那副蓝色的图片,气体都集中在靠近星系中心的区域,而在伽玛暴位置处是一片空白。中间那幅图显示了宿主星系中尘埃的辐射,可以清楚的看到在伽玛暴发生的区域有很强的尘埃辐射,说明那里存在着大量的尘埃。作者通过计算发现,伽玛暴所处的区域的气体和尘埃质量的比例跟星系中心的比例有着非常大的差异(10-100倍),同时也与其他普通的正在进行着恒星形成活动的星系大不一样。这说明了伽玛暴所处的环境是十分特殊的,那里蕴含着大量的尘埃,然而却包含了极少的分子气体。这样一个极端的气体尘埃质量比例是之前天文学家们从来没有想到的。这是一项令人无比惊讶的发现。


Screen Shot 2014-09-05 at 15.01.33