Repository: scalableminds/webknossos-libs

Issue:
Detect layers by looking for header.wkw
When a layer is not named `color`, `segmentation` or `prediction` it is recognized as a wkw layer. However, it should be possible to detect a layer simply by looking for a `header.wkw` file. Then we can detect arbitrary layer names.


Discussion:

Resolving patch:
diff --git a/wkcuber/export_wkw_as_tiff.py b/wkcuber/export_wkw_as_tiff.py
--- a/wkcuber/export_wkw_as_tiff.py
+++ b/wkcuber/export_wkw_as_tiff.py
@@ -130,15 +130,7 @@ def export_tiff_slice(
 ):
     (
         batch_number,
-        (
-            tiff_bbox,
-            dest_path,
-            name,
-            dataset_path,
-            tiling_size,
-            batch_size,
-            downsample,
-        ),
+        (tiff_bbox, dest_path, name, dataset_path, tiling_size, batch_size, downsample),
     ) = export_args
     tiff_bbox = tiff_bbox.copy()
     number_of_slices = min(tiff_bbox["size"][2] - batch_number * batch_size, batch_size)
diff --git a/wkcuber/metadata.py b/wkcuber/metadata.py
--- a/wkcuber/metadata.py
+++ b/wkcuber/metadata.py
@@ -12,6 +12,8 @@
 from .mag import Mag
 from typing import List
 from .utils import add_verbose_flag, setup_logging, add_scale_flag
+from pathlib import Path
+from os.path import basename, normpath
 
 
 def get_datasource_path(dataset_path):
@@ -309,13 +311,22 @@ def detect_segmentation_layer(
 
 def detect_layers(dataset_path, max_id, compute_max_id, exact_bounding_box=None):
     # Detect metadata for well-known layers (i.e., color, prediction and segmentation)
-    for layer_name in ["color", "prediction"]:
-        if path.exists(path.join(dataset_path, layer_name)):
-            yield detect_standard_layer(dataset_path, layer_name, exact_bounding_box)
+    if path.exists(path.join(dataset_path, "color")):
+        yield detect_standard_layer(dataset_path, "color", exact_bounding_box)
     if path.exists(path.join(dataset_path, "segmentation")):
         yield detect_segmentation_layer(
             dataset_path, "segmentation", max_id, compute_max_id, exact_bounding_box
         )
+    available_layer_names = set(
+        [
+            basename(normpath(Path(x).parent.parent))
+            for x in glob.glob(dataset_path + "/*/*/header.wkw")
+        ]
+    )
+    for layer_name in available_layer_names:
+        # color and segmentation are already checked explicitly to ensure downwards compatibility (some older datasets don't have the header.wkw file)
+        if layer_name not in ["color", "segmentation"]:
+            yield detect_standard_layer(dataset_path, layer_name, exact_bounding_box)
 
 
 if __name__ == "__main__":


Test patch:
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
--- a/tests/test_metadata.py
+++ b/tests/test_metadata.py
@@ -13,7 +13,7 @@
 )
 
 
-def test_element_class_convertion():
+def test_element_class_conversion():
     test_wkw_path = os.path.join("testoutput", "test_metadata")
     prediction_layer_name = "prediction"
     prediction_wkw_info = WkwDatasetInfo(
@@ -103,5 +103,5 @@ def test_mapping_detection():
 
 
 if __name__ == "__main__":
-    test_element_class_convertion()
+    test_element_class_conversion()
     test_mapping_detection()