Skip to content

Commit

Permalink
Fix binary map calc for maps with list of crop labels
Browse files Browse the repository at this point in the history
  • Loading branch information
hannah-rae committed Feb 5, 2024
1 parent 3982b09 commit 1f3c68c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 101 deletions.
176 changes: 81 additions & 95 deletions maps/Rwanda_2019/intercomparison.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/compare_covermaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,26 @@ def get_binary_image(self, aoi, projection="EPSG:4326"):
"""
Creates a binary image for a covermap in given country.
"""
binary_image = (
image = (
self.ee_asset.mosaic().clip(aoi).reproject(crs=projection, scale=self.resolution)
)

# Convert the image to binary classes: 1 (crop), 0 (noncrop)
if self.crop_labels is None:
binary_image = binary_image.gte(self.probability)
binary_image = image.gte(self.probability)

# Check if crop_labels are an ordered list
elif len(self.crop_labels) > 2 and self.crop_labels == list(
range(self.crop_labels[0], self.crop_labels[-1] + 1)
):
binary_image = binary_image.gte(self.crop_labels[0]).And(
binary_image.lte(self.crop_labels[-1])
binary_image = image.gte(self.crop_labels[0]).And(
image.lte(self.crop_labels[-1])
)
else:
binary_image = binary_image.eq(self.crop_labels[0])
binary_image = image.eq(self.crop_labels[0])
if len(self.crop_labels) > 1:
for crop_value in self.crop_labels[1:]:
binary_image = binary_image.Or(binary_image.eq(crop_value))
binary_image = binary_image.Or(image.eq(crop_value))

return binary_image.rename("crop")

Expand Down

0 comments on commit 1f3c68c

Please sign in to comment.