@@ -993,6 +993,12 @@ def xyz_to_index(x, y, z, thumbnail_size, tile_size):
993993 default = "sitkNearestNeighbor" ,
994994 help = "SimpleITK interpolator used to resize images when creating summary image" ,
995995 )
996+ opt_arg_parser .add_argument (
997+ "--float_precision" ,
998+ type = positive_int ,
999+ default = None ,
1000+ help = "Precision for floating point numbers. Use only if exact numeric equality across platforms is required (i.e. for testing)" ,
1001+ )
9961002 # Use the function docstring as the text in the parser description and a custom
9971003 # RawDescriptionAndDefaultHelpFormatter so that the docstring layout
9981004 # is maintained, otherwise it is line-wrapped and the formatting is lost, and the
@@ -1141,7 +1147,21 @@ def xyz_to_index(x, y, z, thumbnail_size, tile_size):
11411147 if args .ignore_problems :
11421148 df .dropna (inplace = True , thresh = 2 )
11431149 # save the raw information, create directory structure if it doesn't exist
1144- df .to_csv (args .output_file , index = False )
1150+ # if floating point precision was specified, convert the floating point tuples to the
1151+ # desired precision. the dataframe's to_csv method will format the columns with floating point type.
1152+ float_format_str = None
1153+ if args .float_precision :
1154+ float_format_str = f"%.{ args .float_precision } f"
1155+ df ["image spacing" ] = df ["image spacing" ].apply (
1156+ lambda x : np .round (x , decimals = args .float_precision )
1157+ )
1158+ df ["image origin" ] = df ["image origin" ].apply (
1159+ lambda x : np .round (x , decimals = args .float_precision )
1160+ )
1161+ df ["axis direction " ] = df ["axis direction" ].apply (
1162+ lambda x : np .round (x , decimals = args .float_precision )
1163+ )
1164+ df .to_csv (args .output_file , index = False , float_format = float_format_str )
11451165
11461166 # minimal analysis on the image information, detect image duplicates and plot the image size,
11471167 # spacing and min/max intensity values of scalar image distributions as scatterplots.
0 commit comments