Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In plot_posterior: showing priors for evolution calculations and enabling easy overplotting of results #126

Open
4 tasks
gabrielastro opened this issue Nov 13, 2024 · 0 comments
Labels
implementation: intermediate Some time investment required to implement priority: medium Medium priority type: bug Something isn't working type: feature New feature or request

Comments

@gabrielastro
Copy link

gabrielastro commented Nov 13, 2024

Hello Tomas,

Thanks again for all the improvements you have been making lately!

About plot_posterior() used with results from FitEvolution:

  • Should species ignore the flags inc_luminosity and inc_mass since the luminosity and mass are plotted by default? Activating the flags gives two rows and two columns with luminosity and mass (duplicating what was already included). Or just leave it up to the user to use his head 😉.

  • Currently, show_priors "does not work" in the sense that it does not show the Gaußian priors on the mass, for example. The documentation reveals that it is designed to work with normal_prior of FitModel or setup_retrieval only, but of course it would be nice to extend it to here.

  • When overplotting results from runs with two families of evolution curves, I need many lines of code to overplot results: actually to plot them, to weight them by the relative number of samples, then to add by hand a legend (which I am not really able to position exactly easily in general), and I do not have the derived values printed on top of the posteriors for both sets of models. This is an almost complete sketch of what I have:

import corner
import numpy as np
import matplotlib.lines as mlines# first set of results
Etikett1 = 'sonora-bobcat_myobj'
Etikett1Text = 'Bobcat, solar'
figPost = plot_posterior(tag=Etikett1, …)

# number of samples in the first set 
N1 = len(database.get_samples(Etikett1).samples)

# second set of results
Etikett2 = 'bhac15_myobj'
Etikett2Text = 'BHAC15'
box2 = database.get_samples(Etikett2)
Farbe2 = 'mediumblue'

# overplot the second set
N2 = len(database.get_samples(Etikett2).samples)
## TODO: "zorder=-10" does not place the contours of the second model under those of the first?
corner.corner(box2.samples, fig=figPost, color=Farbe2, zorder=-10, weights=np.ones(N2)*N1/N2)

# define legend title and create sample lines for the legend
Legendentitel = r'My object, log L/L_{sun} = -3.5 ± 0.1'
Legendeneintrag1 = mlines.Line2D([], [], color='black', label=Etikett1Text)
Legendeneintrag2 = mlines.Line2D([], [], color=Farbe2, label=Etikett2Text)

# add the legend, somehow placing it somewhere :); details will depend on the number of columns/rows
plt.legend(frameon=False, bbox_to_anchor=(0., 4., 1., 1.), loc=1, fontsize=15,
		  handles=[Legendeneintrag1,Legendeneintrag2], title=Legendentitel, title_fontsize=17)

plt.savefig(os.getcwd()+'/posterior_withcomparison.pdf', bbox_inches='tight')

Oof! that was many lines… (Thanks to @dfm at dfm/corner.py#82 (comment) and @kponder at dfm/corner.py#63 (comment) for pieces of this.)

  • And this code, long enough, does not even add column titles with the best values of the second model, as in Zhang et al. (2024):
    Zhang_et_al_2024_Abb9-Teil
    That would be even more Handarbeit, I fear.

It feels as though the last two points are the kind of functionality which species likes to offer to users: just give the tag, a colour, a name, and voilà!, out comes a beautiful plot with the comparison. There have been several other papers recently doing this and it could be a good addition to species!

Thanks,

Gabriel

@tomasstolker tomasstolker added type: bug Something isn't working type: feature New feature or request priority: medium Medium priority implementation: intermediate Some time investment required to implement labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implementation: intermediate Some time investment required to implement priority: medium Medium priority type: bug Something isn't working type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants