From 7d66344dea6f6f2f8d99a31c490d2ef71858d64f Mon Sep 17 00:00:00 2001 From: juacrumar Date: Tue, 19 Mar 2024 09:04:08 +0100 Subject: [PATCH] reuse the same function for fonll --- src/pineko/fonll.py | 7 ++++++- src/pineko/theory.py | 29 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index 3e3824e3..806cd5a1 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -12,6 +12,7 @@ import yaml from . import configs, parser, theory_card +from .theory import read_grids_from_nnpdf logger = logging.getLogger(__name__) @@ -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 diff --git a/src/pineko/theory.py b/src/pineko/theory.py index 3f1222f0..d65ed8f8 100644 --- a/src/pineko/theory.py +++ b/src/pineko/theory.py @@ -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 @@ -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. @@ -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"]