Skip to content

Commit

Permalink
final minor fixes in plottings
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Apr 2, 2024
1 parent f6b106c commit 84a8ed0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
29 changes: 19 additions & 10 deletions validphys2/src/validphys/dataplots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Plots of relations between data PDFs and fits.
"""

from __future__ import generator_stop

from collections import defaultdict
Expand All @@ -26,8 +27,8 @@
from validphys.coredata import KIN_NAMES
from validphys.plotoptions.core import get_info, kitable, transform_result
from validphys.results import chi2_stat_labels, chi2_stats
from validphys.utils import sane_groupby_iter, scale_from_grid, split_ranges
from validphys.sumrules import polarized_sum_rules
from validphys.utils import sane_groupby_iter, scale_from_grid, split_ranges

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -937,28 +938,28 @@ def compute_hists(preds, nbins=10):

def compute_ellipse(preds_x, preds_y, nstd=3):
covmat = np.cov(preds_x, preds_y)
eigval, eigvec =np.linalg.eig(covmat)
eigval, eigvec = np.linalg.eig(covmat)
sqrt_eigval = np.sqrt(eigval)

return {
"xy": (preds_x.mean(), preds_y.mean()),
"width": 2. * nstd * sqrt_eigval[0],
"height": 2. * nstd * sqrt_eigval[1],
"angle": np.degrees(np.arctan2(*eigvec[:,0][::-1])),
"width": 2.0 * nstd * sqrt_eigval[0],
"height": 2.0 * nstd * sqrt_eigval[1],
"angle": np.degrees(np.arctan2(*eigvec[:, 0][::-1])),
"fill": False,
"linewidth": 2.,
"linewidth": 2.0,
"color": "C0",
}

predictions = polarized_sum_rules(pdf, Q, lims=[(xmin, 1)])
if not angular_momentum:
xpreds = np.array(predictions["g"])
ypreds = np.array(predictions["singlet"]) / 2.
ypreds = np.array(predictions["singlet"]) / 2.0
else:
preds_low_x = polarized_sum_rules(pdf, Q, lims=[(1e-4, xmin)])
xpreds = np.array(predictions["g"]) + np.array(predictions["singlet"]) / 2.
xpreds = 1/2 - xpreds # substract the proton spin
ypreds = - (np.array(preds_low_x["g"]) + np.array(preds_low_x["singlet"]) / 2.)
xpreds = np.array(predictions["g"]) + np.array(predictions["singlet"]) / 2.0
xpreds = 1 / 2 - xpreds # substract the proton spin
ypreds = -(np.array(preds_low_x["g"]) + np.array(preds_low_x["singlet"]) / 2.0)

params = {
"width_ratios": [6, 1],
Expand Down Expand Up @@ -1014,6 +1015,14 @@ def compute_ellipse(preds_x, preds_y, nstd=3):
return fig


@figure
def plot_orbital_momentum(pdf, Q, xmin=0.001):
"""In addition to plotting the correlated spin moments as in `plot_polarized_momentum`,
it also plots the contributions from the Orbital Angular Momentum.
"""
return plot_polarized_momentum(pdf, Q, xmin, angular_momentum=True)


@figuregen
def plot_smpdf(pdf, dataset, obs_pdf_correlations, mark_threshold: float = 0.9):
"""
Expand Down
13 changes: 5 additions & 8 deletions validphys2/src/validphys/pdfplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Plots of quantities that are mostly functions of the PDFs only.
"""

import abc
import copy
import functools
Expand Down Expand Up @@ -526,12 +527,7 @@ def plot_pdfvardistances(

class BandPDFPlotter(PDFPlotter):
def __init__(
self,
*args,
pdfs_noband=None,
show_mc_errors=True,
legend_stat_labels=True,
**kwargs,
self, *args, pdfs_noband=None, show_mc_errors=True, legend_stat_labels=True, **kwargs
):
if pdfs_noband is None:
pdfs_noband = []
Expand Down Expand Up @@ -619,8 +615,9 @@ def draw(self, pdf, grid, flstate):
xplotting_grids_repr = self.boundary_xplotting_grids[0]
unpol_stats = xplotting_grids_repr.select_flavour(flstate.flindex).grid_values
unpol_cv = unpol_stats.central_value()
ax.plot(xgrid, unpol_cv, color="red")
ax.plot(xgrid, -unpol_cv, color="red")
unpol_stdv = unpol_stats.errorbarstd()
ax.plot(xgrid, unpol_cv + unpol_stdv, color="red")
ax.plot(xgrid, -(unpol_cv + unpol_stdv), color="red")
return super().draw(pdf, grid, flstate)


Expand Down

0 comments on commit 84a8ed0

Please sign in to comment.