Archive for the 'IDL' Category

Jan 19 2008

IDL Procedures to do Simple but Hard to Figure out Things

Published under IDL

Until I get around to making a dedicated section on this site for IDL-related stuff, I have to post this here. Most, if not all, of you will not care about this at all. I’d suggest simply ignoring it.

Apply_hanning.pro
A function that takes a time series and applies a Hanning filter to it. You can actually do this in IDL in one line, but this adds a few checks for errors. It can handle 1D and 2D arrays.

Contour_on_map.pro
A procedure that will take a 2D array of values, with corresponding 1D arrays of latitudes and longitudes and then plot it on a map. This may sound simple, and it is, but it’s trickier than it sounds because IDLs documentation is not so good.

Cumulative_correlation.pro
A procedure that will plot the cumulative correlation of two time series. This makes it easier to see over what temporal, or spatial, frequencies the time series correlate than, for instance, a power spectrum from a Fourier transform.

Interpolate_bad_points
Exactly as it sounds. It finds the “bad” points in a time series and does a linear interpolation to fill them in.

Plot2axis.pro
Plot two time series on the same plot, but with different vertical axis. Allows lots of customization using keywords. Important note: This procedure will not work as currently written unless you have a function called numtostring() which takes a number (integer, float, or double), and converts it into a string variable. This is a function I wrote that I have not released yet. If you wish to use this procedure, just replace all occurrences of “numtostring(” with string(”; without the quotes.

Silence_math_errors.pro
Again, exactly as it sounds. Will make it so IDL doesn’t display those silly math error, like the floating underflow. Note: there really isn’t a good reason to use this; the displaying of the errors doesn’t hurt anything, and it’s better to actually fix the error than just ignore it.

No responses yet

Nov 15 2007

Showing simple contouring in IDL

Published under IDL

I’ve had trouble getting the IDL contour procedure to give me exactly what I want when both printing to the screen and the postscript device. I think I’ve finally figured it out, with a lot of help from the website of David Fanning. If this seems too basic for you, or you don’t have any desire to use IDL, then you may quit reading now.

I’ve decided to release the code, in the hopes that it may help someone else. This is free software, you may do with it as you wish.

CONTOUR_ON_MAP.PRO

This should work on Windows, Mac, and Linux machines, but has only been tested on one particular flavor of Linux. It has also only been tested on one version of IDL. The code can be broken down into the following sections:

default variables: set the default variables so if the user specifies only the minimum information a usable plot is still made
setting device: postscript or the screen
set_map: use the built-in IDL procedure

configure levels: Those first three steps are fairly straightforward. The difficulty is in setting the contours correctly. Let’s say I want a contour plot with 5 equally spaced contours. IDL has a keyword in its CONTOUR procedure for this: NLEVELS. However, this keyword does not always produce the desired amount of contours. IDL uses as a suggestion for the amount of contours to display. Therefore, I force it to have the number of levels that the user specifies.

contour: Call the IDL CONTOUR procedure.

colorbar: The COLORBAR procedure (courtesy D. Fanning) seems to be device dependent… although the documentation says it is device independent. That’s probably because I don’t fully understand the workings of how IDL does its color thing. Therefore, the calling of the colorbar procedure, needs to depend upon which device is being written to.

cleanup: Yeah! We’re all done. Let’s see what it looks like.

I’ve been working with 500mb geopotential height data lately. I’ve also been doing principle components analysis a lot. Therefore, I did the PCA of the last ~50 years of winter geopotential height anomalies. (No need to understand this, from this point on, it’s just pretty pictures.) As you can see, it’s simple to create contours on the map of different projections.

Orthographic Projection:

500mb EOF1

Mercator Projection:

500mb EOF2

Sinusoidal Interrupted Mollweide Projection:

500mb EOF3

It only took 3 commands at the IDL prompt to produce the 3 plots above (1 for each). Easy. :-)

No responses yet