class TestCellListSTORM(ArrayTestCase): def setUp(self): f_path = os.path.dirname(os.path.realpath(__file__)) self.cell_list = load( os.path.join(f_path, 'test_data', 'test_synth_cell_storm.hdf5')) self.cell = self.cell_list[0] x = np.arange(20) y = np.exp(-x / 5) img_3d = self.cell.data.data_dict['fluorescence'][ np.newaxis, :, :] * y[:, np.newaxis, np.newaxis] self.cell.data.add_data(img_3d, 'fluorescence', 'flu_3d') data = Data() data.add_data(self.cell.data.binary_img, 'binary') self.empty_cell = Cell(data) def test_l_dist(self): nbins = 50 with self.assertRaises(IndexError): x, y = self.empty_cell.l_dist(nbins) with self.assertRaises( ValueError): # todo refactor to stay as KeyError? x, y = self.cell.l_dist(nbins, data_name='notexisting') with self.assertRaises(ValueError): x, y = self.cell.l_dist(nbins, method='notexisting') storm_int_sum = np.sum(self.cell.data.data_dict['storm']['intensity']) x, y = self.cell.l_dist(nbins, data_name='storm', r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='storm', method='box', r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='storm', method='box', storm_weight=True, r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='fluorescence') x, y = self.cell.l_dist(nbins, data_name='fluorescence', method='box') x, y = self.cell.l_dist( nbins, method='box', ) x, y = self.cell.l_dist(nbins, method='box', l_mean=0.75 * self.cell.length, norm_x=True) x, y = self.cell.l_dist(nbins, method='box', norm_x=True) x, y = self.cell.l_dist(nbins, method='box', r_max=np.inf) x, y = self.cell.l_dist(nbins, method='box', r_max=1) x, y = self.cell.l_dist(nbins, method='box', r_max=0) x, y_list = self.cell.l_dist(nbins, data_name='flu_3d') self.assertEqual(len(y_list), 20) def test_l_classify(self): p, b, m = self.cell.l_classify(data_name='storm') total = len(self.cell.data.data_dict['storm']) self.assertEqual(p + b + m, total) p, b, m = self.cell.l_classify() total = len(self.cell.data.data_dict['storm']) self.assertEqual(p + b + m, total) def test_r_dist(self): stop = 15 step = 0.5 with self.assertRaises(IndexError): x, y = self.empty_cell.r_dist(stop, step) with self.assertRaises( ValueError): # todo refactor to stay as KeyError? x, y = self.cell.r_dist(stop, step, data_name='notexisting') with self.assertRaises(ValueError): x, y = self.cell.r_dist(stop, step, method='notexisting') stop = 15 step = 0.5 bins_box = np.arange(0, stop + step, step) + 0.5 * step bins = np.arange(0, stop + step, step) storm_int_sum = np.sum(self.cell.data.data_dict['storm']['intensity']) x, y = self.cell.r_dist(data_name='storm', stop=stop, step=step) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.r_dist(data_name='storm', stop=stop, step=step, storm_weight=True) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.r_dist(stop, step, data_name='fluorescence') self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l='full') x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l='poles') with self.assertRaises(AssertionError): x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=0) with self.assertRaises(AssertionError): x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=0.5) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1e-3) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1e-10) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1 - 1e-10) self.assertArrayEqual(bins, x) def test_phi_dist(self): step = 0.5 with self.assertRaises(IndexError): x, yl, yr = self.empty_cell.phi_dist(step) with self.assertRaises( ValueError): # todo refactor to stay as KeyError? x, yl, yr = self.cell.phi_dist(step, data_name='notexisting') with self.assertRaises(ValueError): x, yl, yr = self.cell.phi_dist(step, method='notexisting') stop = 180 bins_box = np.arange(0, stop + step, step) + 0.5 * step bins = np.arange(0, stop + step, step) x, y = self.cell.data.data_dict['storm'][ 'x'], self.cell.data.data_dict['storm']['y'] lc, rc, psi = self.cell.coords.transform(x, y) b = np.logical_and(psi != 0, psi != 180) # only localizations at poles storm_int_sum = np.sum( self.cell.data.data_dict['storm']['intensity'][b]) x, yl, yr = self.cell.phi_dist(step, data_name='storm', r_max=np.inf) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(yl + yr), storm_int_sum) x, yl, yr = self.cell.phi_dist(step, data_name='storm', storm_weight=True, r_max=np.inf) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(yl + yr), storm_int_sum) x, yl, yr = self.cell.phi_dist(step, data_name='storm', r_max=0) self.assertEqual(np.sum(yl + yr), 0) x, yl, yr = self.cell.phi_dist(step, data_name='fluorescence') self.assertArrayEqual(bins, x) x, yl, yr = self.cell.phi_dist(step, data_name='fluorescence', r_min=-5) x, yl, yr = self.cell.phi_dist(step, data_name='fluorescence', r_max=0) x, yl, yr = self.cell.phi_dist(step, data_name='fluorescence', r_max=0, r_min=5) self.assertEqual(np.sum(yl + yr), 0)
class TestCellListSTORM(ArrayTestCase): def setUp(self): f_path = os.path.dirname(os.path.realpath(__file__)) self.cell_list = load( os.path.join(f_path, 'test_data', 'test_synth_cell_storm.hdf5')) self.cell = self.cell_list[0] data = Data() data.add_data(self.cell.data.binary_img, 'binary') self.empty_cell = Cell(data) def test_l_dist(self): nbins = 50 with self.assertRaises(IndexError): x, y = self.empty_cell.l_dist(nbins) with self.assertRaises( ValueError): # todo refactor to stay as KeyError? x, y = self.cell.l_dist(nbins, data_name='notexisting') with self.assertRaises(ValueError): x, y = self.cell.l_dist(nbins, method='notexisting') storm_int_sum = np.sum(self.cell.data.data_dict['storm']['intensity']) x, y = self.cell.l_dist(nbins, data_name='storm', r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='storm', method='box', r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='storm', method='box', storm_weight=True, r_max=20) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.l_dist(nbins, data_name='fluorescence') x, y = self.cell.l_dist(nbins, data_name='fluorescence', method='box') x, y = self.cell.l_dist( nbins, method='box', ) x, y = self.cell.l_dist(nbins, method='box', l_mean=0.75 * self.cell.length, norm_x=True) x, y = self.cell.l_dist(nbins, method='box', norm_x=True) x, y = self.cell.l_dist(nbins, method='box', r_max=np.inf) x, y = self.cell.l_dist(nbins, method='box', r_max=1) x, y = self.cell.l_dist(nbins, method='box', r_max=0) def test_l_classify(self): pass def test_r_dist(self): stop = 15 step = 0.5 with self.assertRaises(IndexError): x, y = self.empty_cell.r_dist(stop, step) with self.assertRaises( ValueError): # todo refactor to stay as KeyError? x, y = self.cell.r_dist(stop, step, data_name='notexisting') with self.assertRaises(ValueError): x, y = self.cell.r_dist(stop, step, method='notexisting') stop = 15 step = 0.5 bins_box = np.arange(0, stop + step, step) + 0.5 * step bins = np.arange(0, stop + step, step) storm_int_sum = np.sum(self.cell.data.data_dict['storm']['intensity']) x, y = self.cell.r_dist(data_name='storm', stop=stop, step=step) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.r_dist(data_name='storm', stop=stop, step=step, storm_weight=True) self.assertArrayEqual(bins_box, x) self.assertEqual(np.sum(y), storm_int_sum) x, y = self.cell.r_dist(stop, step, data_name='fluorescence') self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l='full') x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l='poles') with self.assertRaises(AssertionError): x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=0) with self.assertRaises(AssertionError): x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=0.5) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1e-3) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1e-10) self.assertArrayEqual(bins, x) x, y = self.cell.r_dist(stop, step, data_name='fluorescence', limit_l=1 - 1e-10) self.assertArrayEqual(bins, x)