Skip to content

Commit e279904

Browse files
committed
Skip pyproj Transformer in chunk worker when Numba handles transform (#1045)
For supported CRS pairs, the chunk worker now tries the Numba fast path BEFORE creating a pyproj.Transformer. If Numba succeeds (which it does for all 10+ supported projections), the Transformer is never created, saving ~15ms of pyproj setup per chunk. Before: 2 Transformer.from_crs calls per reproject (grid + chunk) After: 1 call (grid only, ~500 points for boundary estimation) The grid computation still uses pyproj for boundary transforms since it's only ~500 points and runs once. The per-pixel transform (millions of points) is handled entirely by Numba.
1 parent 7c499df commit e279904

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

xrspatial/reproject/__init__.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,27 @@ def _reproject_chunk_numpy(
174174
src_crs = pyproj.CRS.from_wkt(src_wkt)
175175
tgt_crs = pyproj.CRS.from_wkt(tgt_wkt)
176176

177-
# Build inverse transformer: target -> source
178-
transformer = pyproj.Transformer.from_crs(
179-
tgt_crs, src_crs, always_xy=True
180-
)
177+
# Try Numba fast path first (avoids creating pyproj Transformer)
178+
numba_result = None
179+
try:
180+
from ._projections import try_numba_transform
181+
numba_result = try_numba_transform(
182+
src_crs, tgt_crs, chunk_bounds_tuple, chunk_shape,
183+
)
184+
except (ImportError, ModuleNotFoundError):
185+
pass
181186

182-
# Source CRS coordinates for each output pixel
183-
src_y, src_x = _transform_coords(
184-
transformer, chunk_bounds_tuple, chunk_shape, transform_precision,
185-
src_crs=src_crs, tgt_crs=tgt_crs,
186-
)
187+
if numba_result is not None:
188+
src_y, src_x = numba_result
189+
else:
190+
# Fallback: create pyproj Transformer (expensive)
191+
transformer = pyproj.Transformer.from_crs(
192+
tgt_crs, src_crs, always_xy=True
193+
)
194+
src_y, src_x = _transform_coords(
195+
transformer, chunk_bounds_tuple, chunk_shape, transform_precision,
196+
src_crs=src_crs, tgt_crs=tgt_crs,
197+
)
187198

188199
# Convert source CRS coordinates to source pixel coordinates
189200
src_left, src_bottom, src_right, src_top = source_bounds_tuple

0 commit comments

Comments
 (0)