From cb9656dce45c25ad529a5ca78c39fc556ac27b89 Mon Sep 17 00:00:00 2001
From: Andi <andi.gerken@gmail.com>
Date: Tue, 1 Nov 2022 16:02:22 +0100
Subject: [PATCH] Fixed bug in update_ids

---
 src/robofish/io/app.py  | 14 +++++++-------
 src/robofish/io/file.py |  4 +++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/robofish/io/app.py b/src/robofish/io/app.py
index de2b236..f89674b 100644
--- a/src/robofish/io/app.py
+++ b/src/robofish/io/app.py
@@ -350,13 +350,13 @@ def update_individual_ids(args=None):
                         assert n_fish == len(
                             f.entities
                         ), f"Number of fish in file {file} is not the same as in the previous file."
-
-                    if video is None:
-                        video = f.attrs["video"]
-                    else:
-                        assert (
-                            video == f.attrs["video"]
-                        ), f"Video in file {file} is not the same as in the previous file."
+                    if "video" in f.attrs:
+                        if video is None and "video" in f.attrs:
+                            video = f.attrs["video"]
+                        else:
+                            assert (
+                                video == f.attrs["video"]
+                            ), f"Video in file {file} is not the same as in the previous file."
 
                     for e, entity in enumerate(f.entities):
                         entity.attrs["individual_id"] = running_individual_id + e
diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py
index e07a252..5ca9801 100644
--- a/src/robofish/io/file.py
+++ b/src/robofish/io/file.py
@@ -79,6 +79,7 @@ class File(h5py.File):
         calendar_time_points: Iterable = None,
         open_copy: bool = False,
         validate_poses_hash: bool = True,
+        calculate_data_on_close: bool = True,
     ):
         """Create a new RoboFish Track Format object.
 
@@ -147,6 +148,7 @@ class File(h5py.File):
 
         self.path = path
         self.validate_when_saving = validate_when_saving
+        self.calculate_data_on_close = calculate_data_on_close
 
         if open_copy:
             assert (
@@ -275,7 +277,7 @@ class File(h5py.File):
         super().__exit__(type, value, traceback)
 
     def close(self):
-        if self.mode != "r":
+        if self.mode != "r" and self.calculate_data_on_close:
             self.update_calculated_data()
         super().close()
 
-- 
GitLab