comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Trying to map georeferenced data with NaN's
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Trying to map georeferenced data with NaN's [message #45386] Thu, 01 September 2005 14:46
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Konig writes:

> Hi there
>
> I have 2D arrays that contain values from 0 - 100 (percentages) as well
> as plenty of NaN's (NaN is not the same as zero for me) on a regular
> lon/lat grid. I.e. I have
>
> GRIDDED FLOAT = Array[1801, 150]
> LAT_GRID FLOAT = Array[150]
> LON_GRID FLOAT = Array[1801]
>
> The latter two contain the locations.
>
> *** What I would like to do:
> I would like to see my data on a map with the NaN's in a different
> color. The built-in plotting routine seem to always show NaN's as zeros,
> which is not ok for me.
>
> *** What I've tried so far:
>
> ; Prepare plotting
> loadct, 1, bottom=20, ncolors=101, /silent ; ct for data (see below)
> device, decomposed=0, retain = 2
> window, 2, xsize=1200, ysize=500
> landColor = fsc_color('charcoal',200)
> NaNcolor = fsc_color('light gray',10)
>
> map_set, /hires, /continents, con_color=landColor, $
> limit=[58, -180, 89, 180], /cylindrical ; Data is Arctic
>
> ; Let's treat the data
> gr_is_nan = where(finite(gridded,/NAN),count)
> if (count lt 0) then gridded[gr_is_nan] = -10
> gridded_plot = gridded + 20
> ; data now going from 10 to 120 (10: NaN, 20-120: values)

I think this will work, but it seems, uh, strange. :-)
I think I would grid the data like this into values 20 to 120:

gridded_plot = BytScl(gridded, /NAN, Top=100) + 20B

Then, to set the NAN pixels:

nanindices = Where(Finite(gridded, /NAN) EQ 0, count)
IF count GT 0 THEN gridded_plot[nanindices] = 10B

Next, you want to tell the contour plot where to get its
colors from:

c_colors = Indgen(101) + 20 ; from 20 to 120

> ; Plot it
> contour,gridded_plot, x_grid, y_grid, /cell_fill, $
> levels = indgen(11)*10+20, $
> /overplot

Add the contour colors:

contour,gridded_plot, x_grid, y_grid, /cell_fill, $
levels = indgen(11)*10+20, $
/overplot, C_COLORS=c_colors

> *** Problems I have (in decreasing importance):
> - NaN's are not shown in in NaNcolor but with the same color as zeros
> (or not at all?), even though that had been working for me at some other
> point.

Scaling and contour colors should solve this problem.
>
> - The data seems to become rescaled, i.e. the rearranged data values
> (from 20-120) do not use the color indices from 20-120 but from 0-255.
> Can I tell 'contour' *not* to rescale? Should I use another plotting
> command instead? Which one? And it works with maps?

You were forgetting the C_COLOR keyword to the contour command.

> - If I try to overplot data from another time (a new 'gridded') it does
> not completely overplot earlier data, but only where it is not NaN.
> (This might be connected to the first question.)

I think it is. Try the new scaling approach.

> - I get "Floating underflow" errors each time I call 'contour'. Why? How
> can I prevent them?

I'll add your name to the petition we are sending to
RSI. There are 854,356 names ahead of yours. (Uh, I think
I've added my own name more than once. :-) And, by the way,
they are not "errors", they are warnings. They can (almost
always) be safely ignored. You can prevent them by making
sure your minimum value doesn't exceed the underflow value
for your machine:

yourdata = yourdata > (marchar(/Double)).xmin

It is a gigantic pain in the ass to check them, in my opinion.
Why doesn't RSI check them!? :-)

> - I don't know how I can put titles on my plots. It works for the
> original 'map_set' call, but I would like to update the title with the
> 'contour' or 'map_continents' call, but none of them seem to do anything.

Well, these commands are "overplotting", not "plotting" (as
you are using them), so they are not erasing anything that
exists previously on the display, just drawing over the top
of what is already there. If you wanted a new Title command
you could do the MAP_SET call again, or you could probably
figure out a way to draw and erase the title with XYOUTS.
For example, something like this:

MAP_SET, ...., Position=[0.05, 0.05, 0.95, 0.85]
x_title_loc = (!X.Window[1]- !X.Window[0]) / 2 + !X.Window[0]
y_title_loc = 0.92

XYOUTS, x_title_loc, y_title_loc, /Normal, 'This is the Title', $
Color=FSC_Color('Sky Blue', !D.Table_Size-2), Charsize=1.75, $
Alignment=0.5

And, to erase:

XYOUTS, x_title_loc, y_title_loc, /Normal, 'This is the Title', $
Color=!P.Background, Charsize=1.75, Alignment=0.5

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Trying to map georeferenced data with NaN's [message #45387 is a reply to message #45386] Thu, 01 September 2005 14:31 Go to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Chris,

please don't reply to an existing message if you want to start a new
topic. Many newsreaders (like Thunderbird, which you and I are using)
use header data other than the subject to assign messages to a topic /
thread. For me, your message is shown in the thread "Search IDL content
with Spotlight".

Thanks,
Benjamin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Trying to map georeferenced data with NaN's
Next Topic: IDL Community Supports Hurricane Victims

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:47:47 PDT 2025

Total time taken to generate the page: 0.00632 seconds