diff --git a/src/robofish/io/app.py b/src/robofish/io/app.py index de2b236ac65682edd038b10082db3e0481e36a52..f89674b513778f3c5e3d85b079277474e7672bba 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 e07a252cb4388e562afd749806f6e772fd5e3543..5ca9801b002dd9ab637c7222deb2807979b6d43a 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()