Skip to content

Commit

Permalink
reimplemented ITER_cyl
Browse files Browse the repository at this point in the history
  • Loading branch information
dodu94 committed Feb 16, 2025
1 parent 54cc9a0 commit d01b59d
Show file tree
Hide file tree
Showing 31 changed files with 60,339 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/source/dev/insertbenchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ across the different transport codes. The binnings are the following:
* - User
* - Segments
* - Cosine
* - Cells-Segments
* - Cor A (not fully supported)
* - Cor B (not fully supported)
* - Cor C (not fully supported)
Expand Down
10 changes: 10 additions & 0 deletions docs/source/dev/pp_gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ plot_args
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.

Barplot
-------

plot_args

* ``maxgroups``: indicates the maximum number of values that are plotted in a single row (to avoid overcrowding).
by default it is set to 20.
* ``log``: if True, the y-axis is set to log scale. Default is False. The code also analyses the data to be plotted
and if the values span in less than 2 order of magnitude the log scale is not applied.
1 change: 1 addition & 0 deletions docs/source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python-docx
aspose-words
requests
f4enix >= 0.8.1
seaborn
# DOC reqs
sphinx
esbonio
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
# openmc @ git+https://github.com/openmc-dev/[email protected]#egg=openmc
"pyyaml",
"ttkthemes",
"seaborn"
]
[project.optional-dependencies]
dev = [
Expand Down
7 changes: 1 addition & 6 deletions src/jade/config/atlas_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,4 @@ class PlotType(Enum):
CE = "ce"
DOSE_CONTRIBUTION = "dose contribution"
WAVES = "waves"
# EXP = "exp points"
# EXP_GROUP = "exp points group"
# CE_EXP_GROUP = "exp points group CE"
# DISCRETE_EXP = "discrete exp points"
# GROUPED_BARS = "grouped bars"
# WAVES = "waves"
BARPLOT = "barplot"
2 changes: 1 addition & 1 deletion src/jade/post/excel_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def add_sheets(self):
for df, val, tag in zip(
[dfs[1], dfs[2]], ["ref", "target"], [self.ref_tag, self.target_tag]
):
sheet_name = f"{val} rel. err."
sheet_name = f"{val} rel. err. {self.cfg.name}"
title = f"{tag} Relative Error for {self.cfg.name}"
self._add_sheet(sheet_name, df, title=title)
# apply standard formatting for error sheets
Expand Down
119 changes: 119 additions & 0 deletions src/jade/post/plotter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import math
from abc import ABC, abstractmethod

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from f4enix.input.libmanager import LibManager
from matplotlib.axes import Axes
from matplotlib.figure import Figure
Expand Down Expand Up @@ -786,6 +788,84 @@ def _get_figure(
return output


class BarPlot(Plot):
def _get_figure(self) -> tuple[Figure, list[Axes]]:
# Get optional data
if self.cfg.plot_args is not None:
log = self.cfg.plot_args.get("log", False)
maxgroups = self.cfg.plot_args.get("max_groups", 20)
else:
log = False
maxgroups = 20

# Override log parameter if variation is low on y axis
if log:
spread = _checkYspread(self.data, self.cfg.y)
if spread <= 2: # less than 2 orders of magnitude
log = False

# # Assuming nobody will never print 20 libraries, will introduce a
# # check though
# single_width = 1 / len(self.data) - 0.05 # the width of the bars

# Check if the data is higher than max
labels = self.data[0][1][self.cfg.x].values
nrows = len(labels) // maxgroups + 1
if nrows == 1:
nlabels = len(labels)
else:
nlabels = maxgroups

# Concat all datasets
to_concat = []
for codelib, df in self.data:
df["code-lib"] = codelib
to_concat.append(df)
global_df = pd.concat(to_concat)

fig, axes = plt.subplots(nrows=nrows, sharex=True)
if isinstance(axes, Axes):
axes = [axes]
# Compute the position of the labels in the different rows
# and the datasets
added_labels = 0
for i in range(nrows):
ax = axes[i]
idx_chunk = labels[added_labels : added_labels + nlabels]
df = global_df[global_df[self.cfg.x].isin(idx_chunk)]

# Adjourn nlabels
added_labels += nlabels
if len(labels) - added_labels > maxgroups:
nlabels = maxgroups
else:
nlabels = len(labels) - added_labels

# plot
sns.barplot(
data=df,
x=self.cfg.x,
y=self.cfg.y,
hue="code-lib",
palette="dark",
alpha=0.6,
ax=ax,
)
if log:
ax.set_yscale("log")
ax.grid(True, which="major", linewidth=0.75, axis="y", alpha=0.5)
ax.grid(True, which="minor", linewidth=0.30, axis="y", alpha=0.5)

# Since it may be multiple rows, the y label should only be in the middle one
axes[len(axes) // 2].set_ylabel(self.cfg.y_labels[0])

axes[-1].set_xlabel(self.cfg.x)
# rotate ticks if needed
_rotate_ticks(axes[-1])

return fig, axes


class PlotFactory:
@staticmethod
def create_plot(
Expand All @@ -801,6 +881,8 @@ def create_plot(
return DoseContributionPlot(plot_config, data)
elif plot_config.plot_type == PlotType.WAVES:
return WavesPlot(plot_config, data)
elif plot_config.plot_type == PlotType.BARPLOT:
return BarPlot(plot_config, data)
else:
raise NotImplementedError(
f"Plot type {plot_config.plot_type} not implemented"
Expand Down Expand Up @@ -951,3 +1033,40 @@ def _shorten_x_name(ax: Axes, shorten_x_name: int) -> None:
split = label.get_text().split("_")
new_labels.append(" ".join(split[-shorten_x_name:]))
ax.set_xticklabels(new_labels)


def _checkYspread(data: list[tuple[str, pd.DataFrame]], value_col: str):
"""
Compute the min and max values across all datasets and return the spread
"""

maxval = 0
minval = 1e36

for _, df in data:
ymin = df[value_col].min()
ymax = df[value_col].max()

# If min is a negative value, spread computation loses meaning.
if ymin < 0:
return 1e36

# adjourn max and min val across dataset
minval = min(minval, ymin)
maxval = max(maxval, ymax)

# min val or max val could be 0 -> ValueError
try:
up = math.log10(ymax)
except ValueError:
up = 0

try:
down = math.log10(ymin)
except ValueError:
down = 0

spread = up - down

return spread
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Neutron flux:
results:
- Total neutron flux
plot_type: barplot
title: Total neutron flux in ITER Cylindrical SDDR
x_label: Location
y_labels: Neutron flux [#/cm^2/s]
x: Cells-Segments
y: Value
plot_args:
log: true
Gamma flux at 0s after shutdown:
results:
- Total gamma flux
plot_type: barplot
title: Total photon flux at 0s after shutdown
x_label: Location
y_labels: Photon flux [#/cm^2/s]
x: Cells
y: Value
subsets: [{'result': 'Gamma flux', 'values': {'Time': ['0s']}}]
plot_args:
log: true
Gamma flux at 1e6s after shutdown:
results:
- Total gamma flux
plot_type: barplot
title: Total photon flux at 1e6s after shutdown
x_label: Location
y_labels: Photon flux [#/cm^2/s]
x: Cells
y: Value
subsets: [{'result': 'Gamma flux', 'values': {'Time': ['1e6s']}}]
plot_args:
log: true
SDDR at 0s after shutdown:
results:
- SDDR
plot_type: barplot
title: SDDR in ITER Cylindrical SDDR
x_label: Location
y_labels: SDDR [#/cm^2/s]
x: Cells
y: Value
subsets: [{'result': 'SDDR', 'values': {'Time': ['0s']}}]
plot_args:
log: true
SDDR at 1e6s after shutdown:
results:
- SDDR
plot_type: barplot
title: SDDR in ITER Cylindrical SDDR
x_label: Location
y_labels: SDDR [#/cm^2/s]
x: Cells
y: Value
subsets: [{'result': 'SDDR', 'values': {'Time': ['1e6s']}}]
plot_args:
log: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Neutron flux:
results:
- Neutron flux
comparison_type: percentage
table_type: pivot
x: Cells-Segments
y: Energy
value: Value
add_error: true
conditional_formatting: {"red": 20, "orange": 10, "yellow": 5}
#
Gamma flux:
results:
- Gamma flux
comparison_type: percentage
table_type: pivot
x: [Time, Location]
y: Energy
value: Value
add_error: true
conditional_formatting: {"red": 20, "orange": 10, "yellow": 5}
#
SDDR:
results:
- SDDR
comparison_type: percentage
table_type: pivot
x: Cells
y: Time
value: Value
add_error: true
conditional_formatting: {"red": 20, "orange": 10, "yellow": 5}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
_cells_segments_inverted: &locations
22-1: front cyl - hole
22-2: front cyl - cyl
22-3: front cyl - gap
22-4: front cyl - SS
23-1: end cyl - hole
23-2: end cyl - cyl
23-3: end cyl - gap
23-4: end cyl - SS
24-1: front plate - hole
24-2: front plate - cyl
24-3: front plate - gap
24-4: front plate - SS
25-1: end plate - hole
25-2: end plate - cyl
25-3: end plate - gap
25-4: end plate - SS
_times: &times
1: '0s'
2: '1e6s'
#
Neutron flux:
concat_option: no_action
202: [['replace', {'column': 'Cells-Segments', 'values': *locations}]]
Total neutron flux:
concat_option: no_action
242: [['replace', {'column': 'Cells-Segments', 'values': *locations}]]
Gamma flux:
concat_option: concat
14:
- ['replace', {'column': 'Time', 'values': *times}]
- [add_column, {"column": "Location", "values": 10}]
34:
- ['replace', {'column': 'Time', 'values': *times}]
- [add_column, {"column": "Location", "values": 11}]
44:
- ['replace', {'column': 'Time', 'values': *times}]
- [add_column, {"column": "Location", "values": 12}]
54:
- ['replace', {'column': 'Time', 'values': *times}]
- [add_column, {"column": "Location", "values": 13}]
Total gamma flux:
concat_option: no_action
74: [['replace', {'column': 'Time', 'values': *times}]]
SDDR:
concat_option: no_action
124:
- ['replace', {'column': 'Time', 'values': *times}]

Loading

0 comments on commit d01b59d

Please sign in to comment.