excess smoothing with smth_bath tool

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
rubash

excess smoothing with smth_bath tool

#1 Unread post by rubash »

The Matlab tool smth_bath.m smooths much more than needed because of a reversed decision statement in the main loop (4th line down). The code is:

Code: Select all

while (n < npass && max(max(r)) > rlim),
  hsmth=shapiro2(hout,order,2);
  r=rfactor(hsmth,rmask);
  ind=find(r < rlim);
  if (~isempty(ind)),
    hout(ind)=hsmth(ind);
    n=n+1;
  else
    break;
  end,
end,
The filtered cells used should be those with r > rlim. Simply reversing the inequality doesn't work because r is calculated using a forward step and ind found using r > rlim would only replace one of the two cells. What is needed is something like the following:

Code: Select all

while (n < npass && max(max(r)) > rlim),
  hsmth=shapiro2(hout,order,2);
  r=rfactor(hsmth,rmask);
  Nx = size(r)(2);
  Ny = size(r)(1);
  for i=1:Nx,
    for j=1:Ny,
      if (r(j,i) > rlim),
        if (j < Ny-2 & i < Nx-2)
          hout(j+1,i)   = hsmth(j+1,i);
          hout(j+1,i+1) = hsmth(j+1,i+1);
          hout(j  ,i)   = hsmth(j  ,i);
          hout(j  ,i+1) = hsmth(j  ,i+1);
        elseif (j < Ny-2 & i == Nx-2) % right edge
          hout(j,i) = hsmth(j,i);
          hout(j+1,i) = hsmth(j+1,i);
        elseif (j == Ny-2 && i < Nx-2) % top
          hout(j,i) = hsmth(j,i);
          hout(j,i+1) = hsmth(j,i+1);
        else %  upper right corner
          hout(j,i) = hsmth(j,i);
        endif
      endif
    end
  end
  n=n+1;
end,

mathieu

Re: excess smoothing with smth_bath tool

#2 Unread post by mathieu »

In general, I do not recommend to use the Shapiro filter.
There are two problems, even for this modified version:
---There is a termination problem, i.e. for some bathymetries the filter does not converge to the right bathymetry.
---The perturbation to the bathymetry is large.

There are some matlab scripts available from http://drobilica.irb.hr/~mathieu/Bathymetry/ for doing the bathymetry filtering.

If you want some Shapiro style method with no termination problem and smaller perturbation, then I would recommend GRID_LaplacianSelectSmooth_rx0. Otherwise, you have the Martinho-Batteen method, Mellor-Ezer-Oey method and linear programming formulations, but they are more expensive computationally.

rubash

Re: excess smoothing with smth_bath tool

#3 Unread post by rubash »

Mathieu, thanks for the code and the advice. Aside from one test run with ROMS I haven't tried Shapiro filtering myself yet. Normally I use the SLPMAX routine from POM.

My posting above concerns a bug I wanted to warn people about, not a choice of filters. It's about code that applies the filter repeatedly to every cell except most of the ones needing filtering. It succeeds because it replaces the forward cell in the cells identified by r each time it loops (while it is also busy replacing all the innocent cells with cells that are even more innocent.) The tool would over-smooth regardless of the choice of filters.

Post Reply