Example #1
0
def test_difftodect_com_flip_rot_scale(dim):
    lt_ctx = lt.Context(InlineJobExecutor())
    data_shape = (2, 2, dim, dim)
    data = np.zeros(data_shape)
    data[0, 0, 7, 7] = 1
    data[0, 1, 7, 8] = 1
    data[1, 1, 8, 8] = 1
    data[1, 0, 8, 7] = 1
    source_shape = data_shape[2:]
    target_shape = data_shape[2:]

    f = diffraction_to_detector(lamb=1,
                                diffraction_shape=target_shape,
                                pixel_size_real=1,
                                pixel_size_detector=1 /
                                (np.array(target_shape)) * 4,
                                cy=source_shape[0] / 2,
                                cx=source_shape[1] / 2,
                                flip_y=True,
                                scan_rotation=-90.)
    m = image_transformation_matrix(
        source_shape=source_shape,
        target_shape=target_shape,
        affine_transformation=f,
    )
    transformed_data = apply_matrix(data, m, target_shape)
    ds = lt_ctx.load('memory', data=data, sig_dims=2)
    transformed_ds = lt_ctx.load('memory', data=transformed_data, sig_dims=2)
    com_a = lt_ctx.create_com_analysis(dataset=ds,
                                       mask_radius=np.inf,
                                       flip_y=True,
                                       scan_rotation=-90.,
                                       cy=target_shape[0] / 2,
                                       cx=target_shape[1] / 2)

    com_res = lt_ctx.run(com_a)

    trans_com_a = lt_ctx.create_com_analysis(dataset=transformed_ds,
                                             mask_radius=np.inf,
                                             flip_y=False,
                                             scan_rotation=0.,
                                             cy=target_shape[0] / 2,
                                             cx=target_shape[1] / 2)
    trans_com_res = lt_ctx.run(trans_com_a)
    print(com_res.field.raw_data)
    print(trans_com_res.field.raw_data)

    assert np.allclose(com_res.field.raw_data,
                       np.array(trans_com_res.field.raw_data) / 4)
Example #2
0
def test_difftodect_identity():
    data_shape = np.random.randint(1, 77, 3, dtype=int)
    data = np.random.random(data_shape)
    source_shape = data_shape[1:]
    target_shape = data_shape[1:]

    f = diffraction_to_detector(lamb=1,
                                diffraction_shape=target_shape,
                                pixel_size_real=1,
                                pixel_size_detector=1 /
                                (np.array(target_shape)),
                                cy=source_shape[0] / 2,
                                cx=source_shape[1] / 2,
                                flip_y=False,
                                scan_rotation=0.)
    m = image_transformation_matrix(
        source_shape=source_shape,
        target_shape=target_shape,
        affine_transformation=f,
    )
    assert np.allclose(data, apply_matrix(data, m, target_shape))