{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IRAF and Astropy Installation\n", "\n", "In this chapter, we will install the necessary softwares/packages that we will use throughout this course. It includes:\n", "\n", "* **Anaconda** (including most of necessary Python packages)\n", "\n", "* IRAF-included **Astroconda** (including most of astronomy-related packages)\n", "\n", "* **Astropy**\n", "\n", " * photutils\n", " * ginga\n", " \n", "* **Editor** for Python (only if you dislike Spyder; optional)\n", "\n", "* **Image Displayer**\n", "\n", " * SAO ds9\n", " * ginga\n", "\n", "The installation may take some time. If you have nothing to do, read the next section during the installation.\n", "\n", "-----\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Anaconda\n", "\n", "All the IRAF/Astropy packages will be downloaded via a platform called **Anaconda**. So let's download [Anaconda](https://www.continuum.io/downloads). If you are running out of space and really want very small package, try **miniconda**.\n", "\n", "It doesn't matter which one you choose (Python 2 or 3). I recommend to use Anaconda3 and use Python 3, since it is the *future* of Python. \n", "\n", "When the download is done, turn the terminal on and type as the website says.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. IRAF\n", "\n", "There have been a lot of different ways to install IRAF: First people had to download with a lot of commands including \"`cd ..`\", \"`wget blahblah`\", etc. Then STScI developed a huge pack of all necessary softwares, named **Ureka**. But using Ureka is deprecated since April 2016. Now we use **AstroConda**. There are reasons for these transformations, and you may be able to find the reasons as time goes, if you are interested.\n", "\n", "Anyway, let's do the IRAF installation via Anaconda! The following is identical to the official website of [AstroConda](http://astroconda.readthedocs.io/en/latest/installation.html).\n", "\n", "In terminal, type the followings (This may take **tens of minutes** depending on the internet connections!)\n", "\n", " conda update --all\n", " conda config --add channels http://ssb.stsci.edu/astroconda\n", " conda create -n iraf python=2.7 iraf-all pyraf-all stsci\n", "\n", "The name of the environment, `iraf`, is `iraf27` in the original official website, but I just prefer `iraf` for it's shorter. You can set it as any name you like.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Astropy and Photutils\n", "\n", "Astropy is the name of a project which devotes its human power in developing a *single* package containing tools useful for astronomers in Python language([GitHub](https://github.com/astropy/astropy/wiki), [Official website](http://www.astropy.org/), [The most recent stable distribution documentation](http://docs.astropy.org/en/stable/)). \n", "\n", "You should have Astropy by default if you used Anaconda.\n", "\n", "\n", "### Affiliated: photutils\n", "You may have found the so-called \"affiliated\" packages listed [here](http://www.astropy.org/affiliated/). Astropy is installed by Anaconda, but not these affiliated packages. Among these, you SHOULD download [photutils](http://photutils.readthedocs.io/en/stable/). To download, type\n", "\n", " conda install -c astropy photutils\n", "\n", "on the terminal. \n", "\n", "\n", "### Affiliated: Ginga (optional)\n", "Please see the \"image displayer\" section.\n", "\n", "\n", "### Testing Packages\n", "\n", "You can simply test the installation by tests. Run ipython from terminal:\n", " \n", " ipython\n", " \n", "Then you are now in the ipython console, and type\n", "\n", "``` python\n", "import astropy, photutils\n", "photutils.test()\n", "astropy.test()\n", "```\n", "\n", "These will take quite long time, especially astropy takes very long time. (So I didn't show you the full result)\n", "\n", "You need to do it only once when you first installed these packages. If you want to test only some part of the whole package, you can specify the module, e.g., you can test `astropy.io.fits` by:\n", "\n", "```python\n", "astropy.test(package='io.fits')\n", "```\n", "\n", "While the test is going on, look at the names of the directories, like `astropy/table`, `astropy/units`, etc. These are the names we will encounter very frequently, so this test is not only to **test**, but also to get accustomed to the astropy and python language.\n", "\n", "Each dot(`.`) means `test passed` and `x` means `test failed`. But some of the failures are just OK. `s` means it is skipped for some reason. \n", "\n", "I did tests for **Astropy 1.3.1 and Photutils 0.3.1** (took ~ 10 mins) and got the following messages:\n", "\n", "```bash\n", "(long long test explanations....)\n", "======================== 1056 passed, 2 skipped, 2 xfailed in 82.18 seconds ========================\n", "(long long test explanations....)\n", "Some tests are known to fail when run from the IPython prompt; especially, but not limited to tests involving logging and warning handling. Unless you are certain as to the cause of the failure, please check that the failure occurs outside IPython as well. See http://docs.astropy.org/en/stable/known_issues.html#failing-logging-tests-when-running-the-tests-in-ipython for more information.\n", "== 24 failed, 8717 passed, 75 skipped, 42 xfailed, 1 xpassed, 2 pytest-warnings in 573.02 seconds ==\n", "```\n", "\n", "The astropy will do the tests automatically (takes ~ 10 minutes). There might be some errors, but usually they are not important, so you can ignore them. If \"`astropy.test()`\" itself does not work, please check whether the installation of Anaconda had been done correctly.\n", "\n", "-----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Editors\n", "\n", "There are bunch of different editors (including IDEs = Integrated Development Environment) to edit the codes. I personally use spyder (it is installed from Anaconda by default, and you can use it by double-click the spyder app icon or type `spyder &` on the terminal). \n", "\n", "Some may prefer **Wing** IDE, which is widely being used in educational institutions, or **PyDev**, **PyCharm**, and even **VI** or **Emacs**. VI is quite powerful since it is accessible for virtually all of the computers around the world by default, and the debugger, gdb, is also accessible on terminal. If you have an IDE, it most likely contain its own fancy debugger, too. For Windows computers, **Visual Studio** is also a good choice. For Ubuntu, **gedit** or **geany** are also attractable choices. **Atom** is also a fancy editor. I use geany for miscellaneous and short works because it is extremely light, and Atom for coding C language-based programs. \n", "\n", "I have tried all the aforementioned editors, and settled down to the lightest, fastest, most intuitive/interactive, and yet functional editors after ~ 1 year of trial and error. BUT this is just my personal opinion, and you may find very different solution. I have many friends who use VI only for all the coding works. If you can, I recommend to use VI as your main editor, and at least learn how to use it. I don't use VI just because for me it is too difficult to use it.\n", "\n", "-----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. Image Displayer\n", "In astronomical image reduction process, you need some tools to display images on computer screen to interactively investigate the images. There is a *historical standard*, which is kind of an *affiliated package of IRAF*, [SAO ds9](http://ds9.si.edu/site/Download.html). The most recent version as of Feb 2017 is ver 7.5. Some people use [Maxim DL](http://diffractionlimited.com/product/maxim-dl/), but it's commercial and used mostly by amateur astronomers. In the future, as Python gets more and more intention, Ginga will be another powerful option. We are not sure when Ginga will become quite *perfect*, but until then, I recommend you to use both of them. Their pros and cons will be explained from now.\n", "\n", "### SAO ds9\n", "\n", "SAO ds9 was made for Chandra X-ray observation, but became so powerful that it has been used for decades by virtually all astronomers. It has many powerful features, which mostly are not yet fully implemented to Ginga. By the system default, you will use ds9 to open any FITS image.\n", "\n", "If you want to run ds9, you can do `ds9 &` on terminal. Once you've got used to ds9, you can do a bit advanced command such as \n", "\n", " ds9 -zscale image01.fits image02.fits image03.fits -single &\n", "\n", "or \n", "\n", " ds9 -zscale image*.fits -single &. \n", " \n", "For more command line options, see [this link](http://ds9.si.edu/doc/ref/command.html).\n", "\n", "If you want to turn ds9 on IRAF console, put exclamation mark (!):\n", "\n", " ecl> !ds9 &\n", " \n", "and `!ds9 image*.fits -single &`, etc, will work identically. There is another task called DISPLAY in IRAF. Type `epar display` to see the parameters. Some frequently used commands are the zscale command, e.g., `displ image*.fits z1=100 z2=3000`.\n", "\n", "\n", "### Ginga: Astropy Affiliated\n", "[Ginga](https://ginga.readthedocs.io/en/latest/) (pronounced *ging-ga*, which means galaxy in Japanese; the reason for the name is explained in the link) is an affiliated package of astropy, and is used for FITS image viewer. If you do not want ginga, please refer to SAO ds9 in later section.\n", "\n", "If you want to download it, type\n", "\n", " conda install -c astropy ginga\n", "\n", "It is made to serve the role as SAO ds9, but to perform some useful calculations that ds9 cannot do by default. ds9 has tremendous power when it is used *with* IRAF, but that is not a favorable solution for Python users. So Ginga is made to fully funtional with Python only, as well as to be able to interact with IRAF as ds9 does.\n", "\n", "You can use `ginga &` on terminal or `ecl> !ginga &` on IRAF console. Although you can do `ginga image.fits &` as you did for ds9, it is usually better to use interactive drag-and-drop way to open image than command line. In Ginga, you can also use `tools -> FBrowser`.\n", "\n", "\n", "I couldn't find how to use Ginga with IRAF yet.... Though [this official site](http://ginga.readthedocs.io/en/latest/manual/plugins_global/iraf.html) says you can. I think this is a [known bug](https://trello.com/c/6mt7oBXZ/44-iraf-plugin-implemented) that you actually cannot.\n", "\n", "\n", "### Displayers from Python\n", "Although it is not recommended, you may want to open ds9 or ginga from Python (e.g., iPython or Spyder), than terminal or Windows command prompt. In such case, you can `import` a module called `subprocess`. Using `subprocess`, you can run the command from Python as if you are typing it on terminal:\n", "\n", "``` python\n", "import subprocess as sp\n", "\n", "# Open SAO ds9:\n", "sp.call(\"ds9\")\n", "# Open ginga:\n", "sp.call(\"ginga\")\n", "```\n", "\n", "You can use various different ways, such as module `os`, or `check_call`, `Popen`, etc. But it is not recommended to open `ginga` or `ds9` from python in most instances, as far as I know.\n", "\n", "-----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. The Zen of Python\n", "\n", "Python is a programming langauge. Most importantly, it is __object oriented__ and __interpreted__, __high-level language__. In short, it means **\"Python is quite powerful, modern, intuitive, flexible, and easy to use.\"**\n", "\n", "\n", "The following is so-called __The Zen of Python__. As the name says, it consist of some *morals* that python keeps in mind. These are not only for the python developers, but also for any python users to code in __pythonic__ way.\n", "\n", "\n", "* Beautiful is better than ugly. \n", "* Explicit is better than implicit. \n", "* Simple is better than complex. \n", "* Complex is better than complicated. \n", "* Flat is better than nested. \n", "* Sparse is better than dense. \n", "* Readability counts. \n", "* Special cases aren't special enough to break the rules. \n", "* Although practicality beats purity. \n", "* Errors should never pass silently. \n", "* Unless explicitly silenced. \n", "* In the face of ambiguity, refuse the temptation to guess. \n", "* There should be one-- and preferably only one --obvious way to do it. \n", "* Although that way may not be obvious at first unless you're Dutch.\n", "\n", " * *Unless you're Dutch*: See [Stack Exchange](http://ell.stackexchange.com/questions/85517/zen-of-python-meaning-of-unless-youre-dutch).\n", " * *\"The inventor of Python is a Dutch programmer named Guido van Rossum. It is probably a reference to the inventor of Perl, Larry Wall who is not Dutch and invented a language where there a at least 50 ways to do any one thing. – ColleenV♦ Mar 24 '16 at 22:29\"*\n", "\n", "* Now is better than never.\n", "* Although never is often better than *right* now.\n", "* If the implementation is hard to explain, it's a bad idea.\n", "* If the implementation is easy to explain, it may be a good idea.\n", "* Namespaces are one honking great idea -- let's do more of those!\n", "\n", "In Korean,\n", "\n", "* (아름다운 것이 못생긴(추한) 것 보다 낫다)\n", "* (명시하는 것이 암시하는 것 보다 낫다)\n", "* (간결한 것이 복잡한 것 보다 낫다)\n", "* (복잡한 것이 난잡한 것 보다 낫다)\n", "* (수평적인 것이 계층화된 것 보다 낫다)\n", "* (성긴(듬성듬성한) 것이 밀집된 것 보다 낫다)\n", "* (가독성은 중요하다)\n", "* (특별한 경우(예외)들은 기존 규칙을 깰 만큼 특별한 게 아니다)\n", "* (비록 실용성은 (규칙의) 순수성을 깰 정도로 중요하지만.)\n", "* (오류는 절대 조용히 넘어가서는 안 된다)\n", "* (명시적으로 그러라고 하기 전에는.)\n", "* (모호함 앞에서, 추측하려는 유혹을 거절하라.)\n", "* (무언가를 할 때 하나의 자명한 방식이 존재한다 -- 가장 좋은 것은 오직 하나 뿐일 것이다)\n", "* (비록 그 방식이 단번에 떠오르지 않을지라도 말이다.)\n", "* (지금이라도 하는 게 아예 안 하는 것 보다 낫다) \n", "* (비록 종종 아예 안 하는 게 *지금 당장* 하는 것 보다 나을지라도)\n", "* (만약 구현 결과가 설명하기 어렵다면, 그것은 안 좋은 것이다.)\n", "* (만약 구현 결과가 설명하기 쉽다면, 그것은 좋은 것일지도 모른다.)\n", "* (네임스페이스는 엄청 좋은 것이다: 더 많이 쓰자!)\n", "\n", " \n", "If you want to see this __The Zen of Python__, you can type `import this`:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The Zen of Python, by Tim Peters\n", "\n", "Beautiful is better than ugly.\n", "Explicit is better than implicit.\n", "Simple is better than complex.\n", "Complex is better than complicated.\n", "Flat is better than nested.\n", "Sparse is better than dense.\n", "Readability counts.\n", "Special cases aren't special enough to break the rules.\n", "Although practicality beats purity.\n", "Errors should never pass silently.\n", "Unless explicitly silenced.\n", "In the face of ambiguity, refuse the temptation to guess.\n", "There should be one-- and preferably only one --obvious way to do it.\n", "Although that way may not be obvious at first unless you're Dutch.\n", "Now is better than never.\n", "Although never is often better than *right* now.\n", "If the implementation is hard to explain, it's a bad idea.\n", "If the implementation is easy to explain, it may be a good idea.\n", "Namespaces are one honking great idea -- let's do more of those!\n" ] } ], "source": [ "import this" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }