Exemple #1
0
def test_get_shifted_base():
    data = np.random.random((6, 7))
    tile_origin = np.array((0, 0))
    tile_shape = np.array((6, 7))
    target_tup, offsets = get_shifted(arr_shape=np.array(data.shape),
                                      tile_origin=tile_origin,
                                      tile_shape=tile_shape,
                                      shift=np.array((0, 0)))
    print(target_tup)
    print(offsets)
    (target_slice, source_slice) = to_slices(target_tup, offsets)
    print(target_slice, source_slice)
    res = np.full(tile_shape, 17, dtype=data.dtype)
    res[target_slice] = data[source_slice]
    print("result:", res)
    print("data:", data)
    assert np.all(res == data)
    assert res.dtype == data.dtype
    assert res.shape == data.shape
Exemple #2
0
def test_get_shifted_minus_partial():
    data_shape = np.array((6, 7))
    data = np.random.random(data_shape)
    tile_origin = np.array((1, 2))
    tile_shape = np.array((3, 4))
    target_tup, offsets = get_shifted(arr_shape=np.array(data.shape),
                                      tile_origin=tile_origin,
                                      tile_shape=tile_shape,
                                      shift=np.array((-1, -2)))
    print(target_tup)
    print(offsets)
    (target_slice, source_slice) = to_slices(target_tup, offsets)
    res = np.full(tile_shape, 17, dtype=data.dtype)
    res[target_slice] = data[source_slice]
    print("result:", res)
    print("data:", data)

    assert np.all(res == data[:3, :4])
    assert res.dtype == data.dtype
Exemple #3
0
def test_get_shifted_plus():
    data_shape = np.array((4, 5))
    data = np.random.random(data_shape)
    tile_origin = np.array((0, 0))
    tile_shape = data_shape
    target_tup, offsets = get_shifted(arr_shape=np.array(data.shape),
                                      tile_origin=tile_origin,
                                      tile_shape=tile_shape,
                                      shift=np.array((1, 2)))
    print(target_tup)
    print(offsets)
    (target_slice, source_slice) = to_slices(target_tup, offsets)
    res = np.full(tile_shape, 17, dtype=data.dtype)
    res[target_slice] = data[source_slice]
    print("result:", res)
    print("data:", data)
    assert np.all(res[:-1, :-2] == data[1:, 2:])
    assert np.all(res[-1:] == 17)
    assert np.all(res[:, -2:] == 17)
    assert res.dtype == data.dtype
    assert res.shape == data.shape
Exemple #4
0
def mask_tile_pair(center_tile, tile_origin, tile_shape, filter_center, sy,
                   sx):
    '''
    Numerical work horse for :meth:`mask_pair_shift`, including tiling support.

    The tiling support could be used to calculate the mask stack on the fly,
    including support for UDF.process_tile().

    Parameters
    ----------

    center_tile : numpy.ndarray
        Tile cut out from :code:`filter_center` for re-use to increase efficiency
    tile_origin : tuple
        Origin of the tile to calculate
    tile_shape : tuple
        Shape of the tile
    filter_center : numpy.ndarray
        Center illumination, i.e. zero order disk.
    sy, sx : float
        Trotter shift value in px

    Returns
    -------
    mask_positive : numpy.ndarray
        Positive trotter tile
    target_tup_p : numpy.ndarray of int
        Start and stop indices per axis that were used for shifting the positive trotter tile.
    offsets_p : numpy.ndarray
        Offsets per axis that were used for shifting the positive trotter tile.
    mask_negative : numpy.ndarray
        Negative trotter tile
    target_tup_n : numpy.ndarray
        Start and stop indices per axis that were used for shifting the negative trotter tile.
    offsets_n : numpy.ndarray
        Offsets per axis that were used for shifting the negative trotter tile.
    '''
    sy, sx, = np.int(np.round(sy)), np.int(np.round(sx))
    positive_tile = np.zeros_like(center_tile)
    negative_tile = np.zeros_like(center_tile)
    # We get from negative coordinates,
    # that means it looks like shifted to positive
    target_tup_p, offsets_p = get_shifted(arr_shape=np.array(
        filter_center.shape),
                                          tile_origin=tile_origin,
                                          tile_shape=tile_shape,
                                          shift=np.array((-sy, -sx)))
    # We get from positive coordinates,
    # that means it looks like shifted to negative
    target_tup_n, offsets_n = get_shifted(arr_shape=np.array(
        filter_center.shape),
                                          tile_origin=tile_origin,
                                          tile_shape=tile_shape,
                                          shift=np.array((sy, sx)))

    sta_y, sto_y, sta_x, sto_x = target_tup_p.flatten()
    off_y, off_x = offsets_p
    positive_tile[sta_y:sto_y,
                  sta_x:sto_x] = filter_center[sta_y + off_y:sto_y + off_y,
                                               sta_x + off_x:sto_x + off_x]
    sta_y, sto_y, sta_x, sto_x = target_tup_n.flatten()
    off_y, off_x = offsets_n
    negative_tile[sta_y:sto_y,
                  sta_x:sto_x] = filter_center[sta_y + off_y:sto_y + off_y,
                                               sta_x + off_x:sto_x + off_x]

    mask_positive = center_tile * positive_tile * (negative_tile == 0)
    mask_negative = center_tile * negative_tile * (positive_tile == 0)

    return (mask_positive, target_tup_p, offsets_p, mask_negative,
            target_tup_n, offsets_n)