def test_minimal_pairs(): """ This should return the pairs of elements from list1 and list2 with minimal difference between their values. """ list1 = [0, 5, 10, 15, 20, 25] list2 = [3, 12, 19, 21, 26, 29] assert list(minimal_pairs(list1, list2)) == [(1, 0, 2), (2, 1, 2), (4, 2, 1), (5, 4, 1)]
def _homogenize_params(self, other, maxdiff=1): """ Return triple with a tuple of indices (in self and other, respectively), factors and constants at these frequencies. Parameters ---------- other : `radiospectra.CallistoSpectrogram` Spectrogram to be homogenized with the current one. maxdiff : float Threshold for which frequencies are considered equal. """ pairs_indices = [ (x, y) for x, y, d in minimal_pairs(self.freq_axis, other.freq_axis) if d <= maxdiff ] pairs_data = [(self[n_one, :], other[n_two, :]) for n_one, n_two in pairs_indices] # XXX: Maybe unnecessary. pairs_data_gaussian = [(gaussian_filter1d(a, 15), gaussian_filter1d(b, 15)) for a, b in pairs_data] # If we used integer arithmetic, we would accept more invalid # values. pairs_data_gaussian64 = np.float64(pairs_data_gaussian) least = [ leastsq(self._to_minimize(a, b), [1, 0])[0] for a, b in pairs_data_gaussian64 ] factors = [x for x, y in least] constants = [y for x, y in least] return pairs_indices, factors, constants
def test_closest(): assert (list(minimal_pairs([50, 60], [0, 10, 20, 30, 40, 51, 52])) == [(0, 5, 1), (1, 6, 8)])
def test_minimum_pairs_end_diff(): assert (list(minimal_pairs([0, 1, 2, 8], [1, 2, 3, 4])) == [(1, 0, 0), (2, 1, 0), (3, 3, 4)])
def test_minimum_pairs_commotative(): A = [0, 1, 2] B = [1, 2, 3] first = list(minimal_pairs(A, B)) assert first == [(b, a, d) for a, b, d in minimal_pairs(B, A)]