@@ -4,13 +4,30 @@ cimport numpy as np
44
55cdef calculate_weights(np.ndarray[np.float64_t, ndim= 2 ] src_point,
66 np.ndarray[np.float64_t, ndim= 2 ] tgt_point):
7- # src_min src_max
8- # |----------| : Source
9- # tgt_min tgt_max
10- # |------------| : Target
11- # |----------| : Delta (src_max - src_min)
12- # |----| : Overlap (between src & tgt)
13- # weight = overlap / delta
7+ """
8+ Calculate weights for a given point.
9+
10+ The following visually illustrates the calculation::
11+
12+ src_min src_max
13+ |----------| : Source
14+ tgt_min tgt_max
15+ |------------| : Target
16+ |----------| : Delta (src_max - src_min)
17+ |----| : Overlap (between src & tgt)
18+ weight = overlap / delta
19+
20+ Parameters
21+ ----------
22+ src_point (2d double array) - Source point (at a specific location).
23+ tgt_point (2d double array) - Target point (at a specific location).
24+
25+ Returns
26+ -------
27+ 2d double array - Weights corresponding to shape [src_point.shape[0],
28+ tgt_point.shape[0]].
29+
30+ """
1431 cdef Py_ssize_t src_ind, tgt_ind
1532 cdef np.float64_t delta, weight
1633 cdef np.ndarray[np.float64_t, ndim= 2 ] weights
@@ -31,6 +48,28 @@ cdef calculate_weights(np.ndarray[np.float64_t, ndim=2] src_point,
3148cdef apply_weights(np.ndarray[np.float64_t, ndim= 3 ] src_point,
3249 np.ndarray[np.float64_t, ndim= 3 ] tgt_point,
3350 np.ndarray[np.float64_t, ndim= 3 ] src_data):
51+ """
52+ Perform conservative interpolation.
53+
54+ Conservation interpolation on of a dataset between a provided source
55+ coordinate and a target coordinate.
56+
57+ Parameters
58+ ----------
59+ src_points (3d double array) - Source coordinate, taking the form
60+ [axis_interpolation, z_varying, 2].
61+ tgt_points (3d double array) - Target coordinate, taking the form
62+ [axis_interpolation, z_varying, 2].
63+ src_data (3d double array) - The source data, the phenonenon data to be
64+ interpolated from ``src_points`` to ``tgt_points``. Taking the form
65+ [broadcasting_dims, axis_interpolation, z_varying].
66+
67+ Returns
68+ -------
69+ 3d double array - Interpolated result over target levels (``tgt_points``).
70+ Taking the form [broadcasting_dims, axis_interpolation, z_varying].
71+
72+ """
3473 cdef Py_ssize_t ind
3574 cdef np.ndarray[np.float64_t, ndim= 3 ] results
3675 cdef np.ndarray[np.float64_t, ndim= 2 ] weights
@@ -50,6 +89,29 @@ cdef apply_weights(np.ndarray[np.float64_t, ndim=3] src_point,
5089
5190
5291def conservative_interpolation (src_points , tgt_points , src_data ):
92+ """
93+ Perform conservative interpolation.
94+
95+ Conservation interpolation of a dataset between a provided source
96+ coordinate and a target coordinate. All inputs are recast to 64-bit float
97+ arrays before calculation.
98+
99+ Parameters
100+ ----------
101+ src_points (3d array) - Source coordinate, taking the form
102+ [axis_interpolation, z_varying, 2].
103+ tgt_points (3d array) - Target coordinate, taking the form
104+ [axis_interpolation, z_varying, 2].
105+ src_data (3d array) - The source data, the phenonenon data to be
106+ interpolated from ``src_points`` to ``tgt_points``. Taking the form
107+ [broadcasting_dims, axis_interpolation, z_varying].
108+
109+ Returns
110+ -------
111+ 3d double array - Interpolated result over target levels (``tgt_points``).
112+ Taking the form [broadcasting_dims, axis_interpolation, z_varying].
113+
114+ """
53115 return apply_weights(src_points.astype(' float64' ),
54116 tgt_points.astype(' float64' ),
55117 src_data.astype(' float64' ))
0 commit comments