def test_sample_peaks(): pm = _load() rtmin = pm.spectra[0].rt rtmax = pm.spectra[-1].rt mzmin = min(min(s.peaks[:, 0]) for s in pm.spectra) mzmax = max(max(s.peaks[:, 0]) for s in pm.spectra) res = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, 1) assert res is not None assert res.shape == (1, 2) res = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, 10000) assert res is not None assert res.shape == (9876, 2) s0 = pm.spectra[0] pm.spectra = [s0] res = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, 10000) assert res is not None assert res.shape == (76, 2), res.shape dist = np.linalg.norm(res[0:2, :] - pm.spectra[0].peaks[0:2, :]) assert dist == 0.0
def do_backspace_pressed(self, filter, evt): """ reset axes of plot """ all_peaks = [] for i, (pm, rtmin, rtmax, mzmin, mzmax, npeaks) in enumerate(self.data): peaks = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, npeaks) curve = self.curves[i] curve.set_data(peaks[:, 0], peaks[:, 1]) all_peaks.append(peaks) if len(all_peaks): self.all_peaks = np.vstack(all_peaks) else: self.all_peaks = np.zeros((0, 2)) self.reset_x_limits()
def resample_peaks(self, mzmin, mzmax): if mzmin == self.latest_mzmin and mzmax == self.latest_mzmax: return self.latest_mzmin = mzmin self.latest_mzmax = mzmax all_peaks = [] for i, (pm, rtmin, rtmax, __, __, npeaks) in enumerate(self.data): peaks = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, npeaks) curve = self.curves[i] curve.set_data(peaks[:, 0], peaks[:, 1]) all_peaks.append(peaks) if len(all_peaks): self.all_peaks = np.vstack(all_peaks) else: self.all_peaks = np.zeros((0, 2))