Posts Tagged ‘ ipython

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.

Whos in Python

Probably my most frequently used Matlab command is the “whos” command – it’s great for debugging.  A quick way to check on the variables in your Matlab workspace.

According to the comments here, it seems like it should work in iPython in a very similar way.  It looks like the main difference is that you get way more than what you would normally get in Matlab.  In Matlab you would just get all of the variables in the workspace, but in iPython, you get the variables, functions, objects, etc (which I don’t want!)… but you should be able to type “whos array” or “whos function” to restrict the search.

Unfortunately I can’t test this until next week when I’m back home and have access to my laptop.  Hopefully it does the trick!

Installing SciPy and Matplotlib

Hm.  Well, in all the excitement of installing NumPy, and configuring Emacs for Python, I neglected to actually install SciPy.  I thought I was going to have to do something pretty complicated, but it turns out that SciPy was available through Synaptic.  That makes my life much easier.  I also never got around to installing Matplotlib…also found in Synaptic!  I guess that the versions that come with the OS’s aren’t always the most up-to-date and stable, but I’m going to go ahead and take that risk in the interest of moving forward in my quest.  (whatever that is).

I think I like Matplotlib and iPython because they are both somewhat reminiscent of Matlab (my favorite!).  Why would I want to go to all this trouble to figure out Matplotlib and iPython, Numpy and Scipy?  Because they are FREE!  And it’s fun to figure it all out.  Keeps me entertained.

Installed IPython

Another thing I remember using before was iPython. This is an interactive shell that you can use to do Python specific tasks.  I vaguely recall a similarity between iPython and Matlab’s command line.  But I’ll have to re-familiarize myself with what it does.  Hey presto – It’s all done, easy peasy.  Just like Matlab!  :-)