Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ requirements:
- sphinx # documentation
- recommonmark
- sphinx_rtd_theme
- dataclasses # [py==36]

test:
requires:
Expand Down
2 changes: 2 additions & 0 deletions doc/sphinx/source/theory/FastInterface.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _fktables:

============================================================
Fast Interface (FK tables)
============================================================
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/source/vp/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ vp-guide
./nnprofile.md
./scripts.md
./theorycov/index
./pydataobjs.rst
29 changes: 29 additions & 0 deletions doc/sphinx/source/vp/pydataobjs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _pyobjs:

Python based data objects
=========================

Internal data formats such as PDF sets, CommonData, or :ref:`FKTables
<fktables>` files are currently accessed through the `libnnpdf` C++ code
(interfaced trough the SWIG wrappers). However there is a :ref:`project
<https://github.com/NNPDF/nnpdf/issues?q=label%3Adestroyingc%2B%2B+>` underway
to make these resources available in terms of standard Python containers
(particularly numpy arrays and pandas dataframes). The objectives include
simplifying the codebase, increasing the ease of use and enabling more advanced
computation and storage strategies.

Loading FKTables
----------------

Currently only FKTables can be directly without C++ code. This is implemented
in the :py:mod:`validphys.fkparser` module. For example::

from validphys.fkparser import load_fktable
from validphys.loader import Loader
l = Loader()
fk = l.check_fktable(setname="ATLASTTBARTOT", theoryID=53, cfac=('QCD',))
res = load_fktable(fk)

results in an :py:mod:`validphys.coredata.FKTableData` object containing all the information needed to compute a
convolution. In particular the ``sigma`` property contains a dataframe
representing the partonic cross-section (including the cfactors).
71 changes: 71 additions & 0 deletions validphys2/src/validphys/coredata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Data containers backed by Python managed memory (Numpy arrays and Pandas
dataframes). This module is intended to substitute large parts of the C++
wrappers.

"""
import dataclasses
import numpy as np
import pandas as pd

@dataclasses.dataclass(eq=False)
class FKTableData:
"""
Data contained in an FKTable

Parameters
----------
hadronic : bool
Whether a hadronic (two PDFs) or a DIS (one PDF) convolution is needed.

Q0 : float
The scale at which the PDFs should be evaluated (in GeV).

ndata : int
The number of data points in the grid.

xgrid : array, shape (nx)
The points in x at which the PDFs should be evaluated.

sigma : DataFrame
For hadronic data, the columns are the indexes in the ``NfxNf`` list of
possible flavour combinations of two PDFs. The MultiIndex contains
three keys, the data index, an index into ``xgrid`` for the first PDF
and an idex into ``xgrid`` for the second PDF, indicating if the points in
``x`` where the PDF should be evaluated.

For DIS data, the columns are indexes in the ``Nf`` list of flavours.
The MultiIndex contains two keys, the data index and an index into
``xgrid`` indicating the points in ``x`` where the PDF should be
evaluated.

metadata : dict
Other information contained in the FKTable.
"""
hadronic: bool
Q0: float
ndata: int
xgrid: np.array
sigma: pd.DataFrame
metadata: dict = dataclasses.field(default_factory=dict, repr=False)

@dataclasses.dataclass(eq=False)
class CFactorData:
"""
Data contained in a CFactor

Parameters
----------

description : str
Information on how the data was obtained.

central_value : array, shape(ndata)
The value of the cfactor for each data point.

uncertainty : array, shape(ndata)
The absolute uncertainty on the cfactor if available.
"""
description: str
central_value: np.array
uncertainty: np.array
Loading