Skip to content

Commit

Permalink
reuse the same function for fonll
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Mar 19, 2024
1 parent 1ea50fa commit 7d66344
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/pineko/fonll.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import yaml

from . import configs, parser, theory_card
from .theory import read_grids_from_nnpdf

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -228,8 +229,12 @@ def assembly_combined_fk(
else:
tcard["DAMPPOWERb"] = 0
tcard["DAMPPOWERc"] = 0

# Getting the paths to the grids
grids_name = grids_names(configs.configs["paths"]["ymldb"] / f"{dataset}.yaml")
grids_name = read_grids_from_nnpdf(dataset)
if grids_name is None:
grids_name = grids_names(configs.configs["paths"]["ymldb"] / f"{dataset}.yaml")

for grid in grids_name:
# Checking if it already exists
new_fk_path = configs.configs["paths"]["fktables"] / str(theoryid) / grid
Expand Down
29 changes: 17 additions & 12 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@
logger = logging.getLogger(__name__)


def _load_grids_from_nnpdf(dataset_name):
"""Load the list of fktables/grids necessary from a NNPDF dataset."""
# Hide the validphys import to avoid unnecessary failures
def read_grids_from_nnpdf(dataset_name):
"""Read the list of fktables given a dataset name.
If NNPDF is not available, returns None.
Parameters
----------
dataset_name: str
"""
generic_info = configs.configs.get(configs.GENERIC_OPTIONS, {})
if not generic_info.get("nnpdf", False):
return None

# Import NNPDF only if we really want it!
from nnpdf_data import legacy_to_new_map
from validphys.commondataparser import EXT
from validphys.loader import Loader
Expand Down Expand Up @@ -79,12 +90,6 @@ def operator_cards_path(self):
"""Suffix paths.operator_cards with theory id."""
return configs.configs["paths"]["operator_cards"] / str(self.theory_id)

@property
def use_nnpdf(self):
"""Whether to use NNPDF for the loading of data information."""
generic_info = configs.configs.get(configs.GENERIC_OPTIONS, {})
return generic_info.get("nnpdf", False)

def ekos_path(self, tid=None):
"""Suffix paths.ekos with theory id.
Expand Down Expand Up @@ -137,9 +142,9 @@ def load_grids(self, ds):
grids : dict
mapping basename to path
"""
if self.use_nnpdf:
# Take fktable information from NNPDF
raw_grids = _load_grids_from_nnpdf(ds)
# Take fktable information from NNPDF
raw_grids = read_grids_from_nnpdf(ds)
if raw_grids is not None:
grids = [self.grids_path() / i for i in raw_grids]
else:
paths = configs.configs["paths"]
Expand Down

0 comments on commit 7d66344

Please sign in to comment.