def it_catches_collisions_in_bg(): cy_ims = np.zeros((n_cycles, h, w)) _peak(cy_ims[0], x, y) # Add a second peak nearby offset_x = 5.0 _peak(cy_ims[0], x + offset_x, y) # A uniform drop is a common thing that happens as a result of a filter # so simulate that here with a constant bg_shift = -2.0 _cy_ims = cy_ims + bg_shift radrow = radiometry_cy_ims( _cy_ims, locs=np.array([[y, x], [y, x + offset_x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) sig = radrow[0, 0, 0] noi = radrow[0, 0, 1] bg_med = radrow[0, 0, 2] bg_std = radrow[0, 0, 3] # It will be brighter because of the contention assert np.abs(sig - 1134.0) < 20.0 # 1134.0 is empirical assert np.abs(bg_med - bg_shift) < 0.5 assert np.abs(bg_std) > 50 # empirical
def it_finds_changes_over_cycles(): n_cycles = 3 w, h = 21, 21 cy_ims = np.zeros((n_cycles, h, w)) x, y = w / 2.0, h / 2.0 amp_per_cycle = [1000.0, 900.0, 100.0] for cy_i in range(n_cycles): _peak(cy_ims[cy_i], x, y, amp=amp_per_cycle[cy_i]) radrow = radiometry_cy_ims( cy_ims, locs=np.array([[y, x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) for cy_i in range(n_cycles): sig = radrow[0, cy_i, 0] noi = radrow[0, cy_i, 1] bg_med = radrow[0, cy_i, 2] bg_std = radrow[0, cy_i, 3] assert np.abs(sig - amp_per_cycle[cy_i]) < 2.00 assert np.abs(noi) < 0.1 assert np.abs(bg_med) < 0.05
def it_finds_many_locs_with_jitter(): n_cycles = 1 w, h = 128, 128 cy_ims = np.zeros((n_cycles, h, w)) locs = [(y, x) for y in np.linspace(10, 110, 8) for x in np.linspace(10, 110, 8)] locs = np.array(locs) locs = locs + np.random.uniform(-1, 1, size=locs.shape) for loc in locs: _peak(cy_ims[0], loc[1], loc[0]) radmat = radiometry_cy_ims( cy_ims, locs=locs, reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) # assert np.all(np.abs(radmat[:, :, 0] - 1000.0) < 0.01) # # Why is this suddenly larger? Originally it was alwasy less than 0.2 # # but now it varys up to 1. But I don't see where the difference is # assert np.all(np.abs(radmat[:, :, 1]) < 1.0) sig = radmat[:, :, 0] noi = radmat[:, :, 1] bg_med = radmat[:, :, 2] bg_std = radmat[:, :, 3] assert np.all(np.abs(sig - 1000.0) < 3.20) assert np.all(np.abs(noi) < 1.0) assert np.all(np.abs(bg_med) < 0.10) assert np.all(np.abs(bg_std - 3.0) < 1.0)
def it_finds_fractional_loc(): n_cycles = 1 w, h = 21, 21 for y in np.linspace(h / 2.0 - 2.0, h / 2.0 + 2.0, 7): for x in np.linspace(w / 2.0 - 2.0, w / 2.0 + 2.0, 7): cy_ims = np.zeros((n_cycles, h, w)) _peak(cy_ims[0], x, y) radrow = radiometry_cy_ims( cy_ims, locs=np.array([[y, x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) sig = radrow[0, 0, 0] noi = radrow[0, 0, 1] bg_med = radrow[0, 0, 2] bg_std = radrow[0, 0, 3] assert np.abs(sig - 1000.0) < 2.00 assert np.abs(noi) < 0.1 assert np.abs(bg_med) < 0.05 assert np.abs(bg_std - 3.0) < 1.0
def it_finds_way_off_center(): n_cycles = 1 w, h = 21, 21 y = h / 2.0 - 3.4 x = w / 2.0 + 2.1 cy_ims = np.zeros((n_cycles, h, w)) _peak(cy_ims[0], x, y) radrow = radiometry_cy_ims( cy_ims, locs=np.array([[y, x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) sig = radrow[0, 0, 0] noi = radrow[0, 0, 1] bg_med = radrow[0, 0, 2] bg_std = radrow[0, 0, 3] assert np.abs(sig - 1000.0) < 2.00 assert np.abs(noi) < 0.1 assert np.abs(bg_med) < 0.05 assert np.abs(bg_std - 3.0) < 1.0
def it_finds_one_peak_centered(): peak_mea = reg_psf.hyper_peak_mea w, h = peak_mea * 2, peak_mea * 2 n_cycles = 1 y = h / 2.0 x = w / 2.0 cy_ims = np.zeros((n_cycles, h, w)) _peak(cy_ims[0], x, y) radrow = radiometry_cy_ims( cy_ims, locs=np.array([[y, x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) sig = radrow[0, 0, 0] noi = radrow[0, 0, 1] bg_med = radrow[0, 0, 2] bg_std = radrow[0, 0, 3] assert np.abs(sig - 1000.0) < 2.00 assert np.abs(noi) < 0.1 assert np.abs(bg_med) < 0.05 assert np.abs(bg_std - 3.0) < 1.0
def it_bg_corrects_with_no_collisions(): cy_ims = np.zeros((n_cycles, h, w)) _peak(cy_ims[0], x, y) # A uniform drop is a common thing that happens as a result of a filter # so simulate that here with a constant bg_shift = -2.0 _cy_ims = cy_ims + bg_shift radrow = radiometry_cy_ims( _cy_ims, locs=np.array([[y, x]]), reg_psf_samples=reg_psf_samples, peak_mea=reg_psf.hyper_peak_mea, ) sig = radrow[0, 0, 0] bg_med = radrow[0, 0, 2] bg_std = radrow[0, 0, 3] assert np.abs(sig - 999.0) < 1.0 assert np.abs(bg_med - bg_shift) < 0.5 assert np.abs(bg_std - 3.0) < 0.5