diff --git a/src/python/librir/video_io/IRMovie.py b/src/python/librir/video_io/IRMovie.py index f93d540..aab70a3 100644 --- a/src/python/librir/video_io/IRMovie.py +++ b/src/python/librir/video_io/IRMovie.py @@ -4,7 +4,7 @@ import os import tempfile from pathlib import Path -from typing import List, Union +from typing import List, Optional, Union import numpy as np import pandas as pd @@ -145,6 +145,7 @@ def __init__(self, handle): self._frame_attributes_d = {} self._file_attributes = FileAttributes(self.filename) self._file_attributes.attributes = get_global_attributes(self.handle) + self._registration_file = None self.calibration = "DL" @@ -227,13 +228,13 @@ def close(self): self.__tempfile__ = None @property - def registration_file(self) -> Path: + def registration_file(self) -> Optional[Path]: """ Returns the registration file name for this camera, and tries to download it from ARCADE if not already done. """ - - return self._registration_file + if self._registration_file: + return self._registration_file @registration_file.setter def registration_file(self, value) -> None: @@ -249,7 +250,7 @@ def registration(self) -> bool: """ Returns True is video registration is activated, false otherwise """ - if self._registration_file.exists(): + if self._registration_file is not None and self._registration_file.exists(): return motion_correction_enabled(self.handle) return False diff --git a/tests/python/test_IRMovie.py b/tests/python/test_IRMovie.py index 6f6ca93..7cf97b3 100644 --- a/tests/python/test_IRMovie.py +++ b/tests/python/test_IRMovie.py @@ -18,6 +18,17 @@ def test_IRMovie_with_filename_as_input(filename): assert mov.filename == filename +@pytest.mark.instantiation +def test_IRMovie_with_handle_as_input(array): + with IRMovie.from_numpy_array(array) as movie: + new_mov = IRMovie(movie.handle) + assert new_mov.handle == movie.handle + new_mov.__tempfile__ = None + movie.__tempfile__ = None + with pytest.raises(RuntimeError): + IRMovie(0) + + @pytest.mark.instantiation def test_IRMovie_instantiation_with_2D_numpy_array(valid_2D_array): mov = IRMovie.from_numpy_array(valid_2D_array) diff --git a/tests/python/test_registration.py b/tests/python/test_registration.py index 7f55429..d334c92 100644 --- a/tests/python/test_registration.py +++ b/tests/python/test_registration.py @@ -113,6 +113,7 @@ def test_set_registration_file_to_IRMovie( movie_with_polygon_drawn: IRMovie, reg: MaskedRegistratorECC ): images = movie_with_polygon_drawn.data + assert not movie_with_polygon_drawn.registration # Set the first image reg.start(images[0]) @@ -124,6 +125,8 @@ def test_set_registration_file_to_IRMovie( reg.to_reg_file(reg_file) movie_with_polygon_drawn.registration_file = reg_file movie_with_polygon_drawn[0] + assert movie_with_polygon_drawn.registration + os.unlink(reg_file)