diff --git a/docs/release_notes/next/fix-2397-fix-fits_file_support b/docs/release_notes/next/fix-2397-fix-fits_file_support new file mode 100644 index 00000000000..fc29add799d --- /dev/null +++ b/docs/release_notes/next/fix-2397-fix-fits_file_support @@ -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. diff --git a/mantidimaging/core/io/loader/loader.py b/mantidimaging/core/io/loader/loader.py index e78fa99e69d..adedf8a1e1e 100644 --- a/mantidimaging/core/io/loader/loader.py +++ b/mantidimaging/core/io/loader/loader.py @@ -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: diff --git a/mantidimaging/core/io/utility.py b/mantidimaging/core/io/utility.py index 5bbe702427d..ca2c8a05ff5 100644 --- a/mantidimaging/core/io/utility.py +++ b/mantidimaging/core/io/utility.py @@ -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