def setUp(self):
        """ Setup function TestTypes for class Reconstruction """

        self.ReconstructionObj = Reconstruction(
            c, dX, dY, dXg, dYg, dXqg, dYqg, Xr, Yr, dXq, dYq, outx_cal,
            outy_cal, dXql, dYql, dWx, dWy, Wf1, W, Wrms, delta, yb, x_edge,
            z_basis, coeff, nz, mz, nn, a, b, a1, b1, theta, jx, jy, ma, xx,
            outx_l)

        self.c = self.ReconstructionObj.c
        self.dX = self.ReconstructionObj.dX
        self.dY = self.ReconstructionObj.dY
        self.dXg = self.ReconstructionObj.dXg
        self.dYg = self.ReconstructionObj.dYg
        self.dXqg = self.ReconstructionObj.dXqg
        self.dYqg = self.ReconstructionObj.dYqg
        self.Xr = self.ReconstructionObj.Xr
        self.Yr = self.ReconstructionObj.Yr
        self.dXq = self.ReconstructionObj.dXq
        self.dYq = self.ReconstructionObj.dYq
        self.outx_cal = self.ReconstructionObj.outx_cal
        self.outy_cal = self.ReconstructionObj.outy_cal
        self.dXql = self.ReconstructionObj.dXql
        self.dYql = self.ReconstructionObj.dYql
        self.dWx = self.ReconstructionObj.dWx
        self.dWy = self.ReconstructionObj.dWy
        self.Wf1 = self.ReconstructionObj.Wf1
        self.W = self.ReconstructionObj.W
        self.Wrms = self.ReconstructionObj.Wrms
        self.delta = self.ReconstructionObj.delta
        self.yb = self.ReconstructionObj.yb
        self.x_edge = self.ReconstructionObj.x_edge
        self.z_basis = self.ReconstructionObj.z_basis
        self.coeff = self.ReconstructionObj.coeff
        self.nz = self.ReconstructionObj.nz
        self.mz = self.ReconstructionObj.mz
        self.nn = self.ReconstructionObj.nn
        self.a = self.ReconstructionObj.a
        self.b = self.ReconstructionObj.b
        self.a1 = self.ReconstructionObj.a1
        self.b1 = self.ReconstructionObj.b1
        self.theta = self.ReconstructionObj.theta
        self.jx = self.ReconstructionObj.jx
        self.jy = self.ReconstructionObj.jy
        self.ma = self.ReconstructionObj.ma
        self.xx = self.ReconstructionObj.xx
        self.outx_l = self.ReconstructionObj.outx_l

        pass
示例#2
0
    'DetectorInit': [0, -500.0, 0],
    'StartAngle': 0,
    'EndAngle': 2 * pi,
    'NumberOfDetectorPixels': [512, 384],
    'DetectorPixelSize': [0.5, 0.5],
    'NumberOfViews': 90,
    'ImagePixelSpacing': [0.5, 0.5, 0.5],
    'NumberOfImage': [256, 256, 256],
    'PhantomCenter': [0, 0, 0],
    'Origin': [0, 0, 0],
    'Method': 'Distance',
    'FilterType': 'hann',
    'cutoff': 1,
    'GPU': 1
}
R = Reconstruction(params)
filename = 'Shepp_Logan_3d_256.dat'

R.LoadRecon(filename, params['NumberOfImage'])
ph = R.image
R.forward()
print(R.proj.shape)
proj0 = R.proj
R.SaveProj('proj_SheppLogan256_90.dat')

# R.Filtering()
R.backward()
R.SaveRecon('Recon_SheppLogan256_90.dat')
R.image = np.zeros(params['NumberOfImage'], dtype=np.float32)
eps = 1e-5
norm1 = Reconstruction(params)
示例#3
0
import numpy as np
import glob, sys, os
import logging
import time
import matplotlib.pyplot as plt

pi = np.pi
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
# data = np.fromfile('Shepp_Logal_3d_256.dat', dtype=np.float32).reshape([256, 256, 256])
params = {'SourceInit': [0, 1000.0, 0], 'DetectorInit': [0, -500.0, 0], 'StartAngle': 0,
          'EndAngle': 2 * pi, 'NumberOfDetectorPixels': [512, 384], 'DetectorPixelSize': [0.5, 0.5],
          'NumberOfViews': 90, 'ImagePixelSpacing': [0.5, 0.5, 0.5], 'NumberOfImage': [256, 256, 256],
          'PhantomCenter': [0, 0, 0], 'Origin': [0, 0, 0], 'Method': 'Distance', 'FilterType': 'hann', 'cutoff': 1,
          'GPU': 1, 'DetectorShape': 'Flat'}
