Biboroku

Saturday, February 6, 2010

Cooking Japanese Rice

Filed under: Cooking — nomo17k @ 17:16

Just a reminder for myself on how to cook short-grain rice of sticky kind, with a regular pot. The amount will be good for three servings or four, depending on how much you like rice.  The exact timing is give or take.

  1. Take 360 mL of rice and wash and rinse repeatedly until water becomes clear.
  2. Fill the pot with the rice and 400 mL of water, and cover with a lid.  Let it sit for about 15 minutes.
  3. Bring the rice to boil, with medium to high heat (with my electric stove, this is 6/8 and takes about 6.5 minutes).
  4. Once boiling, turn down the heat to medium low, until “holes” starts to appear (4/8 and takes about 1.5 minutes).
  5. Bring the heat to low (2/8 and 5 minutes).
  6. Turn the heat to max for 10 seconds to blow off excess water.
  7. Turn the heat off and let it sit for about 15 minutes.
  8. Fluff it up and serve!

That’s it.

Wednesday, January 20, 2010

scipy.interpolate.bisplrep

Filed under: Python — nomo17k @ 19:06

Tried using scipy.interpolate.bisplrep to obtained a smooth interpolated image. It turns out that this function is not capable of handling 2D image when one side is more than 256 pixels.

This should be documented in SciPy…

Just a note for myself, hoping not to make the same damn mistake again.

Saturday, January 16, 2010

Wacom Intuos Tablet on Debian Lenny

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

First, install a package:

# apt-get install wacom-tools

Add the following lines to /etc/X11/xorg.conf:

# Device entries for Wacom Intuous:
Section "InputDevice"
	Identifier	"stylus"
	Driver		"wacom"
	Option		"Type"		"stylus"
	Option		"Mode"		"Absolute"
	Option		"USB"		"on"
	Option		"Threshold"	"10"
	Option		"Tilt"		"on"
	Option		"Device"	"/dev/input/wacom"
EndSection

Section "InputDevice"
	Identifier	"eraser"
	Driver		"wacom"
	Option		"Type"		"eraser"
	Option		"Mode"		"Absolute"
	Option		"USB"		"on"
	Option		"Tilt"		"on"
	Option		"Threshold"	"10"
	Option		"Device"	"/dev/input/wacom"
EndSection

Section "InputDevice"
	Identifier	"cursor"
	Driver		"wacom"
	Option		"Type"		"cursor"
	Option		"Mode"		"Relative"
	Option		"USB"		"on"
	Option		"Threshold"	"10"
	Option		"Device"	"/dev/input/wacom"
EndSection

Section "InputDevice"
	Identifier	"pad"
	Driver		"wacom"
	Option		"Device"	"/dev/input/wacom"
	Option		"Type"		"pad"
	Option		"USB"		"on"
EndSection

# Add InputDevice lines in SeverLayout:
Section "ServerLayout"
	...

	InputDevice	"stylus"	"SendCoreEvents"
	InputDevice	"eraser"	"SendCoreEvents"
	InputDevice	"cursor"	"SendCoreEvents"
	InputDevice	"pad"		""
EndSection

Reboot (or insert wacom module).

Using with GIMP

To use cool features like pressure sensitivity and eraser with GIMP, go to: File -> Preferences -> Input Devices -> Configure Extended Input Devices, and set stylus, cursor, eraser, pad to “Screen.” This should be it!

Monday, January 4, 2010

python-sao

Filed under: Python, Research — nomo17k @ 00:35

Man, pysao is extremely useful.  Controlling DS9 from Python has never been easier.  Thank you, whoever is developing the software.

Tuesday, December 29, 2009

“Line in” doesn’t work by default on Leopard

Filed under: Leopard, Mac OS X — nomo17k @ 16:56

How lame…

Fortunately there is an application called LineIn which makes possible pass through (sounds coming in at line in goes to line out directly).  Just install it and enable “Pass Thru.”  That’s it.

Friday, November 27, 2009

PyRAF Tips

Filed under: Python, Research — nomo17k @ 13:55

The Standard Calling Sequence for an IRAF Task within a Python Script

This is just an example of how to run an IRAF task as if it is part of a Python module using PyRAF. It ensures that the task parameters are set to their default values, and a user overrides only those parameters which need to be customized for a particular task.


#!/usr/bin/env python
from pyraf import iraf
from pyraf.irafpar import IrafParList

def default_irafpar(task):
    # Return the IrafParList object for default parameters.
    return IrafParList(task.getName(), parlist=task.getDefaultParList())

def main():
    # Load IRAF packages.
    iraf.gemini(_doprint=0)
    iraf.gmos(_doprint=0)

    # Get default parameters and override some.
    yes, no = 'yes', 'no'
    plist = default_irafpar(iraf.gprepare)
    plist.setParList(inimages = 'someimage.fits',
                     rawpath = '/astro/data/',
                     fl_addmdf = yes,
                     mdfdir = '../mdf/',
                     logfile = '',
                     verbose = yes)

    # Run the task.
    iraf.gsprepare(ParList=plist)

    return

if __name__ == '__main__':
    main()

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 choose the program in 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).

Download Version 0.2.1

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.5.2 or better (http://www.python.org/)
  • NumPy 1.3 or better (http://www.scipy.org/Download/)
  • SWIG 1.3.36 or better (http://www.swig.org/)

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>squid</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.

Next Page »

Blog at WordPress.com.