示例#1
0
def run():
    # download to this folder
    current_folder = os.sep.join(__file__.split(os.sep)[:-1])
    dpc_demo_data_path = os.path.join(current_folder, 'SOFC')
    if not os.path.exists(dpc_demo_data_path):
        zip_file_url = 'https://www.dropbox.com/s/963c4ymfmbjg5dm/SOFC.zip?dl=1'
        import download
        download.run()
        # download_zip(zip_file_url, current_folder)

    # 1. Set parameters
    start_point = [1, 0]
    first_image = 1
    pixel_size = (55, 55)
    focus_to_det = 1.46e6
    scan_xstep = 0.1
    scan_ystep = 0.1
    scan_rows = 121
    scan_cols = 121
    energy = 19.5
    roi = None
    padding = 0
    weighting = 1.
    bad_pixels = None
    solver = 'Nelder-Mead'
    images = ImageSequence(dpc_demo_data_path + "/*.tif")
    img_size = images[0].shape
    ref_image = np.ones(img_size)
    scale = True
    negate = True

    print('running dpc')
    # 2. Use dpc.dpc_runner
    phase, amplitude = dpc.dpc_runner(
        ref_image, images, start_point, pixel_size, focus_to_det, scan_rows,
        scan_cols, scan_xstep, scan_ystep, energy, padding, weighting, solver,
        roi, bad_pixels, negate, scale)

    # 3. Save intermediate and final results
    print('saving dpc output to disk in --> %s' % current_folder)
    scipy.misc.imsave(os.path.join(current_folder, 'phase.jpg'), phase)
    np.savetxt(os.path.join(current_folder, 'phase.txt'), phase)
    scipy.misc.imsave(os.path.join(current_folder, 'amplitude.jpg'), amplitude)
    np.savetxt(os.path.join(current_folder, 'amplitude.txt'), amplitude)
示例#2
0
def test_dpc_end_to_end():
    """
    Integrated test for DPC based on dpc_runner.

    """

    start_point = [1, 0]
    pixel_size = (55, 55)
    focus_to_det = 1.46e6
    scan_rows = 2
    scan_cols = 2
    scan_xstep = 0.1
    scan_ystep = 0.1
    energy = 19.5
    roi = None
    padding = 0
    weighting = 1
    bad_pixels = None
    solver = 'Nelder-Mead'
    img_size = (40, 40)
    scale = True
    negate = True
    num_imgs = scan_rows * scan_cols

    ref_image = np.ones(img_size)
    image_sequence = np.ones((num_imgs, img_size[0], img_size[1]))

    # test the one-shot API
    phase, amplitude = dpc.dpc_runner(ref_image, image_sequence, start_point,
                                      pixel_size, focus_to_det, scan_rows,
                                      scan_cols, scan_xstep, scan_ystep,
                                      energy, padding, weighting, solver, roi,
                                      bad_pixels, negate, scale)

    # get the generator
    gen = dpc.lazy_dpc(ref_image, image_sequence, start_point, scan_rows,
                       scan_cols, solver, roi, bad_pixels)
    for partial_results in gen:
        pass
    phi, a = dpc.reconstruct_phase_from_partial_info(partial_results, energy,
                                                     scan_xstep, scan_ystep,
                                                     pixel_size[0],
                                                     focus_to_det, negate,
                                                     scale, padding, weighting)
    assert_array_almost_equal(phi, np.zeros((scan_rows, scan_cols)))
    assert_array_almost_equal(a, np.ones((scan_rows, scan_cols)))

    # make sure we are getting the same results from the generator and the
    # one-shot API.  We better, since the one-shot API wraps the generator!
    assert_array_almost_equal(phase, phi)
    assert_array_almost_equal(amplitude, a)

    # test to make sure I can do half of the image sequence
    first_half_gen = dpc.lazy_dpc(ref_image, image_sequence[:num_imgs // 2],
                                  start_point, scan_rows, scan_cols, solver,
                                  roi, bad_pixels)
    for first_half_partial_results in first_half_gen:
        pass
    second_half_gen = dpc.lazy_dpc(ref_image,
                                   image_sequence[num_imgs // 2:],
                                   start_point,
                                   scan_rows,
                                   scan_cols,
                                   solver,
                                   roi,
                                   bad_pixels,
                                   dpc_state=first_half_partial_results)
    for second_half_partial_results in second_half_gen:
        pass

    phi_partial, a_partial = dpc.reconstruct_phase_from_partial_info(
        second_half_partial_results, energy, scan_xstep, scan_ystep,
        pixel_size[0], focus_to_det, negate, scale, padding, weighting)

    assert_array_almost_equal(phi_partial, phi)
    assert_array_almost_equal(a_partial, a)
示例#3
0
def test_dpc_end_to_end():
    """
    Integrated test for DPC based on dpc_runner.

    """

    start_point = [1, 0]
    pixel_size = (55, 55)
    focus_to_det = 1.46e6
    scan_rows = 2
    scan_cols = 2
    scan_xstep = 0.1
    scan_ystep = 0.1
    energy = 19.5
    roi = None
    padding = 0
    weighting = 1
    bad_pixels = None
    solver = 'Nelder-Mead'
    img_size = (40, 40)
    scale = True
    negate = True
    num_imgs = scan_rows * scan_cols

    ref_image = np.ones(img_size)
    image_sequence = np.ones((num_imgs, img_size[0], img_size[1]))

    # test the one-shot API
    phase, amplitude = dpc.dpc_runner(
        ref_image, image_sequence, start_point, pixel_size, focus_to_det,
        scan_rows, scan_cols, scan_xstep, scan_ystep, energy, padding,
        weighting, solver, roi, bad_pixels, negate, scale)

    # get the generator
    gen = dpc.lazy_dpc(ref_image, image_sequence, start_point, scan_rows,
                       scan_cols, solver, roi, bad_pixels)
    for partial_results in gen:
        pass
    phi, a = dpc.reconstruct_phase_from_partial_info(
        partial_results, energy, scan_xstep, scan_ystep, pixel_size[0],
        focus_to_det, negate, scale, padding, weighting
    )
    assert_array_almost_equal(phi, np.zeros((scan_rows, scan_cols)))
    assert_array_almost_equal(a, np.ones((scan_rows, scan_cols)))

    # make sure we are getting the same results from the generator and the
    # one-shot API.  We better, since the one-shot API wraps the generator!
    assert_array_almost_equal(phase, phi)
    assert_array_almost_equal(amplitude, a)

    # test to make sure I can do half of the image sequence
    first_half_gen = dpc.lazy_dpc(ref_image, image_sequence[:num_imgs//2],
                                  start_point, scan_rows, scan_cols, solver,
                                  roi, bad_pixels)
    for first_half_partial_results in first_half_gen:
        pass
    second_half_gen = dpc.lazy_dpc(ref_image, image_sequence[num_imgs//2:],
                                   start_point, scan_rows, scan_cols, solver,
                                   roi, bad_pixels,
                                   dpc_state=first_half_partial_results)
    for second_half_partial_results in second_half_gen:
        pass

    phi_partial, a_partial = dpc.reconstruct_phase_from_partial_info(
        second_half_partial_results, energy, scan_xstep, scan_ystep,
        pixel_size[0], focus_to_det, negate, scale, padding, weighting
    )

    assert_array_almost_equal(phi_partial, phi)
    assert_array_almost_equal(a_partial, a)