Skip to content

Fix error in setting max half-width in node search#6547

Merged
PaulWessel merged 3 commits intomasterfrom
node-search-fix
Apr 10, 2022
Merged

Fix error in setting max half-width in node search#6547
PaulWessel merged 3 commits intomasterfrom
node-search-fix

Conversation

@PaulWessel
Copy link
Member

When we need to access all nodes inside a given search radius (as we do in grdfilter, nearneighbor, grdmask etc), we first determine limits on the number of rows and columns away from the search center. For geographic data this also means we consider the change in longitudinal distance with latitude. All this works fine. However, because for high latitudes (even ±90) we may divide by cos(lat) and hence we had a "safety valve" that clipped the upper limit of how many columns we may want to search to either side of a node to n_columns/2. This is an error: If you are at the far left column and have a search radius that equals or exceeds the longitude range then you want all the columns to be inside, hence the upper limit must be n_columns.

No tests affected but I ran into this with a grdseamount research case where I only used a small region to view a portion of a seamount whose radius exceeded half the width and things got oddly clipped in longitude but not in latitude...

uff

When we need to access all nodes inside a search radius, we first determine limits on the number of rows and columns away from the center.  For geographic data this also means we consider the change in longitudinal distance with latitude.  All this works fine.  However, we had a "safety valve" that set the upper limit of how many columns we may want to search to either side of a node to n_columns/2.  This is an error: If you are at the far left column and have a search radius that equals or exceeds the longitude range then you want all the columns to be inside, hence the upper limit must be n_columns.
No tests affected but I ran into this with a grdseamount  research case where I only used a small region to view a portion of a seamount whose radius exceeded half the width and things got oddly clipped...
@PaulWessel PaulWessel added the bug Something isn't working label Apr 10, 2022
@PaulWessel PaulWessel added this to the 6.4.0 milestone Apr 10, 2022
@PaulWessel PaulWessel requested review from joa-quim and seisman April 10, 2022 13:04
@PaulWessel PaulWessel self-assigned this Apr 10, 2022
@PaulWessel
Copy link
Member Author

Also a good example of a problem that does take a bit of testing and debugging to figure out, and in the end a single line of code is at fault (and have been so for years).

Anso no point letting d_row exceed n_rows since it may add to allocation burden elsewhere.  And the limit on x is also true for Cartesian of course.
@PaulWessel PaulWessel requested review from Esteban82 and anbj April 10, 2022 13:35
@PaulWessel
Copy link
Member Author

Just note after that I wrote the summary on top I realized we can improve matters further:

  • The upper limit of n_columns also applies to the Cartesian case
  • A similar limit of n_rows should also apply to the y-direction

Without these we might occasionally request too much memory for a filter, so might as well impose these limits. Again, no change to any tests.

@PaulWessel
Copy link
Member Author

I guess it is Easter Sunday and only godless Norwegians are working. I will review this myself...

@PaulWessel PaulWessel merged commit 1b618df into master Apr 10, 2022
@PaulWessel PaulWessel deleted the node-search-fix branch April 10, 2022 16:30
@joa-quim
Copy link
Member

I guess it is Easter Sunday

That's next Sunday. Today is the day when we go chase for wild orchids.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants