Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fonll docstr and json loading #163

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
25 changes: 22 additions & 3 deletions src/pineko/fonll.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ class InconsistentInputsError(Exception):
"""Raised if the inputs are not consistent with FONLL."""


def _json_theory_read(theory_info):
"""Read the theory info from a pineappl grid.

Theory information within pineappl grids might not be saved in a consistent
json-compatible way. This functions corrects some found problems.
"""
try:
ret = json.loads(theory_info)
except json.decoder.JSONDecodeError:
# Some grids have the theories saved with incompatible formats
ret = json.loads(theory_info.replace("'", '"').replace("True", "true"))
return ret
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved


class FONLLInfo:
"""Class containing all the information for FONLL predictions."""

Expand Down Expand Up @@ -98,7 +112,11 @@ def dataset_name(self):
@property
def theorycard_no_fns_pto(self):
"""Return the common theory info between the different FONLL FK tables."""
theorycards = [json.loads(self.fks[p].key_values()["theory"]) for p in self.fks]
theorycards = []
for pinefk in self.fks.values():
thinfo = pinefk.key_values()["theory"]
theorycards.append(_json_theory_read(thinfo))

# Only these should differ
for card in theorycards:
del card["FNS"]
Expand All @@ -123,11 +141,12 @@ def Q2grid(self):
def update_fk_theorycard(combined_fk, input_theorycard_path):
"""Update theorycard entries for the combined FK table.

Update by reading the yamldb of the original theory.
Update by reading the yaml file of the original theory.
"""
with open(input_theorycard_path, encoding="utf-8") as f:
final_theorycard = yaml.safe_load(f)
theorycard = json.loads(combined_fk.key_values()["theory"])

theorycard = _json_theory_read(combined_fk.key_values()["theory"])
theorycard["FNS"] = final_theorycard["FNS"]
theorycard["PTO"] = final_theorycard["PTO"]
theorycard["NfFF"] = final_theorycard["NfFF"]
Expand Down
Loading