MNGuenther / allesfitter

allesfitter is a convenient wrapper around the packages ellc (light curve and RV models), dynesty (static and dynamic nested sampling) emcee (Markov Chain Monte Carlo sampling) and celerite (Gaussian Process models).
MIT License
60 stars 36 forks source link

[Error] NS_output not generated #35

Closed martindevora closed 3 years ago

martindevora commented 3 years ago

Hello, I launched a fit for 3 planets. It seemed to run fine, even though it took 14 hours : ) The problem appeared when calling allesfitter.ns_output. This is the stack I found:

Filling the Basement

allesfitter version
---------------------
v1.2.2

Shifting epochs into the data center
------------------------------------
Companion SOI_1
    input epoch: 1691.0105488696813
    shifted epoch: 1810.854818157887
    shifted by 11 periods
Companion SOI_2
    input epoch: 1689.975239903956
    shifted epoch: 1802.7797961014235
    shifted by 6 periods
Companion SOI_3
    input epoch: 1693.4444089962353
    shifted epoch: 1814.7627571365817
    shifted by 9 periods
100%|██████████| 235/235 [11:53<00:00,  3.04s/it]
100%|██████████| 235/235 [11:51<00:00,  3.03s/it]
100%|██████████| 235/235 [12:04<00:00,  3.08s/it]
Traceback (most recent call last):
  File "/home/martin/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/201.7846.77/plugins/python/helpers/pydev/pydevd.py", line 1438, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/martin/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/201.7846.77/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/martin/git_repositories/sherlockpipe/test.py", line 12, in <module>
    allesfitter.ns_output("/mnt/0242522242521AAD/dev/workspaces/git_repositories/sherlockpipe/run_tests/analysis/dietrich/TIC467179528_all/fit_0")
  File "/home/martin/.local/lib/python3.8/site-packages/allesfitter/nested_sampling_output.py", line 132, in ns_output
    fig, axes = afplot_per_transit(posterior_samples_for_plot, inst, companion)
  File "/home/martin/.local/lib/python3.8/site-packages/allesfitter/general_output.py", line 794, in afplot_per_transit
    xx = np.arange(x[ind][0], x[ind][-1]+dt, dt)
IndexError: index 0 is out of bounds for axis 0 with size 0

Process finished with exit code 1

Running allesfitter 1.2.2 version with Python 3.8.

Results: Only the PDFs appear in the results folder together to the log files, which are not showing the exception. I'm attaching my working allesfitter folder so you can try debugging this. Expected: I'm missing the rest of files with the fit data, like the ns_table and ns_derived_table CSVs.

fit_0.zip

Can you tell whether it is a coding bug or I did something wrong with the settings or params files?

Kind regards, Martín.

martindevora commented 3 years ago

I found out that one of the midtransit times returned by get_tmid_observed_transits is out of the data. Therefore the array usage fails to retrieve any points.

martindevora commented 3 years ago

The difference is probably coming from the function using thefast_fit_width setting as window:

tmid_observed_transits = get_tmid_observed_transits(x, params_median[companion+'_epoch'], params_median[companion+'_period'], base.settings['fast_fit_width'])

meanwhile the single transit data for the plot is extracted from the time series using the window parameter coming from the kwargs: ind = np.where((x >= (t - window/2.)) & (x <= (t + window/2.)))[0]

In my case, for the first companion, the values are:

window = 0.333333 #which is the default 8./24. given by the function
fast_fit_width = 0.7213164833452207 #given by the allesfitter settings file.

Given the previous information, either you would have to unify the width parameter used for both calculations or you need to check the length of the ind variable before doing array operations based on it. I will do some tests.

Kind regards.

MNGuenther commented 3 years ago

Hi @martindevora,

Thanks for digging into this and elaborating your findings! I assume this means you were able to solve the problem fully by yourself then?

I remember there were some issues with using window = fast_fit_width, hence I chose the 0.33333 as a fixed value that seemed to work well in all test cases. Of course, there is always a break point. I'll monitor it and come back to this when a similar issue occurs again.

(Thanks for your patience! This fell through the cracks while I was moving from MIT to ESA this summer.)

martindevora commented 3 years ago

Hi! Thanks for answering.

I came up with a home-made solution that works well but I think that Allesfitter needs to handle it too. I can suggest a Pull Request and if you find it fine merge it into your main branch. Is it ok?

Regards.

MNGuenther commented 3 years ago

Hi @martindevora!

Thanks again for providing all these insights, that is super helpful. I actually came to discuss a related issue with another user yesterday, and that led me to make the zoom windows for the plots more dynamic - i.e., automatically choose a zoom window that is 3 * the median of the fitted transit duration. In that process, I also updated the redundancy / contradiction of the parameters "window" and "fast_fit_width" from the code lines you copied above. I also tested it all on your fit_0.zip attached above, and it ran well.

All updates are in v1.2.7 (pip-installable by this evening).

Feel free to reopen this in case you encounter other issues with the new fix!