Tuesday, July 15, 2008
Organic Code Development
So out went that approach, and I started with the simple goal of getting a single barb to appear on the plot, using the most direct and manual way possible. Once that was achieved, I added a couple more to the test and made sure that they scaled right, and were positioned properly. From here then some refactoring occurred and things were broken into more logical groups, and manual hard coded things were replaced with more flexible (and arguably) simple code. Here's the (more or less) final result.
I now have 320 lines of commented and documented code ("borrowing" a lot of the documentation and input processing from a similar matplotlib function, quiver). I'm just amused that this kind of procedure always seems to work better for me. I was stuck for days trying to get this working, trying to figure out where to begin. It was so much easier to start with a simple, small goal and build on it. Then again, this might work better for me because I'm a scientist who codes rather than a software engineer/developer. It could also be because every time I do something like this, I'm learning a new API or even an entirely new library. Maybe if I finally developed a deep expertise with something, I might be able to think at a slightly higher level....nah. :)
I think I've really only ever succeeded in designing and implementing one project, my radar emulator . While it turned out well, it's not a design that at this point I'm in love with (though I'm stuck with it at this point). Then again, I started that in 2003, when I was far less experienced. Another project I've been kicking around in my head forever, a simple data visualization program, is persistently stuck in the design phase. Granted, it's predecessor grew organically and became unwieldy, but that was C++, where refactoring is a nightmare. But it did have the benefit of actually existing in code and being (somewhat) useful, which is more than I can say for an idea floating around in my head.
Anyhow, less rambling, more code! On to Skew-T's!
Links for the day (aka. Other people's stuff)
http://www.johndcook.com/blog/2008/07/15/getting-to-the-bottom-of-things/
I think this one hits the nail on the head about multi-tasking and information overload. Also explains why the days that I manage to ignore Google reader and Thunderbird for extended periods of time are my most productive, even though the actual total time spent doing either isn't any less. I probably would see great productivity gains if I managed to restrict how often I look at either of those. I've noticed this summer just how hard it is to get back in a groove on something once you've gotten out, both taking 5 minutes away from intensive coding or taking a multi-day (week?) break from a certain topic. Our brains are like computers in a way, there's only so much you can keep readily accessible.
http://bitecode.co.uk/2008/07/my-views-on-python/
There's not much more I can add here, python just rocks. :) I can't believe there was once upon a time that I did analysis and even generated images using only C (and maybe *shudder* Excel).
Tuesday, July 1, 2008
Programmatically saving Matlab figures
saveas
to allow doing this, but it has two drawbacks for me:- When I save figures, I usually maximize them so that the spacing looks better and I get higher resolution figures
- Regardless of the maximization,
saveas
resizes everything and you get (usually) a bad mix of spacing and font sizes. So many of my figures have labels and things that look like crap, with tick labels overlapping each other and other issues like this. At least, that's my experience using Matlab on Linux. At any rate,saveas
does not normally give me figures I want to hand in with a homework assignment, let alone a presentation or a publication.
I have found a couple of nuggets that allow me to programmatically create graphics just like the ones I would have on screen. The first nugget, which solves the 2nd problem of resizing is as follows:
set(fig, 'PaperPositionMode', 'auto')
where fig
is your figure handle. You can also just pass gcf
. This wonderful little command, according to the Matlab documentation (where this was buried): "...ensures that the printed version is the same size as the onscreen version. With PaperPositionMode
set to auto
MATLAB does not resize the figure to fit the current value of the PaperPosition
." Fantastic.
The second nugget is a way to set the figure size to fill the screen (I found this one in the Mathworks file share through a Google search):
set(fig,'units','normalized','outerposition',[0 0 1 1]);
You may or may not want to save and restore the original value of units around this call. At any rate, with these two commands, I can now create figures with my code that look how I want them without requiring any intervention on my part using the GUI. That's wonderful for making my workflow better.