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

Fixed data_info #106

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
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
Loading