Skip to content

Commit

Permalink
Cleanup types in .crop method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill888 committed May 13, 2024
1 parent 61a43e6 commit 2c0390a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions odc/geo/_xr_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,21 @@ def crop(
.. seealso:: :py:meth:`odc.geo.xr.mask`
"""
meta: ODCExtension = xx.odc
sdims = meta.spatial_dims
gbox = meta.geobox

if sdims is None or gbox is None:
raise ValueError("Can't locate spatial dimensions")

if not isinstance(gbox, GeoBox):
raise ValueError("Can't crop GCPGeoBox")

# Create new geobox with pixel grid of `xx` but enclosing `poly`.
poly_geobox = xx.odc.geobox.enclosing(poly)
poly_geobox = gbox.enclosing(poly)

# Calculate ROI slices into `xx` for intersection between both geoboxes.
roi = xx.odc.geobox.overlap_roi(poly_geobox)
roi = gbox.overlap_roi(poly_geobox)

# Verify that `poly` overlaps with `xx` by checking if the returned
# ROI is empty
Expand All @@ -350,9 +360,6 @@ def crop(
)

# Crop spatial dims of `xx` using ROI
sdims = spatial_dims(xx)
if sdims is None:
raise ValueError("Can't locate spatial dimensions")
xx_cropped = xx.isel({sdims[0]: roi[0], sdims[1]: roi[1]})

# Optionally mask data outside rasterized `poly`
Expand Down

0 comments on commit 2c0390a

Please sign in to comment.