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_tfor 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_constantsmodule - API cleanup/documentation for the helper module
- a NetCDF nearest-neighbor example and new regression coverage
Main changes
- accelerate exact
grid_t%closest_cell_idfor regular grids and add batched exact lookup support - add reusable
spatial_index_tinmo_spatial_indexfor exact nearest-neighbor search in Cartesian and spherical space - add
grid_t%build_spatial_indexfor grid-backed index construction - add
nearest_regridder_tinmo_grid_scalerfor arbitrary source/target nearest-neighbor remapping - add optional
derive_target_maskto 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.f90and accompanying NetCDF test files for nearest-neighbor regridding - move grid-independent helpers,
data_t, and NetCDF helper routines intomo_grid_helper - restore legacy
mo_gridcompatibility exports fordata_t,mask_from_var, anddata_from_var - introduce
mo_grid_constantsas the shared home for grid selector constants - shorten
mo_grid_helperpublic helper names by dropping thegrid_prefix and add Doxygen\briefplus inline dummy-argument docs throughout the module
API / compatibility notes
-
mo_gridkeeps the compatibility-facing API fordata_t,mask_from_var, anddata_from_var -
mo_grid_helperhelper names were intentionally cleaned up and now use shorter names such asvalue_in_closed_interval,shift_longitude_near_query,quad_contains_point,append_candidate_id, andupdate_best_metric -
nearest_regridder_tis additive and does not change existingscaler_tbehavior -
mo_grid_helperremains the implementation home for stateless helpers;mo_gridkeeps grid semantics and TBPs
Tests
- extend
test_mo_gridfor exact nearest lookup, wide-grid behavior, spherical wrap handling,in_cell, helper TBPs, and spatial-index-backed grid lookup - extend
test_mo_grid_scalerfor 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