Skip to content

Commit

Permalink
combine dask ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Ai committed Aug 22, 2024
1 parent a9bdd82 commit f1f2771
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ odc-dscache>=0.2.3
odc-stac @ git+https://github.com/opendatacube/odc-stac@69bdf64

# odc-stac is in PyPI
odc-stats[ows] @ git+https://github.com/opendatacube/odc-stats@d7307d9
odc-stats[ows] @ git+https://github.com/opendatacube/odc-stats@a9bdd82

# For ML
tflite-runtime
Expand Down
23 changes: 8 additions & 15 deletions odc/stats/plugins/lc_treelite_cultivated.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def generate_features(input_block, bands_indices):
return output_block


def cultivated_predict(input_block, bands_indices):
feature_block = generate_features(input_block, bands_indices)
cc = mask_and_predict(feature_block, ptype="categorical", nodata=NODATA)
return cc


class StatsCultivatedClass(StatsMLTree):
NAME = "ga_ls_cultivated"
SHORT_NAME = NAME
Expand All @@ -240,23 +246,10 @@ def measurements(self) -> Tuple[str, ...]:

def predict(self, input_array):
bands_indices = dict(zip(self.input_bands, np.arange(len(self.input_bands))))
input_features = da.map_blocks(
generate_features,
cc = da.map_blocks(
cultivated_predict,
input_array,
bands_indices,
chunks=(
input_array.chunks[0],
input_array.chunks[1],
15 + len(bands_indices) - bands_indices["bcdev"] - 1,
),
dtype="float32",
name="generate_features",
)
cc = da.map_blocks(
mask_and_predict,
input_features,
ptype="categorical",
nodata=NODATA,
drop_axis=-1,
dtype="float32",
name="cultivated_predict",
Expand Down

0 comments on commit f1f2771

Please sign in to comment.