Esempio n. 1
0
def run(in_filename, out_filename, in_transforms, scale, verbose_flag,
        debug_flag):

    if type(in_filename) is list:
        filename = in_filename
    else:
        filename = [in_filename]

    if type(in_transforms) is list:
        transforms = in_transforms
    else:
        transforms = [in_transforms]

    input_files = filename + transforms

    if debug_flag:
        print input_files
        print

    util.verify_inputs(input_files)

    in_points = ctf.print_points_from_file(in_filename, verbose_flag)

    cmd = [
        "antsApplyTransformsToPoints", "-d", "3", "-i", in_filename, "-o",
        out_filename, "-t"
    ] + transforms
    util.iw_subprocess(cmd, debug_flag, debug_flag)

    # Perform scaling

    out_points = pd.read_csv(out_filename, sep=',', header=0)
    out_points = ctf.scale_points(out_points, scale, debug_flag)

    # Fix Comment Column
    out_points['comment'] = in_points['comment']

    #
    ctf.write_points(out_filename, out_points, verbose_flag)
Esempio n. 2
0
def main():

    ## Parsing Arguments
    #
    #

    parser = argparse.ArgumentParser(prog='iwCtf_where')

    parser.add_argument("in_image", help="Input image")
    parser.add_argument("out_filename", help="CSV output points")

    parser.add_argument("-v",
                        "--verbose",
                        help="Verbose flag",
                        action="store_true",
                        default=False)
    parser.add_argument("--debug",
                        help="Debug flag",
                        action="store_true",
                        default=False)

    inArgs = parser.parse_args()

    #
    #
    #

    image = nb.load(inArgs.in_image)
    data = image.get_data()
    nshape = image.shape + (1, 1, 1)

    step_01 = np.where(data > 0)
    label = np.extract(data > 0, data)

    x = step_01[0].tolist()
    y = step_01[1].tolist()
    z = step_01[2].tolist()

    if nshape[3] > 1:
        t = step_01[3].tolist()
    else:
        t = 0 * len(x)

    comment = [' '] * len(x)

    util.verify_inputs([inArgs.in_image], inArgs.debug)

    tmp = pd.DataFrame(
        {
            'x': x,
            'y': y,
            'z': z,
            't': t,
            'label': label,
            'comment': comment
        },
        columns=['x', 'y', 'z', 't', 'label', 'comment'])
    iras_points = tmp.sort_values(['label', 'x', 'y', 'z', 't'],
                                  ascending=[1, 1, 1, 1, 1])

    ctf.write_points(inArgs.out_filename, iras_points, inArgs.verbose)
Esempio n. 3
0
if __name__ == "__main__":

    ## Parsing Arguments
    #
    #

    parser = argparse.ArgumentParser(prog='iwCtf_icsa_to_wlps')

    parser.add_argument("in_filename", help="CSV input points")
    parser.add_argument("out_filename", help="CSV output points")
    parser.add_argument("-t", "--transform", help="Transform")

    parser.add_argument("-v",
                        "--verbose",
                        help="Verbose flag",
                        action="store_true",
                        default=False)
    parser.add_argument("--debug",
                        help="Debug   flag",
                        action="store_true",
                        default=False)

    inArgs = parser.parse_args()

    input_files = [inArgs.in_filename, inArgs.transform]

    util.verify_inputs(input_files, inArgs.debug)

    ctf.wlps_to_icsa(inArgs.in_filename, inArgs.out_filename, inArgs.transform,
                     inArgs.verbose, inArgs.debug)
Esempio n. 4
0
if __name__ == "__main__":

    ## Parsing Arguments
    #
    #

    parser = argparse.ArgumentParser(prog='iwCtf_matrices')

    parser.add_argument("in_filename", help="CSV input points")
    parser.add_argument("out_filename", help="CSV output points")
    parser.add_argument("-t", "--transforms", help="Transform")

    parser.add_argument("-v",
                        "--verbose",
                        help="Verbose flag",
                        action="store_true",
                        default=False)

    inArgs = parser.parse_args()

    #
    #
    #

    input_files = [inArgs.in_filename, inArgs.transforms]
    util.verify_inputs(input_files)

    ctf.wras_to_wlps(inArgs.in_filename, inArgs.out_filename,
                     inArgs.transforms, inArgs.verbose)
Esempio n. 5
0
    ## Parsing Arguments
    #
    #

    parser = argparse.ArgumentParser(prog='iwCtf_iras_to_wlps')

    parser.add_argument("in_filename", help="CSV input points")
    parser.add_argument("out_filename", help="CSV output points")
    parser.add_argument("-t",
                        "--transform",
                        help="Affine image transform",
                        nargs=1)

    parser.add_argument("-v",
                        "--verbose",
                        help="Verbose flag",
                        action="store_true",
                        default=False)
    parser.add_argument("--debug",
                        help="Debug flag",
                        action="store_true",
                        default=False)

    inArgs = parser.parse_args()

    util.verify_inputs([inArgs.in_filename] + inArgs.transform, inArgs.debug)

    ctf.iras_to_wlps(inArgs.in_filename, inArgs.out_filename, inArgs.transform,
                     inArgs.verbose, inArgs.debug)
Esempio n. 6
0
import iwUtilities     as util
import iwCtf        as ctf

