Skip to content

align/concat/combine_nested implementation #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better errors
  • Loading branch information
dcherian committed Jun 12, 2025
commit 06af30a6f0a5216074f2fdccab85b713cc441caa
30 changes: 25 additions & 5 deletions src/rasterix/raster_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def _assert_transforms_are_compatible(*affines) -> None:
# TODO: offsets could be multiples
# offset should be compatible too
A1 = affines[0]
for A2 in affines[1:]:
assert A1.a == A2.a
assert A1.b == A2.b
assert A1.d == A2.d
assert A1.e == A2.e
for index, A2 in enumerate(affines[1:]):
if A1.a != A2.a or A1.b != A2.b or A1.d != A2.d or A1.e != A2.e:
raise ValueError(
f"Transform parameters are not compatible for affine 0: {A1}, and affine {index + 1} {A2}"
)


class AffineTransform(CoordinateTransform):
Expand Down Expand Up @@ -573,4 +573,24 @@ def bbox_to_affine(bbox: BoundingBox, rx, ry) -> Affine:
def as_compatible_bboxes(*indexes: RasterIndex) -> tuple[BoundingBox, ...]:
transforms = tuple(i.transform() for i in indexes)
_assert_transforms_are_compatible(*transforms)

expected_off_x = tuple(t.c + i._shape["x"] * t.a for i, t in zip(indexes, transforms))
expected_off_y = tuple(t.f + i._shape["y"] * t.d for i, t in zip(indexes, transforms))

off_x = tuple(t.c for t in transforms)
off_y = tuple(t.c for t in transforms)

if all(o == off_x[0] for o in off_x[1:]) and all(o == off_y[0] for o in off_y[1:]):
raise ValueError("Attempting to concatenate arrays with same transform along X or Y.")

if any(a != b for a, b in zip(off_x, expected_off_x)):
raise ValueError(
f"X offsets are incompatible. Provided offsets {off_x}, expected offsets: {expected_off_x}"
)

if any(a != b for a, b in zip(off_y, expected_off_y)):
raise ValueError(
f"Y offsets are incompatible. Provided offsets {off_y}, expected offsets: {expected_off_y}"
)

return tuple(i.bbox for i in indexes)
3 changes: 1 addition & 2 deletions tests/test_raster_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_sel_slice():
],
)
def test_concat_and_combine_nested_1D(transforms, concat_dim):
"""Models two side-by-side tiles in"""
"""Models two side-by-side tiles"""
crs_attrs = pyproj.CRS.from_epsg(4326).to_cf()

datasets = [
Expand Down Expand Up @@ -146,7 +146,6 @@ def test_concat_and_combine_nested_1D(transforms, concat_dim):
],
)
def test_concat_errors(transforms, concat_dim):
"""Models two side-by-side tiles in"""
crs_attrs = pyproj.CRS.from_epsg(4326).to_cf()

datasets = [
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy