def test_subprocess_write(self):
     shm = SharedMemory((100, 100), np.uint16)
     with shm.txn() as m:
         m[:] = 0
     with multiprocessing.Pool(1) as pool:
         pool.apply(write_something, (shm, (40, 50), 89))
     with shm.txn() as m:
         self.assertEqual(m[40, 50], 89)
 def test_subprocess_read(self):
     shm = SharedMemory((100, 100), np.uint16)
     a = np.random.RandomState(1234).randint(0, 65535, (100, 100))
     with shm.txn() as m:
         m[:] = a
     with multiprocessing.Pool(1) as pool:
         result = pool.apply(read_something, (shm, (55, 33)))
     self.assertEqual(a[55, 33], result)
示例#3
0
def do_plane(filename:str,
             points:np.ndarray,
             shared_memory:SharedMemory,
             offset:int):
    """

    :param filename: name of file to parse
    :param points: an N x 2 array of X, Y points at which to sample
    :param shared_memory: Shared memory block to write into
    :param offset: offset into block
    """
    patch_size = shared_memory.shape[1]
    half_size = patch_size // 2
    plane = np.pad(tifffile.imread(filename), half_size, mode='reflect')
    for idx, (x, y) in enumerate(points):
        x0 = x
        x1 = x + patch_size
        y0 = y
        y1 = y + patch_size
        with shared_memory.txn() as m:
            m[offset + idx] = plane[y0:y1, x0:x1]
def write_something(shm: SharedMemory, idx, value):
    with shm.txn() as m:
        m[idx] = value
def read_something(shm: SharedMemory, idx):
    with shm.txn() as m:
        return m[idx]