Moving to WordPress.org…
In a completely impulsive decision, I decided to move my WordPress.com blog over to my own domain hosted on Bluehost. It’s impulsive mostly because I have no idea what I’m doing, and am quickly becoming overwhelmed. I don’t know how the transition will go, because I’m still figuring it all out. So far, I’ve got myself space and a domain name at Bluehost – michw.com. Pretty simple. But there’s nothing at michw.com yet. I managed to export this blog to xml, and import it to Bluehost really easily (it can be found, in a sort of incomlete state, at www.michw.com/blog). Now I need to figure out how to get my wordpress.com posts linked over to there. So essentially, most of the content of my blog exists in two places simultaneously. I have no idea what happens when someone searches for something in that blog now. I guess they’ll get directed here…
I did find some helpful stuff on good ol’ Google — such as this document (from this website). Although it may be a bit dated. And it’s discouraging that the links on the blog in their example don’t work any more. But I am guessing that they might have stopped paying WordPress the 10 bucks a year to forward the links to their new site…
Pylint – bug and quality checker in Python
Monica just blogged about Pylint, and I thought it was really cool – it checks your code for bugs and for quality based on Python standards. More information can be found at the Python Pylint page.
SQLite configuration file
I just created a simple configuration file for SQLite. It’s in my home directory, and is called .sqliterc. It contains the following lines:
# SQLite configuration file .echo ON # repeat every command .header ON # print column names .separator "\t" # change default separator to tab .nullvalue "Null" # print the word "Null" rather than having empty fields
Now, every time I start SQLite, these commands will be run.
* Thanks to Kurt, who showed me how to do this!
Getting started with SQLite
I’m just running through some basic commands from Kurt’s SQLite cheatsheet. I guess I already had some version of SQLite installed that came with the Karmic distribution, but it turns out that SQLite3 wasn’t installed. It was easy, I just did a sudo apt-get install sqlite3.
Kurt made a couple of website/tutorial suggestions in his notes:
A database overview and tutorial
Data Types
Speed and optimization
FFT Review
I haven’t done signal processing of any sort for a while now (that’s not to say I ever did very much of it) – but I occasionally find myself needing to do some filtering or frequency spectrum analysis. And as usual, I always need to look up how I did it before. I should really write myself a little cheat sheet. But since I don’t have time for that now, here’s a quick link: FFT Tutorial. It’s from someone in the EE department at the University of Rhode Island. I had a quick look and I like it because it provides some theory, and also a Matlab example (and it’s pretty clearly written using LaTeX – yeah!). And while I’m on the topic of signal processing, here’s a link to a tutorial by Richard Lyons: “Quadrature Signals, Complex but not Complicated“. I like this one because it has a movie trivia question on page 3. And I totally knew the answer without looking.
Interpolation using Scipy/Numpy
As part of a little script I’m writing, I need to do some simple linear interpolation. The Matlab equivalent of what I’m doing is called ‘interp1′. So far I’ve come across two ways to do 1-d, linear interpolation. One is ‘interp’ in numpy. The other is ‘interp1d’ in scipy.interpolate. I’m not completely sure of the difference. Is one faster? Is one older? I’ve googled around a bit, but still haven’t found a clear answer. For now, I’ve implemented ‘interp1d’, which is less similar to Matlab’s ‘interp1′. You first define an interpolated object given your x and y vectors. Then you call that object with your new x-values to generate the new y-values.
And here is an example, chopped out of my code:
depthvector1 = r_[0:nadirdepth:DepthIncrement] interpfun1 = interp1d(depth1,ssp1) # my x and y vectors sspvector1 = interpfun1(depthvector1) # find the new y's for this x
GUIs – wxPython and wxGlade
I think I’m going to have to stop putting this off: it’s time to start learning about GUIs. I’ve decided to begin with wxGlade, which means that I am going to have to learn about wxPython first. I’m starting with this little tutorial for making a simple text editor. Then there’s a wxGlade tutorial that I’d like to go through. I think if I got through these two things, I’d at least have something to build on, because at this point I don’t really know how to do anything. Well, except for maybe two TKinter commands. And no one seems to think TKinter is even worth learning…
“Repmat” function in Numpy/Scipy?
I’m such a Matlab user. I just want to repeat an array or matrix X times, which I can do easily in Matlab using ‘repmat’. I’m sure this is super easy, and I’m just not seeing something obvious. Any tips? Is it something like concatenating copies of an array with itself? vstack?
…
Hey – I just found what I was looking for: I can do what I need to do here using the ’tile’ function in numpy. It works like this:
from numpy import *
x = array([1,2]) # create a simple array
bigx = tile(x,(2,1))
And the output is:
array([[1,2],
[1,2]])
Awesome! Now I can get rid of those pesky nested loops!
Also something interesting that I just discovered while messing with this in iPython: even if ‘x’ in this example is not created as an array (say it’s a list or a tuple) – it doesn’t matter – numpy still understands it, and then outputs an array object! Amazing.
Reverse axis direction in Pylab
I have been trying to remember how to do this FOREVER! I’m trying to plot a sound speed profile with depth along the y-axis and sound speed along the x-axis. But if I don’t reverse axes, the depth increases up, which isn’t really very intuitive. In Matlab, it’s pretty easy. But how to do it in Python/Pylab? Here’s what the plot looked like before reversing the y-axis.
Here’s the code I used to reverse the axis:
from pylab import *
### SKIPPING SOME CODE HERE
# Plot sound speed profiles
plot(sspvector1,(depthvector1))
plot(sspvector2,(depthvector2),'r')
# Reverse the y-axis
ax = gca()
ax.set_ylim(ax.get_ylim()[::-1])
title('Sound speed profiles')
xlabel('Sound speed (m/s)')
ylabel('Depth (m)')
grid()
show()
Python – matrices or arrays?
Sometimes I think I have my biggest breakthroughs while biking home. Tonight, for instance, it dawned on me (on the stretch between the beach and Patterson) just how awful the Matlab version of my ray tracing code really is. And I realised that I could vastly improve its simplicity and efficiency by using matrices (Yikes! Why on earth did I implement all of those nested loops?). I pictured the steps and the math involved, the Matlab commands that I would need, and got really excited – until I realized that I don’t know how to do any of the same stuff in Python yet. First of all, I need to figure out how to work with arrays in Matlab. Thankfully, there’s a special page on Scipy.org Matlab users who are trying to migrate to Numpy/Scipy. Yes! And here it is: Numpy for Matlab Users. My first question was, “How do I make it do element-wise operations?” In Matlab, you need to modify the operator, for example using “.*” to multiply by elements, and just “*” to do matrix multiplication. Matlab thinks in linear algebra for 2d matrices. But, as I quickly learned, the default array in Numpy does element by element operations, unless you create a special matrix object. Awesome.

