Skip to content

Commit

Permalink
Add skimage to coil profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
po09i committed Aug 18, 2023
1 parent e45ba0b commit 24c69b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions shimmingtoolbox/cli/create_coil_profiles.py
Expand Up @@ -18,17 +18,19 @@
from shimmingtoolbox.masking.threshold import threshold as mask_threshold

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
GAMMA = 42.576E6 # in Hz/Tesla
GAMMA = 42.576E6 # in Hz/Tesla

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


@click.group(context_settings=CONTEXT_SETTINGS,
help="Create coil profiles according to the specified algorithm as an argument e.g. st_create_coil_profiles xxxxx")
help="Create coil profiles according to the specified algorithm as an argument e.g. st_create_coil_"
"profiles xxxxx")
def coil_profiles_cli():
pass


@click.command(
context_settings=CONTEXT_SETTINGS,
)
Expand All @@ -39,7 +41,7 @@ def coil_profiles_cli():
@click.option('--relative-path', 'path_relative', type=click.Path(exists=True), required=False, default=None,
help="Path to add before each file in the config file. This allows to have relative paths in the config "
"file. If this option is not specified, absolute paths must be provided in the config file.")
@click.option('--unwrapper', type=click.Choice(['prelude']), default='prelude', show_default=True,
@click.option('--unwrapper', type=click.Choice(['prelude', 'skimage']), default='prelude', show_default=True,
help="Algorithm for unwrapping")
@click.option('--threshold', type=float, required=True,
help="Threshold for masking. Allowed range: [0, 1] where all scaled values lower than the threshold are "
Expand All @@ -55,9 +57,10 @@ def coil_profiles_cli():
help="Output filename of the coil profiles NIfTI file. Supported types : '.nii', '.nii.gz'")
@click.option('-v', '--verbose', type=click.Choice(['info', 'debug']), default='info', help="Be more verbose")
def from_field_maps(fname_json, path_relative, autoscale, unwrapper, threshold, gaussian_filter, sigma,
fname_output, verbose):
""" Create \u0394B\u2080 coil profiles from acquisitions defined in the input json file. The output is in Hz/<current> where
current depends on the value in the configuration file"""
fname_output, verbose):
""" Create \u0394B\u2080 coil profiles from acquisitions defined in the input json file. The output is in
Hz/<current> where current depends on the value in the configuration file
"""

# Set logger level
set_all_loggers(verbose)
Expand Down Expand Up @@ -311,7 +314,7 @@ def from_field_maps(fname_json, path_relative, autoscale, unwrapper, threshold,
"position (in mm). Input should be --offset x y z. Defaulted to 0 0 0")
@click.option('--flip', 'dims_to_flip', required=False, type=(float, float, float), default=(1, 1, 1),
help="Dimensions (XYZ order) to flip in the wires' geometry (1 for no flip, -1 for flip). "
"Input should be --flip x y z. Defaulted to 1 1 1.")
"Input should be --flip x y z. Defaulted to 1 1 1.")
@click.option('--software', type=click.Choice(['autocad']), default='autocad',
help=f"Software from which the geometries were extracted.")
@click.option('--coil_name', 'coil_name', required=False, type=click.STRING, default="new",
Expand Down
2 changes: 1 addition & 1 deletion shimmingtoolbox/unwrap/skimage_unwrap.py
Expand Up @@ -58,7 +58,7 @@ def skimage_unwrap(nii_wrapped_phase, mag=None, mask=None, threshold=None, fname
nib.save(nii_mask, fname_save_mask)

# Unwrap the phase
ma_wrapped_phase = ma.array(wrapped_phase, mask=~unwrap_mask)
ma_wrapped_phase = ma.array(wrapped_phase, mask=~unwrap_mask.astype(bool))
ma_unwrapped_phase = unwrap_phase(ma_wrapped_phase, rng=0)

# Fill the masked values with 0
Expand Down
6 changes: 3 additions & 3 deletions test/cli/test_cli_create_coil_profiles.py
Expand Up @@ -54,7 +54,6 @@
}


@pytest.mark.prelude
def test_create_coil_profiles():
runner = CliRunner()

Expand All @@ -70,14 +69,14 @@ def test_create_coil_profiles():
['from-field-maps',
'-i', fname_config,
'--relative-path', os.path.join(__dir_testing__, 'ds_b0', 'sub-fieldmap', 'fmap'),
'--unwrapper', 'skimage',
'--threshold', '0.4',
'-o', fname_output], catch_exceptions=False)

assert res.exit_code == 0
assert os.path.isfile(fname_output)


@pytest.mark.prelude
def test_create_coil_profiles_dead_channel1():
runner = CliRunner()

Expand All @@ -97,6 +96,7 @@ def test_create_coil_profiles_dead_channel1():
['from-field-maps',
'-i', fname_config,
'--relative-path', os.path.join(__dir_testing__, 'ds_b0', 'sub-fieldmap', 'fmap'),
'--unwrapper', 'skimage',
'--threshold', '0.4',
'-o', fname_output], catch_exceptions=False)

Expand All @@ -105,7 +105,6 @@ def test_create_coil_profiles_dead_channel1():
assert nib.load(fname_output).shape == (128, 76, 10, 2)


@pytest.mark.prelude
def test_create_coil_profiles_dead_channel2():
runner = CliRunner()

Expand All @@ -126,6 +125,7 @@ def test_create_coil_profiles_dead_channel2():
['from-field-maps',
'-i', fname_config,
'--relative-path', os.path.join(__dir_testing__, 'ds_b0', 'sub-fieldmap', 'fmap'),
'--unwrapper', 'skimage',
'--threshold', '0.4',
'-o', fname_output], catch_exceptions=False)

Expand Down

0 comments on commit 24c69b5

Please sign in to comment.