|
11 | 11 | import numpy as np |
12 | 12 | import odc.geo.xr |
13 | 13 | import xarray as xr |
14 | | -from datacube.utils.geometry import Geometry as Geometry_datacube18 |
15 | | -from datacube.utils.masking import mask_invalid_data |
16 | 14 | from dea_tools.coastal import glint_angle |
17 | 15 | from eo_tides.stats import tide_stats |
18 | 16 | from eodatasets3 import DatasetAssembler, serialise |
@@ -116,8 +114,13 @@ def extract_geobox( |
116 | 114 | the CRS, resolution, shape and extent of the study area). |
117 | 115 |
|
118 | 116 | """ |
119 | | - # List of valid input geometry types (from `odc-geo` or `datacube-core`) |
120 | | - GEOM_TYPES = (odc.geo.geom.Geometry, Geometry_datacube18) |
| 117 | + # List of valid input geometry types (from `odc-geo` or `datacube`). |
| 118 | + # If `datacube` is not installed, only support `odc-geo` geometries |
| 119 | + try: |
| 120 | + from datacube.utils.geometry import Geometry as Geometry_datacube18 |
| 121 | + GEOM_TYPES = (odc.geo.geom.Geometry, Geometry_datacube18) |
| 122 | + except ImportError: |
| 123 | + GEOM_TYPES = (odc.geo.geom.Geometry) |
121 | 124 |
|
122 | 125 | # Either `study_area` or `geom` must be provided |
123 | 126 | if study_area is None and geom is None: |
@@ -253,6 +256,19 @@ def load_data( |
253 | 256 | to generate ODC lineage metadata for DEA Intertidal) |
254 | 257 |
|
255 | 258 | """ |
| 259 | + |
| 260 | + # Attempt to import datacube and raise an error if not available |
| 261 | + try: |
| 262 | + from datacube.utils.masking import mask_invalid_data |
| 263 | + except ImportError as e: |
| 264 | + msg = ( |
| 265 | + "The `load_data` function requires `datacube` to be installed. " |
| 266 | + "Please consider loading data with `odc-stac` instead, or install " |
| 267 | + "DEA Intertidal with the `[datacube]` extra, e.g.: `pip install " |
| 268 | + "dea-intertidal[datacube]`" |
| 269 | + ) |
| 270 | + raise ImportError(msg) from e |
| 271 | + |
256 | 272 | # Set spectral bands to load |
257 | 273 | s2_spectral_bands = [ |
258 | 274 | "nbart_blue", |
|
0 commit comments