diff --git a/src/smefit/analyze/report.py b/src/smefit/analyze/report.py index d9a87368..f9f3236a 100644 --- a/src/smefit/analyze/report.py +++ b/src/smefit/analyze/report.py @@ -70,17 +70,47 @@ 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. @@ -88,8 +118,6 @@ def _load_grouped_info(self, raw_dict, key): ---------- raw_dict: dict raw dictionary with relevant information - key: "datasets" or "coefficients" - key to check Returns _______ @@ -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: diff --git a/src/smefit/analyze/summary.py b/src/smefit/analyze/summary.py index e10ec053..0630de6c 100644 --- a/src/smefit/analyze/summary.py +++ b/src/smefit/analyze/summary.py @@ -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. @@ -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)}}}"