def test_motion_correction_type(): # Double to double test_scan = np.double(np.arange(16).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) assert (result.dtype == np.double), 'Motion correction is changing the scan dtype' #int to double test_scan = np.arange(16).reshape([4, 4]) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) assert (result.dtype == np.double), 'Motion correction is not changing the scan ' \ 'dtype from int64 to double'
def test_motion_correction_type(): # Double to double test_scan = np.double(np.arange(16).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) assert (result.dtype == np.double ), 'Motion correction is changing the scan dtype' #int to double test_scan = np.arange(16).reshape([4, 4]) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) assert (result.dtype == np.double), 'Motion correction is not changing the scan ' \ 'dtype from int64 to double'
def load(self, key): from pipeline.utils import galvo_corrections # load print("Loading scan", flush=True) reader = scanreader.read_scan( (experiment.Scan() & key).local_filenames_as_wildcard) scan = reader[key["field"] - 1, :, :, key["channel"] - 1].astype(np.float32) # raster correction print("Raster correction", flush=True) pipe = (fuse.MotionCorrection() & key).module raster_phase = (pipe.RasterCorrection() & key).fetch1("raster_phase") fill_fraction = (pipe.ScanInfo() & key).fetch1("fill_fraction") scan = galvo_corrections.correct_raster(scan, raster_phase, fill_fraction) # motion correction print("Motion correction", flush=True) x_shifts, y_shifts = (pipe.MotionCorrection() & key).fetch1( "x_shifts", "y_shifts") scan = galvo_corrections.correct_motion(scan, x_shifts, y_shifts) return scan, reader.num_scanning_depths
def test_motion_correction_not_in_place(): test_scan = np.double(np.arange(16).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=[0.1, -0.1], in_place=False) assert_allclose(test_scan, np.arange(16).reshape([4, 4]), err_msg='Motion correction is not creating a copy of the scan when ' 'asked to (in_place=False)')
def test_motion_correction_nan_xy_motion(): test_scan = np.double(np.arange(16).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([np.nan, 0.1])) assert_allclose(result, np.arange(16).reshape([4, 4]), err_msg='Motion correction cannot handle nan in xy_motion')
def test_motion_correction_no_motion(): test_scan = np.double(np.arange(1, 17).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0, 0])) assert_allclose( result, np.arange(1, 17).reshape([4, 4]), err_msg='Motion correction with zero xy_motion changes the result')
def test_motion_correction_list_input(): test_scan = np.double(np.arange(36).reshape([6, 6])) result = galvo_corrections.correct_motion(test_scan, [0.1, -0.1]) desired_result = [[6.5, 7.5, 8.5, 9.5], [12.5, 13.5, 14.5, 15.5], [18.5, 19.5, 20.5, 21.5], [24.5, 25.5, 26.5, 27.5]] assert_allclose(result[1:-1, 1:-1], desired_result, err_msg='Motion correction can not handle xy_motion as a list.')
def test_motion_correction_is_accurate(): test_scan = np.double(np.arange(36).reshape([6, 6])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) desired_result = [[6.5, 7.5, 8.5, 9.5], [12.5, 13.5, 14.5, 15.5], [18.5, 19.5, 20.5, 21.5], [24.5, 25.5, 26.5, 27.5]] assert_allclose(result[1:-1,1:-1], desired_result, err_msg='Motion correction is not ' 'accurate enough')
def test_motion_correction_not_in_place(): test_scan = np.double(np.arange(16).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=[0.1, -0.1], in_place=False) assert_allclose( test_scan, np.arange(16).reshape([4, 4]), err_msg='Motion correction is not creating a copy of the scan when ' 'asked to (in_place=False)')
def test_motion_correction_list_input(): test_scan = np.double(np.arange(36).reshape([6, 6])) result = galvo_corrections.correct_motion(test_scan, [0.1, -0.1]) desired_result = [[6.5, 7.5, 8.5, 9.5], [12.5, 13.5, 14.5, 15.5], [18.5, 19.5, 20.5, 21.5], [24.5, 25.5, 26.5, 27.5]] assert_allclose( result[1:-1, 1:-1], desired_result, err_msg='Motion correction can not handle xy_motion as a list.')
def test_motion_correction_with_ndimensional_input(): test_scan = np.double(np.arange(128).reshape([4, 4, 2, 2, 2])) xy_motion = np.reshape(np.arange(16)/10, [2,1,2,2,2]) result = galvo_corrections.correct_motion(test_scan, xy_motion=xy_motion) desired_first_image = [[25.6, 33.6, 41.6, 49.6], [57.6, 65.6, 73.6, 81.6], [89.6, 97.6, 105.6, 113.6], [96, 104, 112, 120]] assert_allclose(result[:, :, 0, 0, 0], desired_first_image, err_msg='Motion correction is not properly handling n-dimensional ' 'scans')
def test_motion_correction_is_accurate(): test_scan = np.double(np.arange(36).reshape([6, 6])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0.1, -0.1])) desired_result = [[6.5, 7.5, 8.5, 9.5], [12.5, 13.5, 14.5, 15.5], [18.5, 19.5, 20.5, 21.5], [24.5, 25.5, 26.5, 27.5]] assert_allclose(result[1:-1, 1:-1], desired_result, err_msg='Motion correction is not ' 'accurate enough')
def test_motion_correction_with_ndimensional_input(): test_scan = np.double(np.arange(128).reshape([4, 4, 2, 2, 2])) xy_motion = np.reshape(np.arange(16) / 10, [2, 1, 2, 2, 2]) result = galvo_corrections.correct_motion(test_scan, xy_motion=xy_motion) desired_first_image = [[25.6, 33.6, 41.6, 49.6], [57.6, 65.6, 73.6, 81.6], [89.6, 97.6, 105.6, 113.6], [96, 104, 112, 120]] assert_allclose( result[:, :, 0, 0, 0], desired_first_image, err_msg='Motion correction is not properly handling n-dimensional ' 'scans')
def test_motion_correction_no_motion(): test_scan = np.double(np.arange(1, 17).reshape([4, 4])) result = galvo_corrections.correct_motion(test_scan, xy_motion=np.array([0, 0])) assert_allclose(result, np.arange(1, 17).reshape([4, 4]), err_msg='Motion correction with zero xy_motion changes the result')