opendatacube / datacube-core

Open Data Cube analyses continental scale Earth Observation data through time
http://www.opendatacube.org
Apache License 2.0
493 stars 175 forks source link

Cannot pass `odc.geo` GeoBoxes to `dc.load` #1549

Closed robbibt closed 3 months ago

robbibt commented 4 months ago

Expected behaviour

A user may try to use an odc.geo GeoBox to load data from datacube-core. e.g.:

from odc.geo.geobox import GeoBox

gbox = GeoBox.from_bbox(
    [149.036528545, -35.384897602, 149.233835134, -35.198132594], resolution=0.002
)

ds = dc.load(
    product="ga_ls8c_ard_3",
    measurements=["nbart_red", "nbart_green", "nbart_blue"],
    time=("2019-01-10", "2019-01-15"),
    like=gbox,
    resampling="nearest",
    group_by="solar_day",
)

Actual behaviour

However, the code above fails with an AttributeError: image

To make it work correctly, the user must add .compat to the end of the odc.geo GeoBox to get out an older-style datacube GeoBox, e.g. gbox.compat:

from odc.geo.geobox import GeoBox

gbox = GeoBox.from_bbox(
    [149.036528545, -35.384897602, 149.233835134, -35.198132594], resolution=0.002
)

ds = dc.load(
    product="ga_ls8c_ard_3",
    measurements=["nbart_red", "nbart_green", "nbart_blue"],
    time=("2019-01-10", "2019-01-15"),
    like=gbox.compat,
    resampling="nearest",
    group_by="solar_day",
)

Even though our timeline for odc-geo integration isn't expected until version 1.9, it would be very helpful to support odc-geo GeoBoxes in dc.load even in version 1.8 to allow users to start writing code that integrates with odc-geo.

This could be as simple as detecting odc-geo GeoBoxes and converting them via the .compat method internally within datacube-core.

Environment information

Note: Stale issues will be automatically closed after a period of six months with no activity. To ensure critical issues are not closed, tag them with the Github pinned tag. If you are a community member and not a maintainer please escalate this issue to maintainers via GIS StackExchange or Slack.

robbibt commented 4 months ago

Interested in your thoughts @SpacemanPaul @Ariana-B @omad. Would definitely make the product team's lives easier by letting us start using odc-geo functionality before it's fully/officially integrated in version 1.9.

Given there's an existing .compat method on the odc-geo GeoBoxes, I imagine this could be as simple as just calling that method under the hood in dc.load if a user passes in an odc-geo GeoBox instead of a datacube-core one.

SpacemanPaul commented 4 months ago

Makes sense to me.