Skip to content

Commit

Permalink
Add destructor for ImageMosaic to close h5 file
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Mar 7, 2024
1 parent 6712b3d commit ea021ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions brainglobe_stitch/image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def __init__(self, directory: Path):
self.tiles[0].resolution_pyramid
)

def __del__(self):
if self.h5_file is not None:
self.h5_file.close()

def load_mesospim_directory(self) -> None:
"""
Load the mesoSPIM directory and its data into the ImageMosaic.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_unit/test_image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def image_mosaic(naive_bdv_directory):
os.remove(naive_bdv_directory / "test_data_bdv_tile_config.txt")
image_mosaic = ImageMosaic(naive_bdv_directory)

return image_mosaic
yield image_mosaic

del image_mosaic


def test_image_mosaic_init(image_mosaic, naive_bdv_directory):
Expand All @@ -24,3 +26,16 @@ def test_image_mosaic_init(image_mosaic, naive_bdv_directory):
image_mosaic.h5_path
== naive_bdv_directory / "test_data_original_bdv.h5"
)
assert (
image_mosaic.meta_path
== naive_bdv_directory / "test_data_bdv.h5_meta.txt"
)
assert image_mosaic.h5_file is not None
assert len(image_mosaic.channel_names) == 2
assert len(image_mosaic.tiles) == 8
assert len(image_mosaic.tile_names) == 8
assert image_mosaic.x_y_resolution == 4.08
assert image_mosaic.z_resolution == 5.0
assert image_mosaic.num_channels == 2
assert len(image_mosaic.intensity_adjusted) == 5
assert len(image_mosaic.overlaps_interpolated) == 5

0 comments on commit ea021ea

Please sign in to comment.