Skip to content

Commit 9842153

Browse files
spjuhelchahank
andauthored
Apply suggestions from code review
Co-authored-by: Chahan M. Kropf <chahan.kropf@usys.ethz.ch>
1 parent 76e237f commit 9842153

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

climada/trajectories/interpolation.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def exponential_interp_imp_mat(
150150

151151
def linear_interp_arrays(arr_start: np.ndarray, arr_end: np.ndarray) -> np.ndarray:
152152
r"""
153-
Performs linear interpolation between two NumPy arrays over their first dimension.
153+
Performs linear interpolation between two n x m NumPy arrays over their
154+
first dimension (n rows).
154155
155156
This function interpolates each metric (column) linearly across the time steps
156157
(rows), including both the start and end states.
@@ -175,6 +176,11 @@ def linear_interp_arrays(arr_start: np.ndarray, arr_end: np.ndarray) -> np.ndarr
175176
ValueError
176177
If `arr_start` and `arr_end` do not have the same shape.
177178
179+
Example
180+
--------
181+
>>> arr_start = [ [ 1, 1], [1, 2], [10, 20] ]
182+
>>> arr_end = [ [2, 2], [5, 6], [10, 30] ]
183+
>>> linear_interp_arrays(arr_start, arr_end) = [ [1, 1], [3, 4], [10, 30] ]
178184
Notes
179185
-----
180186
The interpolation is performed element-wise along the first dimension
@@ -203,8 +209,7 @@ def exponential_interp_arrays(arr_start: np.ndarray, arr_end: np.ndarray) -> np.
203209
Performs exponential interpolation between two NumPy arrays over their first dimension.
204210
205211
This function achieves an exponential-like transition by performing linear
206-
interpolation in the logarithmic space, suitable to interpolate over a dimension which has
207-
a growth factor.
212+
interpolation in the logarithmic space.
208213
209214
Parameters
210215
----------
@@ -224,6 +229,10 @@ def exponential_interp_arrays(arr_start: np.ndarray, arr_end: np.ndarray) -> np.
224229
------
225230
ValueError
226231
If `arr_start` and `arr_end` do not have the same shape.
232+
233+
See Also
234+
---------
235+
linear_interp_arrays: linear version of the interpolation.
227236
228237
Notes
229238
-----
@@ -264,11 +273,12 @@ def exponential_interp_arrays(arr_start: np.ndarray, arr_end: np.ndarray) -> np.
264273

265274
class InterpolationStrategyBase(ABC):
266275
r"""
267-
Base abstract class for defining a set of interpolation strategies.
276+
Base abstract class for defining a set of interpolation strategies for impact outputs.
268277
269278
This class serves as a blueprint for implementing specific interpolation
270-
methods (e.g., 'Linear', 'Exponential') across different impact dimensions:
271-
Exposure (matrices), Hazard, and Vulnerability (arrays/metrics).
279+
methods (e.g., 'Linear', 'Exponential') for impact outputs (impact matrices
280+
or metrics such as aai_agg, eai_exp or at_event) across the input dimentions
281+
Exposure (impact matrices only), Hazard, and Vulnerability (metrics only).
272282
273283
Attributes
274284
----------

climada/trajectories/test/test_interpolation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def test_exponential_interp_arrays_2d(self):
9595
[
9696
[1, 10, 100], # date 1 metric a,b,c
9797
[1, 10, 100], # date 2 metric a,b,c
98-
[1, 10, 100],
98+
[1, 10, 100], # date 3 metric a,b,c
9999
]
100-
) # date 3 metric a,b,c
100+
)
101101
arr_end = np.array([[2, 20, 200], [2, 20, 200], [2, 20, 200]])
102102
expected = np.array(
103103
[[1.0, 10.0, 100.0], [1.4142136, 14.142136, 141.42136], [2, 20, 200]]

0 commit comments

Comments
 (0)