jkanner / pe-viewer

A web app to make plots of posterior samples, skymaps, and waveforms for gravitational wave events.
1 stars 3 forks source link

Adjust KDE settings #92

Closed jkanner closed 4 months ago

jkanner commented 5 months ago

In some cases, the scipy.stats.gaussian_kde used in the 1d plots under the 2d plot tab smooth over physical boundaries. This is seen for parameters like chi_p and a_1. I suggest using a bounded_1d_kde/bounded_2d_kde to resolve this. You can see the different bounded KDEs implemented in pesummary here. In general I suggest a method=Transform for chi_p and a method=Reflection for a_1 etc. An example code snippet which does this is below:

from pesummary.utils.bounded_1d_kde import bounded_1d_kde
from pesummary.gw.plots.bounds import default_bounds
bounds = default_bounds["a_1"]
fig = samples.plot("a_1", type="hist", kde=True, kde_kwargs={"kde_kernel": bounded_1d_kde, "method": "Reflection", "xlow": bounds.get("low", None), "xhigh": bounds.get("high", None)})
jkanner commented 5 months ago

Below is also a snippet of code which prevents smoothing over the q=1 boundary for a mass_1-mass_2 2d plot:

from pesummary.utils.bounded_2d_kde import Bounded_2d_kde
from pesummary.gw.plots.bounds import default_bounds
xbounds = default_bounds["mass_1"]
ybounds = default_bounds["mass_2"]
fig, _, _, _ = samples.plot(["mass_1", "mass_2"], type="reverse_triangle", module="gw", kde_2d=Bounded_2d_kde, kde_k2d_kwargs={"xlow": xbounds.get("low", None), "xhigh": xbounds.get("high", None), "ylow": ybounds.get("low", None), "yhigh": ybounds.get("high", None)})
jkanner commented 5 months ago

For the 2-d triangle plot, I made the suggested change.

I noticed a strange result when plotting GW150914 along with GW170817:

Screenshot 2024-04-10 at 2 37 34 PM
jkanner commented 5 months ago

For the 1-D plots, I get an error message when I try this code. The mass_2 high bound is mass_1. I get an error that says:

TypeError: '>' not supported between instances of 'numpy.ndarray' and 'str'

This makes me think the code is trying to compare the string mass_1 with some number, or some other bug. I'm not sure how to fix this. For now, I'll leave this change on the branch kde.

Update: I was able to fix this by adding a try/except statement.

jkanner commented 5 months ago

My preference is to not make these changes.