1+ import h5py
2+ import xarray as xr
3+ import numpy as np
4+
5+
6+ class BenchmarkResults :
7+ def __init__ (self , filepath : str ):
8+ self .filepath = filepath
9+
10+ @property
11+ def tallies (self ):
12+ with h5py .File (self .filepath , 'r' ) as f :
13+ tallies = list (f .keys ())
14+ return tallies
15+
16+ def get_tally (self , name : str ) -> xr .DataArray :
17+ return xr .load_dataarray (self .filepath , group = name )
18+
19+
20+ # # Some utilities for data analysis
21+ # def get_means(tally: xr.DataArray) -> xr.DataArray:
22+ # """Extract tally means from the tally DataArray."""
23+ # return tally.sel(column='mean').squeeze()
24+
25+ # def get_stds(tally: xr.DataArray) -> xr.DataArray:
26+ # """Extract tally standard deviations from the tally DataArray."""
27+ # return tally.sel(column='std. dev.').squeeze()
28+
29+ # def get_rstds(tally: xr.DataArray) -> xr.DataArray:
30+ # """Compute tally relative standard deviations from the tally DataArray."""
31+ # mean_vals = get_means(tally)
32+ # std_vals = get_stds(tally)
33+ # return std_vals / mean_vals
34+
35+
36+ # # UQ-TMC base analysis functions - Move in uq/ ?
37+ # def mean_of_means(tally: xr.DataArray) -> xr.DataArray:
38+ # """Compute the mean of the means across realizations."""
39+ # means = get_means(tally)
40+ # return means.mean(dim='realization')
41+
42+ # def std_of_means(tally: xr.DataArray) -> xr.DataArray:
43+ # """Compute the standard deviation of the means across realizations."""
44+ # means = get_means(tally)
45+ # return means.std(dim='realization')
46+
47+ # def rstd_of_means(tally: xr.DataArray) -> xr.DataArray:
48+ # """Compute the relative standard deviation of the means across realizations."""
49+ # mean_vals = mean_of_means(tally)
50+ # std_vals = std_of_means(tally)
51+ # return std_vals / mean_vals
52+
53+ # # UQ-TMC dynamic realization analysis functions - Move in uq/ ?
54+ # def dynamic_mean_of_means(tally: xr.DataArray) -> np.ndarray:
55+ # """Compute the dynamic mean of the means across realizations."""
56+ # means = get_means(tally)
57+ # return np.array([means[:i].mean(dim='realization') for i in range(2, len(means.realization) + 1)])
58+
59+ # def dynamic_std_of_means(tally: xr.DataArray) -> np.ndarray:
60+ # """Compute the dynamic standard deviation of the means across realizations."""
61+ # means = get_means(tally)
62+ # return np.array([
63+ # means[:i].std(dim='realization') for i in range(2, len(means.realization) + 1)
64+ # ])
65+
66+ # def dynamic_rstd_of_means(tally: xr.DataArray) -> np.ndarray:
67+ # """Compute the dynamic relative standard deviation of the means across realizations."""
68+ # means = get_means(tally)
69+ # return np.array([
70+ # means[:i].std(dim='realization') / means[:i].mean(dim='realization')
71+ # for i in range(2, len(means.realization) + 1)
72+ # ])
73+
74+ # def dynamic_rstd_of_rstds(tally: xr.DataArray) -> np.ndarray:
75+ # """Compute the dynamic relative standard deviation of the relative standard deviations across realizations."""
76+ # rstds = dynamic_rstd_of_means(tally)
77+ # return np.array([
78+ # rstds[:i].std() / rstds[:i].mean() for i in range(2, len(rstds) + 1)
79+ # ])
80+
81+ # def derivative_of_dynamic_rstds(tally: xr.DataArray) -> np.ndarray:
82+ # """Compute the derivative of the dynamic relative standard deviations."""
83+ # dynamic_rstds = dynamic_rstd_of_means(tally)
84+ # return np.gradient(dynamic_rstds, axis=0)
0 commit comments