Skip to content

Commit

Permalink
ENH: Use comma separator for lists in python command arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Garcia committed Mar 5, 2025
1 parent 5d882a9 commit f35b6b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
9 changes: 5 additions & 4 deletions applications/rtk3Doutputimage_group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itk
from itk import RTK as rtk

__all__ = [
'add_rtk3Doutputimage_group',
Expand All @@ -8,10 +9,10 @@
# Mimicks rtk3Doutputimage_section.ggo
def add_rtk3Doutputimage_group(parser):
rtk3Doutputimage_group = parser.add_argument_group('Output 3D image properties')
rtk3Doutputimage_group.add_argument('--origin', help='Origin (default=centered)', type=float, nargs='+')
rtk3Doutputimage_group.add_argument('--dimension', help='Dimension', type=int, nargs='+', default=[256])
rtk3Doutputimage_group.add_argument('--spacing', help='Spacing', type=float, nargs='+', default=[1])
rtk3Doutputimage_group.add_argument('--direction', help='Direction', type=float, nargs='+')
rtk3Doutputimage_group.add_argument('--origin', help='Origin (default=centered)', type=rtk.comma_separated_args(float))
rtk3Doutputimage_group.add_argument('--dimension', help='Dimension', type=rtk.comma_separated_args(int), default=[256])
rtk3Doutputimage_group.add_argument('--spacing', help='Spacing', type=rtk.comma_separated_args(float), default=[1])
rtk3Doutputimage_group.add_argument('--direction', help='Direction', type=rtk.comma_separated_args(float))
rtk3Doutputimage_group.add_argument('--like', help='Copy information from this image (origin, dimension, spacing, direction)')

# Mimicks SetConstantImageSourceFromGgo
Expand Down
17 changes: 9 additions & 8 deletions applications/rtkinputprojections_group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itk
from itk import RTK as rtk

__all__ = [
'add_rtkinputprojections_group',
Expand All @@ -13,20 +14,20 @@ def add_rtkinputprojections_group(parser):
rtkinputprojections_group.add_argument('--nsort', help='Numeric sort for regular expression matches', action='store_true')
rtkinputprojections_group.add_argument('--submatch', help='Index of the submatch that will be used to sort matches', type=int, default=0)
rtkinputprojections_group.add_argument('--nolineint', help='Disable raw to line integral conversion, just casts to float', type=bool, default=False)
rtkinputprojections_group.add_argument('--newdirection', help='New value of input projections (before pre-processing)', type=float, nargs='+')
rtkinputprojections_group.add_argument('--neworigin', help='New origin of input projections (before pre-processing)', type=float, nargs='+')
rtkinputprojections_group.add_argument('--newspacing', help='New spacing of input projections (before pre-processing)', type=float, nargs='+')
rtkinputprojections_group.add_argument('--lowercrop', help='Lower boundary crop size', type=int, nargs='+', default=[0])
rtkinputprojections_group.add_argument('--uppercrop', help='Upper boundary crop size', type=int, nargs='+', default=[0])
rtkinputprojections_group.add_argument('--binning', help='Shrink / Binning factos in each direction', type=int, nargs='+', default=[1])
rtkinputprojections_group.add_argument('--wpc', help='Water precorrection coefficients (default is no correction)', type=float, nargs='+')
rtkinputprojections_group.add_argument('--newdirection', help='New value of input projections (before pre-processing)', type=rtk.comma_separated_args(float))
rtkinputprojections_group.add_argument('--neworigin', help='New origin of input projections (before pre-processing)', type=rtk.comma_separated_args(float))
rtkinputprojections_group.add_argument('--newspacing', help='New spacing of input projections (before pre-processing)', type=rtk.comma_separated_args(float))
rtkinputprojections_group.add_argument('--lowercrop', help='Lower boundary crop size', type=rtk.comma_separated_args(int))
rtkinputprojections_group.add_argument('--uppercrop', help='Upper boundary crop size', type=rtk.comma_separated_args(int))
rtkinputprojections_group.add_argument('--binning', help='Shrink / Binning factos in each direction', type=rtk.comma_separated_args(int), default=[1])
rtkinputprojections_group.add_argument('--wpc', help='Water precorrection coefficients (default is no correction)', type=rtk.comma_separated_args(float))
rtkinputprojections_group.add_argument('--spr', help='Boellaard scatter correction: scatter-to-primary ratio', type=float, default=0)
rtkinputprojections_group.add_argument('--nonneg', help='Boellaard scatter correction: non-negativity threshold', type=float)
rtkinputprojections_group.add_argument('--airthres', help='Boellaard scatter correction: air threshold', type=float)
rtkinputprojections_group.add_argument('--i0', help='I0 value (when assumed constant per projection), 0 means auto', type=float)
rtkinputprojections_group.add_argument('--idark', help='IDark value, i.e., value when beam is off', type=float, default=0)
rtkinputprojections_group.add_argument('--component', help='Vector component to extract, for multi-material projections', type=int, default=0)
rtkinputprojections_group.add_argument('--radius', help='Radius of neighborhood for conditional median filtering', type=int, nargs='+', default=[0])
rtkinputprojections_group.add_argument('--radius', help='Radius of neighborhood for conditional median filtering', type=rtk.comma_separated_args(int), default=[0])
rtkinputprojections_group.add_argument('--multiplier', help='Threshold multiplier for conditional median filtering', type=float, default=0)

# Mimicks GetProjectionsFileNamesFromGgo
Expand Down
7 changes: 6 additions & 1 deletion wrapping/rtkExtra.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def CudaImageFromImage(img):
return cuda_img
return img # Return the original image if CUDA is not available

# Returns a lambda function that parses a comma-separated string and converts each element to the specified type.
def comma_separated_args(value_type):
return lambda value: [value_type(s.strip()) for s in value.split(',')]

# Returns the progress percentage
class PercentageProgressCommand:
def __init__(self,caller):
self.percentage = -1
Expand All @@ -45,4 +50,4 @@ def callback(self):
self.percentage = new_percentage

def End(self):
print() # Print newline when execution ends
print() # Print newline when execution ends

0 comments on commit f35b6b7

Please sign in to comment.