kevin218 / Eureka

Eureka! is a data reduction and analysis pipeline intended for time-series observations with JWST.
https://eurekadocs.readthedocs.io/
MIT License
56 stars 44 forks source link

[Bug]: Fails in S5 when attempting to use 'white_fixed' epf parameter #579

Closed cdfortenbach closed 5 months ago

cdfortenbach commented 8 months ago

FAQ check

Instrument

Light curve fitting (Stages 4-6)

What happened?

Single change in S5_epf file causes code to crash during first, white-light curve fit. The change was to line item for param t0. Changed from 'free' to 'white_fixed'. Runs to completion otherwise.

Error traceback output

Starting Stage 5: Light Curve Fitting

Input directory: /home/ec2-user/efs-mount-point/Eureka_v010/DataAnalysis/JWST/WASP-39b/NIRSpec/G395H_nrs1/S2_thru_S6_v3/Stage4/S4_2023-11-10_wasp39b_run1/ap4_bg6/
Output directory: /home/ec2-user/efs-mount-point/Eureka_v010/DataAnalysis/JWST/WASP-39b/NIRSpec/G395H_nrs1/S2_thru_S6_v3/Stage5/S5_2023-11-10_wasp39b_run1/ap4_bg6/
Copying S5 control file
Copying S5 parameter control file
Manually removing data points from meta.manual_clip...

Starting Fit of White-light Light Curve

