guillochon / MOSFiT

Modular Open Source Fitter for Transients
http://mosfit.readthedocs.io/
MIT License
41 stars 53 forks source link

Having issues with the corner plot. #204

Open shashankshalgar opened 2 years ago

shashankshalgar commented 2 years ago

I was trying to run the default case as described on the getting started page:

$mosfit -e LSQ12dlf -m slsn -c

When I try to plot the results using the corner plot, using the cell below:

import logging
logging.disable(logging.WARNING)

par_dict = model['realizations'][0]['parameters']

# Construct chain walker arrays for corner
corner_input = []
with open('../products/chain.json', 'r', encoding = 'utf-8') as f:
    all_chain = np.array(json.load(f))
par_names = all_chain[1]
all_chain = np.asarray(all_chain[0])
all_chain = np.reshape(all_chain,(-1,len(par_names)))

par_labels = []
for i,par_name in enumerate(par_names):
    par_labels.append('$' + ('\\log\\, ' if par_dict[par_name].get('log') else '') +
                 par_dict[par_name]['latex'] + '$')
    if par_dict[par_name].get('log'):
        all_chain[:,i] = np.log10(all_chain[:,i])

cfig = corner.corner(all_chain[-1000:,:], labels=par_labels, quantiles=[0.16, 0.5, 0.84],
                     show_titles=True)
cfig.savefig('../products/corner.pdf')

I get an error:

IndexError                                Traceback (most recent call last)
/tmp/ipykernel_330018/3029066765.py in <module>
      8 with open('products/chain.json', 'r', encoding = 'utf-8') as f:
      9     all_chain = np.array(json.load(f))
---> 10 par_names = all_chain[1]
     11 all_chain = np.asarray(all_chain[0])
     12 all_chain = np.reshape(all_chain,(-1,len(par_names)))

IndexError: index 1 is out of bounds for axis 0 with size 1
​

The format of the chain.json file that is generated is different from what is expected by the mosfit.ipynb file. The all_chain array does not store par_names. I am sorry for the newbie question but is it possible to print the variable names of all the parameters in the chain and their order.