Skip to content
Snippets Groups Projects
Commit a8bf24f8 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Rewriting results for categorical bands

parent 49deb748
No related branches found
No related tags found
No related merge requests found
...@@ -175,6 +175,7 @@ class GeoTIFFService: ...@@ -175,6 +175,7 @@ class GeoTIFFService:
and non-categorical data, producing different statistical measures accordingly. and non-categorical data, producing different statistical measures accordingly.
For categorical data, it computes statistics for each band separately, treating each band as a different category. For categorical data, it computes statistics for each band separately, treating each band as a different category.
For non-categorical data, it computes standard statistical measures for each band.
Args: Args:
combined_raster_data (numpy.ndarray): The combined raster data from all relevant tiles. combined_raster_data (numpy.ndarray): The combined raster data from all relevant tiles.
...@@ -194,6 +195,9 @@ class GeoTIFFService: ...@@ -194,6 +195,9 @@ class GeoTIFFService:
masked_band_data = band_data * polygon_mask if num_bands > 1 else band_data * polygon_mask.squeeze() masked_band_data = band_data * polygon_mask if num_bands > 1 else band_data * polygon_mask.squeeze()
if categorical: if categorical:
# Ignore no-data value (assumed to be 0)
masked_band_data = masked_band_data[masked_band_data != 0]
# Compute categorical statistics for each band # Compute categorical statistics for each band
unique, counts = np.unique(masked_band_data, return_counts=True) unique, counts = np.unique(masked_band_data, return_counts=True)
stats_result[f'band_{band}'] = dict(zip(unique.tolist(), counts.tolist())) stats_result[f'band_{band}'] = dict(zip(unique.tolist(), counts.tolist()))
...@@ -214,6 +218,7 @@ class GeoTIFFService: ...@@ -214,6 +218,7 @@ class GeoTIFFService:
@staticmethod @staticmethod
def compute_entropy(x): def compute_entropy(x):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment