Map plots drop one row and one column?

144 views
Skip to first unread message

Laura H.

unread,
Feb 11, 2021, 1:46:26 AM2/11/21
to idl-pvwave
Hi,

I am trying to plot some data for a region of the eastern Pacific and NW US coast.  In the past, the only maps I've made were global, so it's possible that this effect happened there as well, just wasn't visible.  The problem is that even though I have a 20x20 array and define a region with 20x20 grid cells, only 19 rows and columns are plotted.  (See example map attached.)  I tried changing the map limits to include an addition latitude/longitude and jiggered around the values of image_location, but I always end up with 19 rows and columns.  Is there something odd about where IDL thinks the cells are relative to the lat/lon lines?  Code below.  I have confirmed that avgvar is 20x20 and set up the colors so that the columns can be counted.  The colors should start blue on the left and end up green on the right.

Thanks!

Laura


  m = map("mercator",limit = [30,225,50,245],dimensions=[400,400],position = [0.15,0.2,0.75,0.85])

  grid = m.mapgrid

  grid.label_position = 0

  grid.font_size = 12

  im = image(avgvar,grid_units="degrees",image_location=[225,30],min_value=varlow[i],max_value=varhigh[i],rgb_table = 39,/overplot,title=longvars[i],font_size=14,font_style=1)

  c = MAPCONTINENTS(/USA )

  cb = colorbar(target=im,border_on=1,orientation=1,font_size=12, position=[0.868, 0.2500, 0.9083, 0.7500])



test.lowCF.long-term.mean.png

Jeffrey Burchfield

unread,
Feb 11, 2021, 1:21:24 PM2/11/21
to idl-pvwave
I encounter this issue frequently (i.e., every time) when using IMAGE() with maps and haven't yet discovered a reason why it happens. I work around it by just adding an extra row and column to the image array; it's not a very elegant solution, but it is straightforward (see example below). Probably should have submitted a bug report long ago -- assuming it is, in fact, a bug. 

Cheers,

Jeff

;Make an image array.
imgArr = bindgen(5, 5, start = 10, increment = 10)

;This one will plot incorrectly
img = image(imgArr, $
            image_location = [-85, 25], $
            image_dimensions = [5, 5], $
            map_projection = 'geographic', $            
            grid_units = 'degrees', $
            rgb_table = 74, $
            position = [0.05, 0.05, 0.95, 0.95],$
            dimensions = [800,800])
            
imgGrid = img.mapGrid
imgGrid.grid_long = 1.0d
imgGrid.grid_lat = 1.0d

mc = mapcontinents(/usa)       

;Now let's try and fix it by padding with an extra row/column.
newImgArr = bytarr(6,6)
newImgArr[1,1] = imgArr

;Now the plot is *correct* or, more precisely, it's what we want.
newImg = image(newImgArr, $
  image_location = [-85, 25], $
  image_dimensions = [5, 5], $
  map_projection = 'geographic', $
  grid_units = 'degrees', $
  rgb_table = 74, $
  position = [0.05, 0.05, 0.95, 0.95],$
  dimensions = [800,800])

newImgGrid = newImg.mapGrid
newImgGrid.grid_long = 1.0d
newImgGrid.grid_lat = 1.0d

mc = mapcontinents(/usa)


Laura H.

unread,
Feb 11, 2021, 2:16:37 PM2/11/21
to idl-pvwave
That's a great suggestion, thanks!

Yes, I'd say it's a bug.  Seems like it would be simple to fix.

Laura H.

unread,
Feb 11, 2021, 4:08:22 PM2/11/21
to idl-pvwave
OK, I tried this, but all it accomplished was to get the plot to start on the first row/column instead of the second.  The number of rows/columns in the plot is still 19 instead of 20.....

Laura

New code lines:

  arraysize = size(avgvar)

  nx = arraysize[1] & ny = arraysize[2]

  plotdata = fltarr(nx+1,ny+1)

  plotdata[1:nx,1:ny] = avgvar



