kevin218 / Eureka

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

S5 having issues for NIRSpec for dynesty #326

Closed jovian-explorer closed 2 years ago

jovian-explorer commented 2 years ago

Instrument

NIRSpec (Stage 5)

What happened?

Well, the thing is that S5 runs okay for NIRSpec if I use lsq, or emce. But, for some reason, the emcee works for S5, while the dynesty doesn't. I mean, if I use emcee in S5, then the S6 runs perfectly well as well, but for Dynesty in S5, S5 itself fails. I didn't make any changes to the S5 ecf or epf except the fitting method, but somehow it doesn't run. This is for the tiny dataset. I haven't used the larger one again for now.

This is the ecf file for S5 -

# Eureka! Control File for Stage 5: Lightcurve Fitting

# Stage 5 Documentation: https://eurekadocs.readthedocs.io/en/latest/ecf.html#stage-5

ncpu            8 # The number of CPU threads to use when running emcee or dynesty in parallel

allapers        False                   # Run S5 on all of the apertures considered in S4? Otherwise will use newest output in the inputdir
rescale_err     False                   # Rescale uncertainties to have reduced chi-squared of unity
fit_par         ./S5_fit_par_template.epf   # What fitting epf do you want to use?
verbose         True                    # If True, more details will be printed about steps
fit_method      [dynesty]               #options are: lsq, emcee, dynesty (can list multiple types separated by commas)
run_myfuncs     [batman_tr,polynomial]  #options are: batman_tr, batman_ecl, sinusoid_pc, expramp, GP, and polynomial (can list multiple types separated by commas)

# Limb darkening controls (not yet implemented)
#fix_ld          False #use limb darkening file?
#ld_file         /path/to/limbdarkening/ld_outputfile.txt  #location of limb darkening file

# General fitter
old_fitparams   None # filename relative to topdir that points to a fitparams csv to resume where you left off (set to None to start from scratch)

#lsq
lsq_method      'Nelder-Mead' # The scipy.optimize.minimize optimization method to use
lsq_tol         1e-6    # The tolerance for the scipy.optimize.minimize optimization method
lsq_maxiter     None    # Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. Set to None to use the default value

#mcmc
old_chain       None    # Output folder relative to topdir that contains an old emcee chain to resume where you left off (set to None to start from scratch)
lsq_first       True    # Initialize with an initial lsq call (can help shorten burn-in, but turn off if lsq fails). Only used if old_chain is None
run_nsteps      1000
run_nwalkers    200
run_nburn       500     # How many of run_nsteps should be discarded as burn-in steps

#dynesty
run_nlive       1024    # Must be > ndim * (ndim + 1) // 2
run_bound       'multi'
run_sample      'auto'
run_tol         0.1

#GP inputs
kernel_inputs   ['time'] #options: time
kernel_class    ['Matern32'] #options: ExpSquared, Matern32, Exp, RationalQuadratic for george, Matern32 for celerite (sums of kernels possible for george separated by commas)
GP_package      'celerite' #options: george, celerite

# Plotting controls
interp          False   # Should astrophysical model be interpolated (useful for uneven sampling like that from HST)

# Diagnostics
isplots_S5      5       # Generate few (1), some (3), or many (5) figures (Options: 1 - 5)
testing_S5      False   # Boolean, set True to only use the first spectral channel
testing_model   False   # Boolean, set True to only inject a model source of systematics
hide_plots      False   # If True, plots will automatically be closed rather than popping up

# Project directory
topdir          /home/keshav/Data/JWST-Sim/NIRSpec

# Directories relative to topdir
inputdir        /Stage4   # The folder containing the outputs from Eureka!'s S4 pipeline (will be overwritten if calling S4 and S5 sequentially)
outputdir       /Stage5

This is the epf -

# Stage 5 Fit Parameters Documentation: https://eurekadocs.readthedocs.io/en/latest/ecf.html#stage-5-fit-parameters

