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

Home » Public Forums » archive » Re: Anisotropic smoothing operations
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: Anisotropic smoothing operations [message #24831] Thu, 26 April 2001 15:31
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
Craig Markwardt wrote:

>
> Question by an idiot:

You are decidedly not an idiot. You must have meant 'for' not 'by'.

> couldn't you use KRIG2D/TRIANGULATE/TRIGRID for
> this? They're designed to take irregular points to a regular grid and
> filling in the gaps.
>
Yes and no. This is my same old question about gridding data that a ship
collected along a 300km long straight line. The ship stopped every 10-20km
and dropped a thermometer into the water, measuring temperature (and other
things) every 0.5m.

KRIG2D: I would love to use this, but (a) it is very slow for more than
300ish data points and (b) I really don't know how to set the input parameters
so they have a physical meaning.

TRIGRID: This is what we have been using... because the temperature casts are
different lengths the triangulation introduces interpolation where it is
unreasonable to expect any, thus we have to introduce ad hoc masking. This is
identical to the problem Liam encountered recently using MODIS data. In
general terms, this method works (when we mask) for measurements of fields
that have soft and sharp gradients (temperature, salinity) but not so well for
spikes and discontinuities (pigments, plankton cells per unit volume, doughnut
crumbs per unit volume.)

A while back, when I called the newsgroup-hotline for help, quite a number of
nice ideas were suggested. We are simply exploring some other techniques.
Liam provided two different approaches: inverse distance weighting and region
growing (that is the one we are trying now.) You had suggested coming up
with a response function that 'follows' each cast line downward. We haven't
tried that yet

We have seen nice results with the region growing (repeated smoothing) method,
except that the smoothing window must be square. In the water column, vertical
gradients are sharped than horizontal ones; hence the desire to using a
rectangualr smoothing window. I thought, ever the optimistic programmer,
that I would just slip the CONVOL function in the place of SMOOTH. Bonk.

Actually, Jaco, hit on something, the counter (counts the number times a
cell/pixel has been sampled) holds the key. FIRST, start with the entire grid
as ZERO rather than the user defined MISSING value. At the end of the
sprinkle/smooth iterations, simply examine the counter cells that hold '0',
these will be filled with the USER defined MISSING value.

Something like the following is pretty much what the code that Liam sent me
does (except it uses SMOOTH instead of CONVOL). I would add the missing check
at the end.


grid = FltArr(nx,ny)
count = fltarr(nx,ny)
kernal = replicate(1.0, winX, winY)
scale = total(kernal)

For i = 0, n_iterations-1 Do Begin
;sprinkle
grid[dataX, dataY] = dataZ
count[dataX, dataY] = count[DataX, dataY] + 1.0

;smooth
grid = CONVOL(grid, kernal, scale, /edge_truncate)
count = CONVOL(count, kernal, scale, /edge_truncate)

EndFor

;check for missing values
A = where(count eq 0.0, missing_count)
If missing_count GT 0 Then Grid[A] = missing

Thanks,

Ben
--
Ben Tupper
248 Lower Round Pond Road
POB 106
Bristol, ME 04539

Tel: (207) 563-1048
Email: PemaquidRiver@tidewater.net
Re: Anisotropic smoothing operations [message #24833 is a reply to message #24831] Thu, 26 April 2001 11:41 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Ben Tupper <pemaquidriver@tidewater.net> writes:
...
>
> That's a good idea. I'm not sure how to implement it in my situation.
>
> I am using a routine for building a 2d grid from scattered data.
> The grid is initialized with a user defined MISSING value (in my
> case, NAN.) The data is sprinkled over the grid then smoothed with
> the moving boxcar. This sprinkle/smooth sequence is repeated a
> number of times. Using SMOOTH, the NANs are replaced by (real)
> smoothed values as the influence of the scattered data values grows
> outward. It is possible (likely) that there will be NANs remaining
> on the grid after the sprinkle/smooth iterations have been
> completed. These areas will be in the regions of the grid where the
> original data values are sparse. That is the effect I would like to
> achieve.

Question by an idiot: couldn't you use KRIG2D/TRIANGULATE/TRIGRID for
this? They're designed to take irregular points to a regular grid and
filling in the gaps.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Anisotropic smoothing operations [message #24835 is a reply to message #24833] Thu, 26 April 2001 10:15 Go to previous message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
Jaco van Gorkom wrote:

>> ...
>> Is there a way to make CONVOL treat missing data as SMOOTH does?
>
> What I do is set all NaN values in the input array to zero, do the smoothing with CONVOL, and divide
> the result by a similarly smoothed version of the original FINITE(InputArray). Where this division
> is one by zero, the output element should be NaN, which you might want to set it to by hand to avoid
> the arithmetic error thing. If you want to bother.
>

Hello,


That's a good idea. I'm not sure how to implement it in my situation.

I am using a routine for building a 2d grid from scattered data. The grid is initialized with a user
defined MISSING value (in my case, NAN.) The data is sprinkled over the grid then smoothed with the
moving boxcar. This sprinkle/smooth sequence is repeated a number of times. Using SMOOTH, the NANs
are replaced by (real) smoothed values as the influence of the scattered data values grows outward. It
is possible (likely) that there will be NANs remaining on the grid after the sprinkle/smooth iterations
have been completed. These areas will be in the regions of the grid where the original data values are
sparse. That is the effect I would like to achieve.


Thanks,

Ben


--
Ben Tupper
248 Lower Round Pond Road
POB 106
Bristol, ME 04539

Tel: (207) 563-1048
Email: PemaquidRiver@tidewater.net
Re: Anisotropic smoothing operations [message #24843 is a reply to message #24835] Thu, 26 April 2001 03:25 Go to previous message
Jaco van Gorkom is currently offline  Jaco van Gorkom
Messages: 97
Registered: November 2000
Member
Ben Tupper wrote:
> How can I smooth a 2d image with a rectangular (rather than square)
> smoothing window?

Your post presents the answer rather completely already, with demo code and all. Like you, I use
CONVOL for this. I have been wanting to write up a general routine, allowing for fractional
smoothing window widths, circular/elliptical smoothing windows, etc., but I never really got round
to it. I must have all the elements spread somewhere through my codes by now, though. I might post
it in future.

> ...
> Is there a way to make CONVOL treat missing data as SMOOTH does?

What I do is set all NaN values in the input array to zero, do the smoothing with CONVOL, and divide
the result by a similarly smoothed version of the original FINITE(InputArray). Where this division
is one by zero, the output element should be NaN, which you might want to set it to by hand to avoid
the arithmetic error thing. If you want to bother.

Cheers,
Jaco

----------------
Jaco van Gorkom e-mail: gorkom@rijnh.nl
FOM-Instituut voor Plasmafysica "Rijnhuizen", The Netherlands
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Regridding.
Next Topic: Re: sec : U Re: MPI_Plot Was: Something else

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

Current Time: Wed Oct 08 13:36:07 PDT 2025

Total time taken to generate the page: 0.00764 seconds