Skip to content

Commit

Permalink
try to address: 'weighting-signal-loss' is only relavant to
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinma9 committed Jan 18, 2023
1 parent 3c2920f commit 80f45c6
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions shimmingtoolbox/cli/b0shim.py
Expand Up @@ -31,14 +31,35 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def command_required_option_from_option(require_name, require_map):

class CommandOptionRequiredClass(click.Command):

def invoke(self, ctx):
require = ctx.params[require_name]
if require not in require_map:
raise click.ClickException(
"Unexpected value for --'{}': {}".format(
require_name, require))
if ctx.params[require_map[require].lower()] is None:
raise click.ClickException(
"With {}={} must specify option --{}".format(
require_name, require, require_map[require]))
super(CommandOptionRequiredClass, self).invoke(ctx)

return CommandOptionRequiredClass

@click.group(context_settings=CONTEXT_SETTINGS,
help="Shim according to the specified algorithm as an argument e.g. st_b0shim xxxxx")
def b0shim_cli():
pass


@click.command(context_settings=CONTEXT_SETTINGS)
required_options = {
'grad': ['w_signal_loss', 'reg_factor'],
'mse': 'reg_factor',
'mae': 'reg_factor',
}
@click.command(context_settings=CONTEXT_SETTINGS, cls=command_required_option_from_option('opt_criteria', required_options))
@click.option('--coil', 'coils', nargs=2, multiple=True, type=(click.Path(exists=True), click.Path(exists=True)),
help="Pair of filenames containing the coil profiles followed by the filename to the constraints "
"e.g. --coil a.nii cons.json. If you have more than one coil, use this option more than once. "
Expand Down Expand Up @@ -74,19 +95,16 @@ def b0shim_cli():
help="Regularization factor for the current when optimizing. A higher coefficient will penalize higher "
"current values while 0 provides no regularization. Not relevant for 'pseudo-inverse' "
"optimizer_method.")
########################################################################################################################
@click.option('--optimizer-criteria', 'opt_criteria', type=click.Choice(['mse', 'mae','grad']), required=False,
default='mse', show_default=True,
help="Criteria of optimization for the optimizer 'least_squares'."
" mse: Mean Squared Error, mae: Mean Absolute Error, grad: Signal Loss")
@click.option('--weighting-signal-loss', 'w_signal_loss', type=click.FLOAT, required=False, default=0.0, show_default=True,
help="weighting for signal loss recovery. Since there is generally a compromise between B0 inhomogeneity"
" and signal loss recovery, a higher coefficient will put more weights to recover the signal loss over "
"the B0 inhomogeneity.")
@click.option('--epi_echo_time', 'epi_te', type=click.FLOAT, required=False, default=0.0, show_default=True,
help="EPI acquistion parameter Echo Time (TE).")
# add grad option
@click.option('--optimizer-criteria', 'opt_criteria', type=click.Choice(['mse', 'mae','grad']), required=False,
default='mse', show_default=True,
help="Criteria of optimization for the optimizer 'least_squares'."
" mse: Mean Squared Error, mae: Mean Absolute Error, grad: Signal Loss")
########################################################################################################################
@click.option('--mask-dilation-kernel-size', 'dilation_kernel_size', type=click.INT, required=False, default='3',
show_default=True,
help="Number of voxels to consider outside of the masked area. For example, when doing dynamic shimming "
Expand Down

0 comments on commit 80f45c6

Please sign in to comment.