Grid spatial search index

Summary

This MR improves nearest-cell search and nearest-neighbor regridding for large and irregular grids, and cleans up the grid helper/module structure introduced along the way.

It includes:

  • an exact and batched nearest-active-cell search path
  • a reusable KD-tree spatial index for Cartesian and spherical coordinates
  • a dedicated nearest_regridder_t for arbitrary nearest-neighbor remapping
    • target-mask derivation based on source-cell containment
  • a refactor of grid-independent helpers into mo_grid_helper
  • a new shared mo_grid_constants module
  • API cleanup/documentation for the helper module
  • a NetCDF nearest-neighbor example and new regression coverage

Main changes

  • accelerate exact grid_t%closest_cell_id for regular grids and add batched exact lookup support
  • add reusable spatial_index_t in mo_spatial_index for exact nearest-neighbor search in Cartesian and spherical space
  • add grid_t%build_spatial_index for grid-backed index construction
  • add nearest_regridder_t in mo_grid_scaler for arbitrary source/target nearest-neighbor remapping
  • add optional derive_target_mask to the nearest regridder, now based on source-cell containment rather than nearest masked source centers
  • add grid_t%in_cell(i,j,x,y,aux) for regular and aux-grid containment checks
  • add 04_nc_nearest.f90 and accompanying NetCDF test files for nearest-neighbor regridding
  • move grid-independent helpers, data_t, and NetCDF helper routines into mo_grid_helper
  • restore legacy mo_grid compatibility exports for data_t, mask_from_var, and data_from_var
  • introduce mo_grid_constants as the shared home for grid selector constants
  • shorten mo_grid_helper public helper names by dropping the grid_ prefix and add Doxygen \brief plus inline dummy-argument docs throughout the module

API / compatibility notes

  • mo_grid keeps the compatibility-facing API for data_t, mask_from_var, and data_from_var
  • mo_grid_helper helper names were intentionally cleaned up and now use shorter names such as value_in_closed_interval, shift_longitude_near_query, quad_contains_point, append_candidate_id, and update_best_metric
  • nearest_regridder_t is additive and does not change existing scaler_t behavior
  • mo_grid_helper remains the implementation home for stateless helpers; mo_grid keeps grid semantics and TBPs

Tests

  • extend test_mo_grid for exact nearest lookup, wide-grid behavior, spherical wrap handling, in_cell, helper TBPs, and spatial-index-backed grid lookup
  • extend test_mo_grid_scaler for nearest regridding, mixed Cartesian/spherical cases, and derived target masks
  • add test_mo_spatial_index
  • add NetCDF fixtures for nearest-neighbor example/test coverage
Edited by Sebastian Müller

Merge request reports

Loading