From 441de54dea6970f7ae613f7bf59075f3a1c0295e Mon Sep 17 00:00:00 2001
From: Constantin Pape <constantin.pape@iwr.uni-heidelberg.de>
Date: Fri, 16 Aug 2019 15:47:11 +0200
Subject: [PATCH] Fix some path issues and error handling in bdv script

---
 data/0.3.0/images/prospr-6dpf-1-whole-ref-SPM.xml        | 2 +-
 data/0.3.0/misc/bdv_server.txt                           | 3 +++
 .../sbem-6dpf-1-whole-segmented-ariande-neuropil.xml     | 2 +-
 .../sbem-6dpf-1-whole-segmented-cats-neuropil.xml        | 2 +-
 scripts/files/bdv_server.py                              | 9 ++++++---
 scripts/files/copy_helper.py                             | 1 +
 6 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/data/0.3.0/images/prospr-6dpf-1-whole-ref-SPM.xml b/data/0.3.0/images/prospr-6dpf-1-whole-ref-SPM.xml
index 37d5e72..889b518 100644
--- a/data/0.3.0/images/prospr-6dpf-1-whole-ref-SPM.xml
+++ b/data/0.3.0/images/prospr-6dpf-1-whole-ref-SPM.xml
@@ -2,7 +2,7 @@
   <BasePath type="relative">.</BasePath>
   <SequenceDescription>
     <ImageLoader format="bdv.hdf5">
-      <hdf5 type="relative">../rawdata/prospr-6dpf-1-whole-ref-SPM.h5</hdf5>
+        <hdf5 type="relative">../../rawdata/prospr-6dpf-1-whole-ref-SPM.h5</hdf5>
     </ImageLoader>
     <ViewSetups>
       <ViewSetup>
diff --git a/data/0.3.0/misc/bdv_server.txt b/data/0.3.0/misc/bdv_server.txt
index acc8bfb..7b5323e 100644
--- a/data/0.3.0/misc/bdv_server.txt
+++ b/data/0.3.0/misc/bdv_server.txt
@@ -207,9 +207,12 @@ prospr-6dpf-1-whole-segmented-RestOfAnimal	../images/prospr-6dpf-1-whole-segment
 prospr-6dpf-1-whole-segmented-Stomodeum	../images/prospr-6dpf-1-whole-segmented-Stomodeum.xml
 prospr-6dpf-1-whole-segmented-VNC	../images/prospr-6dpf-1-whole-segmented-VNC.xml
 prospr-6dpf-1-whole-six12-MED	../images/prospr-6dpf-1-whole-six12-MED.xml
+prospr-6dpf-1-whole-ref-SPM	../images/prospr-6dpf-1-whole-ref-SPM.xml
 sbem-6dpf-1-whole-segmented-chromatin-labels	../segmentations/sbem-6dpf-1-whole-segmented-chromatin-labels.xml
 sbem-6dpf-1-whole-segmented-tissue-labels	../segmentations/sbem-6dpf-1-whole-segmented-tissue-labels.xml
 sbem-6dpf-1-whole-segmented-muscle	../segmentations/sbem-6dpf-1-whole-segmented-muscle.xml
 sbem-6dpf-1-whole-segmented-cells-labels	../segmentations/sbem-6dpf-1-whole-segmented-cells-labels.xml
 sbem-6dpf-1-whole-segmented-nuclei-labels	../segmentations/sbem-6dpf-1-whole-segmented-nuclei-labels.xml
 sbem-6dpf-1-whole-segmented-cilia-labels	../segmentations/sbem-6dpf-1-whole-segmented-cilia-labels.xml