R = Reconstruction(params)
filename = 'Shepp_Logan_3d_256.dat'
# filename = 'Shepp_Logan_3d_256.dat'

R.LoadRecon(filename, params['NumberOfImage'])
ph = R.image
start_time = time.time()
R.forward()
log.info('Forward %f' % (time.time() - start_time))
print(R.proj.shape)
proj0 = R.proj
R.SaveProj('proj_SheppLogan256_90.dat')

start_time = time.time()
R.Filtering()
R.backward()
示例#4
0
    'DetectorInit': [0, -500.0, 0],
    'StartAngle': 0,
    'EndAngle': 2 * pi,
    'NumberOfDetectorPixels': [512, 384],
    'DetectorPixelSize': [0.5, 0.5],
    'NumberOfViews': 180,
    'ImagePixelSpacing': [0.5, 0.5, 0.5],
    'NumberOfImage': [256, 256, 256],
    'PhantomCenter': [0, 0, 0],
    'Origin': [0, 0, 0],
    'Method': 'Distance',
    'FilterType': 'hann',
    'cutoff': 1,
    'GPU': 1
}
R = Reconstruction(params)
filename = 'Shepp_Logan_3d_256.dat'
# ph = np.fromfile(filename, dtype=np.float32).reshape([256, 256, 256])
R.LoadRecon(filename, params['NumberOfImage'])
ph = R.image
R.forward()
# R.proj.tofile('proj_SheppLogan256_180.dat', sep='', format='')

R.image = np.ones(params['NumberOfImage'], dtype=np.float32)
eps = 1e-5
norm = Reconstruction(params)
norm.proj = np.ones([
    params['NumberOfViews'], params['NumberOfDetectorPixels'][1],
    params['NumberOfDetectorPixels'][0]
],
                    dtype=np.float32)
