From c09d209d8dd62f37e215c6bf55da4a699aaf63b3 Mon Sep 17 00:00:00 2001
From: Andi Gerken <andi.gerken@gmail.com>
Date: Fri, 18 Feb 2022 18:06:59 +0100
Subject: [PATCH] Fixed bug

---
 src/robofish/io/app.py  | 2 +-
 src/robofish/io/file.py | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/robofish/io/app.py b/src/robofish/io/app.py
index d463494..0518ded 100644
--- a/src/robofish/io/app.py
+++ b/src/robofish/io/app.py
@@ -94,8 +94,8 @@ def validate(args=None):
     error_code = 0
     for file, sf in sf_dict.items():
         filled_file = (str)(file).ljust(max_filename_width + 3)
-        file.close()
         validity, validity_message = sf.validate(strict_validate=False)
+        sf.close()
         if not validity:
             error_code = 1
         print(f"{filled_file}:{validity}\t{validity_message}")
diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py
index d5ba5f9..0637e89 100644
--- a/src/robofish/io/file.py
+++ b/src/robofish/io/file.py
@@ -752,8 +752,11 @@ class File(h5py.File):
             elif isinstance(c, list):
                 this_c = c[fish_id]
 
-            if max_timesteps is None:
-                max_timesteps = poses.shape[1] - 1
+            max_timesteps = (
+                min(max_timesteps, poses.shape[1] - 1)
+                if max_timesteps is not None
+                else poses.shape[1] - 1
+            )
             timesteps = min(max_timesteps + skip_timesteps, poses.shape[1] - 1)
             for t in range(skip_timesteps, timesteps, step_size):
                 if lw_distances:
-- 
GitLab