#Name        Value         Free?          PriorPar1    PriorPar2    PriorType
# PriorType can be U (Uniform), LU (Log Uniform), or N (Normal).
# If U/LU, PriorPar1 and PriorPar2 represent upper and lower limits of the parameter/log(the parameter).
# If N, PriorPar1 is the mean and PriorPar2 is the standard deviation of a Gaussian prior.
#-------------------------------------------------------------------------------------------------------
#
# ------------------
# ** Transit/eclipse parameters **
# ------------------
rp           0.173010       'free'         0.1         0.3          U
#fp           0.008         'free'         0            0.5          U
# ----------------------
# ** Phase curve parameters **
# ----------------------
#AmpCos1      0.4           'free'         0            1            U
#AmpSin1      0.01          'free'         -1           1            U
#AmpCos2      0.01          'free'         -1           1            U
#AmpSin2      0.01          'free'         -1           1            U
# ------------------
# ** Orbital parameters **
# ------------------
per          4.055259       'free'         4.055259     1e-5         N
t0           0.5            'free'         0.4     0.6     U
time_offset  0              'independent'
inc          87.93          'free'         85       90        U
a            11.612         'free'         10         13         U
ecc          0.0            'fixed'        0            1            U
w            90.            'fixed'        0            180          U
# -------------------------
# ** Limb darkening parameters **
# Choose limb_dark from ['uniform', 'linear', 'quadratic', 'kipping2013', 'square-root', 'logarithmic', 'exponential', '4-parameter']
# -------------------------
limb_dark    'kipping2013'  'independent'
u1           0.5            'free'         0            1            U
u2           0.5            'free'         0            1            U
# --------------------
# ** Systematic variables **
# polynomial model variables (c0--c9 for 0th--3rd order polynomials in time); Fitting at least c0 is very strongly recommended!
# expramp model variables (r0--r2 for one exponential ramp, r3--r5 for a second exponential ramp)
# GP model parameters (A, WN, m1, m2) in log scale
# --------------------
c0           1              'free'         0.95         1.05         U
c1           0              'free'         -0.1         0.1          U
#A            -5            'free'         -20.         -5.          U
#WN           -15           'free'         -20.         -10.         U
#m1           -5            'free'         -10.         0.           U
# -----------
# ** White noise **
# Use scatter_mult to fit a multiplier to the expected noise level from Stage 3 (recommended)
# Use scatter_ppm to fit the noise level in ppm
# Use WN parameter in GP model parameters to account for white noise in the GP model
# -----------
scatter_mult 1              'free'         1            0.1          N

Error traceback output

