Пример #1
0
 def create(self, ftype, dtype = None, shape = None, order = None, 
                  file_type_to_name = None, directory = None, expression = None, 
                  values = None, prefix = None, extension = None, debug = None, **kwargs):
   filename = self.filename(ftype=ftype,  file_type_to_name=file_type_to_name,
                            directory=directory, expression=expression, 
                            values=values, prefix=prefix, 
                            debug=debug, **kwargs)
   io.create(filename, shape=shape, dtype=dtype, order=order)
   return filename
Пример #2
0
def _test():
    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    from importlib import reload
    reload(top)

    label = top.cube_labeled()
    top.print_cube(label)

    # Test rotations
    c = np.zeros((3, 3, 3), dtype=bool)
    c[1, 0, 0] = True
    top.print_cube(c)

    cs = [top.rotate(c, axis=2, steps=r) for r in range(4)]
    [top.print_cube(cc) for cc in cs]

    reload(top)
    l = top.cube_labeled()
    rts = top.rotations6(l)

    [top.print_cube(r) for r in rts]

    reload(top)
    b = top.cube_from_index(6)
    i = top.cube_to_index(b)
    print(i, 6)

    us = np.zeros((3, 3, 3), dtype=int)
    us[1, 1, 2] = 1
    us[1, 0, 1] = 1
    us[1, 2, 0] = 2

    r12 = top.rotations12(us)
    [top.print_cube(cc) for cc in r12]

    #check configuration utlity
    reload(top)
    index = 11607
    source = top.cube_from_index(index)

    c = top.index_from_binary(source)
    c[1, 1, 1] == index

    x = np.random.rand(1500, 500, 500) > 0.6
    c = top.index_from_binary(x)

    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    #check fortran vs c order
    x = np.random.rand(5, 5, 5) > 0.35
    y = np.asanyarray(x, order='F')

    ix = top.index_from_binary(x)
    iy = top.index_from_binary(y)

    ax = ix.array
    ay = iy.array

    #%% profile
    import io
    io.DEFAULT_BUFFER_SIZE = 2**32

    import pstats, cProfile

    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    x = np.ones((3000, 500, 1000), dtype=bool, order='F')

    import ClearMap.IO.IO as io
    import ClearMap.ParallelProcessing.DataProcessing.ArrayProcessing as ap
    ap.write('test.npy', x)

    y = io.as_source('test.npy')
    z = io.create('resuly.npy', shape=y.shape, order='C', dtype='uint32')

    cProfile.runctx(
        "c =top.index_from_binary(y, method='!shared', sink=z, verbose=True, processes=None)",
        globals(), locals(), "Profile.prof")

    s = pstats.Stats("Profile.prof")
    s.strip_dirs().sort_stats("time").print_stats()

    import mmap
    mmap.ACCESS_COPY