nuclear-multimessenger-astronomy / nmma

A pythonic library for probing nuclear physics and cosmology with multimessenger analysis
https://nuclear-multimessenger-astronomy.github.io/nmma/
GNU General Public License v3.0
33 stars 58 forks source link

ValueError when plotting analysis results due to timeshift #280

Closed bfhealy closed 11 months ago

bfhealy commented 11 months ago

I'm getting the an error after sampling completes when running lightcurve-analysis on demo transient photometry from SkyPortal.

Command:

lightcurve-analysis --model Bu2022Ye --svd-path svdmodels --outdir outdir --label ZTF21aaqjmps_Bu2022Ye --trigger-time 59294.2687730999 --data ZTF21aaqjmps.dat --prior priors/Bu2022Ye.prior --tmin 0.01 --tmax 7 --dt 0.1 --error-budget 1.0 --nlive 51 --Ebv-max 0.5724 --interpolation-type tensorflow --sampler pymultinest --plot

Error:

2023-11-29 10:05:53 nmma: Traceback (most recent call last):
  File "/Users/bhealy/nmma/api/app.py", line 216, in run_nmma_model
    main(args=parser.parse_args(args))
  File "/Users/bhealy/nmma/nmma/em/analysis.py", line 993, in main
    analysis(args)
  File "/Users/bhealy/nmma/nmma/em/analysis.py", line 808, in analysis
    num = (y_det - interp(t_det)) ** 2
  File "/Users/bhealy/miniforge3/envs/nmma_env/lib/python3.10/site-packages/scipy/interpolate/_polyint.py", line 80, in __call__
    y = self._evaluate(x)
  File "/Users/bhealy/miniforge3/envs/nmma_env/lib/python3.10/site-packages/scipy/interpolate/_interpolate.py", line 755, in _evaluate
    below_bounds, above_bounds = self._check_bounds(x_new)
  File "/Users/bhealy/miniforge3/envs/nmma_env/lib/python3.10/site-packages/scipy/interpolate/_interpolate.py", line 789, in _check_bounds
    raise ValueError("A value ({}) in x_new is above "
ValueError: A value (6.070891298244533) in x_new is above the interpolation range's maximum value (5.154269626136102).

I think this is happening because a time value (6.07 days) is beyond the interpolation range (up to 5.15 days) after the latter was shortened by a nonzero timeshift. The line performing the interpolation, added ~2 weeks ago, is below:

https://github.com/nuclear-multimessenger-astronomy/nmma/blob/1432bccab1719eb1a450962649fbd03267f5f70d/nmma/em/analysis.py#L808

I'll be following up shortly with a PR to shift all times in this part of the code by the same timeshift, which should hopefully resolve this issue.