+sbem-6dpf-1-whole-segmented-ariande-neuropil	../segmentations/sbem-6dpf-1-whole-segmented-ariande-neuropil.xml
+sbem-6dpf-1-whole-segmented-cats-neuropil	../segmentations/sbem-6dpf-1-whole-segmented-cats-neuropil.xml
diff --git a/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-ariande-neuropil.xml b/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-ariande-neuropil.xml
index 2bab095..5f99490 100644
--- a/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-ariande-neuropil.xml
+++ b/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-ariande-neuropil.xml
@@ -2,7 +2,7 @@
   <BasePath type="relative">.</BasePath>
   <SequenceDescription>
     <ImageLoader format="bdv.hdf5">
-      <hdf5 type="relative">../rawdata/sbem-6dpf-1-whole-segmented-ariande-neuropil.h5</hdf5>
+        <hdf5 type="relative">../../rawdata/sbem-6dpf-1-whole-segmented-ariande-neuropil.h5</hdf5>
     </ImageLoader>
     <ViewSetups>
       <ViewSetup>
diff --git a/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-cats-neuropil.xml b/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-cats-neuropil.xml
index 008437a..270aa82 100644
--- a/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-cats-neuropil.xml
+++ b/data/0.3.0/segmentations/sbem-6dpf-1-whole-segmented-cats-neuropil.xml
@@ -2,7 +2,7 @@
   <BasePath type="relative">.</BasePath>
   <SequenceDescription>
     <ImageLoader format="bdv.hdf5">
-      <hdf5 type="relative">../rawdata/sbem-6dpf-1-whole-segmented-cats-neuropil.h5</hdf5>
+        <hdf5 type="relative">../../rawdata/sbem-6dpf-1-whole-segmented-cats-neuropil.h5</hdf5>
     </ImageLoader>
     <ViewSetups>
       <ViewSetup>
diff --git a/scripts/files/bdv_server.py b/scripts/files/bdv_server.py
index 39eb1b0..df40515 100644
--- a/scripts/files/bdv_server.py
+++ b/scripts/files/bdv_server.py
@@ -9,11 +9,12 @@ def add_to_bdv_config(name, path, bdv_config, relative_paths, ref_dir):
     h5path = get_h5_path_from_xml(path, return_absolute_path=True)
     if not os.path.exists(h5path):
         msg = 'Path to h5-file in xml does not exist - %s, %s' % (path, h5path)
-        return RuntimeError(msg)
+        raise RuntimeError(msg)
 
     if relative_paths:
         path = os.path.relpath(path, ref_dir)
     bdv_config[name] = path
+    return bdv_config
 
 
 def make_bdv_server_file(folder, out_path, relative_paths=True):
@@ -29,13 +30,15 @@ def make_bdv_server_file(folder, out_path, relative_paths=True):
         if name in privates:
             continue
         path = os.path.join(folder, 'images', '%s.xml' % name)
-        add_to_bdv_config(name, path, bdv_config, relative_paths, ref_dir)
+        bdv_config = add_to_bdv_config(name, path, bdv_config,
+                                       relative_paths, ref_dir)
 
     for name in seg_names:
         if name in privates:
             continue
         path = os.path.join(folder, 'segmentations', '%s.xml' % name)
-        add_to_bdv_config(name, path, bdv_config, relative_paths, ref_dir)
+        bdv_config = add_to_bdv_config(name, path, bdv_config,
+                                       relative_paths, ref_dir)
 
     with open(out_path, 'w') as f:
         for name, path in bdv_config.items():
diff --git a/scripts/files/copy_helper.py b/scripts/files/copy_helper.py
index db30de4..f9fba57 100644
--- a/scripts/files/copy_helper.py
+++ b/scripts/files/copy_helper.py
@@ -4,6 +4,7 @@ from .xml_utils import copy_xml_with_newpath, get_h5_path_from_xml
 from .sources import get_image_names, get_segmentation_names, get_segmentations
 
 
+# TODO double check this
 def copy_file(xml_in, xml_out):
     h5path = get_h5_path_from_xml(xml_in, return_absolute_path=True)
     xml_dir = os.path.split(xml_out)[0]
-- 
GitLab