示例#5
0
def main():
    """Run entire pipeline"""

    # retrieve arguments
    args = parse_args("pedigree args")

    # construct pedigree data structure
    ped = PedigreeTree(args.struct_filename)

    # leave one out approach (sequenced individual we wish to reconstruct)
    left_out = []

    # construct IBDs data structures (type: list)
    IBDs = IBD.get_IBDs(args.germ_filename, left_out)  # toggle to leave out
    #IBDs = IBDs[:100] # testing for speed

    # assign IBDs to individuals in pedigree
    IBD.ibd_to_indvs(IBDs, ped)

    # cohort size info
    cohort_dist = [len(ibd.get_indvs()) for ibd in IBDs]
    #print("cohort min size", min(cohort_dist))
    #print("cohort max size", max(cohort_dist))

    ############################################################################
    # Pre-process IDs

    # find chromosome and SNP info
    chrom, SNP_lst = util.parse_chrom(args.map_filename)
    print("CHROM", chrom)

    # get IBD sequence information to use throughout
    with open(args.json_filename) as json_data:
        ibd_dict = json.load(json_data)

    # find indvs with no genotyped descendants (won't be able to reconstruct)
    no_seqd = util.no_seq_descendants(ped.indvs)

    # separate into genotyped and not initially (later on these will be
    # reconstructed and "yet to be constructed"
    # the idea is that hopefully we move most the ids to reconstruct at the end!
    reconstruct_ids = []
    ancestral_ids = []
    for id, indv in ped.indvs.items():
        if id == "0":
            continue
        if indv.genotyped:
            reconstruct_ids.append(id)
        elif id not in no_seqd:
            ancestral_ids.append(id)

    print("----------------")
    num_geno = len(reconstruct_ids)
    print("Genotyped:", num_geno)
    print("No genotyped descendants:", len(no_seqd))
    print("To reconstruct:", len(ancestral_ids))
    print("----------------")

    # finally, create a Reconstruction object that we will modify throughout
    reconstruction = Reconstruction(IBDs, ibd_dict, ped, reconstruct_ids, \
        ancestral_ids, chrom, SNP_lst, source_max_prob=args.max_prob)

    ############################################################################
    # FIRST: things we do only once

    # reconstruction first step: group IBDs from genotyped individuals
    print("Grouping IBDs from genotyped individuals...")
    reconstruction.initialize_genotyped()

    # identify sources and add them to IBDs
    print("Identify sources for IBDs...")
    reconstruction.identify_sources()

    ############################################################################
    # NOW ENTER ITERATIVE LOOP

    # now reconstruct!
    print("Reconstructing...")
    building = True
    num_recon = len(reconstruction.reconstruct_ids)

    # continue looping until we are not building new individuals
    iter = 0
    while building:
        print("\nITERATION", iter)

        # start from source with smallest number of paths and work from there
        # the first time, we use IBDs, then we need to use bad_ibds
        if iter == 0:
            reconstruction.root_all_IBDs(IBDs)
        else:
            reconstruction.root_all_IBDs(bad_ibds)

        # group unsequenced individuals
        print("Grouping IBDs from remaining individuals...")
        reconstruction.group_all(False)

        print("Analyzing groups...")
        good_indvs, bad_ibds = reconstruction.find_bad_sources()
        print('num good indvs', len(good_indvs))
        print(good_indvs)
        print('num bad ibds', len(bad_ibds))

        # TODO if we have conflicts with "super certain" IBDs that is bad -
        # shouldn't remove them

        # after noting these conflicts, update!
        # 1) move good_indvs out of ancestral and into reconstructed, groups too
        reconstruction.move_to_constructed(good_indvs)

        # 2) remove bad ibds from all individuals, and remove associated source
        # TODO double check we don't remove from good reconstructions
        reconstruction.remove_bad_sources(bad_ibds)

        # 3) go through votes and determine bad IBDs
        # TODO we could remove them from the groups as well, but not certain
        other_bad_ibds = reconstruction.bad_from_votes(IBDs)
        print("num bad ibds from votes", len(other_bad_ibds))

        # now repeat rooting with bad_ibds (no leave one out)
        print("Non-geno Reconstructed", len(reconstruction.reconstruct_ids) - \
            num_geno)

        # check if we are finished
        if len(reconstruction.reconstruct_ids) == num_recon:
            building = False
        else:
            num_recon = len(reconstruction.reconstruct_ids)
        iter += 1

    # after, optionally save images TODO shouldn't regroup here for runtime
    reconstruction.group_all(False)

    # write out .ped file (optional)
    if args.ped_filename != None:
        reconstruction.write_ped(args.ped_filename)
示例#6
0
    # return R


# data = np.fromfile('Shepp_Logal_3d_256.dat', dtype=np.float32).reshape([256, 256, 256])

params = {'SourceInit': [0, 1000.0, 0], 'DetectorInit': [0, -500.0, 0], 'StartAngle': 0,
          'EndAngle': 2 * pi, 'NumberOfDetectorPixels': [512, 384], 'DetectorPixelSize': [0.78125, 0.78125],
          'NumberOfViews': 180, 'ImagePixelSpacing': [0.5, 0.5, 0.5], 'NumberOfImage': [512, 512, 512],
          'PhantomCenter': [0, 0, 0], 'Origin': [0, 0, 0], 'Method': 'Distance', 'FilterType': 'ram-lak',
          'cutoff': 0.3, 'GPU': 1}
# params = {'SourceInit': [0, 1000.0, 0], 'DetectorInit': [0, -500.0, 0], 'StartAngle': 0,
#          'EndAngle': 2 * pi, 'NumberOfDetectorPixels': [512, 384], 'DetectorPixelSize': [0.5, 0.5],
#          'NumberOfViews': 45, 'ImagePixelSpacing': [0.5, 0.5, 0.5], 'NumberOfImage': [256, 256, 256],
#          'PhantomCenter': [0, 0, 0], 'Origin': [0, 0, 0], 'Method': 'Distance', 'FilterType': 'ram-lak', 
#          'cutoff': 0.3, 'GPU': 1}
R = Reconstruction(params)
# filename = 'Shepp_Logan_3d_256.dat'
filename = '../Projection/R_004/full_recon.dat'
# filename='/home/leehoy/CTReconstruction/python/Shepp_Logan_3d_256.dat'

R.LoadRecon(filename, params['NumberOfImage'])
ph = np.copy(R.image)
R.forward()
log.debug(R.proj.shape)
# log.debug(R.proj.dtype)
proj0 = np.copy(R.proj)

R.Filtering()
R.backward()

norm1 = Reconstruction(params)