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

Home » Public Forums » archive » griddata function and countour plot
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
griddata function and countour plot [message #94278] Thu, 23 March 2017 10:18 Go to next message
kghreep21 is currently offline  kghreep21
Messages: 7
Registered: March 2017
Junior Member
Hello Idl Users,
I tried to interpolate the following scattered data using 2 -D griddata function

lat=[32.05, 30.43,29.02,25.48, 24.13,32.49, 32.47,32.06,29.40]
lon=[20.16,20.10, 21.34, 21.08, 23.18, 21.51, 22.35, 23.55, 24.32]
w=[9.80,4.95,5.20, 5.60, 5.20, 11.65, 11.75, 8.75, 7.40]
and use this gridded data to create a contour plot on the map using the following code:-
:___________________________________________________________ _____
pro test

lat=[32.05, 30.43,29.02,25.48, 24.13,32.49, 32.47,32.06,29.40]
lon=[20.16,20.10, 21.34, 21.08, 23.18, 21.51, 22.35, 23.55, 24.32]
w=[9.80,4.95,5.20, 5.60, 5.20, 11.65, 11.75, 8.75, 7.40]

scaled = BYTSCL(w, TOP = !D.TABLE_SIZE - 4) + 1B
; display the data values with respect to the color table.
FOR i = 0L, (N_ELEMENTS(Lat) - 1) DO PLOTS, Lat[i], Lon[i],$
PSYM = -1, SYMSIZE = 2., COLOR = scaled[i]

; Preprocess and sort the data.

GRID_INPUT, lat_data, lon_data, scaled, xSorted, ySorted, dataSorted

; Initialize the grid parameters.
gridSize = [51, 51]

; Use the equation of a straight line and the grid parameters to
; determine the x of the resulting grid.
slope = (MAX(xSorted) - MIN(xSorted))/(gridSize[0] - 1)
intercept = MIN(xSorted)
xGrid = (slope*FINDGEN(gridSize[0])) + intercept

; Use the equation of a straight line and the grid parameters to
; determine the y of the resulting grid.
slope = (MAX(ySorted) - MIN(ySorted))/(gridSize[1] - 1)
intercept = MIN(ySorted)
yGrid = (slope*FINDGEN(gridSize[1])) + intercept

; Grid the data with the Radial Basis Function method.
grid = GRIDDATA(xSorted, ySorted, dataSorted, $
DIMENSION = gridSize, METHOD = 'RadialBasisFunction')

; Plot Structure using Fanning subroutines
psObject = Obj_New("FSC_PSConfig")
psObject->GUI
thisDevice = !D.Name
Set_Plot, "PS"
Device, _Extra=psObject->GetKeywords(FontType=fonttype)
;?????????????????????????

TVLCT, FSC_Color(soil_colors, /Triple), 1

Erase, Color=FSC_Color('white')

map_set, /cylindrical, 0,0, limit=[19,08,38,28],/continent,/grid, $
/NoErase, Position=[0.1, 0.1, 0.8, 0.9], MLINESTYLE =0, $
MLINETHICK =2,GLINETHICK=2 ; mercator ; cylindrical

cgText,14000,5250,/device, 'Egypt', CHARSIZE=1.5,font=1,ORIENTATION=90.0
cgText, 7400,6700,/device, 'Libya', CHARSIZE=1.5,font=1,ORIENTATION=0.0
cgText, 13500,2000,/device, 'Sudan', CHARSIZE=1.5,font=1,ORIENTATION=45.0
cgText,8000,2500,/device, 'Chad', CHARSIZE=1.5,font=1,ORIENTATION=0.0
cgText, 4500,2500,/device, 'Niger', CHARSIZE=1.5,font=1,ORIENTATION=0.0
cgText,2500,5500,/device, 'Algeria', CHARSIZE=1.5,font=1,ORIENTATION=90.0
cgText, 2500,11000,/device, 'Tunisia', CHARSIZE=1.5,font=1,ORIENTATION=45.0
cgText, 6000,12000,/device, 'The Mediterranean Sea', $
CHARSIZE=1.5,font=1,ORIENTATION=0.0
cgText, 7000,400,/device, 'Longitude', CHARSIZE=1.5,font=1,ORIENTATION=0.0
cgText, 1000,5500,/device, ' Latitude', CHARSIZE=1.5,font=1,ORIENTATION=90.0

soil_colors = ['purple', 'dodger blue', 'dark green', 'lime green', $
'green yellow', 'yellow', 'hot pink', 'crimson']
SOILC = fltarr(n_elements(lat_data))
TVLCT, FSC_Color(soil_colors, /Triple), 1
soilc_colors = BytScl(soilc, Top=7) + 1B

Plots,lon, lat, PSym=4, COLOR=FSC_Color('red'), SymSize=0.45
map_continents, /coasts,/countries, color=0, /hires, /bold, linestyle=0,
background=50,thick=5

Map_Grid,/box, CHARSIZE=1.0,font=1,thick=1.5;, Color=FSC_Color('black')

CONTOUR,grid, xGrid,yGrid, /XSTYLE, /YSTYLE, /FILL, $
LEVELS = BYTSCL(INDGEN(18), TOP = !D.TABLE_SIZE - 4) + 1B, $
C_COLORS = BYTSCL(INDGEN(18), TOP = !D.TABLE_SIZE - 4) + 1B,$
TITLE = 'The Resulting Grid with Radial Basis Function', $
XTITLE = 'Lat', YTITLE = 'lon'

Device, /Close_File
Set_Plot, thisDevice
Obj_Destroy, psObject

end
:____________________________ the contour lines aren't projected on the right
map.
Can any IDL experts help me
my Best wishes
Mohamoud
Re: griddata function and countour plot [message #94279 is a reply to message #94278] Thu, 23 March 2017 15:12 Go to previous message
kghreep21 is currently offline  kghreep21
Messages: 7
Registered: March 2017
Junior Member
Dear IDL Users
I had succeeded to interpolate a scattered data using 2-D girddata, but It can't projected on the right position on the map according to the following code.
Could you please help me to correct this error.
_____________
pro t1

lat=[32.05, 30.43,29.02,25.48, 24.13,32.49, 32.47,32.06,29.40]
lon=[20.16,20.10, 21.34, 21.08, 23.18, 21.51, 22.35, 23.55, 24.32]
w=[9.80,4.95,5.20, 5.60, 5.20, 11.65, 11.75, 8.75, 7.40]

scaled = BYTSCL(w, TOP = !D.TABLE_SIZE - 4) + 1B
; display the data values with respect to the color table.
FOR i = 0L, (N_ELEMENTS(Lat) - 1) DO PLOTS, Lat[i], Lon[i],$
PSYM = -1, SYMSIZE = 2., COLOR = scaled[i]

; Preprocess and sort the data.

GRID_INPUT, lon, lat, w, xSorted, ySorted, dataSorted

; Initialize the grid parameters.
gridSize = [51, 51]

; Use the equation of a straight line and the grid parameters to
; determine the x of the resulting grid.
slope = (MAX(xSorted) - MIN(xSorted))/(gridSize[0] - 1)
intercept = MIN(xSorted)
xGrid = (slope*FINDGEN(gridSize[0])) + intercept

; Use the equation of a straight line and the grid parameters to
; determine the y of the resulting grid.
slope = (MAX(ySorted) - MIN(ySorted))/(gridSize[1] - 1)
intercept = MIN(ySorted)
yGrid = (slope*FINDGEN(gridSize[1])) + intercept

; Grid the data with the Radial Basis Function method.
grid = GRIDDATA(xSorted, ySorted, dataSorted, $
DIMENSION = gridSize, METHOD = 'RadialBasisFunction')
print, grid
nlevels =30
step = (Max(grid) - Min(grid)) / nlevels
levels = IndGen(nlevels) * step + Min(grid)
LoadCT, 33, NColors=nlevels, Bottom=1

SetDecomposedState, 0, CurrentState=currentState

Contour, grid, xgrid,ygrid, /Cell_Fill, $
Levels=levels, Background=cgColor('white'), $
Position=[0.125, 0.125, 0.95, 0.80], $
Color=cgColor('black'), XStyle=1, YStyle=1, $
C_Colors=IndGen(nlevels)+1
Contour, grid, ygrid, xgrid, /Overplot, $
Color=cgColor('black'), Levels=levels, $
C_Labels=everyOther
map_set, /cylindrical, 0,0, limit=[ceil(min(lat)-0.5)-1.,ceil(min(lon)-0.5)-1., ceil( max(lat)+0.5)+1., ceil(max(lon)+0.5)+1.],/continent, $
/NoErase, Position=[0.1, 0.1, 0.8, 0.9], MLINESTYLE =0, MLINETHICK =2,$
GLINETHICK=2
print, min(xgrid), min(ygrid), max(xgrid), max(ygrid)
print, min(lat), min(lon), max(lat), max(lon)
SetDecomposedState, currentState

cgColorbar, Range=[Min(grid),Max(grid)], $
Divisions=30, XTicklen=1, XMinor=0, $
AnnotateColor='black', NColors=30, Bottom=1, $
Position=[0.125, 0.915, 0.955, 0.95], $
Charsize=0.75
end
__________ Khaled
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Fresh new error: "% Unable to allocate memory: ensuring string length."
Next Topic: Gridding to the Surface of a Sphere

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

Current Time: Wed Oct 08 07:15:12 PDT 2025

Total time taken to generate the page: 0.00360 seconds