Wednesday, August 26, 2009

cython vs f2py

I had a go at optimizing some code this past week, and ended up learning to use both cython and f2py.

f2py is much easier to use. If you want to write a function in fortran and use it in python, all you do is write the code and add specifications using comments in the fortran code.

cython is more natural to code. The code style is C/fortran-like: think in terms of loops instead of arrays. The syntax is python-like, which makes coding somewhat clearer and simpler.

For my code, I found that cython was ~10% slower than fortran.

Check out the plfits in:
http://code.google.com/p/agpy/source/browse/#svn/trunk/

Monday, August 17, 2009

How to make a pretty image

The most difficult requirement to satisfy is WCS matching. Each image has to be in exactly the same pixel space in order to overlay them successfully in an image program. The process is generally to use Montage's mProject to project the images into the same plane, then mAdd with a blank map of a given size so that the dimensions in pixels are identical.

Once that's done, I load the images into GIMP. However, GIMP reads .fits files as 256 bit data - which is essentially useless because most (interesting) images have a dynamical range >~1000. So I usually make images emphasizing the faint emission in log scale with the high and low ends cut off (I use DS9 to determine high/low). I make a second copy showing the details of the very bright regions, again in logscale but it ends up being a different log scale - essentially, my transfer function becomes a broken power law.

The tricks in GIMP are numerous, but primarily two:
1. Rotate the color table ~60 degrees
2. Use images as "Layer Masks" (aka alpha layers) on a solid color background

There's also the nice trick when using radio data of using optical or some other wavelength to provide the high-resolution details, while the radio emission provides the intensity.

Saturday, August 15, 2009

FITS manipuation with imagemagick, gimp, etc.

It is possible to convert .fits files to .png, .jpg, etc:
convert -normalize a.fits a.png

To get things to come out nicely, you have to do the scaling essentially by hand in python/idl/iraf. DS9 is only useful for finding out what scaling you want to use; past that it's pretty much not useable.

To make colors look nice in the GIMP, use solid background layers with your image as the alpha mask. Then put your image in with itself as an alpha mask so you can easily control the whiteness (saturation) of the color you've selected.

I'll be blogging about this more as I prep my next entry for the NRAO photo contest.

Friday, August 14, 2009

Acquiring DSS images

This is the way to get DSS images:
ESO's batch downloader

Thursday, August 13, 2009

login shell

to change your default login shell, use chsh

Wednesday, August 12, 2009

Quicksilver sounds

To switch sound source from the command line:
switchaudio

Use this to make scripts such as:

#!/bin/bash
/Users/adam/humor/SwitchAudioSource -s "Built-in Line Output"
afplay /Users/adam/humor/losinghorn.wav
/Users/adam/humor/SwitchAudioSource -s "Built-in Output"


Then make triggers in Quicksilver by:

  1. Go to trigger pane, make new hotkey trigger
  2. press "." to allow you to type a command
  3. make sure the action is "Run"
  4. hook up a hotkey
  5. if it doesn't work, just try again. Persist through crashes, they happen often.



Follow-up: You can also control the volume!
http://discussions.apple.com/thread.jspa?threadID=585781
osascript -e 'set volume output volume 100'