Archive for the ‘ Coding ’ Category

Digital log book

Ever since reading Kurt and Monica’s blog posts on org-mode back in January, I have been wanting to check it out for myself.  And the second week of my PhD studies seems like as good a time as any.  Oh, wait.  A month ago would have been better, what with the learning curve and all.  But it’s okay.

Org-mode website

I’ve been following David O’Toole’s Org-mode tutorial to get started.

Incidentally, while reading Monica’s post on org-mode, I noticed she was using Aquamacs (emacs for macOSX), something else I’ve been meaning to try… so many fun, new things to discover!  :-)

Matlab in 32-bit Mode

When using the Matlab interface to Antelope, you need to use the 32-bit version of Matlab.  The default for my version of Matlab (2010a) is 64-bit.  So when opening it in the terminal, I need to do:

matlab maci

Ray tracing – matrix math

Today was my last day at Reson, and I’m finally getting around to writing the Python version of my ray tracing script.  What I want to do is take sound speed profiles as input, and compute the difference in depth that would result from using one versus the other at different multibeam launch angles.  It’s just a little tool that I’d like to have to figure out how much error I could expect given two profiles.

So far, I’ve read in the profile (from a text file), and parsed the data:

filename = 'ssp.txt'

ssp = []
depth = []

file1 = open(filename)
for line in file1.readlines():
#    print line
    splitup = line.split()
    ssp.append(float(splitup[1]))
    depth.append(float(splitup[0]))

After this, I defined an array of launch angles (relative to horizontal, so +/- 75 degrees was actually 15 – 165), and an array of sound speed values interpolated from the sound speed profile to a certain depth increment (1m), and down to a given water depth (10m).


LaunchAngle = r_[15.:166.:5.] # array of launch angles in degrees
LaunchAngleRadians = LaunchAngle*pi/180
nadirdepth = 100 # nadir depth in meters
DepthIncrement = 0.5 # depth increment in m

if nadirdepth > max(depth):
    ssp.append(0.016*(nadirdepth - max(depth)))
    depth.append(nadirdepth)

if min(depth)>0:
    ssp = insert(ssp,0,ssp[0])
    depth = insert(depth,0,0)

depthvector = r_[0:nadirdepth:DepthIncrement]
interpfun = interp1d(depth,ssp)
sspvector = interpfun(depthvector)

And as if that much wasn’t suspicious enough, I decided that I wanted to do all of the calcs using matrix math. I figured I’d ditch all the loops that were in my original Matlab script, and replace them with some nice streamlined matrices. So efficient. The problem is that there are some exceptions that I need to take care of, that are difficult to deal with when doing everything in a series of matrices. For example, when the sound speed in a certain layer is the same as the sound speed in the first layer – then the gradient is zero, and the radius of curvature is infinite. Here’s what I’ve hacked together so far. It’s not pretty.


thetaLaunch = tile(LaunchAngleRadians,(size(depthvector),1))
depthmat = transpose(tile(depthvector,(size(LaunchAngleRadians),1)))
sspmat = transpose(tile(sspvector,(size(LaunchAngleRadians),1)))

g = (sspmat - sspvector[0]) / DepthIncrement

Rc = -sspvector[0]/(g*cos(thetaLaunch))

thetamat = arccos( ((Rc*cos(thetaLaunch)) - DepthIncrement ) / Rc )

dx = (Rc*sin(thetamat) - Rc*sin(thetaLaunch))
dxnandex = isnan(dx)
dx[dxnandex] = DepthIncrement/tan(thetaLaunch[dxnandex])
dx[0,] = 0
dxsum = cumsum(dx,axis=0)

Yuck. But at least I managed to get some rays that made sense.

The next step is to convert the ray paths to two-way travel times, and then compare the depth that would be calculated if the ray tracing were done with a second sound speed profile.

Inkscape + Latex on Mac

I thought this was going to be trivial – it seemed so easy on Ubuntu.  But I getting Textex working with Inkscape on a Mac is a bit different.  I found these instructions on the mactex-wiki.  I’m not gonna lie.  It looks terrifying, and involves changing several lines of code in textext.py and textext.inx, and moving and deleting files from various folders in the inkscape package.

