Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
annie-xd-wang committed Dec 18, 2024
1 parent 88b1638 commit e0c9340
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/navigate/model/data_sources/bdv_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def write(self, data: npt.ArrayLike, **kw) -> None:
if e.errno == 28:
logger.error("No disk space left on device. Closing the file.")
self.close()
raise "No disk space left on device."
raise Exception("No disk space left on device.")

self._current_frame += 1

Expand Down
19 changes: 10 additions & 9 deletions src/navigate/model/features/image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def __init__(
#: int: Minimum disk space required in bytes.
self.min_disk_space = 10 * 1024 * 1024 * 1024 # 10 GB

#: float: Time of last disk space check
self.last_disk_space_check = 0

# initialize saving
self.initialize_saving(sub_dir, image_name)

Expand All @@ -165,12 +168,14 @@ def save_image(self, frame_ids):
Index into self.model.data_buffer.
"""

last_disk_space_check = time.time()

for idx in frame_ids:
if (idx < 0) or (idx > (self.number_of_frames - 1)):
msg = f"Received invalid index {idx}. Skipping this frame."
logger.debug(f"Received invalid index: {msg}.")
continue

# Check disk space at regular intervals to prevent running out of space
if time.time() - last_disk_space_check > self.disk_space_check_interval:
if time.time() - self.last_disk_space_check > self.disk_space_check_interval:
_, _, free = shutil.disk_usage(self.save_directory)
logger.info(f"Free Disk Space: {free / 1024 / 1024 / 1024} GB")
if free < self.min_disk_space:
Expand All @@ -181,12 +186,7 @@ def save_image(self, frame_ids):
("warning", "Insufficient Disk Space. Acquisition Terminated")
)
return
last_disk_space_check = time.time()

if (idx < 0) or (idx > (self.number_of_frames - 1)):
msg = f"Received invalid index {idx}. Skipping this frame."
logger.debug(f"Received invalid index: {msg}.")
continue
self.last_disk_space_check = time.time()

# check the saving flag
if self.saving_flags:
Expand Down Expand Up @@ -308,6 +308,7 @@ def calculate_and_check_disk_space(self):
Assumes 16-bit image type, without compression."""

self.last_disk_space_check = time.time()
# Return disk usage statistics in bytes
_, _, free = shutil.disk_usage(self.save_directory)
logger.info(f"Free Disk Space: {free}")
Expand Down

0 comments on commit e0c9340

Please sign in to comment.