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.

Numerical instabilities with occultations of very high order maps

See original GitHub issue

Hi Rodrigo, I noticed that flux sometimes diverges for occultations in both emitted and reflected light with very high order maps (l > 20). Here’s a reproducible example:

map = starry.Map(ydeg=25, reflected=False)
map.add_spot(amp=0.01, sigma=0.01, lat=41., lon=20.)

xo = np.linspace(-1, 1, 100)
yo = np.linspace(-0.08, -0.132, 100)
zo = np.ones(len(xo))
ro = 0.8552
theta = np.linspace(28.5, 28.7, 100)

flux = map.flux(theta=theta, xo=xo, yo=yo, zo=zo, ro=ro)

fig, ax = plt.subplots(2, 1, figsize=(5, 5))

ax[0].set_xlim(-1.1, 1.1)
ax[0].set_ylim(-1.1, 1.1)
ax[0].axis("off")
ax[0].imshow(map.render(), origin="lower", cmap="plasma", extent=(-1, 1, -1, 1))
npts = len(xo)
for n in list(range(0, npts, npts // 3)) + [npts - 1]:
    circ = plt.Circle(
        (xo[n], yo[n]), radius=ro, color="k", fill=True, clip_on=False, alpha=0.2
    )
    ax[0].add_patch(circ)
    
ax[1].plot(flux, 'k.')

And this is the output: image

It’s an edge case that probably doesn’t matter for inference. I noticed it because I generate fake data from very high order maps.

Starry version:'1.0.1.dev43+gf871d249'

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rodlugercommented, Apr 3, 2020

Ok, thanks for finding this. Here’s a slightly simpler version that shows the instability as a function of k^2 (Equation D23 in the paper):

import starry
import matplotlib.pyplot as plt
import numpy as np
starry.config.lazy = False

map = starry.Map(ydeg=20, reflected=False)
map[1:, :] = 1
xo = np.logspace(-2, np.log10(2.0), 10000)
yo = 0
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)
plt.plot(ksq, flux)
plt.xscale("log")
plt.show()

image

Looks like things are bad for k^2 > 1, although the instability sets in a bit before that. My guess is the evaluation of the J integral (Equation D39) gets unstable. It might help to replace the upward/downward recursion with a tridiagonal solver. I’ll look into it.

0reactions
rodlugercommented, Feb 22, 2021

Punting on this for now. Feel free to reopen if a better solution is needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Occultation Mapping of Io's Surface in the Near-infrared. I ...
These observations encode a wealth of information about the volcanic features on its surface. We built a generative model for the observed ...
Read more >
The Potential for Discriminating Microphysical Processes in ...
Accurate representation of cloud microphysical processes in numerical weather and climate models has proven challenging, in part because of the highly ...
Read more >
FAQs — starry 1.1.1 documentation - Read the Docs
1. I get weird output when I call starry functions. 2. I get a ValueError when instantiating a pymc3 model. 3. How do...
Read more >
Maps in reflected light — starry 1.0.0 documentation
The spherical harmonic coefficients of a map in reflected light are an expansion of the object's albedo (instead of its emissivity, ...
Read more >
An efficient high-order numerical solver for diffusion equations ...
Strongly anisotropic diffusion problems present a numerical challenge, because errors in the direction parallel to the magnetic field may have significant ...
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