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

Home » Public Forums » archive » Re: grid plots
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: grid plots [message #41969] Thu, 09 December 2004 12:06
Andrew Loughe is currently offline  Andrew Loughe
Messages: 9
Registered: October 1998
Junior Member
Martin,

What is so irregular about your data on the gaussian grid that
you cannot use contour with /cell_fill? From my understanding
of a gaussian grid, the longitudes are quite regular, and the
latitudes can be easily computed, thus providing x and y vectors
for the contour routine.

-Andy

== Please delete OMIT from my return address ==



Martin wrote:
> Hello everyone,
>
> I've been trying to find a way of doing this for ages, but my head is
> sore after banging it against my computer screen!
>
> I have an irregularly gridded dataset (gaussian grid) and I want to be
> able to 1) interpolate it onto a regular grid and 2) plot the data so
> that each grid square is coloured depending on the value within each
> square.
>
> I have a problem with 2) in that I can't find any IDL routines that do
> this. Does anyone happen to know how to go about this at all? I'd be
> grateful for a any suggestions you might have.
>
> Many thanks
>
> Martin
>
Re: grid plots [message #41986 is a reply to message #41969] Thu, 09 December 2004 07:33 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Martin writes:

>
> I have a problem with 2) in that I can't find any IDL routines that do
> this. Does anyone happen to know how to go about this at all? I'd be
> grateful for a any suggestions you might have.

Here is something I just knocked out, called ColorGrid.
It grids an irregular grid, each grid rectangle set
equal to the value of the grid at that location.

Cheers,

David

;*********************************************************** ************
PRO ColorGrid

; Create example data.
x = RandomU(-3L, 20) * 20
x = x[Sort(x)]
y = Indgen(20)
data = BytScl(Dist(20))

; Load colors
LoadCT, 5

; Decomposed color.
IF (!D.Flags AND 256) NE 0 THEN $
Device, Decomposed=0, Get_Decomposed=theState

; Set up the coordinate system.
Plot, x, y, /NoData, XStyle=5, YStyle=5

; Draw polygons.
FOR j=0,N_Elements(x)-2 DO BEGIN
FOR k=0,N_Elements(y)-2 DO BEGIN
Polyfill, [x[j], x[j], x[j+1], x[j+1], x[j]], $
[y[k], y[k+1], y[k+1], y[k], y[k]], $
Color=data[j,k], /Data
ENDFOR
ENDFOR

; Redraw plot.
Plot, x, y, /NoData, /NoErase, XStyle=1, YStyle=1

; Draw grid.
FOR j=1,N_Elements(x)-1 DO $
PLOTS, [x[j], x[j]], [!Y.CRange[0], !Y.CRange[1]]
FOR j=1,N_Elements(y)-1 DO $
PLOTS, [!X.CRange[0], !X.CRange[1]], [y[j], y[j]]

; Clean-up.
IF (!D.Flags AND 256) NE 0 THEN $
Device, Decomposed=theState

END
;*********************************************************** ************

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: grid plots [message #41988 is a reply to message #41986] Thu, 09 December 2004 07:28 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
Kenneth Bowman wrote:
> In article <1102591840.222724.104440@f14g2000cwb.googlegroups.com>,
> "Martin" <m.doyle@uea.ac.uk> wrote:
>
>
>> Hello everyone,
>>
>> I've been trying to find a way of doing this for ages, but my head is
>> sore after banging it against my computer screen!
>>
>> I have an irregularly gridded dataset (gaussian grid) and I want to be
>> able to 1) interpolate it onto a regular grid and 2) plot the data so
>> that each grid square is coloured depending on the value within each
>> square.
>>
>> I have a problem with 2) in that I can't find any IDL routines that do
>> this. Does anyone happen to know how to go about this at all? I'd be
>> grateful for a any suggestions you might have.
>
>
> There are two ways to do this that come to mind.
>
> One is to use POLYFILL to draw a polygon for each grid cell with the
> desired color. This is probably not the best way, as the PS device only
> supports 256 colors for line graphics, and it may look ugly on some map
> projections (e.g., when grid cells are not rectangles).
>
> The other way is to create an image, but not interpolate the data:
>
> MAP_SET, /HAMMER, LIMIT=limit, /ISOTROPIC, /NOBORDER
>
> data = DIST(15)
> bilinear = 0
> proj = MAP_IMAGE(data, i0, j0, ni, nj, $
> COMPRESS=1, BILINEAR=bilinear, $
> LATMIN=-90.0, LONMIN=0.0, LATMAX=90.0, LONMAX=360.0)
>
> image = BYTSCL(proj)
> IF (!D.NAME EQ 'PS') THEN $
> TV, image, i0, j0, XSIZE=ni, YSIZE=nj $
> ELSE $
> TV, image, i0, j0
>
> MAP_CONTINENTS
> MAP_GRID, GLINESTYLE=0
>
>
> Change bilinear to 1 to see the effects of interpolating. You can do
> something more complicated than a simple BYTSCL to define the colors for
> your data.
>
> Ken Bowman

