Skip to content

Commit

Permalink
implemented Tiara-FC
Browse files Browse the repository at this point in the history
  • Loading branch information
dodu94 committed Feb 13, 2025
1 parent 2bd2a8e commit add6eb2
Show file tree
Hide file tree
Showing 68 changed files with 16,430 additions and 19 deletions.
5 changes: 5 additions & 0 deletions docs/source/dev/pp_gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ plot_args
* ``subcases``: a list of subcases to be plotted. The first value is the name of the column that identify the
subcasese while the second value is a list of the subcases to be plotted. This will cause the plot to be split
in as many rows as the number of subcases.
* ``shorten_x_name``: this type of plots can be categorical. In the event of using the
cases as x axis, the long names of the benchmark runs can become problematic. This option
will split the name of the benchmark run on the '_' symbols and retain only the last N chunks
where N is the specified *shorten_x_name* value.
* ``rotate_ticks`` if set to True, the x-axis ticks are rotated by 45 degrees. default is False.

Waves
-----
Expand Down
7 changes: 7 additions & 0 deletions src/jade/config/excel_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -105,6 +106,7 @@ class TableConfig:
conditional_formatting: dict[str, float] | None = None
change_col_names: dict[str, str] | None = None
subsets: list[dict] | None = None
select_runs: re.Pattern | None = None

def __post_init__(self):
# the conditional formatting dictionary has a fixed structure
Expand All @@ -115,6 +117,10 @@ def __post_init__(self):

@classmethod
def from_dict(cls, dictionary: dict, name) -> TableConfig:
select_runs = dictionary.get("select_runs", None)
if select_runs is not None:
select_runs = re.compile(select_runs)

return cls(
name=name,
results=dictionary["results"],
Expand All @@ -127,4 +133,5 @@ def from_dict(cls, dictionary: dict, name) -> TableConfig:
conditional_formatting=dictionary.get("conditional_formatting"),
change_col_names=dictionary.get("change_col_names"),
subsets=dictionary.get("subsets"),
select_runs=select_runs,
)
21 changes: 21 additions & 0 deletions src/jade/post/excel_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import re
from pathlib import Path

import pandas as pd
Expand Down Expand Up @@ -63,6 +64,11 @@ def process(self) -> None:
target_df = self._get_table_df(
table_cfg.results, raw_folder, subsets=table_cfg.subsets
)
# If requested, select only a subsets of the runs
if table_cfg.select_runs:
target_df = self._apply_select_runs(
re.compile(table_cfg.select_runs), target_df
)
reference_dfs[table_cfg.name] = target_df

# then we can produce one excel comparison file for each target
Expand All @@ -81,6 +87,12 @@ def process(self) -> None:
target_df = self._get_table_df(
table_cfg.results, raw_folder, subsets=table_cfg.subsets
)
# If requested, select only a subsets of the runs
if table_cfg.select_runs:
target_df = self._apply_select_runs(
re.compile(table_cfg.select_runs), target_df
)