So before I embark on that journey, I’m going to try just blindly copying textext.py and textext.inx into the Inkscape extensions folder.  Oh hey, I got the textext item in the Extensions menu:

Next problem:  I click on the Textext option, and get this error:

Couldn’t find python-lxml in Fink, so I tried fink install lxml-py26…. and it didn’t work. :-(

It’s too late to be messing with this tonight. Maybe tomorrow. Or maybe Inkscape is not the answer – there’s got to be a better way!!

Maybe next time I’ll look into this blog post.

Diagrams in Mac

Here we go again… I was trying to draw a little diagram, and since I’m using a Mac, figured I’d look up OmniGraffle.  But OmniGraffle is now $100 for the basic package – and $200 for professional.  It wouldn’t be quite so painful except I got it for free back when I got my old Mac Powerbook back in 2006.

So it’s back to Inkscape.  I love open source!  It was an easy install – I decided to take a pass on compiling from source, and just grabbed the .dmg file from the downloads page. And of course, I already went through the whole Inkscape plus Latex thing a while ago.

And, for fun, here’s a screen shot of Inkscape in action:

… who needs OmniGraffle anyway… (sniffle)

Emacs Meta Key on Mac

To use the Meta Key in Emacs on a Mac computer, just go to the Terminal preferences –> settings –> keyboard, and check the box that says “use option key as meta key”. Easy peasy.

Use Alt/Option key as Meta Key in Emacs

Simple beam pattern in Python

It’s been a long time since I’ve

(a) used Python, numpy, scipy, or matplotlib

(b) done a beam pattern calculation of any kind

So I thought it would be a good chance to brush up on several things all at once, and maybe even have the satisfaction of making a pretty picture at the end of the night.

Well, here’s the (perhaps not so) pretty picture:

This was so simple, I’m almost embarrassed to post it, but it will probably be helpful for me later, so here it is.  What is it?  I pretended I had two little pingers spaced 5 wavelengths apart, sending out continuous sinusoidal waves.  I summed these signals at each of the elements in a 2-D grid, plotted the resulting magnitudes, and voila.

What I had to learn:

- How to use exp() using numpy – I had to load it separately for some reason, otherwise it would default to the exp() that comes with the basic math package, which doesn’t allow computations on arrays.

-How to plot an image, a la “imagesc” in Matlab.  This is accomplished using <code>imshow(datahere)</code>, and a colorbar can be added using <code>colorbar()</code>.

-How to do a screen capture of a certain area on a Mac computer:  command+shift+4 gives you crosshairs so you can pick what you like.

It would have been nice to add some attenuation, but I’m too tired now.  One more thing that I need to figure out though, what’s the best way to post my code?  I probably should figure out how to put it up on the bluehost server (where this blog lives), and link to it from here.

Trying out GRASS GIS

It seems like the next logical step, in a way – I’ve already got GMT and MB-System. Might as well try out the GRASS free GIS software.  I just downloaded it using sudo apt-get install grass in Ubuntu. And it looks like there’s a pretty easy installer for Mac also.

This screenshot is from the Ubuntu version – don’t get too excited though – the cool display is due to Compiz-Fusion, not GRASS.  But the overall effect is impressive.  (Nice to know that I’m more concerned with how the UI looks than the functionality of the program).

Fink – Numpy and Scipy

I got some Fink tips from Kurt on my post from a couple of days ago. I’m going to re-post them here:

fink configure # Say yes to unstable (which means gets actual updates – stable is missing lots)
fink selfupdate-rsync (do this once to get rsync, after just do fink selfupdate)
fink list py26 # See all the fink pythkn 2.6 packages

Once I’d done this, I installed Scipy using:

fink install scipy-py26

Numpy was installed automatically with scipy.

Next up, matplotlib:

fink install matplotlib-py26

Ubuntu – change custom screensaver text

The default text in the GLText screensaver in Ubuntu is “Host-Name, Kernel Version”. To change this, go to the screensaver folder in the terminal, and copy the gltext.desktop file to your home directory. Open gltext.desktop for editing (using emacs, for example), and change the line that reads:

Exec=gltext -root

to

Exec=gltext -root -front -text 'whatever text you like'

Might need to change permissions. I just ran chmod 777 and that did the trick.

This worked for me using Ubuntu 10.04 (Lucid Lynx).