How to use the starry._core.math function in starry

To help you get started, we’ve selected a few starry 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 rodluger / starry / starry / kepler.py View on Github external
def _get_periods(self):
        periods = [None for sec in self._secondaries]
        for i, sec in enumerate(self._secondaries):
            if sec.porb:
                periods[i] = sec.porb
            else:
                periods[i] = (
                    (2 * np.pi)
                    * sec._a ** (3 / 2)
                    / (math.sqrt(G_grav * (self._primary._m + sec._m)))
                )
        return math.to_array_or_tensor(periods)
github rodluger / starry / starry / kepler.py View on Github external
X = math.cast(design_matrix)

        # Get the data vector
        f = math.cast(self._flux)

        # Check for bodies whose priors are set
        self._solved_bodies = []
        inds = []
        dense_L = False
        for k, body in enumerate(self._bodies):

            if body.map._mu is None or body.map._L is None:

                # Subtract out this term from the data vector,
                # since it is fixed
                f -= body.map.amp * math.dot(X[:, self._inds[k]], body.map.y)

            else:

                # Add to our list of indices/bodies to solve for
                inds.extend(self._inds[k])
                self._solved_bodies.append(body)
                if body.map._L.kind in ["matrix", "cholesky"]:
                    dense_L = True

        # Do we have at least one body?
        if len(self._solved_bodies) == 0:
            raise ValueError("Please provide a prior for at least one body.")

        # Keep only the terms we'll solve for
        X = X[:, inds]
