Module Expr Str Import alias Import alias alias Import alias Import alias identifier Import alias Import alias identifier ClassDef bases body Assign NameStore Num Assign NameStore Num FunctionDef arguments args defaults body Expr Str Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr Print Str Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad keyword AttributeLoad NameLoad attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore ListLoad Num Num Num Num Num Num Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore ListLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Return ListLoad Call NameLoad Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad Call NameLoad SubscriptLoad NameLoad Index Num decorator_list NameLoad FunctionDef arguments args defaults body Expr Str Return CompareEq AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str If Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Return NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Num Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Num Assign NameStore Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice Num If NameLoad body Return ListLoad Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad SubscriptLoad NameLoad Index Num Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Num Return Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice Num decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Num Num Num Expr Call AttributeLoad NameLoad attr Num Num Num Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Num Return Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Slice Num decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Num Num Num Expr Call AttributeLoad NameLoad attr Num Num Num Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Return TupleLoad NameLoad Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If NameLoad body Return ListLoad Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad SubscriptLoad NameLoad Index Num Call NameLoad SubscriptLoad NameLoad Index Num Return ListLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str If Call NameLoad NameLoad Call NameLoad Call AttributeLoad NameLoad attr body Assign NameStore Num orelse If Call NameLoad NameLoad Call NameLoad Call AttributeLoad NameLoad attr body Assign NameStore Num orelse Raise Call NameLoad Str Assign NameStore Num Assign NameStore ListLoad For NameStore Call NameLoad NameLoad body Assign NameStore ListLoad For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad If CompareLt Call NameLoad NameLoad NameLoad body Assign NameStore Num Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr CompareGt NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Slice Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Dict For NameStore GeneratorExp NameLoad comprehension NameStore NameLoad CompareGt NameLoad Num body Assign NameStore Call AttributeLoad NameLoad attr CompareEq NameLoad NameLoad Assign SubscriptStore NameLoad Index NameLoad SubscriptLoad NameLoad Index Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Dict For NameStore GeneratorExp NameLoad comprehension NameStore NameLoad CompareGt NameLoad Num body Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Dict For NameStore GeneratorExp NameLoad comprehension NameStore NameLoad CompareGt NameLoad Num body Assign NameStore Call AttributeLoad NameLoad attr CompareEq NameLoad NameLoad Assign SubscriptStore NameLoad Index NameLoad Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore CompareEq NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr keyword Num Return SubscriptLoad Call AttributeLoad NameLoad attr NameLoad Index Num decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults Num body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr CompareEq NameLoad NameLoad keyword Num Return Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Num AttributeLoad NameLoad attr decorator_list NameLoad decorator_list
N/A N/A 
Created on Oct 29, 2014
Common functions that can be useful in any Python module development
 N/A vtk N/A os sys N/A traceback N/A numpy np N/A time N/A SimpleITK sitk Util N/A N/A N/A OK 0 N/A ERROR 1 print_last_exception N/A N/A N/A N/A N/A  Print in console the debug information for the last Exception occurred
        :return:
         N/A N/A exc_type exc_value exc_traceback N/A N/A sys exc_info N/A *** EXCEPTION OCCURRED:  N/A N/A N/A traceback print_exception exc_type exc_value exc_traceback file N/A sys stdout N/A staticmethod get_dimensions N/A N/A vtk_mrml_volume_node N/A N/A N/A  Return a list of 3 positions with the dimensions of the volume (XYZ)
        :param vtk_mrml_volume_node: vtkMRMLVolumeNode or any subclass
        :return: list of 3 integer positions
         N/A bounds N/A 0 0 0 0 0 0 N/A N/A N/A vtk_mrml_volume_node GetRASBounds bounds N/A rastoijk N/A N/A vtk vtkMatrix4x4 N/A N/A N/A vtk_mrml_volume_node GetRASToIJKMatrix rastoijk N/A bounds N/A N/A bounds N/A 0 N/A bounds N/A 2 N/A bounds N/A 5 1 N/A dimensions N/A N/A rastoijk MultiplyPoint bounds N/A N/A N/A int N/A round N/A dimensions N/A 0 N/A int N/A round N/A dimensions N/A 1 N/A int N/A round N/A dimensions N/A 2 N/A staticmethod is_windows N/A N/A N/A N/A N/A  Current system platform is Windows based
        :return:
         N/A N/A N/A N/A os sys platform win32 N/A staticmethod create_directory N/A N/A path N/A N/A N/A  Create a directory if it does not exist yet and give the maximum permissions
        :param path: Full path of the directory
        :return: True if the directory was created or False if it already existed
         N/A N/A N/A N/A os path exists path N/A N/A False N/A N/A N/A os makedirs path N/A N/A N/A os chmod path 511 N/A True N/A staticmethod get_file_extension N/A N/A file_path N/A N/A N/A  Return the extension of a file (with the dot included)
        :param file_path: relative or absolute file path
        :return: extension with dot (ex: ".xml")
         N/A N/A f ext N/A N/A N/A os path splitext file_path N/A ext N/A staticmethod ras_to_ijk N/A N/A volume_node ras_coords convert_to_int N/A True N/A N/A  Transform a list of RAS coords to IJK
        :param volume_node: vtk mrml scalar node
        :param ras_coords: list or array of RAS coordinates
        :param convert_to_int: return IJK coordinates as integer
        :return: list of IJK coordinates (xyz)
         N/A rastoijk N/A N/A vtk vtkMatrix4x4 N/A N/A N/A volume_node GetRASToIJKMatrix rastoijk N/A cl N/A list ras_coords N/A N/A N/A cl append 1 N/A l N/A list N/A N/A N/A rastoijk MultiplyPoint cl N/A -1 N/A convert_to_int N/A N/A N/A N/A int N/A l N/A 0 N/A int N/A l N/A 1 N/A int N/A l N/A 2 N/A l N/A staticmethod ijk_to_ras N/A N/A volume_node ijk_coords N/A N/A N/A  Transform a list of IJK coords to RAS
        :return: list of RAS coordinates (xyz)
         N/A ijktoras N/A N/A vtk vtkMatrix4x4 N/A N/A N/A volume_node GetIJKToRASMatrix ijktoras N/A cl N/A list ijk_coords N/A N/A N/A cl append 1 N/A N/A list N/A N/A N/A ijktoras MultiplyPoint cl N/A -1 N/A staticmethod __switch_ras_lps__ N/A N/A coords N/A N/A N/A  Convert from RAS to LPS or viceversa (it is just flipping the first axis)
        :return: list of 3 coordinates
         N/A lps_to_ras_matrix N/A N/A vtk vtkMatrix4x4 N/A N/A N/A lps_to_ras_matrix SetElement 0 0 -1 N/A N/A N/A lps_to_ras_matrix SetElement 1 1 -1 N/A cl N/A list coords N/A N/A N/A cl append 1 N/A N/A list N/A N/A N/A lps_to_ras_matrix MultiplyPoint cl N/A -1 N/A staticmethod ras_to_lps N/A N/A coords N/A N/A N/A  Convert coordinates from LPS to RAS
        :param coords:
        :return: list of 3 LPS coordinates
         N/A N/A N/A Util __switch_ras_lps__ coords N/A staticmethod lps_to_ras N/A N/A coords N/A N/A N/A  Convert coordinates from LPS to RAS
        :param coords:
        :return: list of 3 RAS coordinates
         N/A N/A N/A Util __switch_ras_lps__ coords N/A staticmethod get_lps_to_ijk_transformation_matrix N/A N/A volume_node N/A N/A N/A  Get the lps to ijk transformation matrix
        :param volume_node: vtkMRMLScalarNode
        :return:
         N/A matrix N/A N/A vtk vtkMatrix4x4 N/A N/A N/A volume_node GetRASToIJKMatrix matrix N/A id_matrix N/A N/A vtk vtkMatrix4x4 N/A N/A N/A id_matrix Identity N/A N/A N/A id_matrix SetElement 0 0 -1 N/A N/A N/A id_matrix SetElement 1 1 -1 N/A result N/A N/A vtk vtkMatrix4x4 N/A N/A N/A result Multiply4x4 matrix id_matrix result N/A result N/A staticmethod itk_numpy_array N/A N/A itk_image N/A N/A N/A  From a ITK image, return:
        - Numpy array
        - Spacing
        - Origin
        :param itk_image: simple ITK image
        :return: tuple of values (array, spacing, origin)
         N/A arr N/A N/A sitk GetArrayFromImage itk_image N/A itk_image N/A N/A sitk Image N/A N/A arr N/A N/A itk_image GetSpacing N/A N/A itk_image GetOrigin N/A staticmethod itk_numpy_coordinate N/A N/A itk_coordinate N/A N/A N/A  Adapt a coordinate in ITK to a numpy array format handled by VTK (ie in a reversed order)
        :param itk_coordinate: coordinate in ITK (xyz)
        :return: coordinate in numpy (zyx)
         N/A l N/A list itk_coordinate N/A N/A N/A l reverse N/A l N/A staticmethod vtk_numpy_coordinate N/A N/A vtk_coordinate N/A N/A N/A  Adapt a coordinate in VTK to a numpy array format handled by VTK (ie in a reversed order)
        :param itk_coordinate: coordinate in VTK (xyz)
        :return: coordinate in numpy (zyx)
         N/A l N/A list vtk_coordinate N/A N/A N/A l reverse N/A l N/A staticmethod numpy_itk_coordinate N/A N/A numpy_coordinate convert_to_int N/A True N/A N/A  Adapt a coordinate in numpy to a ITK format (ie in a reversed order and converted to int type)
        :param numpy_coordinate: coordinate in numpy (zyx)
        :param convert_to_int: convert the coordinate to int type, needed for SimpleITK image coordinates
        :return: coordinate in ITK (xyz)
         N/A convert_to_int N/A N/A N/A N/A int N/A numpy_coordinate N/A 2 N/A int N/A numpy_coordinate N/A 1 N/A int N/A numpy_coordinate N/A 0 N/A N/A N/A numpy_coordinate N/A 2 N/A numpy_coordinate N/A 1 N/A numpy_coordinate N/A 0 N/A staticmethod numpy_vtk_coordinate N/A N/A numpy_coordinate N/A N/A N/A  Adapt a coordinate in numpy to a VTK format (ie in a reversed order)
        :param numpy_coordinate: coordinate in numpy (zyx)
        :return: coordinate in VTK (xyz)
         N/A l N/A list numpy_coordinate N/A N/A N/A l reverse N/A l N/A staticmethod convert_vtk_matrix_to_list N/A N/A matrix N/A N/A N/A  Convert a vtk matrix object into a list
        :param matrix: vtkMatrix4x4 or vtkMatrix3x3
        :return: list of elements with the same dimensions
         N/A N/A isinstance matrix N/A type N/A N/A vtk vtkMatrix4x4 N/A N/A dim 4 N/A N/A N/A isinstance matrix N/A type N/A N/A vtk vtkMatrix3x3 N/A N/A dim 3 N/A N/A N/A Exception Type not allowed N/A threshold 1e-14 N/A result N/A N/A i N/A range dim N/A N/A row N/A N/A j N/A range dim N/A N/A n N/A N/A matrix GetElement i j N/A N/A N/A abs n threshold N/A N/A n 0 N/A N/A N/A row append n N/A N/A N/A result append row N/A result N/A staticmethod get_labelmap_slices N/A N/A npArray N/A N/A N/A  Get a dictionary with the slices where all the label data are contained in a numpy array
        representing a labelmap.
        The output will be a dictionary of [label_Code: array of slices]
        :param npArray: numpy array representing the image
        :return: dictionary of [label_Code: numpy array of slices]
         N/A N/A N/A Util get_labelmap_slices_from_numpy_array npArray N/A staticmethod get_labelmap_slices N/A N/A np_array N/A N/A N/A  Get a dictionary with the slices where all the label data are contained in a numpy array
        representing a labelmap.
        The output will be a dictionary of [label_Code: array of slices]
        Method 1: "2 steps" process compressing the array. It works much better when there are few slices with data
        :param np_array: numpy array representing the image
        :return: dictionary of [label_Code: numpy array of slices]
         N/A positions N/A N/A np where N/A np_array 0 N/A slices N/A N/A np unique N/A positions N/A 0 N/A boundArray N/A np_array N/A N/A slices N/A N/A N/A labelMaps N/A N/A np unique boundArray N/A result N/A N/A label N/A label N/A label labelMaps N/A label 0 N/A N/A s N/A N/A np where N/A boundArray label N/A N/A result N/A label N/A slices N/A N/A N/A np unique N/A s N/A 0 N/A result N/A staticmethod get_labelmap_slices_2 N/A N/A np_array N/A N/A N/A Get a dictionary with the slices where all the label data are contained. The origin is a numpy array.
        Recall that the array will be read with Z,Y,X coordinates (because of the VTK conversion)
        Method 2: without compressing the array using projections N/A labelMaps N/A N/A np unique np_array N/A result N/A N/A label N/A label N/A label labelMaps N/A label 0 N/A N/A N/A result N/A label N/A N/A Util get_slices_for_label_from_numpy_array np_array label N/A result N/A staticmethod get_labelmap_slices_3 N/A N/A np_array N/A N/A N/A Get a dictionary with the slices where all the label data are contained. The origin is a numpy array.
        Recall that the array will be read with Z,Y,X coordinates (because of the VTK conversion)
        Method 3: without compressing the array using where (VERY SLOW!) N/A labelMaps N/A N/A np unique np_array N/A result N/A N/A label N/A label N/A label labelMaps N/A label 0 N/A N/A s N/A N/A np where N/A np_array label N/A N/A result N/A label N/A N/A np unique N/A s N/A 0 N/A result N/A staticmethod get_slices_for_label_from_numpy_array N/A N/A np_array label N/A N/A N/A Get a numpyArray with the slices where label appears. The origin is a numpy array.
        Recall that the array will be read with Z,Y,X coordinates (because of the VTK conversion)
         N/A t N/A np_array label N/A tproj N/A N/A t any axis 1 N/A tproj N/A N/A tproj any axis 1 N/A N/A N/A N/A np where tproj N/A 0 N/A staticmethod centroid N/A N/A numpyArray labelId N/A 1 N/A N/A  Calculate the coordinates of a centroid for a concrete labelId (default=1)
        :param numpyArray: numpy array
        :param labelId: label id (default = 1)
        :return: numpy array with the coordinates (int format)
         N/A mean N/A N/A np mean N/A N/A np where N/A numpyArray labelId axis 1 N/A N/A N/A np asarray N/A N/A np round mean 0 N/A np int N/A staticmethod N/A