Exemplo n.º 1
0
def processSingleConnection(args):
    global temporary_folder
    i = args

    #steps_done += 1;
    #if steps_done % 100 == 0:
    #  print('Processing step %d / %d...' % (steps_done, steps_total));
    if i % 100 == 0:
        print('Processing step %d...' % i)

    try:
        fid = mp.current_process()._identity[0]
    except:  # mostlikely sequential mode
        fid = 0

    data = smm.get(0)
    mask = smm.get(1)
    skel = smm.get(2)
    spts = smm.get(3)

    res = connectPoint(data,
                       mask,
                       spts,
                       i,
                       skeleton=skel,
                       radius=20,
                       tubeness=None,
                       remove_local_mask=True,
                       min_quality=15.0,
                       verbose=False,
                       maxSteps=12000,
                       costPerDistance=1.0)
    #return res;

    path, score = res
    if len(path) > 0:
        #convert path to indices
        path_flat = np.ravel_multi_index(path.T, data.shape, order=order(data))

        #append to file
        try:
            fid = mp.current_process()._identity[0]
        except:
            fid = 0
            # sequential mode
        fn = '%s/path_%03d.tmp' % (temporary_folder, fid)
        #print fn;

        fb = open(fn, "ab")
        path_flat.tofile(fb)
        fb.close()

    return
Exemplo n.º 2
0
 def propagate(t):
     i, hdl = t
     a = smm.get(hdl)
     #if i % 100000 == 0:
     #  print('i=%d' % i)
     for j in range(1):
         a[i] = i
Exemplo n.º 3
0
def _test():
    #from importlib import reload
    import ClearMap.ParallelProcessing.SharedMemoryManager as smm
    reload(smm)

    def propagate(t):
        i, hdl = t
        a = smm.get(hdl)
        #if i % 100000 == 0:
        #  print('i=%d' % i)
        for j in range(1):
            a[i] = i

    n = 5000000
    hdl = smm.zeros(n, dtype=float)
    print(hdl)
    pool = smm.mp.Pool(processes=2)

    smm.mp.Process()

    pp = pool.map_async(propagate, zip(range(n), [hdl] * n))
    #analysis:ignore
    pool.close()
    pool.join()

    result = smm.get(hdl)
    print(result)

    smm.sma.is_shared(result)
    smm.free(hdl)

    smm.clean()
Exemplo n.º 4
0
def _parallel_mesh(i,
                   coordinates_hdl,
                   radii_hdl,
                   indices_hdl,
                   n_tube_points=15,
                   verbose=False):

    coordinates = smm.get(coordinates_hdl)
    radii = smm.get(radii_hdl)
    start, end = smm.get(indices_hdl)[i]

    coordinates = coordinates[start:end]
    radii = radii[start:end]

    if verbose:
        if i % 1000 == 0:
            print('Mesh calculation %d / %d.' % (i, len(smm.get(indices_hdl))))

    return _mesh(coordinates, radii, n_tube_points)
Exemplo n.º 5
0
def _parallel_interpolate(
        i,
        coordinates_hdl,
        radii_hdl,
        indices_hdl,
        #                             coordinates_interp_hdl, radii_interp_hdl, indices_interp_hdl,
        smooth=5,
        order=2,
        points_per_pixel=0.5,
        verbose=False):
    coordinates = smm.get(coordinates_hdl)
    radii = smm.get(radii_hdl)
    start, end = smm.get(indices_hdl)[i]

    #  coordinates_interp = smm.get(coordinates_interp_hdl);
    #  radii_interp       = smm.get(radii_interp_hdl);
    #  start_interp,end_interp = smm.get(indices_interp_hdl)[i];

    coordinates = coordinates[start:end]
    radii = radii[start:end]

    if verbose:
        if i % 1000 == 0:
            print('Mesh interpolation %d / %d.' %
                  (i, len(smm.get(indices_hdl))))

    #coordinates_interp[start:end], radii_interp[start:end]=

    n_points = _n_points_per_edge(end - start,
                                  points_per_pixel=points_per_pixel)
    #n_points = end_interp - start_interp;

    #coordinates_interp[start_interp:end_interp], radii_interp[start_interp:end_interp] =
    return _interpolate_edge(coordinates,
                             radii,
                             n_points=n_points,
                             smooth=smooth,
                             order=order)
Exemplo n.º 6
0
def _shared(shape=None, dtype=None, order=None, array=None, handle=None):
    if handle is not None:
        array = smm.get(handle)

    if array is None:
        return sma.array(shape=shape, dtype=dtype, order=order)

    elif is_shared(array):
        if shape is None and dtype is None and order is None:
            return array

        shape = shape if shape is not None else array.shape
        dtype = dtype if dtype is not None else array.dtype
        order = order if order is not None else npy.order(array)

        if shape != array.shape:
            raise ValueError('Shapes do not match!')

        if np.dtype(dtype) == array.dtype and order == npy.order(array):
            return array
        else:
            new = sma.array(shape=shape, dtype=dtype, order=order)
            new[:] = array
            return new

    elif isinstance(array, (np.ndarray, list, tuple)):
        array = np.asarray(array)

        shape = shape if shape is not None else array.shape
        dtype = dtype if dtype is not None else array.dtype
        order = order if order is not None else npy.order(array)

        if shape != array.shape:
            raise ValueError('Shapes do not match!')

        new = sma.array(shape=shape, dtype=dtype, order=order)
        new[:] = array
        return new

    else:
        raise ValueError('Cannot create shared array from array %r!' % array)