def __init__(self, parent=None): super().__init__(parent) self._channels = {} self._frameSel = multicolor.FrameSelector("") self._registrator = multicolor.Registrator() self.channelsChanged.connect(self._imageDataChanged) self.registratorChanged.connect(self._imageDataChanged) self.excitationSeqChanged.connect(self._imageDataChanged)
def __init__(self, parent=None): super().__init__(parent) self._smData = None self._filterTable = pd.DataFrame(columns=["track_len", "manual"]) self._frameSel = multicolor.FrameSelector("") self._trackLengthRange = [0, np.inf] self._showManuallyFiltered = True self.showManuallyFilteredChanged.connect(self._updateFiltered) self.filterTableChanged.connect(self._updateFiltered)
def test_restore_frame_numbers(self, selector, flex_selector): """multicolor.FrameSelector.restore_frame_numbers""" ar = np.arange(14) ar = ar[ar != 7] df = pd.DataFrame(ar[:, None], columns=["frame"]) exp = [1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 15, 16] df2 = df.copy() selector.restore_frame_numbers(df2, "da") np.testing.assert_array_equal(df2["frame"], exp) df3 = df.copy() flex_selector.restore_frame_numbers( df3, "da", n_frames=len(selector.excitation_seq)) np.testing.assert_array_equal(df3["frame"], exp) df4 = df.copy() with pytest.raises(ValueError): selector.restore_frame_numbers(df4, "") with pytest.raises(ValueError): flex_selector.restore_frame_numbers(df4, "") null_selector = multicolor.FrameSelector("") df5 = df.copy() null_selector.restore_frame_numbers(df5, "d") pd.testing.assert_frame_equal(df5, df)
def test_eval_seq(self, selector): """multicolor.FrameSelector.eval_seq""" np.testing.assert_array_equal( selector.eval_seq(), np.fromiter(selector.excitation_seq, "U1")) np.testing.assert_array_equal( multicolor.FrameSelector("a +bc * 3 + 2*de").eval_seq(), np.fromiter("abcbcbcdede", "U1")) np.testing.assert_array_equal( multicolor.FrameSelector("a +bc * ? + 2*de").eval_seq(9), np.fromiter("abcbcdede", "U1")) with pytest.raises(ValueError): multicolor.FrameSelector("a +bc * ? + 2*de").eval_seq(10) np.testing.assert_array_equal( multicolor.FrameSelector("a + ? * bc + de").eval_seq(9), np.fromiter("abcbcbcde", "U1")) np.testing.assert_array_equal( multicolor.FrameSelector("a + ? * bc + de").eval_seq(-1), np.fromiter("abcde", "U1")) assert multicolor.FrameSelector("").eval_seq().size == 0
def test_select(self, selector, flex_selector, call_results): """multicolor.FrameSelector.select""" ar = np.arange(21) n = len(selector.excitation_seq) for k, v in call_results.items(): r = selector.select(ar, k) np.testing.assert_array_equal(r, v) assert isinstance(r, np.ndarray) fr = flex_selector.select(ar, k, n_frames=n) np.testing.assert_array_equal(fr, v) assert isinstance(fr, np.ndarray) lst = list(ar) for k, v in call_results.items(): r = selector.select(lst, k) np.testing.assert_array_equal(r, v) assert isinstance(r, helper.Slicerator) fr = flex_selector.select(lst, k, n_frames=n) np.testing.assert_array_equal(fr, v) assert isinstance(fr, helper.Slicerator) df = pd.DataFrame(ar[:, None], columns=["frame"]) for k, v in call_results.items(): r = selector.select(df, k) pd.testing.assert_frame_equal(r, df.loc[v]) fr = flex_selector.select(df, k, n_frames=n) pd.testing.assert_frame_equal(fr, df.loc[v]) # Selecting multiple frame types np.testing.assert_equal(selector.select(ar, "da"), call_results["da"]) np.testing.assert_array_equal(selector.select(lst, "da"), call_results["da"]) pd.testing.assert_frame_equal(selector.select(df, "da"), df.loc[call_results["da"]]) # Empty sequence null_selector = multicolor.FrameSelector("") np.testing.assert_equal(null_selector.select(ar, "d"), ar) np.testing.assert_array_equal(null_selector.select(lst, "d"), lst) pd.testing.assert_frame_equal(null_selector.select(df, "d"), df) # Empty `which` np.testing.assert_array_equal(selector.select(ar, ""), []) np.testing.assert_array_equal(selector.select(lst, ""), []) pd.testing.assert_frame_equal(selector.select(df, ""), df.iloc[:0]) np.testing.assert_array_equal(flex_selector.select(ar, ""), []) np.testing.assert_array_equal(flex_selector.select(lst, ""), []) pd.testing.assert_frame_equal(flex_selector.select(df, "", n_frames=n), df.iloc[:0]) # For non-DataFrames, n_frames is deduced from length ar2 = np.arange(10) np.testing.assert_equal(flex_selector.select(ar2, "c"), [0]) np.testing.assert_equal(flex_selector.select(ar2, "d"), [1, 2, 3, 4, 5, 6, 7]) np.testing.assert_equal(flex_selector.select(ar2, "a"), [8, 9]) # For DataFrames, there should be an error with pytest.raises(ValueError): flex_selector.select(df, "d") # drop a frame which should leave a gap when renumbering drop_frame = 3 df2 = df.drop(drop_frame) for k, v in call_results.items(): data = np.arange(len(v))[:, None] # deal with dropped frame v = np.array(v) mask = v != drop_frame v = v[mask] data = data[mask] r = selector.select(df2, k, renumber=True) np.testing.assert_equal(r.index, v) np.testing.assert_equal(r.to_numpy(), data) fr = flex_selector.select(df2, k, renumber=True, n_frames=n) np.testing.assert_equal(fr.index, v) np.testing.assert_equal(fr.to_numpy(), data)
def test_renumber(self, selector, call_results): """multicolor.FrameSelector._renumber, renumber_frames""" drop_frame = 3 seq = np.fromiter(selector.excitation_seq, "U1") for k, v in call_results.items(): v = np.array(v) mask = v != drop_frame v = v[mask] v2 = np.arange(len(mask))[mask] r = multicolor.FrameSelector._renumber(seq, v, k, restore=False) rr = selector.renumber_frames(v, k, restore=False) for cr in r, rr: np.testing.assert_equal(cr, v2) r2 = multicolor.FrameSelector._renumber(seq, v2, k, restore=True) rr2 = selector.renumber_frames(v2, k, restore=True) for cr in r2, rr2: np.testing.assert_equal(cr, v) # Check behavior in case a frame number not belonging to excitation # type given by `which` parameter is in the list bad = np.array([0, 2, 3, 4]) r = multicolor.FrameSelector._renumber( np.array(["d", "a"]), bad, "d", restore=False) r2 = multicolor.FrameSelector("da").renumber_frames( bad, "d", restore=False) for cr in r, r2: np.testing.assert_array_equal(cr, [0, 1, -1, 2]) # There was a bug when the max frame number was divisible by the # length of the excitation sequence, resulting in f_map_inv being too # short. Ensure that this is fixed by using an array with max == 10 # and the sequence "da". ar = np.arange(0, 11, 2) r = multicolor.FrameSelector._renumber( np.array(["d", "a"]), ar, "d", restore=False) r2 = multicolor.FrameSelector("da").renumber_frames( ar, "d", restore=False) for cr in r, r2: np.testing.assert_equal(cr, np.arange(len(ar))) # Test empty sequence and empty `which` ar2 = np.arange(21) r = multicolor.FrameSelector._renumber( np.array([], dtype="U1"), ar2, "d", restore=False) r2 = multicolor.FrameSelector("").renumber_frames( ar2, "d", restore=False) for cr in r, r2: np.testing.assert_array_equal(cr, ar2) r = multicolor.FrameSelector._renumber( np.array(["d", "a"], dtype="U1"), ar2, "", restore=False) r2 = multicolor.FrameSelector("da").renumber_frames( ar2, "", restore=False) for cr in r, r2: np.testing.assert_array_equal(cr, np.full(ar2.size, -1, dtype=int)) with pytest.raises(ValueError): multicolor.FrameSelector._renumber( np.array(["d", "a"], dtype="U1"), ar2, "", restore=True) with pytest.raises(ValueError): multicolor.FrameSelector("da").renumber_frames( ar2, "", restore=True)
def flex_selector(self): return multicolor.FrameSelector("c + d*? + a*2")
def selector(self): return multicolor.FrameSelector("cddddaa")