David (losiento@peromefrienaspam.com) writes:
> I'm desperately trying to draw contour lines inside continental boundaries
> only (I have irregularly gridded precipitation data). I have test several
> 'brute force' methods (as creating a mask of 1 over land and 0 over seas)
> but none seems to work properly.
>
> Is there any easy (as any esoteric keyword unknown to me) method to do that?
No esoteric keywords, unfortunately. :-(
But here is a modified example from my web page that uses
a mask to only draw the portion of the contours that are
over land:
************************************************************ ***
PRO EXAMPLE
; Pick a seed, so you see what I see. Create data.
seed = -1L
lat = RANDOMU(seed, 40) * (24./1.0) + 24
lon = RANDOMU(seed, 40) * 40.0/1.0 - 112
data = RANDOMU(seed, 40) * 1000
; Colors for plot.
LOADCT, 0
TVLCT, [255, 0], [255, 255], [0,0], 1
thisDevice = !D.Name
Set_Plot, 'Z'
Device, Set_Resolution=[800, 600]
; Set up the map projection of the Eastern US.
MAP_SET, 15, -87, 0, LIMIT=[24,-115,49,-67], $
/CONTINENTS, /USA, /MERCATOR, Position=[0.1,0.1,.9,.9]
; Plot the random data locations.
PLOTS, lon, lat, PSYM=4, COLOR=2
; Grid the irregularly spaced data.
gridData= SPH_SCAT(lon, lat, data, $
BOUNDS=[-115., 24., -67., 49.], GS=[0.5,0.5], BOUT=bout)
; Calculate xlon and ylat vectors corresponding to gridded data.
s = SIZE(gridData)
xlon = FINDGEN(s(1))*((bout(2) - bout(0))/(s(1)-1)) + bout(0)
ylat = FINDGEN(s(2))*((bout(3) - bout(1))/(s(2)-1)) + bout(1)
; Put the contours on the map.
CONTOUR, gridData, xlon, ylat, /OVERPLOT, NLEVELS=20, C_COLOR=1
map = TVRD()
; Now draw the mask.
ERASE
MAP_SET, 15, -87, 0, LIMIT=[24,-115,49,-67], $
/MERCATOR, Position=[0.1,0.1,.9,.9]
Map_Continents, /FILL, /USA, /HIRES, /CONTINENTS
mask = TVRD()
; Display both the upclipped and clipped contours.
Set_Plot, thisDevice
Window, XSize=800, YSize=600, Title='Unclipped contours'
TV, map
Window, 1, XSize=800, YSize=600, Title='Clipped contours'
screen = Where(mask EQ 0)
map[screen] = 0
TV, map
END
************************************************************ *******
It seems to do a reasonably good job.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|