Exemplo n.º 1
0
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(util.minimal_pairs(list1, list2)) == [(1, 0, 2), (2, 1, 2),
                                                      (4, 2, 1), (5, 4, 1)]
Exemplo n.º 2
0
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(util.minimal_pairs(list1, list2)) == [(1, 0, 2), (2, 1, 2),
                                                      (4, 2, 1), (5, 4, 1)]
Exemplo n.º 3
0
 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 : 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
Exemplo n.º 4
0
    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 : 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