Skip to content

Commit

Permalink
avoid unwanted optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Ai committed Aug 21, 2024
1 parent 1065599 commit 41344f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 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@8dfd442
odc-stats[ows] @ git+https://github.com/opendatacube/odc-stats@1065599

# For ML
tflite-runtime
Expand Down
24 changes: 16 additions & 8 deletions odc/stats/plugins/lc_treelite_cultivated.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@

# pylint: disable=invalid-name
def feature_MNDWI(input_block, nbart_green, nbart_swir_1):
return ne.evaluate(
res = ne.evaluate(
"(a-b)/(a+b)",
local_dict={
"a": input_block[..., nbart_green],
"b": input_block[..., nbart_swir_1],
},
).astype("float32")
return res


def feature_BUI(input_block, nbart_swir_1, nbart_nir, nbart_red):
return ne.evaluate(
res = ne.evaluate(
"((a-b)/(a+b))-((b-c)/(b+c))",
local_dict={
"a": input_block[..., nbart_swir_1],
"b": input_block[..., nbart_nir],
"c": input_block[..., nbart_red],
},
).astype("float32")
return res


def feature_BSI(input_block, nbart_swir_1, nbart_red, nbart_nir, nbart_blue):
return ne.evaluate(
res = ne.evaluate(
"((a+b)-(c+d))/((a+b)+(c+d))",
local_dict={
"a": input_block[..., nbart_swir_1],
Expand All @@ -52,6 +54,7 @@ def feature_BSI(input_block, nbart_swir_1, nbart_red, nbart_nir, nbart_blue):
"d": input_block[..., nbart_blue],
},
).astype("float32")
return res


def feature_TCW(
Expand All @@ -63,7 +66,7 @@ def feature_TCW(
nbart_swir_1,
nbart_swir_2,
):
return ne.evaluate(
res = ne.evaluate(
"(0.0315*a+0.2021*b+0.3102*c+0.1594*d+-0.6806*e+-0.6109*f)",
local_dict={
"a": input_block[..., nbart_blue],
Expand All @@ -74,22 +77,24 @@ def feature_TCW(
"f": input_block[..., nbart_swir_2],
},
).astype("float32")
return res


def feature_NDMI(input_block, nbart_nir, nbart_swir_1):
return ne.evaluate(
res = ne.evaluate(
"(a-b)/(a+b)",
local_dict={
"a": input_block[..., nbart_nir],
"b": input_block[..., nbart_swir_1],
},
).astype("float32")
return res


def feature_AWEI_sh(
input_block, nbart_blue, nbart_green, nbart_nir, nbart_swir_1, nbart_swir_2
):
return ne.evaluate(
res = ne.evaluate(
"(a+2.5*b-1.5*(c+d)-0.25*e)",
local_dict={
"a": input_block[..., nbart_blue],
Expand All @@ -99,27 +104,30 @@ def feature_AWEI_sh(
"e": input_block[..., nbart_swir_2],
},
).astype("float32")
return res


def feature_BAEI(input_block, nbart_red, nbart_green, nbart_swir_1):
return ne.evaluate(
res = ne.evaluate(
"(a+0.3)/(b+c)",
local_dict={
"a": input_block[..., nbart_red],
"b": input_block[..., nbart_green],
"c": input_block[..., nbart_swir_1],
},
).astype("float32")
return res


def feature_NDSI(input_block, nbart_green, nbart_swir_1):
return ne.evaluate(
res = ne.evaluate(
"(a-b)/(a+b)",
local_dict={
"a": input_block[..., nbart_green],
"b": input_block[..., nbart_swir_1],
},
).astype("float32")
return res


def generate_features(input_block, bands_indices):
Expand Down

0 comments on commit 41344f6

Please sign in to comment.