From c01faac1e19ef669fa1da4f9e074cf3327d2e3f2 Mon Sep 17 00:00:00 2001 From: Melissari1997 Date: Mon, 15 Jun 2026 17:56:59 +0200 Subject: [PATCH 1/2] Remove redundant np.empty_like allocation in contour coordinate transform (#3351) --- xrspatial/contour.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xrspatial/contour.py b/xrspatial/contour.py index 325583acb..821278b72 100644 --- a/xrspatial/contour.py +++ b/xrspatial/contour.py @@ -789,9 +789,10 @@ def contours( transformed = [] for level, coords in results: - out = np.empty_like(coords) - out[:, 0] = np.interp(coords[:, 0], y_idx, y_coords) - out[:, 1] = np.interp(coords[:, 1], x_idx, x_coords) + out = np.column_stack([ + np.interp(coords[:, 0], y_idx, y_coords), + np.interp(coords[:, 1], x_idx, x_coords), + ]) transformed.append((level, out)) results = transformed From 91a892fbad3be71c65047ea92acf5d87f0b403bf Mon Sep 17 00:00:00 2001 From: Melissari1997 Date: Mon, 15 Jun 2026 18:01:43 +0200 Subject: [PATCH 2/2] Use in-place mutation of coords to reduce peak memory in contour transform (#3351) --- xrspatial/contour.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xrspatial/contour.py b/xrspatial/contour.py index 821278b72..d78a2178b 100644 --- a/xrspatial/contour.py +++ b/xrspatial/contour.py @@ -789,11 +789,9 @@ def contours( transformed = [] for level, coords in results: - out = np.column_stack([ - np.interp(coords[:, 0], y_idx, y_coords), - np.interp(coords[:, 1], x_idx, x_coords), - ]) - transformed.append((level, out)) + coords[:, 0] = np.interp(coords[:, 0], y_idx, y_coords) + coords[:, 1] = np.interp(coords[:, 1], x_idx, x_coords) + transformed.append((level, coords)) results = transformed if return_type == "numpy":