How to use the lightkurve.correctors.DesignMatrix function in lightkurve

To help you get started, we’ve selected a few lightkurve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KeplerGO / lightkurve / lightkurve / correctors / sffcorrector.py View on Github external
Name to pass to `.DesignMatrix` (default: 'spline').
    include_intercept: bool
        Whether to include row of ones to find intercept. Default False.

    Returns
    -------
    dm: `.DesignMatrix`
        Design matrix object with shape (len(x), n_knots*degree).
    """
    from patsy import dmatrix  # local import because it's rarely-used
    dm_formula = "bs(x, df={}, degree={}, include_intercept={}) - 1" \
                 "".format(n_knots, degree, include_intercept)
    spline_dm = np.asarray(dmatrix(dm_formula, {"x": x}))
    df = pd.DataFrame(spline_dm, columns=['knot{}'.format(idx + 1)
                                          for idx in range(n_knots)])
    return DesignMatrix(df, name=name)
github KeplerGO / lightkurve / lightkurve / correctors / sffcorrector.py View on Github external
columns = []
        prior_sigmas = []
        for idx, a, b in zip(range(len(lower_idx)), lower_idx, upper_idx):
            knots = list(np.percentile(self.arclength[a:b], np.linspace(0, 100, bins+1)[1:-1]))
            ar = np.copy(self.arclength)
            ar[~np.in1d(ar, ar[a:b])] = 0
            dm = np.asarray(dmatrix("bs(x, knots={}, degree={}, include_intercept={}) - 1"
                                    "".format(knots, degree, True), {"x": ar}))
            stack.append(dm)
            columns.append(['window{}_bin{}'.format(idx+1, jdx+1)
                            for jdx in range(len(dm.T))])

            # I'm putting VERY weak priors on the SFF motion vectors
            prior_sigmas.append(np.ones(len(dm.T)) * 10000 * self.lc[a:b].flux.std())

        sff_dm = DesignMatrix(pd.DataFrame(np.hstack(stack)),
                              columns=np.hstack(columns),
                              name='sff',
                              prior_sigma=np.hstack(prior_sigmas))


        # long term
        n_knots = int((self.lc.time[-1] - self.lc.time[0])/timescale)
        s_dm = _get_spline_dm(self.lc.time, n_knots=n_knots, include_intercept=True)

        means = [np.average(self.lc.flux, weights=s_dm.values[:, idx]) for idx in range(s_dm.shape[1])]
        s_dm.prior_mu = np.asarray(means)

        # I'm putting WEAK priors on the spline that it must be around 1
        s_dm.prior_sigma = np.ones(len(s_dm.prior_mu)) * 1000 * self.lc.flux.std()

        # additional
github KeplerGO / lightkurve / lightkurve / correctors / sffcorrector.py View on Github external
prior_sigma=np.hstack(prior_sigmas))


        # long term
        n_knots = int((self.lc.time[-1] - self.lc.time[0])/timescale)
        s_dm = _get_spline_dm(self.lc.time, n_knots=n_knots, include_intercept=True)

        means = [np.average(self.lc.flux, weights=s_dm.values[:, idx]) for idx in range(s_dm.shape[1])]
        s_dm.prior_mu = np.asarray(means)

        # I'm putting WEAK priors on the spline that it must be around 1
        s_dm.prior_sigma = np.ones(len(s_dm.prior_mu)) * 1000 * self.lc.flux.std()

        # additional
        if additional_design_matrix is not None:
            if not isinstance(additional_design_matrix, DesignMatrix):
                raise ValueError('`additional_design_matrix` must be a DesignMatrix object.')
            self.additional_design_matrix = additional_design_matrix
            dm = DesignMatrixCollection([s_dm,
                                         sff_dm,
                                         additional_design_matrix])
        else:
            dm = DesignMatrixCollection([s_dm, sff_dm])

        # correct
        clc = super(SFFCorrector, self).correct(dm, **kwargs)

        # clean
        if restore_trend:
            trend = self.diagnostic_lightcurves['spline'].flux
            clc += trend - np.nanmedian(trend)
        clc *= self.raw_lc.flux.mean()
github KeplerGO / lightkurve / lightkurve / correctors / sffcorrector.py View on Github external
Design matrix with shape len(c) x 10
    """
    data = [col, row,
            col**2, row**2,
            col**3, row**3,
            col*row,
            col**2 * row, col * row**2,
            col**2 * row**2]
    names = [r'col', r'row',
             r'col^2', r'row^2',
             r'col^3', r'row^3',
             r'col \times row',
             r'col^2 \times row', r'col \times row^2',
             r'col^2 \times row^2']
    df = pd.DataFrame(np.asarray(data).T, columns=names)
    return DesignMatrix(df, name=name)