Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2397 fits support #2441

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading