Skip to content

Commit 0831ba2

Browse files
alastair-gemmelllbdreyer
authored andcommitted
Make PointInCell regridding scheme public (#2732) (#3390)
* Move PointInCell class and associated classes and methods from experiemental to analysis. WIP - Still need to fix tests. * Move PointInCell related tests from experiemental to analysis * Fix broken PointInCell test, and move it from analysis/regrid to analysis * Add whatsnew file * Fix path in failing tests * Update copyright file header * Minor PR tweaks in response to review comments
1 parent cd76a67 commit 0831ba2

File tree

6 files changed

+528
-487
lines changed

6 files changed

+528
-487
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* :class:`iris.experimental.regrid.PointInCell` moved to
2+
:class:`iris.analysis.PointInCell` to make this regridding scheme public

lib/iris/analysis/__init__.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from iris.analysis._area_weighted import AreaWeightedRegridder
6767
from iris.analysis._interpolation import (EXTRAPOLATION_MODES,
6868
RectilinearInterpolator)
69-
from iris.analysis._regrid import RectilinearRegridder
69+
from iris.analysis._regrid import RectilinearRegridder, CurvilinearRegridder
7070
import iris.coords
7171
from iris.exceptions import LazyAggregatorError
7272
import iris._lazy_data
@@ -2560,3 +2560,67 @@ def regridder(self, src_cube, target_grid):
25602560
from iris.analysis.trajectory import \
25612561
UnstructuredNearestNeigbourRegridder
25622562
return UnstructuredNearestNeigbourRegridder(src_cube, target_grid)
2563+
2564+
2565+
class PointInCell(object):
2566+
"""
2567+
This class describes the point-in-cell regridding scheme for use
2568+
typically with :meth:`iris.cube.Cube.regrid()`.
2569+
2570+
The PointInCell regridder can regrid data from a source grid of any
2571+
dimensionality and in any coordinate system.
2572+
The location of each source point is specified by X and Y coordinates
2573+
mapped over the same cube dimensions, aka "grid dimensions" : the grid may
2574+
have any dimensionality. The X and Y coordinates must also have the same,
2575+
defined coord_system.
2576+
The weights, if specified, must have the same shape as the X and Y
2577+
coordinates.
2578+
The output grid can be any 'normal' XY grid, specified by *separate* X
2579+
and Y coordinates : That is, X and Y have two different cube dimensions.
2580+
The output X and Y coordinates must also have a common, specified
2581+
coord_system.
2582+
2583+
"""
2584+
def __init__(self, weights=None):
2585+
"""
2586+
Point-in-cell regridding scheme suitable for regridding over one
2587+
or more orthogonal coordinates.
2588+
2589+
Optional Args:
2590+
2591+
* weights:
2592+
A :class:`numpy.ndarray` instance that defines the weights
2593+
for the grid cells of the source grid. Must have the same shape
2594+
as the data of the source grid.
2595+
If unspecified, equal weighting is assumed.
2596+
2597+
"""
2598+
self.weights = weights
2599+
2600+
def regridder(self, src_grid, target_grid):
2601+
"""
2602+
Creates a point-in-cell regridder to perform regridding from the
2603+
source grid to the target grid.
2604+
2605+
Typically you should use :meth:`iris.cube.Cube.regrid` for
2606+
regridding a cube. There are, however, some situations when
2607+
constructing your own regridder is preferable. These are detailed in
2608+
the :ref:`user guide <caching_a_regridder>`.
2609+
2610+
Args:
2611+
2612+
* src_grid:
2613+
The :class:`~iris.cube.Cube` defining the source grid.
2614+
* target_grid:
2615+
The :class:`~iris.cube.Cube` defining the target grid.
2616+
2617+
Returns:
2618+
A callable with the interface:
2619+
2620+
`callable(cube)`
2621+
2622+
where `cube` is a cube with the same grid as `src_grid`
2623+
that is to be regridded to the `target_grid`.
2624+
2625+
"""
2626+
return CurvilinearRegridder(src_grid, target_grid, self.weights)

0 commit comments

Comments
 (0)