=========================
Starting dynesty fit.
Starting lnprob: -1594647.14270514
Running dynesty...
53it [00:00, 518.67it/s, bound: 0 | nc: 2 | ncall: 311 | eff(%): 17.042 | loglstar:   -inf <   -inf < 129it [00:00, 573.64it/s, bound: 0 | nc: 2 | ncall: 431 | eff(%): 29.930 | loglstar:   -inf <   -inf <186it [00:00, 541.65it/s, bound: 0 | nc: 2 | ncall: 552 | eff(%): 33.696 | loglstar:   -inf <   -inf <240it [00:00, 511.01it/s, bound: 0 | nc: 3 | ncall: 674 | eff(%): 35.608 | loglstar:   -inf <   -inf <291it [00:00, 489.53it/s, bound: 0 | nc: 3 | ncall: 816 | eff(%): 35.662 | loglstar:   -inf <   -inf <340it [00:00, 357.27it/s, bound: 0 | nc: 3 | ncall: 1036 | eff(%): 32.819 | loglstar:   -inf <   -inf 380it [00:00, 333.24it/s, bound: 0 | nc: 1 | ncall: 1199 | eff(%): 31.693 | loglstar:   -inf <   -inf 416it [00:01, 298.14it/s, bound: 0 | nc: 3 | ncall: 1368 | eff(%): 30.409 | loglstar:   -inf <   -inf 448it [00:01, 270.94it/s, bound: 0 | nc: 8 | ncall: 1542 | eff(%): 29.053 | loglstar:   -inf <   -inf 477it [00:01, 254.68it/s, bound: 0 | nc: 11 | ncall: 1698 | eff(%): 28.092 | loglstar:   -inf <   -inf504it [00:01, 221.94it/s, bound: 0 | nc: 7 | ncall: 1871 | eff(%): 26.937 | loglstar:   -inf < 

<I deleted most of the dynesty iterations>

 3.236 | loglstar:   -inf < 11484it [00:47, 227.35it/s, bound: 187 | nc: 31 | ncall: 354971 | eff(%):  3.235 | loglstar:   -inf < 11509it [00:47, 226.81it/s, bound: 187 | nc: 31 | ncall: 355901 | eff(%):  3.234 | loglstar:   -inf < 11535it [00:47, 240.84it/s, bound: 187 | nc: 31 | ncall: 356769 | eff(%):  3.233 | loglstar:   -inf < -129765.263 <    inf | logz: -129815.713 +/-  0.391 | dlogz: 855.964 >  0.001] 
Traceback (most recent call last):
  File "/home/ec2-user/efs-mount-point/Eureka_v010/DataAnalysis/JWST/WASP-39b/NIRSpec/G395H_nrs1/S2_thru_S6_v3/run_eureka.py", line 33, in <module>
    s5_meta = s5.fitlc(eventlabel, ecf_path=ecf_path, s4_meta=s4_meta)
  File "/home/ec2-user/src/eureka/src/eureka/S5_lightcurve_fitting/s5_fit.py", line 290, in fitlc
    meta, params = fit_channel(meta, time, flux, 0, flux_err,
  File "/home/ec2-user/src/eureka/src/eureka/S5_lightcurve_fitting/s5_fit.py", line 856, in fit_channel
    lc_model.fit(model, meta, log, fitter='dynesty')
  File "/home/ec2-user/src/eureka/src/eureka/S5_lightcurve_fitting/lightcurve.py", line 179, in fit
    fit_model = self.fitter_func(self, model, meta, log, **kwargs)
  File "/home/ec2-user/src/eureka/src/eureka/S5_lightcurve_fitting/fitters.py", line 817, in dynestyfitter
    sampler.run_nested(dlogz=tol, print_progress=True)  # output progress bar
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/sampler.py", line 1020, in run_nested
    for it, results in enumerate(
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/sampler.py", line 843, in sample
    u, v, logl, nc = self._new_point(loglstar_new)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/sampler.py", line 439, in _new_point
    self.update_bound_if_needed(loglstar, ncall=ncall)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/sampler.py", line 327, in update_bound_if_needed
    bound = self.update(subset=subset)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/nestedsamplers.py", line 681, in update
    self.mell.update(self.live_u[subset, :self.ncdim],
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/bounding.py", line 581, in update
    ells = _bounding_ellipsoids(points, firstell)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/dynesty/bounding.py", line 1415, in _bounding_ellipsoids
    k2_res = kmeans2(points / scale,
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/scipy/cluster/vq.py", line 788, in kmeans2
    label = vq(data, code_book)[0]
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/scipy/cluster/vq.py", line 200, in vq
    obs = _asarray_validated(obs, check_finite=check_finite)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/scipy/_lib/_util.py", line 287, in _asarray_validated
    a = toarray(a)
  File "/home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010/lib/python3.9/site-packages/numpy/lib/function_base.py", line 628, in asarray_chkfinite
    raise ValueError(
ValueError: array must not contain infs or NaNs

What operating system are you using?

Ubunto 18.04

What version of Python are you running?

Python 3.9.7

What Python packages do you have installed?

# packages in environment at /home/ec2-user/efs-mount-point/anaconda3/envs/eureka_v010:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             5.1                       1_gnu  
alabaster                 0.7.13                   pypi_0    pypi
asciitree                 0.3.3                    pypi_0    pypi
asdf                      3.0.1                    pypi_0    pypi
asdf-astropy              0.4.0                    pypi_0    pypi
asdf-coordinates-schemas  0.2.0                    pypi_0    pypi
asdf-standard             1.0.3                    pypi_0    pypi
asdf-transform-schemas    0.4.0                    pypi_0    pypi
asdf-unit-schemas         0.1.0                    pypi_0    pypi
asdf-wcs-schemas          0.2.0                    pypi_0    pypi
asteval                   0.9.31                   pypi_0    pypi
astraeus                  0.3                      pypi_0    pypi
astropy                   5.3.4                    pypi_0    pypi
astropy-healpix           1.0.0                    pypi_0    pypi
astroquery                0.4.6                    pypi_0    pypi
astroscrappy              1.1.0                    pypi_0    pypi
asttokens                 2.4.1                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
babel                     2.13.1                   pypi_0    pypi
batman-package            2.4.9                    pypi_0    pypi
bayesicfitting            3.2.0                    pypi_0    pypi
beautifulsoup4            4.12.2                   pypi_0    pypi
bokeh                     2.4.3                    pypi_0    pypi
bottleneck                1.3.7                    pypi_0    pypi
ca-certificates           2023.08.22           h06a4308_0  
ccdproc                   2.4.1                    pypi_0    pypi
celerite                  0.4.2                    pypi_0    pypi
certifi                   2023.7.22                pypi_0    pypi
cffi                      1.16.0                   pypi_0    pypi
cftime                    1.6.3                    pypi_0    pypi
charset-normalizer        3.3.2                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
cloudpickle               3.0.0                    pypi_0    pypi
contourpy                 1.2.0                    pypi_0    pypi
corner                    2.2.2                    pypi_0    pypi
crds                      11.17.9                  pypi_0    pypi
cryptography              41.0.5                   pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
dask                      2023.10.1                pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
docutils                  0.20.1                   pypi_0    pypi
drizzle                   1.14.3                   pypi_0    pypi
dynesty                   2.1.3                    pypi_0    pypi
emcee                     3.1.4                    pypi_0    pypi
eureka                    0.10                     pypi_0    pypi
exceptiongroup            1.1.3                    pypi_0    pypi
executing                 2.0.1                    pypi_0    pypi
exotic-ld                 3.0.0                    pypi_0    pypi
fasteners                 0.19                     pypi_0    pypi
filelock                  3.13.1                   pypi_0    pypi
fonttools                 4.44.0                   pypi_0    pypi
fsspec                    2023.10.0                pypi_0    pypi
future                    0.18.3                   pypi_0    pypi
george                    0.4.0                    pypi_0    pypi
gwcs                      0.19.0                   pypi_0    pypi
h5netcdf                  1.3.0                    pypi_0    pypi
h5py                      3.10.0                   pypi_0    pypi
html5lib                  1.1                      pypi_0    pypi
idna                      3.4                      pypi_0    pypi
imageio                   2.32.0                   pypi_0    pypi
imagesize                 1.4.1                    pypi_0    pypi
importlib-metadata        6.8.0                    pypi_0    pypi
importlib-resources       6.1.1                    pypi_0    pypi
iniconfig                 2.0.0                    pypi_0    pypi
ipython                   8.17.2                   pypi_0    pypi
jaraco-classes            3.3.0                    pypi_0    pypi
jedi                      0.19.1                   pypi_0    pypi
jeepney                   0.8.0                    pypi_0    pypi
jinja2                    3.1.2                    pypi_0    pypi
jmespath                  1.0.1                    pypi_0    pypi
jsonschema                4.19.2                   pypi_0    pypi
jsonschema-specifications 2023.7.1                 pypi_0    pypi
jwst                      1.11.4                   pypi_0    pypi
keyring                   24.2.0                   pypi_0    pypi
kiwisolver                1.4.5                    pypi_0    pypi
lazy-loader               0.3                      pypi_0    pypi
ld_impl_linux-64          2.38                 h1181459_1  
libffi                    3.3                  he6710b0_2  
libgcc-ng                 11.2.0               h1234567_1  
libgomp                   11.2.0               h1234567_1  
libstdcxx-ng              11.2.0               h1234567_1  
lmfit                     1.2.2                    pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
markupsafe                2.1.3                    pypi_0    pypi
matplotlib                3.8.1                    pypi_0    pypi
matplotlib-inline         0.1.6                    pypi_0    pypi
more-itertools            10.1.0                   pypi_0    pypi
ncurses                   6.4                  h6a678d5_0  
netcdf4                   1.6.5                    pypi_0    pypi
networkx                  3.2.1                    pypi_0    pypi
numcodecs                 0.12.1                   pypi_0    pypi
numpy                     1.24.4                   pypi_0    pypi
numpydoc                  1.6.0                    pypi_0    pypi
opencv-python-headless    4.8.1.78                 pypi_0    pypi
openssl                   1.1.1w               h7f8727e_0  
packaging                 23.2                     pypi_0    pypi
pandas                    2.1.2                    pypi_0    pypi
parsley                   1.3                      pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
partd                     1.4.1                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
photutils                 1.9.0                    pypi_0    pypi
pillow                    10.0.1                   pypi_0    pypi
pip                       23.3             py39h06a4308_0  
pluggy                    1.3.0                    pypi_0    pypi
poppy                     1.1.1                    pypi_0    pypi
prompt-toolkit            3.0.39                   pypi_0    pypi
psutil                    5.9.6                    pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pycparser                 2.21                     pypi_0    pypi
pyerfa                    2.0.1.1                  pypi_0    pypi
pygments                  2.16.1                   pypi_0    pypi
pyparsing                 3.1.1                    pypi_0    pypi
pysynphot                 2.0.0                    pypi_0    pypi
pytest                    7.4.3                    pypi_0    pypi
python                    3.9.7                h12debd9_1  
python-dateutil           2.8.2                    pypi_0    pypi
pytz                      2023.3.post1             pypi_0    pypi
pyvo                      1.4.2                    pypi_0    pypi
pyyaml                    6.0.1                    pypi_0    pypi
readline                  8.2                  h5eee18b_0  
referencing               0.30.2                   pypi_0    pypi
reproject                 0.12.0                   pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
rpds-py                   0.12.0                   pypi_0    pypi
scikit-image              0.22.0                   pypi_0    pypi
scipy                     1.9.3                    pypi_0    pypi
secretstorage             3.3.3                    pypi_0    pypi
semantic-version          2.10.0                   pypi_0    pypi
setuptools                68.0.0           py39h06a4308_0  
setuptools-scm            8.0.4                    pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
snowballstemmer           2.2.0                    pypi_0    pypi
soupsieve                 2.5                      pypi_0    pypi
spherical-geometry        1.3.1                    pypi_0    pypi
sphinx                    7.2.6                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.7                    pypi_0    pypi
sphinxcontrib-devhelp     1.0.5                    pypi_0    pypi
sphinxcontrib-htmlhelp    2.0.4                    pypi_0    pypi
sphinxcontrib-jsmath      1.0.1                    pypi_0    pypi
sphinxcontrib-qthelp      1.0.6                    pypi_0    pypi
sphinxcontrib-serializinghtml 1.1.9                    pypi_0    pypi
sqlite                    3.41.2               h5eee18b_0  
stack-data                0.6.3                    pypi_0    pypi
stcal                     1.4.4                    pypi_0    pypi
stdatamodels              1.7.2                    pypi_0    pypi
stpipe                    0.5.1                    pypi_0    pypi
stsci-image               2.3.5                    pypi_0    pypi
stsci-imagestats          1.6.3                    pypi_0    pypi
stsci-stimage             0.2.6                    pypi_0    pypi
svo-filters               0.4.4                    pypi_0    pypi
tabulate                  0.9.0                    pypi_0    pypi
tifffile                  2023.9.26                pypi_0    pypi
tk                        8.6.12               h1ccaba5_0  
tomli                     2.0.1                    pypi_0    pypi
toolz                     0.12.0                   pypi_0    pypi
tornado                   6.3.3                    pypi_0    pypi
tqdm                      4.66.1                   pypi_0    pypi
traitlets                 5.13.0                   pypi_0    pypi
tweakwcs                  0.8.3                    pypi_0    pypi
typing-extensions         4.8.0                    pypi_0    pypi
tzdata                    2023.3                   pypi_0    pypi
uncertainties             3.1.7                    pypi_0    pypi
urllib3                   2.0.7                    pypi_0    pypi
wcwidth                   0.2.9                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.41.2           py39h06a4308_0  
wiimatch                  0.3.1                    pypi_0    pypi
xarray                    2023.10.1                pypi_0    pypi
xz                        5.4.2                h5eee18b_0  
zarr                      2.16.1                   pypi_0    pypi
zipp                      3.17.0                   pypi_0    pypi
zlib                      1.2.13               h5eee18b_0  

Code of Conduct

taylorbell57 commented 8 months ago

Do you mind attaching your ecf and epf files so that we have more information to troubleshoot with?

cdfortenbach commented 8 months ago

Here are the ecf and epf files that I was using when the run failed. I have tried a number of runs since then and still have the problem with 'white-fixed' params. I've tried using that mode with other orbital params with essentially the same result. Eureka_control_files.zip

taylorbell57 commented 5 months ago

Sorry for the very significant delay - I now have much more available time and am trying to resolve a bunch of these older issues. I'll try to reproduce this today and see if I can fix the bug if it's still an issue. I assume you started with the MAST-provided _uncal files, based on your attached ECFs?

cdfortenbach commented 5 months ago

Glad you're back. In the interim I was able to find a way to work around this. It isn't critical now, but I think it would be helpful to have this functionality working in the future. I started with the Eureka! S2ecf, so I used the rateints files from MAST as a starting point.

taylorbell57 commented 5 months ago

So I wasn't able to exactly reproduce your error, but I think I have some clues as to what was going wrong after looking at the plotted outputs, your attached EPF, and the text output you included above.

First, your t0 prior is off by 0.5 days; this is because the t0 you grabbed from Mancini et al. 2018 was likely 2,455,342.96982, and you just dropped the leading 24 while you're actually suppsed to subtract 2,400,000.5 (google "Modified Julian Date" for an explanation of how BJD and MBJD differ). You can quickly tell that this is what was wrong by looking at the fig5101_white_lc_dynestyStartingPoint.png plot that is made using the code that's currently on the main branch (I forget if those StartingPoint figures were made with version 0.10), as there is no transit shown. fig5101_white_lc_dynestyStartingPoint

This significantly wrong t0 prior, combined with the high precision of your broadband lightcurve, and your Gaussian prior on scatter_mult of 1.4 +/- 0.4, likely drove the fit into a very unusual/unphysical regime; my best guess is that scatter_mult went below zero.

If you subtract 0.5 from your t0 starting value and prior mean, that would probably be enough for the fit to at least not crash. Here is what the StartingPoint figure should look like. fig5101_white_lc_dynestyStartingPoint

However, as you can see from the updated StartingPoint figure, the initial guess for c0 is far too small (should be ~1.01), u1 and u2 are both far too large (should be ~0.05), and if you run the fit you'll see that the broadband lightcurve needs a scatter_mult value of around 5 which is very far away from the mean of your prior of 1.4 +/- 0.4; this will also result in a "Reduced Chi-squared" value that is not very close to 1.0 since your prior is too constraining in the scatter_mult term. Instead, uniform prior of 0.5 to 10 might suffice for these particular data. Your prior on ypos is also a bit too constraining, and increasing the prior uncertainty to 1 might constrain it less.

After making those five changes to your EPF (t0, c0, u1, u2, scatter_mult), I get a much closer starting point and end up with a half-decent final fit. The EPF changes I recommend (at least as a starting point, and for these particular data) are

t0                      55342.46982                     'white_fixed'             55342.46982           0.00051                N
u1                      0.05                            'free'                    0.0                   1.0                    U
u2                      0.05                            'free'                    0.0                   1.0                    U
ypos                    0.0                             'free'                    0.0                   1                      N
scatter_mult            5                               'free'                    0.5                   10                     U

which gives you a better starting point: fig5101_white_lc_dynestyStartingPoint

In the future, I strongly recommend you use lsq before trying to use samplers like emcee or dynesty to first make sure your model is adequately able to fit the data before you spend a bunch of time using a sampler. I also strongly recommend looking at the StartingPoint figures as they'll help you craft better priors on your parameters. Additionally, setting run_tol to 0.001 is quite likely excessive and keeping it at 0.1 is most likely just fine (which will speed up your fits).