Skip to content

Commit

Permalink
naive attempt at lazy load
Browse files Browse the repository at this point in the history
  • Loading branch information
uchchwhash committed Feb 19, 2018
1 parent fcc01fc commit db2a874
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion datacube/virtual/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def load(self, index, **query):
""" Mimic `datacube.Datacube.load`. """
datasets = self.find_datasets(index, **query)
raster = self.build_raster(datasets, **query)
data = self.fetch_data(raster)
observations = [self.fetch_data(observation)
for _, observation in raster.split(dim='time')]
data = xarray.concat(observations, dim='time')
return data


Expand Down Expand Up @@ -118,6 +120,15 @@ def filter(self, predicate):
return RasterRecipe(self.grouped_dataset_pile[mask.grouped_dataset_pile],
self.geobox, self.output_measurements)

def split(self, dim='time'):
# this is slightly different from Tile.split
pile = self.grouped_dataset_pile

(length,) = pile[dim].shape
for i in range(length):
yield i, RasterRecipe(pile.isel(**{dim: slice(i, i + 1)}),
self.geobox, self.output_measurements)


class BasicProduct(VirtualProduct):
""" A product already in the datacube. """
Expand Down

0 comments on commit db2a874

Please sign in to comment.