question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre-compiled Mandel & Agol routine?

See original GitHub issue

Hey,

I’m upgrading my planet search into a proper pip-installable package and doing improvements along the way. One part of that is looking to use starry for Mandel & Agol light curve models instead of batman like I’ve been using because of the improved numerical stability stuff. The problem I’m running into is that it seems to require a “flux” routine to be compiled at the very least every time the package is imported. That’s a 10+ second operation, and if that’s required to be run every time I search a star, that’s going to add up and may not be worth it.

Here’s how my code is currently set up:

import warnings
import numpy as np

import starry
starry.config.lazy = False
star = starry.Map(udeg=2)
# don't bother with the theano warnings
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=FutureWarning)
    # compile the flux routine once on loading the package instead
    # of every call to mandel_agol
    star.flux(xo=0, yo=0, zo=1, ro=0.1)

def mandel_agol(bs: np.ndarray, u1: float, u2: float, r2r1: float):
    star[1:3] = [u1, u2]
    # don't bother with the theano warnings
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=FutureWarning)
        return star.flux(xo=0, yo=bs, zo=1, ro=r2r1)

I originally was creating a new Map() object in every call to mandel_agol, but that forced a compilation every function call. So I moved a single object outside the function definition, and that top bit calls star.flux for no reason except to compile the code when I import the file so that future calls in the python session can call mandel_agol without the compilation delay. But if I send off 100 processes to search 100 stars, and each one has to pause for 10 seconds as I import the package to wait for that function to compile, that adds up quickly.

So I guess my question is:

  1. Am I missing anything in starry that already exists to avoid this?

  2. Is it possible to create a “Mandel & Agol” class that is compiled only once when the package is installed (or the function is first called after installation), but never again? starry is an amazing package with lots of bells and whistles, but a simple quadratic limb darkened Mandel & Agol routine is never going to go out of style. Is there any other python version of Mandel & Agol besides batman that people use? As far as I know, starry is the only robust one without all the numerical issues, so exposing a simple pre-compiled mandel_agol function for people like me to get quick values would be valuable.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dfmcommented, Sep 18, 2020

@ethankruse I also just pushed a commit to that exoplanet branch that might make what you need easier. Here’s how you would use it:

from exoplanet.theano_ops.driver import SimpleLimbDark
ld = SimpleLimbDark()
ld.set_u([0.3, 0.2])  # These are the "u" coefficients, not C_l

relative_flux = ld.apply(b, r)  # Where b and r are the same as above, but it'll handle basic broadcasting

I’ve tested that this pickles properly too.

1reaction
rodlugercommented, Jul 17, 2020

Interesting. I’m not sure why the pickle takes so long to load. @dfm any ideas? You must run into similar issues with exoplanet.

I certainly didn’t design starry with this in mind – it should really only be imported once, and maps should only be instantiated a single time, then re-used as often as you need them. That said, the code that computes the Mandel and Agol routine is (relatively) simple. If Dan doesn’t have a better solution, I could spend a couple hours next week to carve out the relevant sections and compile it into a shared library with negligible overhead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analytic Lightcurves for Planetary Transit Searches - arXiv
Analytic Lightcurves for Planetary Transit Searches. Authors:Kaisey Mandel, Eric Agol (Caltech). Download PDF. Abstract: We present exact ...
Read more >
Planetary Transit Routines - Eric Agol, UW Astronomy
Here is a Python version of the quadratic limb-darkening routine written by Jason Eastman. Please acknowledge Jason Eastman and cite Mandel & Agol...
Read more >
Analytical transit model (Mandel & Agol 2002) - PyAstronomy
The MandelAgolLC model can be used to calculate transit light curves with quadratic or non-linear limb darkening based on a circular or general...
Read more >
SimpleLimbDark doesn't vary u1 · Issue #122 · exoplanet-dev ...
It looks like SimpleLimbDark is fast and exactly what I want, but your code example isn't working. set_u doesn't seem to care what...
Read more >
Analytic Light Curves for Planetary Transit Searches
These formulae give a fast and accurate means of computing light curves using limb-darkening coefficients from model atmospheres that should aid in the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found