Beispiel #1
0
    def _createFromExtension(self, extension, max_bins):
        time = []
        mag = []
        err = []
        error_occured = False
        for line in extension.data:
            try:
                time.append(line[self.TIME_COL])
                mag.append(line[self.MAG_COL])
                err.append(line[self.ERR_COL] / self.ERR_MAG_RATIO)
            # Case of no lc
            except IndexError:
                error_occured = True

        if error_occured:
            if len(time) == len(mag) and len(time) > 0:
                if not err or len(err) != len(time):
                    err = np.zeros(len(time))
            else:
                return None

        if len(time) > max_bins:
            red_time, red_mag = to_ekvi_PAA(time, mag, bins=max_bins)
            red_time, red_err = to_ekvi_PAA(time, err, bins=max_bins)
        else:
            return time, mag, err
        return red_time, red_mag, red_err
Beispiel #2
0
    def getFeatures(self, star):
        """
        Get  skewness

        Parameters
        -----------
        star : lcc.entities.star.Star object
            Star to process

        Returns
        -------
        float
            Kurtosis of investigated star
        """
        lc = star.lightCurve
        if self.bins:
            _, mags = to_ekvi_PAA(lc.time, lc.mag, self.bins)
        else:
            mags = lc.mag
        kurt = kurtosis(mags)

        if self.absolute:
            kurt = abs(kurt)

        return kurt
Beispiel #3
0
    def getSpaceCoords(self, stars):
        """
        Get list of skewness values

        Parameters
        -----------
        stars : list of Star objects
            Stars which contain light curves

        Returns
        -------
        list
            List of list of floats
        """
        kurtosis_list = []
        for star in stars:
            if star.lightCurve:
                lc = star.lightCurve
                if self.bins:
                    _, mags = to_ekvi_PAA(lc.time, lc.mag, self.bins)
                else:
                    mags = lc.mag
                kurt = kurtosis(mags)

                if self.absolute:
                    kut = abs(kurt)

            else:
                kurt = None
            kurtosis_list.append(kurt)
        return kurtosis_list
Beispiel #4
0
    def getFeatures(self, star):
        """
        Get density of the star's light curve

        Parameters
        -----------
        star : lcc.entities.star.Star object
            Star to process

        Returns
        -------
        list, iterable, int, float
            Density (points per time lag) of the investigated star
        """
        x, _ = to_ekvi_PAA(star.lightCurve.time, star.lightCurve.mag)
        ren = x.max() - x.min()
        return len(x) / ren
def test_to_ekvi_PAA1():
    n = 100
    x = np.linspace(0, 1, n)
    y = np.random.random_sample(n)

    bins = np.random.randint(5, 30)

    x_ekv1, y_ekv1 = to_ekvi_PAA(x, y,  bins)
    x_ekv2, y_ekv2 = to_ekvi_PAA(x, y, len(x))
    x_ekv3, y_ekv3 = to_ekvi_PAA(x, y, 3 * len(x))

    assert len(x_ekv1) == bins
    assert len(x_ekv2) == len(x)
    assert len(x_ekv3) == len(x)
    assert np.nan not in y_ekv1
    assert np.nan not in y_ekv2
    assert np.nan not in y_ekv3
    assert (y_ekv3 == y).all()
    assert (y_ekv2 == y).all()

    for _ in range(100):
        n = np.random.randint(30, 700)
        x = np.random.random_sample(n)

        x1 = np.linspace(0, 1, n)
        y = np.random.random_sample(n)

        bins = np.random.randint(5, 30)

        x_ekv1, y_ekv1 = to_ekvi_PAA(x, y,  bins)
        x_ekv2, y_ekv2 = to_ekvi_PAA(x, y, len(x))
        x_ekv3, y_ekv3 = to_ekvi_PAA(x, y, 3 * len(x))
        x_ekv4, y_ekv4 = to_ekvi_PAA(x1, y, len(x1))

        assert len(x_ekv1) == bins
        assert len(x_ekv2) == len(x)
        assert len(x_ekv3) == len(x)
        assert np.nan not in y_ekv1
        assert np.nan not in y_ekv2
        assert np.nan not in y_ekv3
        assert (y_ekv4 == y).all()

        thr = 0.1
        assert abs(y_ekv1.mean() - y.mean()) / (y_ekv1.mean() + y.mean()) < thr
        assert abs(y_ekv2.mean() - y.mean()) / (y_ekv2.mean() + y.mean()) < thr
        assert abs(y_ekv3.mean() - y.mean()) / (y_ekv3.mean() + y.mean()) < thr
Beispiel #6
0
    def getAbbe(self, bins=None):
        """
        Compute Abbe value of the light curve

        Parameters
        -----------
        bins : int
            Number of bins from original dimension

        Returns
        --------
        float
            Abbe value of the light curve
        """
        if bins:
            x = to_ekvi_PAA(self.time, self.mag, bins)[1]
        else:
            x = self.mag
        return abbe(x, len(self.time))
    def getSpaceCoords(self, stars):
        """
        Get list of curve densities

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

        Returns
        -------
        list
            Densities of points per time lag
        """
        coo = []
        for star in stars:
            if star.lightCurve:
                x, _ = to_ekvi_PAA(star.lightCurve.time, star.lightCurve.mag)
                ren = x.max() - x.min()
                coo.append(len(x) / ren)
            else:
                coo.append([None])
        return coo
def test_fix_missing():
    x = np.linspace(0, 10, 20)
    y = x.copy()
    x[:5] = np.linspace(-15, -10, 5)

    xx, yy = to_ekvi_PAA(x, y)
    yy[0] = np.nan
    yy[-1] = np.nan

    res1 = fix_missing(xx, yy, replace_at_borders=False)

    assert len(res1[0]) == len(res1[1])
    assert len(res1[0]) == len(xx) - 2
    assert not np.isnan(res1[0]).any()
    assert not np.isnan(res1[1]).any()

    res2 = fix_missing(xx, yy, replace_at_borders=True)

    assert len(res2[0]) == len(res2[1])
    assert len(res2[0]) == len(xx)
    assert not np.isnan(res2[0]).any()
    assert not np.isnan(res2[1]).any()
    assert res2[1][0] == res2[1][1]
    assert res2[1][-2] == res2[1][-1]
    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