improver.regrid.nearest module

Nearest neighbour interpolation functions

lakes_islands(lake_island_indexes, indexes, surface_type_mask, in_latlons, out_latlons, in_classified, out_classified, vicinity)[source]

Updating source points and weighting for 4-unmatching-source-point cases - water surrounded by land or land surrounded by water. This function searches nearest 8 points to check if any matching point exists. Note that a similar function can be found in bilinear.py for bilinear regridding rather than nearest neighbour regridding.

Parameters:
  • lake_island_indexes (ndarray) – Indexes of points which are lakes/islands surrounded by mismatched surface type. These points will be processed by this function.

  • in_latlons (ndarray) – Source points’s latitude-longitudes.

  • out_latlons (ndarray) – Target points’s latitude-longitudes.

  • surface_type_mask (ndarray) – Boolean true if source point type matches target point type.

  • indexes (ndarray) – Source grid point indexes for each target grid point.

  • in_classified (ndarray) – Land/sea type for source grid points (land -> True).

  • out_classified (ndarray) – Land/sea type for target grid points (land -> True).

  • vicinity (float) – Radius of vicinity to search for a matching surface type, in metres.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • Updated indexes - source grid point number for all target grid points.

  • Updated surface_type_mask - matching info between source/target point types.

nearest_regrid(distances, indexes, in_values)[source]

Main regridding function for the nearest neighbour option.

Parameters:
  • distances (ndarray) – Distance from each target grid point to its source grid points.

  • indexes (ndarray) – Source grid point indexes for each target grid point.

  • in_values (ndarray) – Input values with spatial dimensions flattened.

Return type:

ndarray

Returns:

Regridded output values with spatial dimensions flattened.

nearest_with_mask_regrid(distances, indexes, surface_type_mask, in_latlons, out_latlons, in_classified, out_classified, vicinity)[source]

Main regridding function for the nearest distance option. some input just for handling island-like points.

Parameters:
  • distances (ndarray) – Distnace array from each target grid point to its source grid points.

  • indexes (ndarray) – Source grid point indexes for each target grid point.

  • surface_type_mask (ndarray) – Boolean true if source point type matches target point type.

  • in_latlons (ndarray) – Source points’s latitude-longitudes.

  • out_latlons (ndarray) – Target points’s latitude-longitudes.

  • in_classified (ndarray) – Land/sea type for source grid points (land -> True).

  • out_classified (ndarray) – Land/sea type for target grid points (land -> True).

  • vicinity (float) – Radius of specified searching domain, in meter.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • Updated distances - array from each target grid point to its source grid points.

  • Updated indexes - source grid point number for all target grid points.

update_nearest_points(points_with_mismatches, in_latlons, out_latlons, indexes, distances, surface_type_mask, in_classified, out_classified)[source]

Update nearest source points and distances/surface_type to take into account surface type of nearby points.

Parameters:
  • points_with_mismatches (ndarray) – Selected target points which will use Inverse Distance Weighting (idw) approach. These points will be processed by this function.

  • in_latlons (ndarray) – Source points’s latitude-longitudes.

  • out_latlons (ndarray) – Target points’s latitude-longitudes.

  • indexes (ndarray) – Source grid point indexes for each target grid point.

  • distances (ndarray) – Distance from each target grid point to its source grid points.

  • surface_type_mask (ndarray) – Boolean true if source point type matches target point type.

  • in_classified (ndarray) – Land/sea type for source grid points (land -> True).

  • out_classified (ndarray) – Land/sea type for target grid points (land -> True).

Return type:

Tuple[ndarray, ndarray, ndarray]

Returns:

  • Updated indexes - source grid point number for all target grid points.

  • Updated distances - array from each target grid point to its source grid points.

  • Updated surface_type_mask - matching info between source/target point types.