title = TITLE.format(
ref_code.value, ref_lib, code.value, lib, table_cfg.name
)
Expand Down Expand Up @@ -149,6 +161,15 @@ def _get_concat_df_results(
return pd.DataFrame()
return pd.concat(dfs)

@staticmethod
def _apply_select_runs(pattern: re.Pattern, df: pd.DataFrame) -> pd.DataFrame:
to_drop = []
for case in df["Case"].unique():
if pattern.search(case) is None:
to_drop.append(case)
df = df[~df["Case"].isin(to_drop)]
return df


def _check_for_subsets(subsets: list[dict] | None, curr_res) -> None | dict:
if subsets:
Expand Down
2 changes: 1 addition & 1 deletion src/jade/post/excel_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _compare(df1: pd.DataFrame, df2: pd.DataFrame, comparison_type: ComparisonTy
elif comparison_type == ComparisonType.PERCENTAGE:
value = (val1 - val2) / val1 * 100
elif comparison_type == ComparisonType.RATIO:
value = val1 / val2
value = val2 / val1 # reference / target

df["Value"] = value
df["Error"] = error
Expand Down
47 changes: 31 additions & 16 deletions src/jade/post/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,14 @@ def _get_figure(self) -> tuple[Figure, list[Axes]]:
subcases = self.cfg.plot_args.get("subcases", False)
style = self.cfg.plot_args.get("style", "step")
ce_limits = self.cfg.plot_args.get("ce_limits", None)
shorten_x_name = self.cfg.plot_args.get("shorten_x_name", False)
rotate_ticks = self.cfg.plot_args.get("rotate_ticks", False)
else:
subcases = False
style = "step"
ce_limits = None
shorten_x_name = False
rotate_ticks = False

if style not in ["step", "point"]:
raise ValueError(f"Style {style} not recognized")
Expand Down Expand Up @@ -554,9 +558,8 @@ def _get_figure(self) -> tuple[Figure, list[Axes]]:
# limit the ax 2 to [0, 2]
axes[i].set_ylim(bottom=0, top=2)
# redo the ticks if there are more than one subcases
if len(dfs) > 1:
yticks = np.arange(0, 2.5, 0.5)
axes[i].set_yticks(yticks)
axes[i].yaxis.set_major_locator(MultipleLocator(0.25))
axes[i].yaxis.set_minor_locator(AutoMinorLocator(2))

if style == "step":
axes[i].step(
Expand Down Expand Up @@ -594,6 +597,12 @@ def _get_figure(self) -> tuple[Figure, list[Axes]]:
if not ce_limits:
axes[0].legend()

# rotate ticks if requested
if rotate_ticks:
_rotate_ticks(axes[-1])
if shorten_x_name:
_shorten_x_name(axes[-1], shorten_x_name)

return fig, axes


Expand Down Expand Up @@ -656,10 +665,7 @@ def _get_figure(self) -> tuple[Figure, Axes]:
ncol = len(labels) // 20 + 1
axes[0].legend(handles, labels, bbox_to_anchor=(1, 1), ncol=ncol)
# plt.setp(ax.get_xticklabels(), rotation=45, ha="right", rotation_mode="anchor")
for label in axes[-1].get_xticklabels():
label.set_rotation(45)
label.set_ha("right")
label.set_rotation_mode("anchor")
_rotate_ticks(axes[-1])

return fig, axes

Expand Down Expand Up @@ -755,16 +761,9 @@ def _get_figure(

# change the label text
if shorten_x_name:
new_labels = []
for label in axes[-1].get_xticklabels():
split = label.get_text().split("_")
new_labels.append(" ".join(split[-shorten_x_name:]))
axes[-1].set_xticklabels(new_labels)
_shorten_x_name(axes[-1], shorten_x_name)
# Handle x and y global axes
for label in axes[-1].get_xticklabels():
label.set_rotation(45)
label.set_ha("right")
label.set_rotation_mode("anchor")
_rotate_ticks(axes[-1])

output.append((fig, axes))

Expand Down Expand Up @@ -920,3 +919,19 @@ def _apply_CE_limits(

if label is not None:
ax.legend(handles=combined, loc="best")


def _rotate_ticks(ax: Axes) -> None:
# Handle x and y global axes
for label in ax.get_xticklabels():
label.set_rotation(45)
label.set_ha("right")
label.set_rotation_mode("anchor")


def _shorten_x_name(ax: Axes, shorten_x_name: int) -> None:
new_labels = []
for label in ax.get_xticklabels():
split = label.get_text().split("_")
new_labels.append(" ".join(split[-shorten_x_name:]))
ax.set_xticklabels(new_labels)
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ C/E plots:
expand_runs: true
plot_args:
subcases: ["Offset", ['on-axis', '20 cm', '40 cm']]
style: 'step'
ce_limits: [0.5, 1.5]
151 changes: 151 additions & 0 deletions src/jade/resources/default_cfg/benchmarks_pp/atlas/Tiara-FC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
Concrete, 43 MeV, U-238:
results:
- On-axis U-238 FC
- 20 cm U-238 FC
plot_type: ce
title: Tiara U-238 FC detector. Concrete shielding, 43 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_cc-43'
#
Concrete, 68 MeV, U-238:
results:
- On-axis U-238 FC
- 20 cm U-238 FC
plot_type: ce
title: Tiara U-238 FC detector. Concrete shielding, 68 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_cc-68'
#
Iron, 43 MeV, U-238:
results:
- On-axis U-238 FC
- 20 cm U-238 FC
plot_type: ce
title: Tiara U-238 FC detector. Iron shielding, 43 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_fe-43'
#
Iron, 68 MeV, U-238:
results:
- On-axis U-238 FC
- 20 cm U-238 FC
plot_type: ce
title: Tiara U-238 FC detector. Iron shielding, 68 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_fe-68'
#
Concrete, 43 MeV, Th-232:
results:
- On-axis Th-232 FC
- 20 cm Th-232 FC
plot_type: ce
title: Tiara Th-232 FC detector. Concrete shielding, 43 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_cc-43'
#
Concrete, 68 MeV, Th-232:
results:
- On-axis Th-232 FC
- 20 cm Th-232 FC
plot_type: ce
title: Tiara Th-232 FC detector. Concrete shielding, 68 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_cc-68'
#
Iron, 43 MeV, Th-232:
results:
- On-axis Th-232 FC
- 20 cm Th-232 FC
plot_type: ce
title: Tiara Th-232 FC detector. Iron shielding, 43 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_fe-43'
#
Iron, 68 MeV, Th-232:
results:
- On-axis Th-232 FC
- 20 cm Th-232 FC
plot_type: ce
title: Tiara Th-232 FC detector. Iron shielding, 68 MeV.
x_label: Shield thickness
y_labels: 'dummy' # C/E is put automatically
x: Case
y: Value
expand_runs: false
plot_args:
style: 'point'
ce_limits: [0.5, 1.5]
subcases: ["Offset", ['on-axis', '20 cm']]
shorten_x_name: 1
rotate_ticks: true
select_runs: 'Tiara-FC_fe-68'
Loading

0 comments on commit add6eb2

Please sign in to comment.