Commit 3526d6a2 authored by Niklas Bohn's avatar Niklas Bohn
Browse files

Fixed bug in empirical line function, which caused one single remaining...


Fixed bug in empirical line function, which caused one single remaining unprocessed segmentation label.
Signed-off-by: Niklas Bohn's avatarnbohn <nbohn@gfz-potsdam.de>
parent d25b76f5
......@@ -71,7 +71,7 @@ test_sicor_s2:
- export GDAL_DATA=/root/miniconda3/envs/sicor_env/share/gdal
- export PYTHONPATH=$PYTHONPATH:/root # /root <- directory needed later
- pip install pycodestyle --upgrade
- mamba install -c conda-forge pygrib cachetools gdown scikit-learn=0.21.3
- mamba install -c conda-forge pygrib cachetools gdown scikit-learn
- make lint
- make nosetests_s2 # sentinel-2 tests are called here
- pip install sphinx_rtd_theme # Read-the-docs theme for SPHINX documentation
......
......@@ -26,7 +26,6 @@
import numpy as np
from multiprocessing import Pool
import platform
from tqdm import tqdm
from sicor.Tools.EnMAP.multiprocessing import initializer
......@@ -106,10 +105,11 @@ def empirical_line_solution(X, rdn_subset, data_l2a_seg, rows, cols, bands, segs
# about geographic or 3D locations
row_grid, col_grid = np.meshgrid(np.arange(rows), np.arange(cols))
locations = np.array([col_grid.flatten(), row_grid.flatten()]).T
locations_subset = np.zeros((segs, 2))
if land_only:
lbl = np.unique(labels)[1:]
segs = len(lbl)
locations_subset = np.zeros((segs, 2))
for ii, idx in enumerate(lbl):
locations_subset[ii, :] = locations[labels.flat == idx, :].mean(axis=0)
......@@ -122,8 +122,9 @@ def empirical_line_solution(X, rdn_subset, data_l2a_seg, rows, cols, bands, segs
unique_labels = np.arange(0, np.max(lbl) + 1 - len(missing_labels), 1)
else:
locations_subset = np.zeros((segs, 2))
for i in range(segs):
if np.count_nonzero(segs == 1) == 0:
if np.count_nonzero(segs == i) == 0:
pass
else:
locations_subset[i, :] = locations[labels.flat == i, :].mean(axis=0)
......@@ -135,7 +136,7 @@ def empirical_line_solution(X, rdn_subset, data_l2a_seg, rows, cols, bands, segs
if ii not in unique_labels:
missing_labels.append(ii)
unique_labels = np.arange(0, np.max(unique_labels) - len(missing_labels), 1)
unique_labels = np.arange(0, np.max(unique_labels) + 1 - len(missing_labels), 1)
tree = KDTree(locations_subset)
......
......@@ -147,7 +147,7 @@ def sicor_ac_enmap(enmap_l1b, options, unknowns=False, logger=None):
rows=fo_enmap.data_vnir.shape[0],
cols=fo_enmap.data_vnir.shape[1],
bands=fo_enmap.data_vnir.shape[2],
segs=labels_trans.max(),
segs=np.unique(labels_trans).shape[0],
labels=labels_trans,
land_only=fo_enmap.land_only,
processes=fo_enmap.cpu,
......@@ -160,7 +160,7 @@ def sicor_ac_enmap(enmap_l1b, options, unknowns=False, logger=None):
rows=fo_enmap.data_swir.shape[0],
cols=fo_enmap.data_swir.shape[1],
bands=fo_enmap.data_swir.shape[2],
segs=fo_enmap.segs,
segs=np.unique(fo_enmap.labels).shape[0],
labels=fo_enmap.labels,
land_only=fo_enmap.land_only,
processes=fo_enmap.cpu,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment