Exemple #1
0
    def to_letter_rep(self, x):
        """
        Function takes a series of data, x, and transforms it
        to a string representation.

        Parameters
        ----------
        x : list, iterable
            Data series

        Returns
        -------
        str
            SAX word
        list
            Indices
        """
        paaX, indices = to_PAA(normalize(x), self.word_size)
        self.scaling_factor = np.sqrt(len(x) / self.word_size)
        return self.alphabetize(paaX), indices
    def getSpaceCoords(self, stars):
        """
        Get reduced light curve as coordinates

        Parameters
        -----------
        stars : list of Star objects
            Stars with color magnitudes in their 'more' attribute

        Returns
        -------
        list
            List of list of floats
        """
        if not self.bins:
            self.bins = np.min(
                [len(st.lightCurve.mag) for st in stars if st.lightCurve])
            self.LABEL = [
                "Light curve point " + str(i + 1) for i in range(self.bins)
            ]
            print "Setting bins as min: ", self.bins

        coords = []
        for star in stars:
            if star.lightCurve:
                x, y = to_ekvi_PAA(star.lightCurve.time, star.lightCurve.mag)

                if len(y) > self.bins:
                    y, _ = to_PAA(y, self.bins)
                else:
                    y, _ = to_PAA(star.lightCurve.mag, self.bins)
                y = np.array(y)

                if self.height:
                    y = self.height * y / (y.max() - y.min())
                    y = np.array([int(round(q)) for q in y])
                else:
                    y = y / (y.max() - y.min())

                y -= y.mean()
                coords.append(y.tolist())
            else:
                coords.append(None)

        if self.red_dim:
            _coords = [c for c in coords if c]

            if len(_coords[0]) > self.red_dim:
                _coords = self._reduceDimension(_coords)
            else:
                QueryInputError(
                    "Number of samples have to be greater then reduced dimension"
                )

            k = 0
            red_coo = []
            for c in coords:
                if c:
                    red_coo.append(_coords[k])
                    k += 1
                else:
                    red_coo.append([np.NaN])
            coords = red_coo

        return coords
def test_to_PAA():
    for _ in range(100):
        x = np.random.random_sample(np.random.randint(30, 700))

        bins = np.random.randint(5, 30)
        assert len(to_PAA(x, bins)[0]) == bins