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

Coil options #388

Merged
merged 4 commits into from
Nov 28, 2023
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
6 changes: 3 additions & 3 deletions hazenlib/__init__.py
mollybuckley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

The following Tasks are available:
- ACR phantom:
acr_snr | acr_slice_position | acr_slice_thickness | acr_spatial_resolution | acr_uniformity | acr_ghosting | acr_geometric_accuracy

Check failure on line 77 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E501 line too long (132 > 127 characters)

Check failure on line 77 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E501 line too long (132 > 127 characters)
- MagNET Test Objects:
snr | snr_map | slice_position | slice_width | spatial_resolution | uniformity | ghosting
- Caliber phantom:
Expand All @@ -85,7 +85,7 @@

Usage:
hazen <task> <folder> [options]
hazen snr <folder> [--measured_slice_width=<mm>] [options]
hazen snr <folder> [--measured_slice_width=<mm>] [--coil=<head or body>] [options]
hazen acr_snr <folder> [--measured_slice_width=<mm>] [--subtract=<folder2>] [options]
hazen relaxometry <folder> --calc=<T1> --plate_number=<4> [options]

Expand All @@ -95,19 +95,18 @@
General Options: available for all Tasks
--report Whether to generate visualisation of the measurement steps.
--output=<path> Provide a folder where report images are to be saved.
--verbose Whether to provide additional metadata about the calculation in the result (slice position and relaxometry tasks)

Check failure on line 98 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E501 line too long (146 > 127 characters)

Check failure on line 98 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E501 line too long (146 > 127 characters)
--log=<level> Set the level of logging based on severity. Available levels are "debug", "warning", "error", "critical", with "info" as default.

Check failure on line 99 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E501 line too long (162 > 127 characters)

Check failure on line 99 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E501 line too long (162 > 127 characters)

acr_snr & snr Task options:
--measured_slice_width=<mm> Provide a slice width to be used for SNR measurement, by default it is parsed from the DICOM (optional for acr_snr and snr)

Check failure on line 102 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E501 line too long (156 > 127 characters)

Check failure on line 102 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E501 line too long (156 > 127 characters)
--subtract=<folder2> Provide a second folder path to calculate SNR by subtraction for the ACR phantom (optional for acr_snr)

Check failure on line 103 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E501 line too long (136 > 127 characters)

Check failure on line 103 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E501 line too long (136 > 127 characters)

relaxometry Task options:
--calc=<n> Choose 'T1' or 'T2' for relaxometry measurement (required)
--plate_number=<n> Which plate to use for measurement: 4 or 5 (required)
"""


import importlib
import inspect
import logging
Expand Down Expand Up @@ -153,7 +152,7 @@
task = getattr(task_module, selected_task.capitalize())(
input_data=files, report=report, report_dir=report_dir,
**kwargs)
except:

Check failure on line 155 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.9)

E722 do not use bare 'except'

Check failure on line 155 in hazenlib/__init__.py

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.10)

E722 do not use bare 'except'
class_list = [cls.__name__ for _, cls in inspect.getmembers(
sys.modules[task_module.__name__],
lambda x: inspect.isclass(x) and (x.__module__ == task_module.__name__)
Expand Down Expand Up @@ -196,7 +195,8 @@
if arguments['snr'] or arguments['<task>'] == 'snr':
selected_task = 'snr'
task = init_task(selected_task, files, report, report_dir,
measured_slice_width=arguments['--measured_slice_width'])
measured_slice_width=arguments['--measured_slice_width'],
coil=arguments['--coil'])
result = task.run()
elif arguments['acr_snr'] or arguments['<task>'] == 'acr_snr':
selected_task = 'acr_snr'
Expand Down
15 changes: 13 additions & 2 deletions hazenlib/tasks/snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ class SNR(HazenTask):

def __init__(self, **kwargs):
super().__init__(**kwargs)

# measured slice width is expected to be a floating point number
try:
self.measured_slice_width = float(kwargs["measured_slice_width"])
except:
self.measured_slice_width = None

# Determining kernel size based on coil choice. Values of 9 and 25 come from McCann 2013 paper.
mollybuckley marked this conversation as resolved.
Show resolved Hide resolved
try:
coil = kwargs["coil"]
if coil is None or coil.lower() in ["hc", "head"]:
self.kernel_size = 9
elif coil.lower() in ["bc", "body"]:
self.kernel_size = 25
except:
self.kernel_size=9

def run(self) -> dict:

results = self.init_result_dict()
Expand Down Expand Up @@ -134,10 +145,10 @@ def filtered_image(self, dcm: pydicom.Dataset) -> np.array:
a = dcm.pixel_array.astype('int')

# filter size = 9, following MATLAB code and McCann 2013 paper for head coil, although note McCann 2013 recommends 25x25 for body coil.
filter_size = 9

# 9 for head coil, 25 for body coil
# TODO make kernel size optional
filtered_array = ndimage.uniform_filter(a, filter_size, mode='constant')
filtered_array = ndimage.uniform_filter(a, self.kernel_size, mode='constant')
return filtered_array

def get_noise_image(self, dcm: pydicom.Dataset) -> np.array:
Expand Down
Loading