Biboroku

Saturday, November 14, 2009

Installing Freemind on Debian Lenny

Filed under: Debian, Lenny, Linux — nomo17k @ 21:15

Download .deb from Freemind’s sourceforge web page, e.g., freemind_0.8.1-2_all.deb. Then

# apt-get install sun-java6-jre
# apt-get install libcommons-codec-java libcommons-lang-java libjcalendar-java
# apt-get install libjgoodies-forms-java librelaxng-datatype-java
# dpkg -i freemind_0.8.1-2_all.deb

Add the following line to ~/.bashrc:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

(Without the environment variable set, I could not get freemind to run at all.) You can then launch it by typing freemind on the shell or the menu under office.

Sunday, August 2, 2009

KCorrect: kcorrect Python Port Project

Filed under: Python, Research — nomo17k @ 14:01

By Taro Sato (taro at ap.smu.ca)

NOTE: This is a page for my old side programming project, on astrophysical computing.  I just moved it here since I haven’t been tracking access and therefore I don’t know if there has been any serious interest in doing k correction on Python rather than IDL.  If anyone is seriously interested in doing k correction with Python, this whole thing can be made into an open source project for communal use (if we can obtain an approval from the original library developer).

KCorrect is an attempt to wrap some of the utilities available in kcorrect written by Michael Blanton into an easy-to-use Python package. kcorrect is a collection of C/IDL codes which implements k corrections and photometric redshifts with broad-band photometry (and much more).

Motivation

With NumPy quickly maturing into the standard platform for scientific computing with Python, there should be an increasing interest in carrying out astronomical data analysis on Python in near future. Python is a well-designed programming language offering astronomers a simple-to-use yet very powerful platform with all the advantages of a modern programming language (e.g., object orientation, exceptions, namespace) as well as the simplicity of a scripting language, not to mention it is FREE. We (actually I…as of now) hope to contribute to the increase in the usage of Python among astrophysicists.

Conditions of Use

Since KCorrect is simply a Python wrapper to kcorrect (v4_1_4), users are requested to follow the conditions of use described in kcorrect distribution website.

No extra citation is necessary on the use of the Python version.  I changed my mind because there are too many people who are not very sincere.  Please acknowledge the use of this Python version clearly, if you ever use a portion of this program in your published work

Also, please do not modify the program yourself.  If you wish to do that, please consider contributing to the project instead, rather than secretly using it to your liking and don’t even acknowledge somebody else’s effort on which you build your work.

Although we do attemp to ensure that users obtain similar results to the IDL version when desired, bugs are a fact of life; please report bugs and comments to Taro Sato (email address given above) if you suspect the problems occur with the Python version.

General Description

The general concepts of k corrections are well documented in Michael Blanton’s kcorrect distribution website; users of KCorrect are urged to learn the principles behind the software by throughly reading his documentation. There is also an article written by David Hogg which may be of interest for users of kcorrect.

The KCorrect Python port project is totally a volunteer effort by those who love to code in Python, so we have not implemented all the rich functionalities already available in the IDL version of kcorrect (it is slow going without external contributions; please let me know if you can contribute a tiny bit).

Currently Available Functionalities

  • Core implementation of k correction
  • High-level interface for some redshift surveys (so far only SDSS and DEEP)

Installing KCorrect

This version of KCorrect requires the following software to be already installed on your machine:

  • Python 2.3.5 or better (http://www.python.org/)
  • NumPy 1.0rc1 or better (http://www.scipy.org/Download/)
  • SWIG 1.3.24 or better (http://www.swig.org/)
  • kcorrect v1_4_1 (http://cosmo.nyu.edu/mb144/kcorrect/)

(I should mention these are the versions of software used to test the codes; we do not have a rigorous testing environment.)

Download the snapshot version here. README.txt included in the tarball has a detailed installation instruction. If you already have a working installation of the IDL version of kcorrect (which is a requirement), the standard python method

 $ python setup.py install

should simply work.

Usage

Here is an example IPython session:

In [1]: import KCorrect as KC

In [2]: maggie = [1., 4.78, 10.96, 14.45, 19.05]

In [3]: maggie_ivar = [1100., 28., 7.7, 4.4, 2.5]

In [4]: redshift = 0.03

In [5]: filters = KC.FilterList(['sdss_u0.par','sdss_g0.par','sdss_r0.par',
   ...:                          'sdss_i0.par','sdss_z0.par'])

In [6]: kc = KC.KCorrect()

In [7]: kc.set_data(redshift, filters, maggie, maggie_ivar)

In [8]: print kc.kcorrect(band_shift=0.1)
[[-0.38402203 -0.33727303 -0.19066639 -0.15796432 -0.13370053]]

The above example is to be compared to the one given at kcorrect distribution website. What we wanted to do with the Python version is to hide the part of implementation that users really do not want to deal with (e.g., conversions to “AB maggies,” preserving the projection table or the template spectra, etc.). A more typical usage goes like this:

In [11]: redshift = [1.029, 0.9581]

In [12]: deepmag = [[23.112, 22.363, 21.690],[24.668, 23.878, 23.248]]

In [13]: kc = KC.KCorrectDEEP(cosmo=(0.3,0.7,1.0))

In [14]: kc.set_data(redshift, deepmag)

In [15]: print kc.absmag()
[[-21.2052002  -21.69138336 -21.85865593]
 [-19.35534096 -19.64371872 -19.71680069]]

In [16]: vega2ab = KC.vega2ab(kc.filter_list)

In [17]: print kc.absmag() - vega2ab
[[-21.0925668  -21.93185531 -22.3164852 ]
 [-19.24270756 -19.88419066 -20.17462996]]

In [18]: bessell = KC.FilterList(['bessell_V.par','bessell_R.par'])

In [19]: print kc.appmag(filter_list=bessell)
[[ 22.75250435  22.36059952]
 [ 24.18490219  23.83894157]]

Note that the classes in KCorrect package are designed so that users need to define the minimal set of input data. Fine tuning of parameters (e.g., assumed cosmology above) can generally be done using optinal input arguments. We also implement some auxiliary functions such as:

In [28]: KC.get_available_filters()

which returns the list of all available filter file names.

Documentation

At this point, no fancy documentation is available besides this web page. We strive to document the software using Python’s native docstrings. For example, doing

In [29]: help(KC.KCorrectDEEP)

should give you more detailed information about KCorrectDEEP class in KCorrect package.

Thursday, July 30, 2009

Setting Up Squid Proxy Server on Mac OS X Leopard

Filed under: Leopard, Mac OS X — nomo17k @ 13:47

My goal is to set up a very basic proxy server on my Mac box on campus, so that I can have full access to subscription-based academic journals via the proxy on my laptop even when I am off campus.  Some schools provide such (library) proxies but my school unfortunately does not.  I want to set it up such that the proxy requires a password authentication in order not to make it wide open to the public.

Getting and Installing Squid

Download a tarball for a stable version from the repository.  The version that I use here is 2.7.  I assume the file is downloaded to /usr/local/src/squid.

$ cd /usr/local/src/squid
$ gunzip -c squid-2.7.STABLE6.tar.gz | tar xvf -
$ cd squid-2.7.STABLE6
$ ./configure
$ make
$ sudo make install
$ cd helpers/basic_auth/NCSA
$ make
$ sudo make install
$ sudo /usr/local/squid/sbin/squid -z
$ sudo chown -R nobody var

Squid will be installed at /usr/local/squid.  (The last command is necessary to run a daemon as user “nobody.”)

Configure Squid

First, prepare a NCSA-compliant encrypted password file as follows for a user (here with username johndoe).

$ cd /usr/local/squid/etc
$ sudo touch squid_passwd
$ sudo chmod o+r squid_passwd
$ sudo htpasswd squid_passwd johndoe
New password:
Re-type new passwod:
Adding passwod for user johndoe

Now, edit /usr/local/squid/etc/squid.conf. The following lines need to be added:

# Add this to the auth_param section
auth_param basic program /usr/local/squid/libexec/ncsa_auth /usr/local/squid/etc/squid_passwd

# Add this to the bottom of the ACL section
acl ncsa_users proxy_auth REQUIRED

# Add this at the top of the http_access section
http_access allow ncsa_users

Finally, run the server:

$ sudo /usr/local/squid/sbin/squid -N -d 1 -D

With firewall, I allow squid to be open to incoming connections.

The IP address or host name of your Mac box at the port 3128 will be available as a proxy server now.

Launch Squid on Startup with launchd

Under the directory /Library/LaunchDaemons, create a file squid.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>tssquid</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/squid/sbin/squid</string>
      <string>-N</string>
      <string>-d 1</string>
      <string>-D</string>
    </array>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

Then issuing

$ sudo launchctl load -w /Library/LaunchDaemons/squid.plist

will launch squid.  On reboot, the proxy should also be working automatically.

Launch Squid on Startup with SystemStarter

This method should be ignored in favor of the method with launchd described above. This one is incomplete anyways…

This is a server so it would be convenient if the proxy starts up upon reboot automatically.  Here is a Mac way to do it:

$ sudo mkdir /Library/StartupItems/squid
$ sudo touch /Library/StartupItems/squid/squid
$ sudo touch /Library/StartupItems/squid/StartupParameters.plist
$ sudo chmod +x /Library/StartupItems/squid/squid

The newly created files should have contents as follows.

squid:

#!/bin/sh

. /etc/rc.common

StartService()
{
 ConsoleMessage "Starting squid"
 /usr/local/squid/bin/RunCache &
}

StopService()
{
 ConsoleMessage "Stopping squid"
 # TODO: add a command to stop squid
}

RestartService()
{
 ConsoleMessage "Restarting squid"
 # TODO: add a command to restart squid
 StopService
 StartService
}

RunService "$1"

StartupParameters.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist
 SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
 <dict>
 <key>Description</key>
 <string>squid</string>
 <key>Provides</key>
 <array>
 <string>squid</string>
 </array>
 <key>Requires</key>
 <array>
 <string>Network</string>
 </array>
 <key>OrderPreference</key>
 <string>Last</string>
 </dict>
</plist>

References

Quick HOWTO: Ch32 : Controlling Web Access with Squid – Linux Home Networking

Thursday, July 16, 2009

most (a pager application) Binary for Mac OS X Leopard

Filed under: Leopard, Mac OS X — nomo17k @ 13:19

My favorite pager is most, not more or less, so I build a binary. Simply gunzip and put it in your bin directory.

Download MOST version 5.0.0 (S-Lang version pre2.2.0-121) for Mac OS X Leopard.

No warranty of any kind though.

Thursday, July 9, 2009

Logitech MX Revolution in Mac OS X Leopard

Filed under: Leopard, Mac OS X — nomo17k @ 12:27

I want to use this mouse as if it is a 3-button mouse, such that within X a middle click pastes the content in the clipboard.

I find the Logitech Control Center (LCC) for Mac OS X to work just fine.  After installation, it will show up under System Preferences under the category labeled “Other”.

First, in order to make One-Touch Search button (that’s a button right below the vertical scroll wheel) as the third button, plug in your Apple Mighty Mouse, go to System Preferences -> Keyboard & Mouse -> Mouse, and select the middle button to act as “Button 3″.  Then unplug the Mighty Mouse and plug in your MX Revolution again.  Awkward, but it works…

Sunday, June 21, 2009

Miscellaneous Mac OS X Leopard Tips

Filed under: Leopard, Mac OS X — nomo17k @ 13:54

Here is a list of miscellaneous tips when configuring my new iMac to my liking.

Disable Automatic Login & Password Protect the System

Apple Menu -> System Preferences -> Security -> General

Check the following: “Require password to wake this computer from sleep or screen saver” and “Disable automatic login.”

Firefall

Apple Menu -> System Preferences -> Security -> Firewall

and choose “Allow only essential services” for the maximum protection.  Use by-application/service option for more flexibility, when allowing remote login via ssh, for example.

Remote Login with SSH

Apple Menu -> System Preferences -> Sharing

Check “Remote Login.”  Don’t forget to reconfigure the firewall to allow ssh (see above).

Right Clicking with Apple Mouse

Apple Menu -> System Preferences -> Keyboard & Mouse -> Mouse

and specify “Secondary Button” for the right side of your Apple Mouse.

Japanese Input Method

Apple Menu -> System Preferences -> International -> Input Menu

and check the box for Kotoeri.  You can change the input method by clicking on a country-flag icon in the menu bar.

Friday, June 19, 2009

Setting Up Astro Research Environment on Mac OS X Leopard

Filed under: Leopard, Mac OS X, Research — nomo17k @ 18:27

In my new research environment I have an iMac.  My preferred solution is Linux, but I figured that sometimes learning new things is a good thing (though I have to sacrifice my efficiency which I developed over the years using a Debian-based Linux box).

There are nice existing resources, like

so what I leave here is a quickie for myself based on the above sites.

X11

X11 comes with Leopard.  Just drag the X11 icon at /Applications/Utilities/X11 to your dock, so that clicking on it you have an X11 environment in which you can open up a shell terminal (Applications -> Terminal).

Xcode Tools

This one includes all the necessary development applications.  Install these from the Mac OS X installation DVD.  Xcode Tools can be found under the Optional Installs directory.

Fink

As an apt-get afficionado, I like the way I can use the APT-based packaging system on Mac OS X.  Basically you can use the apt-get command the way you do on Debian.  Go to the Fink project web site and download and install the software.  You can browse all the available packages as well.  Nice.

Software for Astrophysics

Use Scisoft for Mac OS X to install a bunch at once.  People are lazy but that’s how innovations arise, I suppose.  The package will be installed at /Applications/scisoft.

IRAF

As of this writing, the version of IRAF is 2.14.  Applying 2.14.1 patch is actually easy by overwriting:

  1. Download IRAF binaries from ftp://iraf.noao.edu/iraf/v214/PCIX/ib.macx.x86.gz to /Applications/scisoft/all/Packages/iraf/irafbin/bin.macintel and just extract the archive with gzip and tar.
  2. Download NOAO binaries from ftp://iraf.noao.edu/iraf/v214/PCIX/nb.macx.x86.gz to /Applications/scisoft/all/Packages/iraf/irafbin/noao.bin.macintel and extract the archive with gzip and tar.
  3. Download the patch from ftp://iraf.noao.edu/iraf/v214/PCIX/patch1.tar.gz to /Applications/scisoft/all/Packages/iraf/iraf and extract the archive with gzip and tar.

It is also recommended to check the versions of external packages.  If outdated, you can simply install them under /Applications/scisoft/all/Packages/iraf/extern.

If you are reusing login.cl file from a Linux installation, make sure to update your home environmental variable:

set home = “/Users/username”

(in Linux, it would be “/home/username” of course.)

IMPORTANT: Also, do not forget to do this:

$ cp /Applications/scisoft/all/Packages/iraf/iraf/dev/imtoolrc ~/.imtoolrc

Otherwise you may see DS9 not behaving well…

DS9

Download from here and install the Leopard X11 version.

Others

TO BE CONTINUED.  Still need to install quite a few packages via apt-get.

sudo apt-get install wget emacs22 gv less

Microsoft Natural Ergonomic Keyboard 4000 on Mac OS X Leopard

Filed under: Leopard, Mac OS X — nomo17k @ 15:54

I just wish the keyboard to work fairly close to iMac keyboard.  Windows (labeled Start) and Alt keys are “flipped,” which is annoying.  Following this article, I set up the keyboard.  Basically

Apple -> System Preferences -> Keyboard & Mouse (under Hardware submenu) -> Keyboard tab -> Modifier Keys

Select keyboard should be “Natural Ergonomic Keyboard 4000″ and you just need to swap the Option and Command modifier key bindings.  That’s it.

However, the above change makes the key locations resemble that of Mac.  I am too used to the PC culture of using Ctrl + some key, and my productivity suffers when I cannot position my left hand that way.  Roughly speaking, the Command key on Mac corresponds to the Ctrl key on PC, so I decided to swap them as well:

MS Natural Ergonomic Keyboard Configuration

This works much better for me.

There are quite a few special keys that do not work the ways they do on Windows, but I don’t use them much anyways so it’s good for now.  I’ll keep adding instructions as I find them on the web.

Wednesday, April 22, 2009

More Japanese Fonts

Filed under: Web — nomo17k @ 13:50

A few collections of web sites listing stylistic Japanese fonts for download:

Some are free, others are not.

My favorite is 国鉄風フォント, which resembles the characters used by kokutetsu, the Japanese national railway system (now JR and privatized).  It has a very retro feel that I like.

Monday, April 20, 2009

Astro Software in Debian Lenny

Filed under: Debian, Lenny, Linux, Research — nomo17k @ 17:44

Here my goal is to build a computing environment where Python is the glue of all the astro-related tools (PyRAF, stsci_python, etc.).

IRAF

In order to use PyRAF, IRAF needs to be installed first.

Python

At the very least, I want the basic Python packages related to science/data analysis:

# apt-get install python ipython python-doc
# apt-get install python-numpy python-scipy python-matplotlib

PyRAF

Install several Python packages:

# apt-get install tk8.4-dev python-tk libf2c2-dev
# apt-get install python-dev python-pmw python-urwid

Test if the required Python modules exists by making sure that no ImportError occurs below:

# python
>>> import readline
>>> import Tkinter
>>> Tkinter._test()
>>> import Pmw
>>> import urwid

If you have an installation of previous version, check the section Cleaning An Old Installation of the installation instruction at the STSci web site to make sure things are clean.

Prepare the source directory:

# mkdir /usr/local/src/python_packages/stsci_python
# cd /usr/local/src/python_packages/stsci_python

Download and extract the source:

# wget http://stsdas.stsci.edu/download/stsci_python_2.7/stsci_python_2.7.tar.gz
# gunzip -c stsci_python_2.7.tar.gz | tar xvf -
# cd stsci_python_2.7/

Normally, using python setup.py install will do the job, but it probably ends in compilation error, complaining the header file cfunc.h not found. In order to force the installation, modify setup.py in the current directory, so that at the very end of the file an additional include directory is defined:

distutils.core.setup(

    # This name is used in various file names to identify this item.
    name="stsci_python",

    # This version is expected to be compared to other version numbers.
    # It will also appear in some file names.
    version="2.7",

    # Apparently, description is not used anywhere.
    description="",

    packages = all_packages,
    package_dir = all_package_dir,
    ext_modules = all_ext_modules,
    scripts = all_scripts,
    data_files = all_data_files,
    include_dirs = ['/usr/lib/python2.5/site-packages/numpy/numarray/numpy']
)

Then we can follow the normal instruction:

# python setup.py install
# cd stscidocs
# python setup.py install

Before running PyRAF for the first time, clear the cache by removing directories under your “pyraf” directory, which is located in where you have your loginuser.cl for IRAF.

That’s it!

Next Page »

Blog at WordPress.com.