diff --git a/docs/release_notes/next/feature-1996-fits-compatibility b/docs/release_notes/next/feature-1996-fits-compatibility new file mode 100644 index 00000000000..d77ae6675c9 --- /dev/null +++ b/docs/release_notes/next/feature-1996-fits-compatibility @@ -0,0 +1 @@ +#1996 : Added .fits file compatibility for Live Viewer diff --git a/mantidimaging/gui/windows/live_viewer/model.py b/mantidimaging/gui/windows/live_viewer/model.py index 4a89dcf4ae8..0e6ee23d960 100644 --- a/mantidimaging/gui/windows/live_viewer/model.py +++ b/mantidimaging/gui/windows/live_viewer/model.py @@ -259,9 +259,8 @@ def _is_image_file(file_name: str) -> bool: :param file_name: name of file :return: True if file is an image file """ - image_extensions = ['.tif', '.tiff'] - file_names = any(file_name.lower().endswith(ext) for ext in image_extensions) - return file_names + image_extensions = ('tif', 'tiff', 'fits') + return file_name.rpartition(".")[2].lower() in image_extensions def remove_path(self): """ diff --git a/mantidimaging/gui/windows/live_viewer/presenter.py b/mantidimaging/gui/windows/live_viewer/presenter.py index bd28b87ee0a..f6b9168b214 100644 --- a/mantidimaging/gui/windows/live_viewer/presenter.py +++ b/mantidimaging/gui/windows/live_viewer/presenter.py @@ -8,6 +8,7 @@ from imagecodecs._deflate import DeflateError from tifffile import tifffile, TiffFileError +from astropy.io import fits from mantidimaging.gui.mvp_base import BasePresenter from mantidimaging.gui.windows.live_viewer.model import LiveViewerWindowModel, Image_Data @@ -77,8 +78,12 @@ def select_image(self, index: int) -> None: def load_and_display_image(self, image_path: Path): try: - with tifffile.TiffFile(image_path) as tif: - image_data = tif.asarray() + if image_path.suffix.lower() in [".tif", ".tiff"]: + with tifffile.TiffFile(image_path) as tif: + image_data = tif.asarray() + elif image_path.suffix.lower() == ".fits": + with fits.open(image_path.__str__()) as fit: + image_data = fit[0].data except (IOError, KeyError, ValueError, TiffFileError, DeflateError) as error: message = f"{type(error).__name__} reading image: {image_path}: {error}" logger.error(message)