Skip to content

Replace quad_bilinear_interp with inverse distance weighting in quad_utils. #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

hkershaw-brown
Copy link
Member

@hkershaw-brown hkershaw-brown commented Jun 3, 2025

Description:

The current quad_utils_mod interpolation method (bilinear) can give out-of-bounds values for some quads.
This problem was originally reported by Nuo Chen in CICE #833 when using the QCEFF.
The CICE bilinear interpolation was replaced by inverse distance weighting in #848. This is the same code as quad utils. Note, replacing the CICE interpolation with quad utils is not done in this pull request.

There is a notebook to call dart from python in https://github.com/hkershaw-brown/DART-probe/blob/main/ice-interp.ipynb if you want to reproduce the interpolation plots (see README for dart library build).

Fixes issue

Fixes #860
Fixes #453 since no rotation needed in the IDW. See #833 for plots of rotations

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Documentation changes needed?

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.

There is no documentation for quad utils at the moment.

Tests

This is a draft at the moment.
Questions to answer:
bitwise differences for which models - who cares, it is a bug fix vs. loads of people care.

Checklist for merging

  • Updated changelog entry
  • Documentation updated
  • Update conf.py

Checklist for release

  • Merge into main
  • Create release from the main branch with appropriate tag
  • Delete feature-branch

Testing Datasets

  • Dataset needed for testing available upon request
  • Dataset download instructions included
  • No dataset needed

@hkershaw-brown
Copy link
Member Author

hkershaw-brown commented Jun 3, 2025

build everything action: https://github.com/NCAR/DART/actions/runs/15426138267 caveat GEOS (Helen are you ever going to fix this? no). edit Yes! #918

@hkershaw-brown hkershaw-brown requested review from jlaucar and Copilot June 5, 2025 18:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request replaces the quad_bilinear_interp interpolation method with an inverse distance weighting (IDW) approach to avoid out-of-bounds issues in quadrilateral interpolation. Key changes include the removal of the bilinear interpolation subroutine, addition of a new quad_idw_interp subroutine with error checking on interpolated values, and updates to build scripts to conditionally include the quad_utils_mod file for the "threed_sphere" location.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
models/utilities/quad_utils_mod.f90 Removed quad_bilinear_interp and added quad_idw_interp implementing IDW interpolation with additional error handling.
build_templates/buildfunctions.sh Updated source file list to conditionally include quad_utils_mod.f90 for the threed_sphere location.
build_templates/buildconvfunctions.sh Similar conditional inclusion of quad_utils_mod.f90 in the source list for threed_sphere.
Comments suppressed due to low confidence (1)

models/utilities/quad_utils_mod.f90:2149

  • The error handling block uses the variables 'string1', 'string2', and 'source' without any visible declarations or initializations. Please ensure these variables are declared and initialized before they are used to report the error.
if(expected_obs < minval(p) .or. expected_obs > maxval(p)) then

…n quad_utils_mod

fixes #860
Same fix as #833 #848 that was for cice model_mod only.
Removed the rotation code - see #453 - does not fix the out-of-bounds
 and is also rotating in the oppostite direction. Not used in IDW.

removed svn detritus.

Using VERTISUNDEF to get horizontal only distances. I am not sure if
this will need to be modififed for other location_mods
The converters in the repo all build succesfully without this change,
because they all use threed_sphere location_mod. However maybe there
are some converters in the wild that do not use threed_sphere.
@hkershaw-brown hkershaw-brown force-pushed the fix-quad-utils-interp branch from 6e40a5d to 3c309e8 Compare June 9, 2025 15:15
@hkershaw-brown hkershaw-brown marked this pull request as ready for review June 9, 2025 15:17
@hkershaw-brown
Copy link
Member Author

Comments suppressed due to low confidence (1)
models/utilities/quad_utils_mod.f90:2149

  • The error handling block uses the variables 'string1', 'string2', and 'source' without any visible declarations or initializations. Please ensure these variables are declared and initialized before they are used to report the error.
if(expected_obs < minval(p) .or. expected_obs > maxval(p)) then

I think you're talking about the endless svn junk

! version controlled file description for error handling, do not edit
character(len=*), parameter :: source = &
"$URL$"
character(len=*), parameter :: revision = "$Revision$"
character(len=*), parameter :: revdate = "$Date$"

@hkershaw-brown hkershaw-brown added the mom6 Modular Ocean Model label Jun 9, 2025
@hkershaw-brown
Copy link
Member Author

Model_mods currently using quad_utils:

MOM6/model_mod.f90
pangu/model_mod.f90
gitm/model_mod.f90
cam-fv/model_mod.f90
aether_lat-lon/model_mod.f90

@hkershaw-brown hkershaw-brown self-assigned this Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpolation mom6 Modular Ocean Model
Projects
None yet
Development

Successfully merging this pull request may close these issues.

quad_utils_mod interpolation method quad_util_mod rotations
1 participant