test.lwCF.long-term.mean.n+1.png

Jeffrey Burchfield

unread,
Feb 12, 2021, 9:11:40 AM2/12/21
to idl-pvwave
Try adding the keyword IMAGE_DIMENSIONS = [20, 20] (assuming it's 20 degrees X 20 degrees in longitude/latitude) to your call to IMAGE(). When you don't set this explicitly IDL sets it based on the number of columns/rows in the image, which will cause it to still plot incorrectly.

-Jeff

Laura H.

unread,
Feb 12, 2021, 11:22:37 PM2/12/21
to idl-pvwave
It worked!  Somehow I had assumed it would know to use 20,20 because I'd defined an area that was 20 deg x 20 deg, not thinking about the fact that I could just as well want to plot 0.25 degree data.

Thanks for your help,

Laura

Ben C

unread,
Feb 23, 2021, 5:56:13 PM2/23/21
to idl-pvwave
This is a bug of sorts where 1 row and 1 column are always clipped, but removing GRID_UNITS='degrees' in your IMAGE call should display things normally. 

Cheers,
Ben
L3Harris Geospatial

Laura H.

unread,
Feb 23, 2021, 6:11:17 PM2/23/21
to idl-pvwave

Interesting.  Why have a grid_units key word, then?  Any chance of having this oddity mentioned in the documentation?

Thanks,

Laura

Brian McNoldy

unread,
Aug 10, 2023, 4:25:31 PM8/10/23
to idl-pvwave
I encountered this, and it's still a bug in v8.8.2.  I have data in degrees, and getting rid of grid_units made it plot nothing, so that needed to stay in.  But if I added a blank row and column at the beginning of the array (and still defined image_dimensions and image_location as expected), it worked.  This took me a day until I found this thread and started trying these tricks out.  I KNEW my array was correct, but could not figure out why the whole thing wouldn't show up on a map.

Brian

Chris Torrence

unread,
Aug 11, 2023, 4:27:08 PM8/11/23
to idl-pvwave
Sorry this bug is still plaguing everyone. Brian, do you have a (fairly) simple reproduce case? I can use some of the other code above, but it's always good to have the exact problem code, so we can make sure that the bug is truly fixed. Note that I'm not promising a fix, as I don't know what's wrong, but I can give it a try.

Cheers,
Chris

Laura H.

unread,
Aug 11, 2023, 6:42:47 PM8/11/23
to idl-pvwave
The funny thing is that this used to work, though I'd have to dig through old files to find out when.

Sangwoo Lee

unread,
Aug 17, 2023, 3:36:37 AM8/17/23
to idl-pvwave
Hi Chris! I've got a simple reproduce case for this issue.

nx = 8
ny = 6
data = HANNING(nx, ny)*30+5+RANDOMN(-1, nx, ny)
HELP, data
PRINT, MIN(data), MAX(data)
limit = [10, 110, 60, 170]

win = WINDOW(DIMENSIONS=[600, 500], /NO_TOOLBAR)
m = MAP('Geographic', LIMIT=limit, MARGIN=0.1, CLIP=0, /CURRENT)
im = IMAGE(data, RGB_TABLE=73, GRID_UNITS=2, /OVERPLOT, $
  IMAGE_LOCATION=[120, 20], IMAGE_DIMENSION=[40, 30])
mc = MAPCONTINENTS(THICK=2)
m.MapGrid.LABEL_POSITION = 0
m.MapGrid.GRID_LONGITUDE = 10
m.MapGrid.GRID_LATITUDE = 10

If you run this code, the original 8x6 data overplotted on this map appears as 7x5 data, which I guess is the same issue discussed in this thread. I hope this helps.

Sangwoo

2023년 8월 12일 토요일 오전 5시 27분 8초 UTC+9에 gort...@gmail.com님이 작성:
Reply all
Reply to author
Forward
0 new messages