Traceback (most recent call last):
  File "/home/keshav/Data/JWST-Sim/NIRSpec/run_eureka.py", line 29, in <module>
    s5_meta = s5.fitlc(eventlabel, ecf_path=ecf_path, s4_meta=s4_meta)
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/s5_fit.py", line 173, in fitlc
    meta = fit_channel(meta,time,flux,channel,flux_err,eventlabel,sharedp,params,log,longparamlist,time_units,paramtitles,chanrng)
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/s5_fit.py", line 257, in fit_channel
    lc_model.fit(model, meta, log, fitter='dynesty')
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/lightcurve.py", line 156, in fit
    fit_model = self.fitter_func(self, model, meta, log, **kwargs)
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/fitters.py", line 644, in dynestyfitter
    plots.plot_corner(samples, lc, meta, freenames, fitter='dynesty')
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/plots_s5.py", line 203, in plot_corner
    fig = corner.corner(samples, fig=fig, quantiles=[0.16, 0.5, 0.84], max_n_ticks=3,
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/corner/corner.py", line 226, in corner
    return corner_impl(
  File "/home/keshav/miniconda3/lib/python3.9/site-packages/corner/core.py", line 121, in corner_impl
    raise ValueError(
ValueError: It looks like the parameter(s) in column(s) 9 have no dynamic range. Please provide a `range` argument.

What operating system are you using?

linux ubuntu 20.04

What version of Python are you running?

Python 3.9.7

What Python packages do you have installed?

(base) keshav@dev:~/Data/JWST-Sim/NIRSpec$ conda list
# packages in environment at /home/keshav/miniconda3:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             4.5                       1_gnu  
alabaster                 0.7.12                   pypi_0    pypi
asdf                      2.10.1                   pypi_0    pypi
asdf-astropy              0.2.1                    pypi_0    pypi
asdf-coordinates-schemas  0.1.0                    pypi_0    pypi
asdf-standard             1.0.2                    pypi_0    pypi
asdf-transform-schemas    0.2.2                    pypi_0    pypi
asdf-wcs-schemas          0.1.1                    pypi_0    pypi
asteval                   0.9.26                   pypi_0    pypi
astraeus                  0.1                      pypi_0    pypi
astropy                   5.0.4                    pypi_0    pypi
astropy-healpix           0.6                      pypi_0    pypi
astroquery                0.4.6                    pypi_0    pypi
astroscrappy              1.1.0                    pypi_0    pypi
asttokens                 2.0.5                    pypi_0    pypi
attrs                     21.4.0                   pypi_0    pypi
babel                     2.10.1                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
batman-package            2.4.8                    pypi_0    pypi
bayesicfitting            3.0.1                    pypi_0    pypi
beautifulsoup4            4.11.1                   pypi_0    pypi
bleach                    5.0.0                    pypi_0    pypi
bokeh                     2.4.2                    pypi_0    pypi
bottleneck                1.3.4                    pypi_0    pypi
brotlipy                  0.7.0           py39h27cfd23_1003  
ca-certificates           2021.10.26           h06a4308_2  
ccdproc                   2.3.1                    pypi_0    pypi
celerite                  0.4.2                    pypi_0    pypi
certifi                   2021.10.8        py39h06a4308_2  
cffi                      1.15.0           py39hd667e15_1  
cftime                    1.6.0                    pypi_0    pypi
charset-normalizer        2.0.4              pyhd3eb1b0_0  
cloudpickle               2.0.0                    pypi_0    pypi
commonmark                0.9.1                    pypi_0    pypi
conda                     4.11.0           py39h06a4308_0  
conda-content-trust       0.1.1              pyhd3eb1b0_0  
conda-package-handling    1.7.3            py39h27cfd23_1  
corner                    2.2.1                    pypi_0    pypi
crds                      11.14.0                  pypi_0    pypi
cryptography              36.0.0           py39h9ce1e76_0  
cycler                    0.11.0                   pypi_0    pypi
cython                    0.29.28                  pypi_0    pypi
dask                      2022.5.0                 pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
docutils                  0.17.1                   pypi_0    pypi
drizzle                   1.13.4                   pypi_0    pypi
dynesty                   1.2.2                    pypi_0    pypi
emcee                     3.1.2                    pypi_0    pypi
entrypoints               0.4                      pypi_0    pypi
eureka                    0.0.1                    pypi_0    pypi
executing                 0.8.3                    pypi_0    pypi
fastjsonschema            2.15.3                   pypi_0    pypi
filelock                  3.6.0                    pypi_0    pypi
fonttools                 4.33.3                   pypi_0    pypi
fsspec                    2022.3.0                 pypi_0    pypi
future                    0.18.2                   pypi_0    pypi
george                    0.4.0                    pypi_0    pypi
greenlet                  1.1.2                    pypi_0    pypi
gwcs                      0.18.1                   pypi_0    pypi
h5netcdf                  1.0.0                    pypi_0    pypi
h5py                      3.1.0                    pypi_0    pypi
html5lib                  1.1                      pypi_0    pypi
idna                      3.3                pyhd3eb1b0_0  
imageio                   2.19.1                   pypi_0    pypi
imagesize                 1.3.0                    pypi_0    pypi
importlib-metadata        4.11.3                   pypi_0    pypi
iniconfig                 1.1.1                    pypi_0    pypi
ipython                   8.3.0                    pypi_0    pypi
jedi                      0.18.1                   pypi_0    pypi
jeepney                   0.8.0                    pypi_0    pypi
jinja2                    3.1.2                    pypi_0    pypi
jmespath                  1.0.0                    pypi_0    pypi
joblib                    1.1.0                    pypi_0    pypi
jsonschema                3.2.0                    pypi_0    pypi
jupyter-client            7.3.1                    pypi_0    pypi
jupyter-core              4.10.0                   pypi_0    pypi
jupyterlab-pygments       0.2.2                    pypi_0    pypi
jwst                      1.3.3                    pypi_0    pypi
keyring                   23.5.0                   pypi_0    pypi
kiwisolver                1.4.2                    pypi_0    pypi
ld_impl_linux-64          2.35.1               h7274673_9  
libffi                    3.3                  he6710b0_2  
libgcc-ng                 9.3.0               h5101ec6_17  
libgomp                   9.3.0               h5101ec6_17  
libstdcxx-ng              9.3.0               hd4cf53a_17  
lmfit                     1.0.3                    pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
lxml                      4.8.0                    pypi_0    pypi
markdown-it-py            2.1.0                    pypi_0    pypi
markupsafe                2.1.1                    pypi_0    pypi
matplotlib                3.5.2                    pypi_0    pypi
matplotlib-inline         0.1.3                    pypi_0    pypi
mdit-py-plugins           0.3.0                    pypi_0    pypi
mdurl                     0.1.1                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
myst-parser               0.17.2                   pypi_0    pypi
nbclient                  0.6.3                    pypi_0    pypi
nbconvert                 6.5.0                    pypi_0    pypi
nbformat                  5.4.0                    pypi_0    pypi
nbsphinx                  0.8.8                    pypi_0    pypi
ncurses                   6.3                  h7f8727e_2  
nest-asyncio              1.5.5                    pypi_0    pypi
netcdf4                   1.5.8                    pypi_0    pypi
networkx                  2.8                      pypi_0    pypi
numpy                     1.22.3                   pypi_0    pypi
numpydoc                  1.3.1                    pypi_0    pypi
openssl                   1.1.1m               h7f8727e_0  
packaging                 21.3                     pypi_0    pypi
pandas                    1.4.2                    pypi_0    pypi
pandeia-engine            1.7                      pypi_0    pypi
pandexo-engine            1.5.3.1                  pypi_0    pypi
pandocfilters             1.5.0                    pypi_0    pypi
parsley                   1.3                      pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
partd                     1.2.0                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
photutils                 1.1.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    9.1.0                    pypi_0    pypi
pip                       21.2.4           py39h06a4308_0  
pluggy                    1.0.0                    pypi_0    pypi
poppy                     1.0.2                    pypi_0    pypi
prompt-toolkit            3.0.29                   pypi_0    pypi
psutil                    5.9.0                    pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
py                        1.11.0                   pypi_0    pypi
pycosat                   0.6.3            py39h27cfd23_0  
pycparser                 2.21               pyhd3eb1b0_0  
pyerfa                    2.0.0.1                  pypi_0    pypi
pyfftw                    0.13.0                   pypi_0    pypi
pygments                  2.12.0                   pypi_0    pypi
pyopenssl                 21.0.0             pyhd3eb1b0_1  
pyparsing                 3.0.9                    pypi_0    pypi
pyrsistent                0.18.1                   pypi_0    pypi
pysocks                   1.7.1            py39h06a4308_0  
pysynphot                 2.0.0                    pypi_0    pypi
pytest                    7.1.2                    pypi_0    pypi
python                    3.9.7                h12debd9_1  
python-dateutil           2.8.2                    pypi_0    pypi
pytz                      2022.1                   pypi_0    pypi
pyvo                      1.3                      pypi_0    pypi
pywavelets                1.3.0                    pypi_0    pypi
pyyaml                    6.0                      pypi_0    pypi
pyzmq                     22.3.0                   pypi_0    pypi
readline                  8.1.2                h7f8727e_1  
recommonmark              0.7.1                    pypi_0    pypi
reproject                 0.8                      pypi_0    pypi
requests                  2.27.1             pyhd3eb1b0_0  
ruamel_yaml               0.15.100         py39h27cfd23_0  
scikit-image              0.19.2                   pypi_0    pypi
scipy                     1.8.0                    pypi_0    pypi
secretstorage             3.3.2                    pypi_0    pypi
semantic-version          2.9.0                    pypi_0    pypi
setuptools                58.0.4           py39h06a4308_0  
six                       1.16.0             pyhd3eb1b0_0  
snowballstemmer           2.2.0                    pypi_0    pypi
soupsieve                 2.3.2.post1              pypi_0    pypi
spherical-geometry        1.2.22                   pypi_0    pypi
sphinx                    4.5.0                    pypi_0    pypi
sphinx-rtd-theme          1.0.0                    pypi_0    pypi
sphinxcontrib-applehelp   1.0.2                    pypi_0    pypi
sphinxcontrib-devhelp     1.0.2                    pypi_0    pypi
sphinxcontrib-htmlhelp    2.0.0                    pypi_0    pypi
sphinxcontrib-jsmath      1.0.1                    pypi_0    pypi
sphinxcontrib-qthelp      1.0.3                    pypi_0    pypi
sphinxcontrib-serializinghtml 1.1.5                    pypi_0    pypi
sqlalchemy                1.4.36                   pypi_0    pypi
sqlite                    3.37.0               hc218d9a_0  
stack-data                0.2.0                    pypi_0    pypi
stcal                     0.6.4                    pypi_0    pypi
stdatamodels              0.2.4                    pypi_0    pypi
stpipe                    0.3.3                    pypi_0    pypi
stsci-image               2.3.5                    pypi_0    pypi
stsci-imagestats          1.6.3                    pypi_0    pypi
stsci-stimage             0.2.5                    pypi_0    pypi
stsynphot                 1.1.0                    pypi_0    pypi
svo-filters               0.4.1                    pypi_0    pypi
synphot                   1.1.1                    pypi_0    pypi
tifffile                  2022.5.4                 pypi_0    pypi
tinycss2                  1.1.1                    pypi_0    pypi
tk                        8.6.11               h1ccaba5_0  
tomli                     2.0.1                    pypi_0    pypi
toolz                     0.11.2                   pypi_0    pypi
tornado                   6.1                      pypi_0    pypi
tqdm                      4.62.3             pyhd3eb1b0_1  
traitlets                 5.2.0                    pypi_0    pypi
tweakwcs                  0.7.4                    pypi_0    pypi
typing-extensions         4.2.0                    pypi_0    pypi
tzdata                    2021e                hda174b7_0  
uncertainties             3.1.6                    pypi_0    pypi
urllib3                   1.26.7             pyhd3eb1b0_0  
wcwidth                   0.2.5                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.37.1             pyhd3eb1b0_0  
xarray                    2022.3.0                 pypi_0    pypi
xz                        5.2.5                h7b6447c_0  
yaml                      0.2.5                h7b6447c_0  
zipp                      3.8.0                    pypi_0    pypi
zlib                      1.2.11               h7f8727e_4  

Code of Conduct

taylorbell57 commented 2 years ago

Have you looked at the plots produced for Stage 5 from the lsq and emcee fits (and any plots made for the dynesty fit before the code crashes)? Does it look like those fitting methods are actually doing a good job and there's just something glitchy with dynesty?

jovian-explorer commented 2 years ago

These are the plots for lsq

fig5101_ch19_lc_lsq fig5103_ch19_all_fits fig5301_ch19_allanplot_lsq fig5302_ch19_res_distri_lsq

jovian-explorer commented 2 years ago

These are for emcee fig5101_ch19_lc_emcee fig5103_ch19_all_fits fig5303_ch19_chain_emcee fig5101_ch19_lc_emcee_lsq fig5501_ch19_corner_emcee fig5301_ch19_allanplot_emcee fig5302_ch19_res_distri_emcee fig5303_ch19_burninchain_emcee

jovian-explorer commented 2 years ago

Dynesty doen't produce any plots before crashing. It does generate a couple of files before crashing. I am copy pasting the log file here, hoping it helps sort the issue.

Starting Stage 2 Reduction
Input directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage1/
Output directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage2/S2_2022-05-18_wasp39b_run1/
Copying S2 control file

Found 1 data file(s) ending in rateints.fits
Starting file 1 of 1
Editing (in place) the waverange in the input file
Running the Spec2Pipeline

Generating x1dints figure

Total time (min): 0.76
Saving Metadata

Starting Stage 3 Reduction

Input directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage2/S2_2022-05-18_wasp39b_run1/
Output directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage3/S3_2022-05-18_wasp39b_run1/ap6_bg7/
Using ap=6, bg=7
Copying S3 control file

Found 1 data file(s) ending in calints.fits
WARNING: Are you using real JWST data? If so, you should edit the flag_bg() function in nirspec.py and look at Issue #193 on Github!
Reading file 1 of 1
  Source position on detector is row 13.
  Automatically getting reference files to convert units to electrons
  Converting from data numbers per second (DN/s) to electrons
  Performing background outlier rejection
  Performing background subtraction
  Creating figures for background subtraction
  Performing optimal spectral extraction
  Creating figures for optimal spectral extraction

Total time (min): 1.45
Stage 3 MAD = 7572 ppm
Generating figure
Saving Metadata

Starting Stage 4: Generate Light Curves

Input directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage3/S3_2022-05-18_wasp39b_run1/ap6_bg7/
Output directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage4/S4_2022-05-18_wasp39b_run1/ap6_bg7/
Copying S4 control file
Loading S3 save file:
/home/keshav/Data/JWST-Sim/NIRSpec/Stage3/S3_2022-05-18_wasp39b_run1/ap6_bg7/S3_wasp39b_ap6_bg7_SpecData.h5
Stage 4 MAD = 5700.39 ppm
Generating light curves
  Bandpass 0 = 1.500 - 1.650
  Bandpass 1 = 1.650 - 1.800
  Bandpass 2 = 1.800 - 1.950
  Bandpass 3 = 1.950 - 2.100
  Bandpass 4 = 2.100 - 2.250
  Bandpass 5 = 2.250 - 2.400
  Bandpass 6 = 2.400 - 2.550
  Bandpass 7 = 2.550 - 2.700
  Bandpass 8 = 2.700 - 2.850
  Bandpass 9 = 2.850 - 3.000
  Bandpass 10 = 3.000 - 3.150
  Bandpass 11 = 3.150 - 3.300
  Bandpass 12 = 3.300 - 3.450
  Bandpass 13 = 3.450 - 3.600
  Bandpass 14 = 3.600 - 3.750
  Bandpass 15 = 3.750 - 3.900
  Bandpass 16 = 3.900 - 4.050
  Bandpass 17 = 4.050 - 4.200
  Bandpass 18 = 4.200 - 4.350
  Bandpass 19 = 4.350 - 4.500

Total time (min): 0.24
Saving results
Input directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage4/S4_2022-05-18_wasp39b_run1/ap6_bg7/
Output directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage5/S5_2022-05-18_wasp39b_run1/ap6_bg7/
Copying S5 control file
Copying S5 parameter control file

Starting Channel 1 of 20

=========================
Starting dynesty fit.
Starting lnprob: -2174602367.8695884
Running dynesty...

Summary
=======
nlive: 1024
niter: 69006
ncall: 2002026
eff(%):  3.498
logz: -6546321.875 +/-  0.312

Number of posterior samples is 70030
Ending lnprob: -6546278.727066302
evamariaa commented 2 years ago

I have seen this error before too and I think it's a convergence problem i.e. the corner package can't deal with dynesty posterior samples where the it can't compute ranges. You can try computing a corner plot with a different package (e.g. getdist) or you could upload the output samples file here and I'll have a quick look!

jovian-explorer commented 2 years ago

S5_wasp39b_ap6_bg7_Table_Save_ch00.txt -

# %ECSV 1.0
# ---
# datatype:
# - {name: time, datatype: float64}
# - {name: wavelength, datatype: float64}
# - {name: bin_width, datatype: float64}
# - {name: lcdata, datatype: float64}
# - {name: lcerr, datatype: float64}
# - {name: model, datatype: float64}
# - {name: residuals, datatype: float64}
# schema: astropy-2.0
time wavelength bin_width lcdata lcerr model residuals
57394.43603119213 1.575 0.07499999999999996 1.0155457685530875 3.924332707897192e-06 1.0144842484011813 0.0010615201519061923
57394.44155418567 1.575 0.07499999999999996 1.0109234952195083 3.927758523430964e-06 1.0144109574989513 -0.0034874622794429655
57394.447077179226 1.575 0.07499999999999996 1.013813117543826 3.940494313841179e-06 1.0143376665966246 -0.0005245490527985286
57394.45260017277 1.575 0.07499999999999996 1.0178055141826958 3.913363008511994e-06 1.0142643756943945 0.0035411384883012875
57394.45812316632 1.575 0.07499999999999996 1.013475484364688 3.902688545326441e-06 1.0141910847921645 -0.000715600427476426
57394.46364615987 1.575 0.07499999999999996 1.013333788089441 3.931072094011074e-06 1.0140661343468236 -0.000732346257382499
57394.46916915342 1.575 0.07499999999999996 1.0080727853784623 3.927104755250912e-06 1.0123825254885064 -0.004309740110044036
57394.47469214696 1.575 0.07499999999999996 1.010609193525835 3.920758159949212e-06 1.0087127900120798 0.001896403513755196
57394.48021514052 1.575 0.07499999999999996 1.0016713095392922 3.887685880760951e-06 1.0037338453289752 -0.002062535789683073
57394.48573813406 1.575 0.07499999999999996 0.9998934386437167 3.882424869632535e-06 0.9992762020026553 0.0006172366410613916
57394.491261127616 1.575 0.07499999999999996 0.9945161858137804 3.88537933706688e-06 0.995433177200871 -0.0009169913870905599
57394.49678412116 1.575 0.07499999999999996 0.9920916730374485 3.84648404891985e-06 0.9921266727075158 -3.499967006725946e-05
57394.50230711471 1.575 0.07499999999999996 0.9900026424453107 3.863176081272516e-06 0.9893527141314593 0.0006499283138513556
57394.50783010826 1.575 0.07499999999999996 0.9897443569720377 3.899580119760886e-06 0.987109617744246 0.0026347392277916715
57394.51335310181 1.575 0.07499999999999996 0.9884265969488489 3.867126093349606e-06 0.985396562451915 0.003030034496933953
57394.51887609535 1.575 0.07499999999999996 0.9836022610773048 3.872286654242764e-06 0.9842131115939431 -0.0006108505166383393
57394.52439908891 1.575 0.07499999999999996 0.9799830059474999 3.890840995311663e-06 0.9835590100968143 -0.003576004149314471
57394.52992208245 1.575 0.07499999999999996 0.9840476191631101 3.889046104800665e-06 0.9834340906025163 0.0006135285605938234
57394.535445076 1.575 0.07499999999999996 0.9830091064161582 3.882635900138912e-06 0.9838382341126964 -0.0008291276965382011
57394.54096806955 1.575 0.07499999999999996 0.9873624204231571 3.878897649632749e-06 0.9847713666350001 0.0025910537881570495
57394.5464910631 1.575 0.07499999999999996 0.9833714675736421 3.891069480234894e-06 0.9862334903382116 -0.002862022764569483
57394.552014056644 1.575 0.07499999999999996 0.9874583540139488 3.894361591560542e-06 0.9882247635113358 -0.0007664094973870439
57394.5575370502 1.575 0.07499999999999996 0.9890077170850284 3.879610829328565e-06 0.9907456732531236 -0.0017379561680951339
57394.56306004374 1.575 0.07499999999999996 0.9959971851199259 3.909305125299672e-06 0.9937974312690409 0.002199753850885
57394.5685830373 1.575 0.07499999999999996 0.9974242261025538 3.889034884168815e-06 0.9973830810058356 4.1145096718153695e-05
57394.57410603084 1.575 0.07499999999999996 0.9987364623954332 3.8940046603574495e-06 1.0015129822708855 -0.0027765198754522435
57394.57962902439 1.575 0.07499999999999996 1.0088620761025175 3.942941495606845e-06 1.0063986345540181 0.002463441548499423
57394.58515201794 1.575 0.07499999999999996 1.01141642519985 3.927430686819446e-06 1.010266143795426 0.0011502814044241916
57394.59067501149 1.575 0.07499999999999996 1.0179291243414301 3.906874700280908e-06 1.0122241109143841 0.005705013427045991
57394.596198005034 1.575 0.07499999999999996 1.0141294027352998 3.919288384899297e-06 1.0123588122355434 0.0017705904997564748
57394.60172099859 1.575 0.07499999999999996 1.0119162726279152 3.930436973215293e-06 1.0122855213332167 -0.0003692487053015281
57394.60724399213 1.575 0.07499999999999996 1.0058215234172458 3.952676079431498e-06 1.0122122304309866 -0.006390707013740782

S5_dynesty_fitparams_ch00.csv -

# rp,per,t0,inc,a,u1,u2,c0,c1,scatter_mult
1.379843943777660231e-01,4.055253872377545754e+00,5.196662246646751582e-01,8.781071196366582399e+01,1.060021701306348341e+01,8.416056027000137219e-01,9.894983986880276916e-01,1.013348239416083985e+00,-1.327014084285402240e-02,1.820953615160138650e+00
-6.833866805777688569e-12,-7.993605777301127091e-15,-1.404404370575207395e-10,-9.362238984067516867e-09,-6.277982578239971190e-10,-2.111181229835779050e-10,-8.994627265224153234e-11,-4.862554803253260616e-12,-4.301120570815442079e-11,-0.000000000000000000e+00
1.140815220068702729e-11,1.154631945610162802e-14,1.026935203540801922e-10,3.444142748776357621e-09,6.052918166687959456e-10,3.809375037633344618e-10,7.709088922780438224e-11,2.940536703022189613e-12,1.345271116726109994e-11,0.000000000000000000e+00
taylorbell57 commented 2 years ago

Aha, as I thought the emcee plots were indeed helpful. If you look at the chain and the corner plot from the emcee fit, you can see that the period and t0 parameters end up bumping into the edges of your prior and behave strangely. The reason for this is the t0 prior setting in your EPF which is centered around 0.5 which would've been from a NIRCam simulation while it should be around 57394.52 for the NIRSpec simulations. We apparently didn't update the t0 value in the template EPF when we updated all the ECFs for our new quickstart manual. emcee is better able to handle such a bad prior, but dynesty fails under such a bad prior apparently. I'll leave this issue open and make a quick patch, but for your own sake you can try updating the t0 line to the following:

t0    57394.52    'free'    57394.5    57394.55    U
jovian-explorer commented 2 years ago

Same error after making the above change as well

Traceback (most recent call last):
File "/home/keshav/Data/JWST-Sim/NIRSpec/run_eureka.py", line 29, in <module>
  s5_meta = s5.fitlc(eventlabel, ecf_path=ecf_path, s4_meta=s4_meta)
File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/s5_fit.py", line 173, in fitlc
  meta = fit_channel(meta,time,flux,channel,flux_err,eventlabel,sharedp,params,log,longparamlist,time_units,paramtitles,chanrng)
File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/s5_fit.py", line 257, in fit_channel
  lc_model.fit(model, meta, log, fitter='dynesty')
File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/lightcurve.py", line 156, in fit
  fit_model = self.fitter_func(self, model, meta, log, **kwargs)
File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/fitters.py", line 644, in dynestyfitter
  plots.plot_corner(samples, lc, meta, freenames, fitter='dynesty')
File "/home/keshav/miniconda3/lib/python3.9/site-packages/eureka/S5_lightcurve_fitting/plots_s5.py", line 203, in plot_corner
  fig = corner.corner(samples, fig=fig, quantiles=[0.16, 0.5, 0.84], max_n_ticks=3,
File "/home/keshav/miniconda3/lib/python3.9/site-packages/corner/corner.py", line 226, in corner
  return corner_impl(
File "/home/keshav/miniconda3/lib/python3.9/site-packages/corner/core.py", line 121, in corner_impl
  raise ValueError(
ValueError: It looks like the parameter(s) in column(s) 9 have no dynamic range. Please provide a `range` argument.
taylorbell57 commented 2 years ago

Yeah, I tried making that one change myself and I'm still getting issues with getting dynesty to converge, so there is clearly more issues with the EPF file than just that one - I'll be working on this for the next hour or so and will write here if/when I figure out a solution.

taylorbell57 commented 2 years ago

Aha, so the issue is that the errors are greatly underestimated during Stage 3 because of how this tiny dataset was made. So using scatter_mult~1 gives uncertainties that are far too small and causes the fitters to have serious issues (and especially dynesty). For this particular sample data set, we'll likely want to use scatter_ppm instead and have the prior be 450 +/- 50 ppm or something like that. I'm running a test now and will confirm that resolves the issue

taylorbell57 commented 2 years ago

Alright, in the pull request linked just above I've added several tweaks that should take care of this issue for you (and also added instructions on how to speed up the dynesty fit which you'd asked about earlier). The changes aren't live in the main branch yet, but you can copy-paste the edits into your own local files if you want to try them out (or do git checkout issue326 to checkout that branch). Once that pull request is approved, this issue will close automatically

jovian-explorer commented 2 years ago

All stages of NIRSpec running perfectly for tiny dataset now. Although, for a large rateints file, it gets killed.

(base) keshav@dev:~/Data/JWST-Sim/NIRSpec$ python3 run_eureka.py 
WARNING: Unable to find an output metadata file from Eureka!'s S2 in the folder:
"/home/keshav/Data/JWST-Sim/NIRSpec/Stage1/"
Assuming this S2 data was produced by the JWST pipeline instead.

Starting Stage 2 Reduction
Input directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage1/
Output directory: /home/keshav/Data/JWST-Sim/NIRSpec/Stage2/S2_2022-05-19_wasp39b_run4/
Copying S2 control file

Found 1 data file(s) ending in rateints.fits
2022-05-19 14:55:07,649 - stpipe.EurekaSpec2Pipeline - INFO - EurekaSpec2Pipeline instance created.
2022-05-19 14:55:07,650 - stpipe.EurekaSpec2Pipeline.bkg_subtract - INFO - BackgroundStep instance created.
2022-05-19 14:55:07,650 - stpipe.EurekaSpec2Pipeline.assign_wcs - INFO - AssignWcsStep instance created.
2022-05-19 14:55:07,651 - stpipe.EurekaSpec2Pipeline.imprint_subtract - INFO - ImprintStep instance created.
2022-05-19 14:55:07,651 - stpipe.EurekaSpec2Pipeline.msa_flagging - INFO - MSAFlagOpenStep instance created.
2022-05-19 14:55:07,652 - stpipe.EurekaSpec2Pipeline.extract_2d - INFO - Extract2dStep instance created.
2022-05-19 14:55:07,654 - stpipe.EurekaSpec2Pipeline.master_background - INFO - MasterBackgroundNrsSlitsStep instance created.
2022-05-19 14:55:07,655 - stpipe.EurekaSpec2Pipeline.master_background.flat_field - INFO - FlatFieldStep instance created.
2022-05-19 14:55:07,656 - stpipe.EurekaSpec2Pipeline.master_background.pathloss - INFO - PathLossStep instance created.
2022-05-19 14:55:07,657 - stpipe.EurekaSpec2Pipeline.master_background.barshadow - INFO - BarShadowStep instance created.
2022-05-19 14:55:07,657 - stpipe.EurekaSpec2Pipeline.master_background.photom - INFO - PhotomStep instance created.
2022-05-19 14:55:07,658 - stpipe.EurekaSpec2Pipeline.wavecorr - INFO - WavecorrStep instance created.
2022-05-19 14:55:07,658 - stpipe.EurekaSpec2Pipeline.flat_field - INFO - FlatFieldStep instance created.
2022-05-19 14:55:07,659 - stpipe.EurekaSpec2Pipeline.srctype - INFO - SourceTypeStep instance created.
2022-05-19 14:55:07,659 - stpipe.EurekaSpec2Pipeline.straylight - INFO - StraylightStep instance created.
2022-05-19 14:55:07,660 - stpipe.EurekaSpec2Pipeline.fringe - INFO - FringeStep instance created.
2022-05-19 14:55:07,661 - stpipe.EurekaSpec2Pipeline.pathloss - INFO - PathLossStep instance created.
2022-05-19 14:55:07,661 - stpipe.EurekaSpec2Pipeline.barshadow - INFO - BarShadowStep instance created.
2022-05-19 14:55:07,662 - stpipe.EurekaSpec2Pipeline.photom - INFO - PhotomStep instance created.
2022-05-19 14:55:07,663 - stpipe.EurekaSpec2Pipeline.resample_spec - INFO - ResampleSpecStep instance created.
2022-05-19 14:55:07,664 - stpipe.EurekaSpec2Pipeline.cube_build - INFO - CubeBuildStep instance created.
2022-05-19 14:55:07,665 - stpipe.EurekaSpec2Pipeline.extract_1d - INFO - Extract1dStep instance created.
Starting file 1 of 1
Editing (in place) the waverange in the input file
Killed
taylorbell57 commented 2 years ago

So I'm pretty sure I encountered that same issue back in September before I got my work laptop which has a tonne of RAM. If you use a tool like htop to monitor your RAM while trying to run Stage 2, you'll likely see that it hits 100% usage (or at least close to that) and then your code gets killed. The issue is with how the simulated file is formatted, not with Eureka (for Stage 2, it's almost all functions from the STScI's jwst package anyway). The simulations for NIRSpec were provided as one large FITS file, and that file gets copied a few times in RAM to do things like sigma clipping, and your RAM likely can't handle that much. Real JWST observations will be broken into multiple smaller pieces that are less RAM intensive like the MIRI and NIRCam simulations. If you have access to a machine with more RAM you could try using that, otherwise there's not much you can do at this point besides trying a different instrument (MIRI and NIRCam should not give you this issue).

jovian-explorer commented 2 years ago

Right now I have only 8GBs of RAM. What RAM would be optimal for this? I am working on exoplanetary atmospheres and need the inferences from this pipeline to be matching the current models like PETITRADTrans, among others, as well as some observed data.

taylorbell57 commented 2 years ago

I think I was encountering that same issue with 12GB of RAM, but I think it was fine when I upgraded to 32 GB (my work laptop now has 64GB which is quite likely overkill). Again, you won't need all that RAM for the real observations, just this one simulated file which is massive. Something in the ballpark of 8-12 GB will probably work plenty fine for the MIRI and NIRCam simulations which are more representative of what the real NIRSpec data will be like (in terms of RAM usage)

jovian-explorer commented 2 years ago

I have to work on the NIRSpec data for my project. I guess I should get some RAM then. Thanks for the help so far. I promise to trouble you again if any issues arise.

taylorbell57 commented 2 years ago

Reopening this issue until Kevin approves my PR which will automatically close this issue

kevin218 commented 2 years ago

Has anyone placed the Stage 2 outputs on Box? That might be the easiest solution.

On Thu, May 19, 2022, 1:00 PM Taylor James Bell @.***> wrote:

Reopened #326 https://github.com/kevin218/Eureka/issues/326.

— Reply to this email directly, view it on GitHub https://github.com/kevin218/Eureka/issues/326#event-6644339762, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFC2C7M6Z3HN4ROWQXE76D3VKZXTPANCNFSM5WG7RK6Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

taylorbell57 commented 2 years ago

I think they may be there, but the photom step will have been run in Stage 2 though, so the data quality may not be good

jovian-explorer commented 2 years ago

I have been trying to install/ run petitRADTRANS. Are there any other good alternatives, to help me interpret results that I get from Eureka?

taylorbell57 commented 2 years ago

Sorry, that's not my expertise and it is beyond the scope of what we will be trying to do within Eureka - I know there are several good packages out there though (PLATON might be one?)