#
# Main Function
#

if __name__ == "__main__":


     ## Parsing Arguments
     #
     #
     
     parser = argparse.ArgumentParser(prog='iwCtf_icsa_to_wlps')
               
     parser.add_argument("in_fiducials",        help="CSV input points" )
     parser.add_argument("out_ctf_matrix",      help="CSV output points" )

     parser.add_argument("--ctf_scale",    help="CTF scale factor",    type=float, default=1)

     parser.add_argument("-v","--verbose",      help="Verbose flag",      action="store_true", default=False )
     parser.add_argument("--debug",             help="Debug   flag",      action="store_true", default=False )

     inArgs = parser.parse_args()

     util.verify_inputs( [ inArgs.in_fiducials ], inArgs.debug)

     ctf.calc_matrix( inArgs.in_fiducials, inArgs.out_ctf_matrix, inArgs.ctf_scale,  inArgs.verbose)
     
Esempio n. 7
0
    step_01 = np.where(data > 0)
    label = np.extract(data > 0, data)

    x = step_01[0].tolist()
    y = step_01[1].tolist()
    z = step_01[2].tolist()

    if nshape[3] > 1:
        t = step_01[3].tolist()
    else:
        t = 0 * len(x)

    comment = [' '] * len(x)

    util.verify_inputs([inArgs.in_image], inArgs.debug)

    tmp = pd.DataFrame(
        {
            'x': x,
            'y': y,
            'z': z,
            't': t,
            'label': label,
            'comment': comment
        },
        columns=['x', 'y', 'z', 't', 'label', 'comment'])
    iras_points = tmp.sort_values(['label', 'x', 'y', 'z', 't'],
                                  ascending=[1, 1, 1, 1, 1])

    ctf.write_points(inArgs.out_filename, iras_points, inArgs.verbose)
Esempio n. 8
0
    
     print
     print output_directory
     print stage_directory
     print

     #
     # Check input files
     #
     util.print_stage("Verifying inputs", inArgs.verbose )

     input_files =      [ os.path.abspath( os.path.join( input_directory, inArgs.image       )),
                          os.path.abspath( os.path.join( input_directory, inArgs.in_icsa     ))
                          ]

     util.verify_inputs( input_files, inArgs.verbose)

     image_filename = input_files[0]
     icsa_fiducials = input_files[1]

     #
     # Check inputs
     #     

     if inArgs.in_icsa.count('.') > 1:
         print
         print inArgs.in_icsa + " must contain only one \".\" "
         print
         exit()

     input_files = [ image_native, 
                     fiducials_native,  
                     util.path_relative_to( input_directory, inArgs.native_to_template[0]  ),
                     util.path_relative_to( input_directory, inArgs.native_to_template[1]  ),
                     util.path_relative_to( input_directory, inArgs.template_to_native[0]  ),
                     util.path_relative_to( input_directory, inArgs.template_to_native[1]  )
                     ]

     if os.path.exists(reference_template):
          input_files  = input_files + [ reference_template ]


     if inArgs.run or inArgs.qi:
          util.print_stage("Verifying inputs", inArgs.verbose )
          util.verify_inputs( input_files, inArgs.verbose)


     if inArgs.qi:

 
          util.fslview([image_native], inArgs.verbose)
          

     #
     # Stage 0 - Rename files to a common name by linking
     #
          
     stage0_directory     = stage_directory[0];     

     stage0_input_files   = input_files
Esempio n. 10
0
        print "inArgs.ants_affine       = " + str(inArgs.ants_affine)
        print "inArgs.ants_warp         = " + str(inArgs.ants_warp)
        print "inArgs.wlps_to_wctf      = " + str(inArgs.wlps_to_wctf)
        print "inArgs.verbose           = " + str(inArgs.verbose)

    #
    # Check inputs
    #

    input_files = [
        inArgs.in_ctf, inArgs.ants_affine, inArgs.ants_warp,
        inArgs.wlps_to_wctf
    ]

    iwUtilities.verify_inputs(input_files)

    #
    # Transform CTF points to Native Space
    #

    cmd = [
        "antsApplyTransformsToPoints", "-d", "3", "-i", inArgs.in_ctf, "-o",
        inArgs.out_native, "-t", "[", inArgs.wlps_to_wctf, ",", "1", "]"
    ]

    iwUtilities.iw_subprocess(cmd, inArgs.verbose, inArgs.verbose)

    clean_nan(inArgs.out_native)

    #
Esempio n. 11
0
if __name__ == "__main__":

    ## Parsing Arguments
    #
    #

    parser = argparse.ArgumentParser(prog='iwCtf_extract_affine')

    parser.add_argument("in_image", help="Input image")
    parser.add_argument("out_affine", help="Filename of affine matrix")

    parser.add_argument(
        "--ras",
        help="Multiply affine by lps affine matrix before saving",
        action="store_true",
        default=False)

    parser.add_argument("-v",
                        "--verbose",
                        help="Verbose flag",
                        action="store_true",
                        default=False)

    inArgs = parser.parse_args()

    util.verify_inputs([inArgs.in_image], inArgs.verbose)

    ctf.extract_affine(inArgs.in_image, inArgs.out_affine, not inArgs.ras,
                       inArgs.verbose)