Skip to content

Commit

Permalink
2397 fits support (#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymeigh2 authored Jan 7, 2025
2 parents 9278674 + 6ae0879 commit 406b43a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/release_notes/next/fix-2397-fix-fits_file_support
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#2397: Fix FITS file support for drag and drop functionality within Mantid Imaging. This fix also resolves FITS file support when launching Mantid Imaging via the CLI with the `--path` optional argument.
4 changes: 3 additions & 1 deletion mantidimaging/core/io/loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def _fitsread(filename: Path | str) -> np.ndarray:
raise RuntimeError(f"Could not load at least one FITS image/table file from: {filename}")

# get the image data
return image[0].data
image_data = image[0].data
image.close(filename)
return image_data


def _imread(filename: Path | str) -> np.ndarray:
Expand Down
16 changes: 11 additions & 5 deletions mantidimaging/core/io/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@
log = getLogger(__name__)

DEFAULT_IO_FILE_FORMAT = 'tif'
NEXUS_PROCESSED_DATA_PATH = "processed-data"
NEXUS_PROCESSED_DATA_PATH = 'processed-data'

THRESHOLD_180 = np.radians(1)


def find_first_file_that_is_possibly_a_sample(file_path: str) -> str | None:
# Grab all .tif or .tiff files
possible_files = glob.glob(os.path.join(file_path, "**/*.tif*"), recursive=True)

"""
Finds the first file that is possibly a tif, .tiff, .fit or .fits sample file.
If files are found, the files are sorted and filtered based on name and returned.
"""
file_types = ['tif', 'tiff', 'fit', 'fits']
for file_type in file_types:
possible_files = glob.glob(os.path.join(file_path, f'**/*.{file_type}'), recursive=True)
if possible_files:
break
for possible_file in sorted(possible_files):
lower_filename = os.path.basename(possible_file).lower()
if "flat" not in lower_filename and "dark" not in lower_filename and "180" not in lower_filename:
if 'flat' not in lower_filename and 'dark' not in lower_filename and '180' not in lower_filename:
return possible_file
return None

Expand Down

0 comments on commit 406b43a

Please sign in to comment.