From 5540de3f65fbcf9aa5282b0ec7cdcf8673b76bd3 Mon Sep 17 00:00:00 2001 From: JackEAllen Date: Mon, 6 Jan 2025 10:59:10 +0000 Subject: [PATCH 1/3] Add FITS Support to find_first_file_that_is_possibly_a_sample() --- mantidimaging/core/io/utility.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 From 63ce4f5f4b87fc4f7890948794bfd895b5ba8976 Mon Sep 17 00:00:00 2001 From: JackEAllen Date: Mon, 6 Jan 2025 11:04:14 +0000 Subject: [PATCH 2/3] Refactor _fitsread to Close File After Reading Image --- mantidimaging/core/io/loader/loader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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: From 6ae0879ef814652e2a557204ca8362df9c876826 Mon Sep 17 00:00:00 2001 From: JackEAllen Date: Mon, 6 Jan 2025 11:29:22 +0000 Subject: [PATCH 3/3] Release Notes --- docs/release_notes/next/fix-2397-fix-fits_file_support | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/release_notes/next/fix-2397-fix-fits_file_support 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.