github rodluger / starry / starry / kepler.py View on Github external
.. note::
            Users may call the :py:meth:`draw` method of this class to draw
            from the posterior after calling :py:meth:`solve`.
        """
        # TODO: Implement for spectral maps?
        self._no_spectral()

        # Check that the data is set
        if self._flux is None or self._C is None:
            raise ValueError("Please provide a dataset with `set_data()`.")

        # Get the full design matrix
        if design_matrix is None:
            assert t is not None, "Please provide a time vector `t`."
            design_matrix = self.design_matrix(t)
        X = math.cast(design_matrix)

        # Get the data vector
        f = math.cast(self._flux)

        # Check for bodies whose priors are set
        self._solved_bodies = []
        inds = []
        dense_L = False
        for k, body in enumerate(self._bodies):

            if body.map._mu is None or body.map._L is None:

                # Subtract out this term from the data vector,
                # since it is fixed
                f -= body.map.amp * math.dot(X[:, self._inds[k]], body.map.y)
github rodluger / starry / starry / kepler.py View on Github external
def position(self, t):
        """Compute the Cartesian positions of all bodies at times ``t``.

        Args:
            t (scalar or vector): An array of times at which to evaluate
                the position in units of :py:attr:`time_unit`.
        """
        x, y, z = self.ops.position(
            math.reshape(math.to_array_or_tensor(t), [-1]) * self._time_factor,
            self._primary._m,
            self._primary._t0,
            math.to_array_or_tensor([sec._m for sec in self._secondaries]),
            math.to_array_or_tensor([sec._t0 for sec in self._secondaries]),
            self._get_periods(),
            math.to_array_or_tensor([sec._ecc for sec in self._secondaries]),
            math.to_array_or_tensor([sec._w for sec in self._secondaries]),
            math.to_array_or_tensor([sec._Omega for sec in self._secondaries]),
            math.to_array_or_tensor([sec._inc for sec in self._secondaries]),
        )
        fac = np.reshape(
            [self._primary._length_factor]
            + [sec._length_factor for sec in self._secondaries],
            [-1, 1],
        )
        return (x / fac, y / fac, z / fac)
github rodluger / starry / starry / maps.py View on Github external
def __init__(self, *args, **kwargs):
            self._lazy = lazy
            if lazy:
                self._math = math.lazy_math
                self._linalg = math.lazy_linalg
            else:
                self._math = math.greedy_math
                self._linalg = math.greedy_linalg
            super(Map, self).__init__(*args, source_npts=source_npts, **kwargs)
github rodluger / starry / starry / kepler.py View on Github external
# Stack our priors
        mu = math.concatenate([body.map._mu for body in self._solved_bodies])

        # Compute the likelihood
        if woodbury:
            if not dense_L:
                # We can just concatenate vectors
                LInv = math.concatenate(
                    [
                        body.map._L.inverse * math.ones(body.map.Ny)
                        for body in self._solved_bodies
                    ]
                )
            else:
                LInv = math.block_diag(
                    *[
                        body.map._L.inverse * math.eye(body.map.Ny)
                        for body in self._solved_bodies
                    ]
                )
            lndetL = math.cast(
                [body.map._L.lndet for body in self._solved_bodies]
            )
            return linalg.lnlike_woodbury(
                X, f, self._C.inverse, mu, LInv, self._C.lndet, lndetL
            )
        else:
            if not dense_L:
                # We can just concatenate vectors
                L = math.concatenate(
                    [
github rodluger / starry / starry / kepler.py View on Github external
mu = math.concatenate([body.map._mu for body in self._solved_bodies])

        if not dense_L:
            # We can just concatenate vectors
            LInv = math.concatenate(
                [
                    body.map._L.inverse * math.ones(body.map.Ny)
                    for body in self._solved_bodies
                ]
            )
        else:
            # FACT: The inverse of a block diagonal matrix
            # is the block diagonal matrix of the inverses.
            LInv = math.block_diag(
                *[
                    body.map._L.inverse * math.eye(body.map.Ny)
                    for body in self._solved_bodies
                ]
            )

        # Compute the MAP solution
        self._solution = linalg.solve(X, f, self._C.cholesky, mu, LInv)

        # Set all the map vectors
        x, cho_cov = self._solution
        n = 0
        for body in self._solved_bodies:
            inds = slice(n, n + body.map.Ny)
            body.map.amp = x[inds][0]
            body.map[1:, :] = x[inds][1:] / body.map.amp
            n += body.map.Ny
github rodluger / starry / starry / kepler.py View on Github external
self._primary._map._f,
            self._primary._map._alpha,
            math.to_array_or_tensor([sec._r for sec in self._secondaries]),
            math.to_array_or_tensor([sec._m for sec in self._secondaries]),
            math.to_array_or_tensor([sec._prot for sec in self._secondaries]),
            math.to_array_or_tensor([sec._t0 for sec in self._secondaries]),
            math.to_array_or_tensor(
                [sec._theta0 for sec in self._secondaries]
            ),
            self._get_periods(),
            math.to_array_or_tensor([sec._ecc for sec in self._secondaries]),
            math.to_array_or_tensor([sec._w for sec in self._secondaries]),
            math.to_array_or_tensor([sec._Omega for sec in self._secondaries]),
            math.to_array_or_tensor([sec._inc for sec in self._secondaries]),
            math.to_array_or_tensor(
                [math.to_array_or_tensor(1.0) for sec in self._secondaries]
            ),
            math.to_array_or_tensor(
                [sec._map._inc for sec in self._secondaries]
            ),
            math.to_array_or_tensor(
                [sec._map._obl for sec in self._secondaries]
            ),
            math.to_array_or_tensor(
                [sec._map._u for sec in self._secondaries]
            ),
            math.to_array_or_tensor(
                [sec._map._f for sec in self._secondaries]
            ),
            math.to_array_or_tensor(
                [sec._map._alpha for sec in self._secondaries]
            ),
github rodluger / starry / starry / maps.py View on Github external
def __init__(self, *args, **kwargs):
            self._lazy = lazy
            if lazy:
                self._math = math.lazy_math
                self._linalg = math.lazy_linalg
            else:
                self._math = math.greedy_math
                self._linalg = math.greedy_linalg
            super(Map, self).__init__(*args, source_npts=source_npts, **kwargs)
github rodluger / starry / starry / maps.py View on Github external
def __init__(self, *args, **kwargs):
            self._lazy = lazy
            if lazy:
                self._math = math.lazy_math
                self._linalg = math.lazy_linalg
            else:
                self._math = math.greedy_math
                self._linalg = math.greedy_linalg
            super(Map, self).__init__(*args, source_npts=source_npts, **kwargs)