Where am I?

Well, more accurately, “where on the filesystem is the source for the currently scoped routine?”, but that’s not a catchy title. In IDL 8.2.2, the ROUTINE_FILEPATH function was modified to return this information when called without any parameters. Here’s a simple program demonstrating this behavior:

pro routine_filepath_no_params
   compile_opt idl2

   print, 'I''m called from a program in the file: ' + routine_filepath()
end

When I run this program, I get:

IDL> routine_filepath_no_params
I'm called from a program in the file: /home/mpiper/VIS/IDL/8/22/demos/src/routine_filepath_no_params.pro

Jim Pendleton, for example, has found this helpful in determining whether a program is being run from a SAVE file or a PRO file. I’ve used it to save a visualization to a PNG file with the same base name as the PRO file in which it’s generated.

(This is, I think, my last 8.2.2 post before 8.2.3 comes out next week!)

Posted in language | Tagged , , | 1 Comment

The bigger picture in 2013

Regular readers of this blog know that I love to show off the neat things you can do with IDL, usually with some code. I thought I’d try something different today, though. As product manager, I help set the agenda for IDL development. So, here’s a look at where we’re going with IDL in the near future.

The big themes for IDL in 2013 are:

  • visualization
  • file access

In the IDL releases this year (8.2.2 in February, 8.2.3 in May and 8.3 this fall), we’re trying to tie development (including improvements, new features and bugfixes) to these themes. Outside issues arise and are addressed, but we’re trying to prioritize stories that fit these themes. So far, this has included new (New) Graphics routines like SCATTERPLOT, BOXPLOT, and soon, BUBBLEPLOT and VOLUME, as well as continued improvements to the performance and usability of NG. For file access, we’ve updated our HDF4, HDF-EOS and CDF libraries, and updates to netCDF, HDF5 and GRIB are on the way.

Looking at the 2013 releases as a whole, I think we’re making good progress in addressing these themes.

(If I get egged on enough, I’ll talk about what we’re thinking about for IDL in 2014, too.)

Posted in VIS | Tagged , | 2 Comments

Coming soon: IDL 8.2.3

IDL 8.2.3 is scheduled to be released on May 21. While this is primarily a maintenance release, we’ve included several new routines. They are:

  • BUBBLEPLOT
  • VOLUME
  • FILE_ZIP
  • FILE_UNZIP
  • FILE_GZIP
  • FILE_GUNZIP
  • FILE_TAR
  • FILE_UNTAR
  • ZLIB_COMPRESS
  • ZLIB_UNCOMPRESS
  • IDLffVideoRead class
  • QUERY_VIDEO
  • READ_VIDEO
  • WRITE_VIDEO
  • TERMINAL_SIZE

BUBBLEPLOT has been an early favorite around VIS. Here’s a sample from Eddie Haskell, the developer who wrote it (click to embiggen):

Life expectancy versus income for selected countries

I’ll post more information on these routines, as well as the rest of what’s included in 8.2.3, on the release date.

Posted in VIS | Tagged , , , | 8 Comments

Modifying the size and position of a plot

In IDL 8 (a.k.a. New) Graphics, you can interactively move and resize plots in a window. For example, make a test plot in red:

IDL> p = plot([0,1], 'r')

Select the plot by clicking the mouse in the interior of the plot frame. To move the plot, click the frame and drag it. To resize the plot, click and drag a manipulator on the corner or middle of the frame.

Once you’ve moved and/or resized a plot, you can programmatically retrieve its new location and size from the POSITION property. For example, I moved and resized my plot to give:

IDL> print, p.position
      0.12656254      0.47788962      0.54761025      0.88085938

Note that these values are in normalized coordinates (x and y range over a unit interval); the first two values give the (x,y) coordinate of the lower left corner of the plot frame, while the last two values give the coordinate of the upper right corner of the plot frame.

In IDL 8.2.2, we modified the POSITION property so that you can also programmatically set the size and position of a plot; e.g.:

IDL> p.position = [0.50, 0.45, 0.90, 0.90]

The result is a plot in the upper left corner of the window:

A programmatically positioned plot.

Posted in visualization | Tagged , , , | Leave a comment

A column sort routine

In spreadsheet programs like Excel or LibreOffice, you can apply a sort on a column to every other column in the spreadsheet. IDL’s SORT function doesn’t provide this functionality, but with a little code, we can make it so. The function COLSORT (get the source code here) accepts a 2D array and the zero-based index of the column to sort on. By default, values are sorted in ascending order; a keyword can be set to sort in descending order. Here’s an example of how the routine works.

Start with a 4 x 5 array of numbers:

IDL> a = round(randomu(seed, 4, 5) * 20.0)
IDL> print, 'Original array:', a, format='(a,/,4(i))'
Original array:
           8           6          14          10
           4           9          18           5
           1          11          13          18
           8           9          11           9
           3          19           4          16

Use COLSORT to perform a reverse sort on column index 1 (the second column) and extend the sort to the other columns in the array:

IDL> sort_index = 1
IDL> b = colsort(a, sort_index, /reverse_sort)

Check the result:

IDL> print, 'Sorted (descending) array:', b, format='(a,/,4(i))'
Sorted (descending) array:
           3          19           4          16
           1          11          13          18
           8           9          11           9
           4           9          18           5
           8           6          14          10

This program could be extended to apply to rows and to arrays of higher dimensionality.

Posted in language, programming | Tagged , , | 2 Comments

Locating NaN and Inf values in an array

(This week’s post is brief because I’m out learning a lot at the 2013 NOAA Satellite Conference!)

The ubiquitous WHERE function can be used to quickly locate values in an array. However, you can’t directly search for the location of IEEE NaN (not a number) and Inf (infinity) values; to do so, you need the FINITE function. Here’s an example.

Start with a simple array:

IDL> a = findgen(5, 2)
IDL> print, a
     0.000000      1.00000      2.00000      3.00000      4.00000
      5.00000      6.00000      7.00000      8.00000      9.00000

and add NaN values at up to three random locations:

IDL> i = floor(randomu(seed, 3)*n_elements(a))
IDL> a[i] = !values.f_nan
IDL> print, a
     0.000000      1.00000      2.00000      3.00000          NaN
          NaN      6.00000      7.00000          NaN      9.00000

OK, so where are the NaNs located? By eye, I can see where they are (indices 4, 5 and 8), but to identify them programmatically, use WHERE with FINITE and “~”, the logical not operator:

IDL> i_nan = where(~finite(a), /null)
IDL> print, i_nan
           4           5           8

Check!

Posted in language | Tagged , , , | Leave a comment

2013 NOAA Satellite Conference

My colleague Thomas Harris (@t_harris) and I will be at the 2013 NOAA Satellite Conference in College Park, MD, next week. We each have a poster:

If you’re attending this conference, please visit our posters and say hello!

Posted in conference | Tagged , , , | 1 Comment