Archive for the ‘ Science ’ Category

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.

Reson 8101 on Ocean Bytes blog

I saw this link on Kurt’s blog – I didn’t even know about the Ocean Bytes blog before.

Reson Seabat 8101 on Ocean Bytes blog

Brian Kidd is an oceanographic technician aboard the R/V Hugh R. Sharp, and in these two videos, he’s being interviewed about the 8101 system.  In the first part, he describes the monitoring and display station, and in the second part, he talks more about the wet side – the transducer and mounting assembly.

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)

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).

Macbook Pro – Fink

Wow, it was so weird to power up the new Macbook Pro.  It’s new, but still so familiar – like coming home after being away for a really long time.  It’s been nearly two years, after all, and ALL Linux during that time (at home, anyway).  Not to worry – I have not abandoned my Ubuntu computer!

So first things first – make sure I have what I need to dive back into Python.  Well, luckily, Python is built in already (2.6.1).  So there’s a step I don’t need to worry about.  Next up – Numpy and Scipy.  It’s been so long since I’ve done this.  When installing open source packages on my Mac before, I used Fink.  I have vague memories of Val and Kurt walking me through it way back when.  Unfortunately I didn’t document it very well the first time.  I’ll keep better track this time.

Some notes on Fink install:

1) No binary for OS 10.6.x.  So I need to do a source install.  Instructions here, starting with downloading the source tarball.

2)  Install Xcode Tools (required for installing packages from source).

  • registered as an Apple Developer (woo, fancy), and downloaded xcode_3.2.3_and_ios_sdk_4.0.1.dmg (good lord, it’s 2.28GB!)
  • Run xcode installation

3) unpack the fink tarball

4) Install Fink base setup using ./bootstrap

5) Set PATH environment variable using /sw/bin/pathsetup.sh

And there’s Fink, all set up (hopefully).  It’s getting late, I’ll save Numpy and Scipy for another day.

MB-System and missing link flags

Thanks for the tip, Kurt!!

I guess this is probably a painfully obvious solution to anyone who knows what they’re doing, but it turns out I was missing the link to GDAL in my install_makefiles script. There’s a line in there that looks like this:


$LFLAGS = "-L$NETCDFLIBDIR -lm -lnetcdf";

It should have had a link to GDAL like this:


$LFLAGS = "-L$NETCDFLIBDIR -lm -lnetcdf -lgdal";

So it worked! It ran with no errors, and seemed to build correctly. So one step closer! I then continued along the instructions to setting the .bashrc file. I had left out one line before, so I added it, and then ran:


$ source .bashrc

To test my GMT and MBSystem installs, I tried:


$ psxy
$ man psxy
$ mbgrid
$ man mbgrid

Since I don’t know how to use GMT and MBSystem yet, I don’t know if these did what they were supposed to. But it seemed like they did, except for mbgrid, which came up with an error: “Unable to open data list file: datalist.mb-1“. But at least it recognized mbgrid as a command and tried to do something!

Ah, finally, I’m getting somewhere! :-)

MB-System install

I’m embarrassed to admit that I haven’t even touched MB-System in ages. I had finally succeeded in getting GMT to install without problems, and thought I was in the clear. But, alas, MB-system gave me even more grief. It wasn’t working out for me, and I just haven’t had time to get back to it in months. Now I’m back at it, and here are the problems I’m seeing. Following the instructions on this page, I’m getting more undefined reference errors. And they all seem to be related to GDAL, again:


gmt_customio.c:(.text+0x7cfc): undefined reference to `GDALGetRasterDataType'
/usr/local/GMT452/lib/libgmt.a(gmt_customio.o): In function `.L1109':
gmt_customio.c:(.text+0x7e20): undefined reference to `GDALGetRasterBand'
gmt_customio.c:(.text+0x7e2a): undefined reference to `GDALGetRasterDataType'
gmt_customio.c:(.text+0x7e94): undefined reference to `GDALRasterIO'
gmt_customio.c:(.text+0x7ea6): undefined reference to `GDALGetRasterNoDataValue'
gmt_customio.c:(.text+0x7ee0): undefined reference to `GDALGetRasterDataType'
gmt_customio.c:(.text+0x7f73): undefined reference to `OSRNewSpatialReference'
gmt_customio.c:(.text+0x7f8a): undefined reference to `OSRImportFromProj4'
gmt_customio.c:(.text+0x7fd3): undefined reference to `OSRDestroySpatialReference'
/usr/local/GMT452/lib/libgmt.a(gmt_customio.o): In function `.L1129':
gmt_customio.c:(.text+0x8158): undefined reference to `GDALClose'
/usr/local/GMT452/lib/libgmt.a(gmt_customio.o): In function `.L1134':
gmt_customio.c:(.text+0x8826): undefined reference to `OSRExportToPrettyWkt'
/usr/local/GMT452/lib/libgmt.a(gmt_customio.o): In function `.L1110':
gmt_customio.c:(.text+0x8a3e): undefined reference to `GDALGetRasterBand'
gmt_customio.c:(.text+0x8e3e): undefined reference to `GDALGetRasterXSize'
gmt_customio.c:(.text+0x8e5d): undefined reference to `GDALGetRasterYSize'
gmt_customio.c:(.text+0x8e81): undefined reference to `GDALGetRasterYSize'
gmt_customio.c:(.text+0x8e91): undefined reference to `GDALGetRasterXSize'
gmt_customio.c:(.text+0x8f23): undefined reference to `GDALClose'
gmt_customio.c:(.text+0x8f28): undefined reference to `GDALDestroyDriverManager'
gmt_customio.c:(.text+0x8f35): undefined reference to `CPLGetLastErrorMsg'
collect2: ld returned 1 exit status
make[2]: *** [../../bin/mbprocess] Error 1
make[2]: Leaving directory `/home/michelle/Documents/mbsystem-5.1.2/src/utilities'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/michelle/Documents/mbsystem-5.1.2/src'
make: *** [all] Error 2

When I was installing GMT, I was also getting undefined reference errors, but I never did figure out what was wrong. It just worked all of a sudden. I think I attributed it to a reboot because I coudn’t figure out what else I had done differently. This time, rebooting does not result in any magical fixes.

Gulf oil spill – Larry’s CNN interview

Thanks, Kurt, for the tip.  Here’s a link to Larry’s interview with CNN, where he talks the search for “phantom” oil plumes.

CNN Video – Phantom plumes

Both of my master’s thesis advisors were down in the Gulf of Mexico recently, searching for these plumes using various types of sensors.

Kurt also linked to the recently released cruise report for the mid-water mapping mission in the Gulf of Mexico:  NOAA Ship Thomas Jefferson Deepwater Horizon Response Mission Report