Skip to content

Commit

Permalink
Merge pull request #106 from LHCfitNikhef/fix-bug-datanames
Browse files Browse the repository at this point in the history
Fixed data_info
  • Loading branch information
LucaMantani authored Dec 13, 2024
2 parents a72532f + 19b1c8b commit 8d2f830
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
46 changes: 37 additions & 9 deletions src/smefit/analyze/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,54 @@ def __init__(self, report_path, result_path, report_config):
self.fits.append(fit)
self.fits = np.array(self.fits)

# Get names of datasets for each fit
self.dataset_fits = []
for fit in self.fits:
self.dataset_fits.append([data["name"] for data in fit.config["datasets"]])

# Loads useful information about data
self.data_info = self._load_grouped_info(report_config["data_info"], "datasets")
self.data_info = self._load_grouped_data_info(report_config["data_info"])
# Loads coefficients grouped with latex name
self.coeff_info = self._load_grouped_info(
report_config["coeff_info"], "coefficients"
)
self.coeff_info = self._load_grouped_coeff_info(report_config["coeff_info"])
self.html_index = ""
self.html_content = ""

def _load_grouped_info(self, raw_dict, key):
"""Load grouped info of coefficients and datasets.
def _load_grouped_data_info(self, raw_dict):
"""Load grouped info of datasets.
Only elements appearing at least once in the fit configs are kept.
Parameters
----------
raw_dict: dict
raw dictionary with relevant information
Returns
_______
grouped_config: pandas.DataFrame
table with information by group
"""
out_dict = {}
for group, entries in raw_dict.items():
out_dict[group] = {}
for val in entries:
if np.any([val[0] in datasets for datasets in self.dataset_fits]):
out_dict[group][val[0]] = val[1]

if len(out_dict[group]) == 0:
out_dict.pop(group)
return pd.DataFrame(out_dict).stack().swaplevel()

def _load_grouped_coeff_info(self, raw_dict):
"""Load grouped info of coefficients.
Only elements appearing at least once in the fit configs are kept.
Parameters
----------
raw_dict: dict
raw dictionary with relevant information
key: "datasets" or "coefficients"
key to check
Returns
_______
Expand All @@ -101,7 +129,7 @@ def _load_grouped_info(self, raw_dict, key):
for group, entries in raw_dict.items():
out_dict[group] = {}
for val in entries:
if np.any([val[0] in fit.config[key] for fit in self.fits]):
if np.any([val[0] in fit.config["coefficients"] for fit in self.fits]):
out_dict[group][val[0]] = val[1]

if len(out_dict[group]) == 0:
Expand Down
8 changes: 6 additions & 2 deletions src/smefit/analyze/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def __init__(self, fits, data_groups, coeff_config):
self.data_info = data_groups
self.coeff_info = coeff_config
self.nfits = len(self.fits)
# Get names of datasets for each fit
self.dataset_fits = []
for fit in self.fits:
self.dataset_fits.append([data["name"] for data in fit.config["datasets"]])

def fit_settings(self):
"""Fit settings table.
Expand Down Expand Up @@ -103,9 +107,9 @@ def write_dataset_table(self):
L.append(f"\\multirow{{{datasets.shape[0]}}}{{*}}{{{group}}}")
for isub, (dataset, link) in enumerate(datasets.items()):
temp = r" & \href{" + link + "}{" + dataset + "} "
for fit in self.fits:
for data in self.dataset_fits:
temp += " & "
if dataset in fit.config["datasets"]:
if dataset in data:
temp += r"$\checkmark$"
if isub != datasets.shape[0] - 1:
temp += f"\\\\ \\cline{{2-{(2 + self.nfits)}}}"
Expand Down

0 comments on commit 8d2f830

Please sign in to comment.