Skip to content

Commit

Permalink
Merge pull request #620 from opendatacube/handle_no_mask_data
Browse files Browse the repository at this point in the history
Attempted fix for main-product/mask-product time extent mismatches.
  • Loading branch information
SpacemanPaul authored Jun 4, 2021
2 parents 96eb442 + 7c5db58 commit 11fd377
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions datacube_ows/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ def data(self, datasets_by_query, skip_corrections=False):
# datasets is an XArray DataArray of datasets grouped by time.
data = None
for pbq, datasets in datasets_by_query.items():
if data is not None and len(data.time) == 0:
# No data, so no need for masking data.
continue
measurements = pbq.products[0].lookup_measurements(pbq.bands)
fuse_func = pbq.fuse_func
if pbq.manual_merge:
Expand Down Expand Up @@ -258,6 +261,18 @@ def data(self, datasets_by_query, skip_corrections=False):
data_new_bands[band] = timed_band_data
data = data.assign(data_new_bands)
continue
elif len(qry_result.time) == 0:
# Time-aware mask product has no data, but main product does.
var = "No data vars in result"
for var in data.data_vars.variables.keys():
break
template = getattr(data, var)
new_data = numpy.ndarray(template.shape)
new_data.fill(0)
qry_result = template.copy(data=new_data)
data_new_bands = {}
for band in pbq.bands:
data_new_bands[band] = qry_result
qry_result.coords["time"] = data.coords["time"]
data = xarray.combine_by_coords([data, qry_result], join="exact")

Expand Down

0 comments on commit 11fd377

Please sign in to comment.