How to use the starry.config 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 / tests / greedy / test_misc.py View on Github external
def test_check_kwargs_map(caplog):
    """Test that we capture bad keyword arguments."""
    starry.config.quiet = False
    caplog.clear()
    map = starry.Map(giraffe=10)
    assert len(caplog.records) >= 1
    assert any(
        [
            "Invalid keyword `giraffe`" in str(rec.message)
            for rec in caplog.records
        ]
github rodluger / starry / tests / greedy / test_high_l_stability.py View on Github external
ro = 0.9
    flux = map.flux(xo=xo, yo=yo, ro=ro)
    bo = np.sqrt(xo ** 2 + yo ** 2)
    ksq = (1 - ro ** 2 - bo ** 2 + 2 * bo * ro) / (4 * bo * ro)

    if plot:
        plt.plot(ksq, flux)
        plt.xscale("log")
        plt.show()

    # Check for gross stability issues here
    assert np.std(flux[ksq > 1]) < 0.1


if __name__ == "__main__":
    starry.config.lazy = False
    plt.style.use("default")
    test_high_l_stability(plot=True)
github rodluger / starry / tests / greedy / test_oren_nayar.py View on Github external
plt.colorbar(im, ax=ax[1])
        im = ax[2].imshow(img_diff, origin="lower", extent=(-1, 1, -1, 1))
        plt.colorbar(im, ax=ax[2])

        fig = plt.figure()
        plt.hist(diff, bins=50)
        plt.xlabel("diff")
        plt.show()

    assert np.abs(mu) < 1e-5, np.abs(mu)
    assert std < 1e-3, std
    assert maxabs < 1e-2, maxabs


if __name__ == "__main__":
    starry.config.lazy = False
    test_terminator_continuity()
    test_half_phase_discontinuity()
    test_approximation()
github rodluger / starry / tests / compare_to_beta / compare.py View on Github external
"""
Functions to compare stuff to the beta version. A work in progress.

"""
import starry
import starry_beta
import numpy as np
import matplotlib.pyplot as plt
import theano
import theano.tensor as tt
import time
from tqdm import tqdm

starry.config.lazy = False


def compare_plot():

    theta = np.linspace(-5, 10, 1000)
    xo = np.linspace(-3, 3, len(theta))
    yo = np.zeros_like(xo) + 0.1
    ro = 0.1

    map = starry.Map(ydeg=1, udeg=1)
    map[1, 0] = 0.5
    map.inc = 45
    plt.plot(xo, map.flux(theta=theta, xo=xo, yo=yo, ro=ro), label="v1", lw=3)

    map_beta = starry_beta.Map(1)
    map_beta[1, 0] = 0.5
github rodluger / starry / starry / kepler.py View on Github external
def _check_kwargs(self, method, kwargs):
        if not config.quiet:
            for key in kwargs.keys():
                message = "Invalid keyword `{0}` in call to `{1}()`. Ignoring."
                message = message.format(key, method)
                logger.warning(message)
github rodluger / starry / starry / ops / utils.py View on Github external
def wrapper(instance, *args, force_compile=False, no_compile=False):
            """
            The magic happens in here.

            """
            if (not no_compile) and ((not config.lazy) or (force_compile)):
                # Compile the function if needed & cache it
                if not hasattr(instance, self.compiled_name):

                    cur_args = list(self.args)
                    # Evaluate any dynamic types. These are tensors
                    # whose types depend on specific properties of the
                    # `Ops` instance that are evaluated at run time.
                    for i, arg in enumerate(cur_args):
                        if isinstance(arg, DynamicType):
                            cur_args[i] = arg(instance)

                    with CompileLogMessage(self.name):
                        with change_flags(compute_test_value="off"):
                            compiled_func = theano.function(
                                [*cur_args],
                                func(instance, *cur_args),
github rodluger / starry / starry / maps.py View on Github external
finite illumination source size. Default is 1. Valid only if
            `reflected` is True.
    """
    # Check args
    ydeg = int(ydeg)
    assert ydeg >= 0, "Keyword `ydeg` must be positive."
    udeg = int(udeg)
    assert udeg >= 0, "Keyword `udeg` must be positive."
    if nw is not None:
        nw = int(nw)
        assert nw > 0, "Number of wavelength bins must be positive."
    source_npts = int(source_npts)
    if source_npts < 1:
        source_npts = 1
    if lazy is None:
        lazy = config.lazy

    # TODO: phase this next warning out
    if source_npts != 1:
        logger.warning(
            "Finite source size is still an experimental feature. "
            "Use it with care."
        )

    # Limb-darkened?
    if (ydeg == 0) and (rv is False) and (reflected is False):

        # TODO: Add support for wavelength-dependent limb darkening
        if nw is not None:
            raise NotImplementedError(
                "Multi-wavelength limb-darkened maps are not yet supported."
            )
github rodluger / starry / starry / kepler.py View on Github external
math.to_array_or_tensor(
                [sec._map._alpha for sec in self._secondaries]
            ),
        )

        # Convert to units of the primary radius
        fac = np.reshape(
            [sec._length_factor for sec in self._secondaries], [-1, 1]
        )
        fac = fac * self._primary._r
        x, y, z = x / fac, y / fac, z / fac
        r = math.to_array_or_tensor([sec._r for sec in self._secondaries])
        r = r / self._primary._r

        # Evaluate if needed
        if config.lazy:
            img_pri = img_pri.eval()
            img_sec = img_sec.eval()
            x = x.eval()
            y = y.eval()
            z = z.eval()
            r = r.eval()

        # We need this to be of shape (nplanet, nframe)
        x = x.T
        y = y.T
        z = z.T

        # Ensure we have an array of frames
        if len(img_pri.shape) == 3:
            nframes = img_pri.shape[0]
        else:  # pragma: no cover
github rodluger / starry / starry / ops / utils.py View on Github external
def __enter__(self):
        config.rootHandler.terminator = ""
        logger.info("Compiling `{0}`... ".format(self.name))
github rodluger / starry / starry / kepler.py View on Github external
math.to_array_or_tensor(
                [sec._map._sigr for sec in self._secondaries]
            ),
        )

        # Convert to units of the primary radiu
        x, y, z = (
            x / self._primary._r,
            y / self._primary._r,
            z / self._primary._r,
        )
        r = math.to_array_or_tensor([sec._r for sec in self._secondaries])
        r = r / self._primary._r

        # Evaluate if needed
        if config.lazy:
            img_pri = img_pri.eval()
            img_sec = img_sec.eval()
            x = x.eval()
            y = y.eval()
            z = z.eval()
            r = r.eval()

        # We need this to be of shape (nplanet, nframe)
        x = x.T
        y = y.T
        z = z.T

        # Ensure we have an array of frames
        if len(img_pri.shape) == 3:
            nframes = img_pri.shape[0]
        else:  # pragma: no cover