Or, if the data sits on a nice rectangular grid, you could just tv a rebinned
version of the array over a plot which establishes your coordinates
system, like this:


;input data
im=dist(10,10)
xrange=[-2.,2]
yrange=[-5.,5]

;establish coordinates
plot,[0,0],[0,0],/nodata,/xstyle,/ystyle,xrange=xrange,yrang e=yrange

;rebin the data array to the right size
res=convert_coord(xrange,yrange,/data,/to_device)
xsize=round(res[0,1]-res[0,0])
ysize=round(res[1,1]-res[1,0])
im2=congrid(im,xsize,ysize,/center)

;plot the image
tv,bytscl(im2),-2,-5,/data,xsize=xsize,ysize=ysize

;overplot of the axis (since the tickmarks were covered by the image)
plot,[0,0],[0,0],/nodata,/xstyle,/ystyle,xrange=xrange,yrang e=yrange,/noerase


This is fast, but works just for device with pixels...

Cheers,
Paolo

--
____________________________________________________________ ________

Paolo Grigis
ETHZ - Institute of Astronomy email: pgrigis@astro.phys.ethz.ch
Scheuchzerstrasse 7
ETH Zentrum phone: ++41 1 632 42 20
8092 Zurich fax : ++41 1 632 12 05
Switzerland http://www.astro.phys.ethz.ch/
____________________________________________________________ ________
Re: grid plots [message #41989 is a reply to message #41988] Thu, 09 December 2004 06:46 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <1102591840.222724.104440@f14g2000cwb.googlegroups.com>,
"Martin" <m.doyle@uea.ac.uk> wrote:

> Hello everyone,
>
> I've been trying to find a way of doing this for ages, but my head is
> sore after banging it against my computer screen!
>
> I have an irregularly gridded dataset (gaussian grid) and I want to be
> able to 1) interpolate it onto a regular grid and 2) plot the data so
> that each grid square is coloured depending on the value within each
> square.
>
> I have a problem with 2) in that I can't find any IDL routines that do
> this. Does anyone happen to know how to go about this at all? I'd be
> grateful for a any suggestions you might have.

There are two ways to do this that come to mind.

One is to use POLYFILL to draw a polygon for each grid cell with the
desired color. This is probably not the best way, as the PS device only
supports 256 colors for line graphics, and it may look ugly on some map
projections (e.g., when grid cells are not rectangles).

The other way is to create an image, but not interpolate the data:

MAP_SET, /HAMMER, LIMIT=limit, /ISOTROPIC, /NOBORDER

data = DIST(15)
bilinear = 0
proj = MAP_IMAGE(data, i0, j0, ni, nj, $
COMPRESS=1, BILINEAR=bilinear, $
LATMIN=-90.0, LONMIN=0.0, LATMAX=90.0, LONMAX=360.0)

image = BYTSCL(proj)
IF (!D.NAME EQ 'PS') THEN $
TV, image, i0, j0, XSIZE=ni, YSIZE=nj $
ELSE $
TV, image, i0, j0

MAP_CONTINENTS
MAP_GRID, GLINESTYLE=0


Change bilinear to 1 to see the effects of interpolating. You can do
something more complicated than a simple BYTSCL to define the colors for
your data.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: To PVM or not to PVM
Next Topic: Convolution of two equally sized arrays

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

Current Time: Wed Oct 08 14:01:29 PDT 2025

Total time taken to generate the page: 0.00805 seconds