matching 2 grids [message #47855] |
Wed, 08 March 2006 14:17  |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
Hi all,
I have 2 sets of lat/lon pairs in different grids - grid1 and grid2,
both in irregular shape and I've filled some zero numbers to make them
regular. grid2 is a subset of grid1. I want to find the coordinates of
x1,y1 in grid1 (lat1/lon1) which are closest to each of the nonzero
lat2/lon2 paris in grid2.
I made a programm with several loops, it is kind of did what I want,
but it is very slow and the boundary is not tidy. my grid1 is 600*600,
and I have 10 grid2 to process.
Is there an IDL function that I could use in this case?
Thanks,
Jenny
|
|
|
|
Re: matching 2 grids [message #47969 is a reply to message #47855] |
Thu, 09 March 2006 12:54  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
David Fanning wrote:
> I don't think this is the right approach, but I don't
> have the time to look into it at the moment. Mark is
> probably scratching his ass and getting his coffee together
> right now. He'll be with you shortly. :-)
Ta da!
Thanks for working out that MGH_MOTLEY is a script, David. To use the
Motley library you *must* add its directory to your path and you *must*
run "@MGH_MOTLEY" first.
It's MGH_EXAMPLE_LOCATE. It has 1D and 2D examples, selected by a
positional parameter called "option".
The term "index space" is one I made up (or plagiarised). Think of a 1-D
IDL array with n elements. The elements are indexed 0 to n-1. Now give
this array some values, monotonically increasing or decreasing (usually
the former) so that we can interpret the array as a 1-D grid in space.
We have a value that represents a position somewhere in the range
covered by this grid and we want to know where it is relative to the
grid. Let the grid array be x and the position we're trying to locate be
x. Let's say we find an index i such that x[i] <= xp <= x[i+1]. In fact,
let's go further and say that xp is exactly half-way between x[i] and
x[i+1]. Then I would say that xp is at position i+0.5 in the index space
of grid x.
For a 2D curvilinear grid (defined by a pair of 2D arrays) the index
space is 2D. The concept is very similar but it's a bit harder to explain.
One of the reasons "index space" is a handy concept is that it is used
by IDL's INTERPOLATE function.
To give an example of the above in terms of Motley functions:
IDL> x = mgh_range(100, 200, STRIDE=20)
IDL> print, x
100 120 140 160 180 200
IDL> xp = 133.
IDL> print, mgh_locate(x, XOUT=xp)
1.65000
--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: matching 2 grids [message #47970 is a reply to message #47855] |
Thu, 09 March 2006 09:52  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jenny writes:
> But I'm near the end of my 5-year long
> Ph.d study, I've ran out of all my patience and energy to learn new
> things now.
Humm. Could be a problem in the future. I'd try for
one of those government jobs. Global Climate Office,
for example. They understand this problem. :-)
> I'll start to learn IDL right after my defense!
Uh, huh.
>
> David, if you are there, could I ask a question about WhereToMulti?
> hope I'm on the right track toward MGH_locate2!
> I think I could use WhereToMulti as the following to convert my inputs
> to 2-D?
I don't think this is the right approach, but I don't
have the time to look into it at the moment. Mark is
probably scratching his ass and getting his coffee together
right now. He'll be with you shortly. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: matching 2 grids [message #47972 is a reply to message #47855] |
Thu, 09 March 2006 09:42  |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
Hi David,
Thanks!
I must confess I haven't learned IDL properly, so I've got penalty from
time to time for some basics. But I'm near the end of my 5-year long
Ph.d study, I've ran out of all my patience and energy to learn new
things now. However, I don't think I could live without using IDL as
long as I would stay in the remote sensing field for the rest of my
life. So don't be surprised if you'd get more silly questions about
your book in a few months - I'll start to learn IDL right after my
defense!
David, if you are there, could I ask a question about WhereToMulti?
hope I'm on the right track toward MGH_locate2!
I think I could use WhereToMulti as the following to convert my inputs
to 2-D?
xr=where(lat2 ne 0.0)
yr=where(lon2 ne 0.0)
wheretomulti, lat2, xr,col1,row2
wheretomulti, lon2,yr,col2,row2
xin=[col1,row1]
yin=[col2,row2]
Are these right? after I use xin and yin as inputs to MGH_locate2a, I
still got errors about "xin,yin need to be 2-D".
-Jenny
|
|
|
Re: matching 2 grids [message #47976 is a reply to message #47855] |
Thu, 09 March 2006 07:36  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jenny writes:
> I didn't find
> mgh_example_locate2.pro in the library.
Are you sure? What are you using to look for them?
Did you download the zip file? Did you extract *everything*
from the zip file? All the routines seem to be there.
> Are Xin and Yin in mgh_locate2
> the index of my lat2 and lon2? how could I get them? could I avoid the
> ponits of zeros in the meanwhile?
Humm. How would you know what the inputs are if you
didn't find the ... Oh, never mind.
Mark will have to help you on the inputs. I have to
admit, I'm confused, too. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|