Skip to content

Commit 139dae9

Browse files
committed
Fix xy_coords size mismatch
I don't know why I didn't use `linspace` in the first place. With `arange` there were floating-point errors that could cause `ceil` to over/under-shoot by 1. Closes #33
1 parent 172ea1c commit 139dae9

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

stackstac/prepare.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,10 @@ def to_coords(
389389
maxy + half_ypixel,
390390
)
391391

392-
# NumPy arange produces `ceil((stop - start)/step)` elements, whereas GDAL rounds (more or less).
393-
# This, combined with floating-point error, can make our coordinates off-by-one in length,
394-
# so we add/remove pixels to `maxx`, `maxy` as necessary to ensure the coordinates end up the same
395-
# size as the array.
396392
height, width = spec.shape
397-
coord_width = np.ceil((maxx - minx) / xres)
398-
extra_width = coord_width - width
399-
if extra_width:
400-
maxx -= xres * extra_width
401-
402-
coord_height = np.ceil((maxy - miny) / yres)
403-
extra_height = coord_height - height
404-
if extra_height:
405-
maxy -= yres * extra_height
406-
407393
# Wish pandas had an RangeIndex that supported floats...
408-
xs = pd.Float64Index(np.arange(minx, maxx, xres))
409-
ys = pd.Float64Index(np.arange(maxy, miny, -yres))
394+
xs = pd.Float64Index(np.linspace(minx, maxx, width, endpoint=False))
395+
ys = pd.Float64Index(np.linspace(maxy, miny, height, endpoint=False))
410396
else:
411397
height, width = spec.shape
412398
if pixel_center:

0 commit comments

Comments
 (0)