Skip to content

Commit

Permalink
added fits compatibility for live viewer (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEAllen authored Dec 14, 2023
2 parents 14f2c7f + bf281b8 commit bd2510a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/release_notes/next/feature-1996-fits-compatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#1996 : Added .fits file compatibility for Live Viewer
5 changes: 2 additions & 3 deletions mantidimaging/gui/windows/live_viewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
9 changes: 7 additions & 2 deletions mantidimaging/gui/windows/live_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd2510a

Please sign in to comment.