Sensitivity API
author: N. Abrate.
file: sensitivity.py
description: read sensitivity profiles and construct an object to perform operations.
- class pyNDUS.sensitivity.Sensitivity(sensitivity_path, duplicate_policy='raise')[source]
Bases:
SensitivityAlgebraMixinClass to read, store, and process multi-group sensitivity profiles from Serpent or ERANOS output files.
- Parameters:
sensitivity_path (str or Path) – Path to the sensitivity file to be read.
- filepath
Path to the sensitivity file. -‘serpent’: should end with “_sens0.m”. -‘eranos’: should end with “.eranos33” or “.eranos1968”.
- Type:
Path
- materials
Mapping of material names to their indices.
- Type:
OrderedDict
- zaid
Mapping of ZAID numbers (e.g., 942390) to their indices.
- Type:
OrderedDict
- zais
Mapping of ZA strings (e.g., ‘Pu-239’) to their indices.
- Type:
OrderedDict
- MTs
Mapping of MT numbers (see ENDF-6 format for the numbers) to their indices.
- Type:
OrderedDict
- group_structure
Energy group structure, stored in ascending order.
- Type:
iterable
- n_groups
Number of energy groups. Sensitivity arrays are stored in ascending energy order, consistently with
group_structure.- Type:
- sens
Sensitivity profiles whose shape is (nResp, nMat, nZaid, nMTs, nE).
- Type:
np.ndarray
- sens_rsd
Relative standard deviations of the sensivity profile. When not available (e.g., for deterministic calculations), it is None. The shape is (nResp, nMat, nZaid, nMTs, nE).
- Type:
np.ndarray
- from_eranos()[source]
Read and parse an ERANOS sensitivity output file. (its extension must be either “.eranos33” for the ECCO-33 group structure or “.eranos1968” for the ECCO-1968 group structure).
- NormalizeSensProfile(sens_profile, energy_vector)[source]
Normalize a sensitivity profile in lethargy.
- get(resp=None, mat=None, MT=None, za=None, g=None)[source]
Extract sensitivity profiles and uncertainties for specified parameters. -‘resp’: response(s) to extract (e.g., ‘keff’, ‘beff’). -‘mat’: material(s) to extract (e.g., ‘total’, ‘m1’). -‘MT’: MT number(s) to extract (e.g., 2, 4, 18). -‘za’: ZA string(s) or number(s) to extract (e.g., ‘Pu-239’, 942390). -‘g’: energy group(s) to extract (e.g., 1, 2, …, n_groups).
- Raises:
SensitivityError – If the file format is not recognized or if the file structure is not as expected.
- __init__(sensitivity_path, duplicate_policy='raise')[source]
Initialize the Sensitivity object and read the sensitivity file.
- Parameters:
sensitivity_path (str, Path, or sequence of str/Path) – Path to one sensitivity file, or multiple Serpent
*_sens0.mfiles to merge. -‘serpent’: should end with “_sens0.m”. -‘eranos’: should end with “.eranos33” or “.eranos1968”.duplicate_policy (str, optional) – Policy for handling duplicate entries in the sensitivity file. Options are: -‘raise’: raise an error if duplicates are found (default). -‘keep_first’: keep the first occurrence and ignore subsequent duplicates. -‘keep_last’: keep the last occurrence and ignore previous duplicates.
- from_serpent()[source]
Read and parse a Serpent sensitivity file using serpentTools.
- Raises:
SensitivityError – If the file structure is not as expected.
- from_eranos()[source]
Read and parse an ERANOS sensitivity output file.
- Raises:
SensitivityError – If the file format or structure is not as expected.
- static NormalizeSensProfile(sens_profile, energy_vector)[source]
Normalize a sensitivity profile in lethargy.
- Parameters:
sens_profile (array-like) – Sensitivity profile (vector of G elements).
energy_vector (array-like) – Energy vector of G+1 limits (not bins).
- Returns:
vector – Sensitivity profile per unit lethargy.
- Return type:
- property filepath
Path to the sensitivity file.
- Returns:
File path.
- Return type:
Path
- property is_multifile
Whether this object was initialized from multiple sensitivity files.
- Returns:
Truewhenfilepathstores a sequence of paths.- Return type:
- property reader
Sensitivity file format (‘serpent’ or ‘eranos’).
- Returns:
File format.
- Return type:
- get_reader()[source]
Determine the reader type based on the file extension.
- Returns:
Reader type (‘serpent’ or ‘eranos’).
- Return type:
- Raises:
SensitivityError – If the file format is not recognized.
- property materials
Mapping of material names to their indices.
- Returns:
Material names and indices.
- Return type:
OrderedDict
- property zaid
Mapping of ZAID numbers to their indices.
- Returns:
ZAID numbers and indices.
- Return type:
OrderedDict
- property zais
Mapping of ZA strings to their indices.
- Returns:
ZA strings and indices.
- Return type:
OrderedDict
- property MTs
Mapping of MT numbers to their indices.
- Returns:
MT numbers and indices.
- Return type:
OrderedDict
- property energy_unit
Unit used by the stored energy group structure.
- Returns:
Canonical unit label, either
"eV"or"MeV".- Return type:
- property energy_grid
Energy group structure with unit metadata.
- Returns:
Stored energy group boundaries and their unit.
- Return type:
- group_structure_as(unit)[source]
Return the energy group structure converted to a requested unit.
- Parameters:
unit (str) – Target energy unit. Supported values are
"eV"and"MeV".- Returns:
Energy group boundaries converted to
unit.- Return type:
- property group_structure_ev
Energy group structure converted to eV.
- Returns:
Energy group boundaries in eV.
- Return type:
- property group_structure_mev
Energy group structure converted to MeV.
- Returns:
Energy group boundaries in MeV.
- Return type:
- property group_structure
Energy group structure.
- Returns:
Energy group boundaries.
- Return type:
iterable
- property sens
Sensitivity profiles.
- Returns:
Sensitivity array whose shape is (nResp, nMat, nZaid, nMTs, nE).
- Return type:
np.ndarray
- property sens_rsd
Relative standard deviations of the sensitivity profiles.
- Returns:
Sensitivity array whose shape is (nResp, nMat, nZaid, nMTs, nE).
- Return type:
np.ndarray
- get(resp=None, mat=None, MT=None, za=None, g=None, group_order='ascending')[source]
Extract sensitivity profiles and uncertainties for specified parameters.
- Parameters:
resp (str or list, optional) – Response(s) to extract, e.g., ‘keff’, ‘beff’. If None, all responses are extracted.
mat (str or list, optional) – Material(s) to extract, e.g., ‘total’, ‘m1’. If None, all materials are extracted.
MT (int or list, optional) – MT number(s) to extract, e.g., 2, 4, 18. If None, all MTs are extracted.
za (str, int, or list, optional) – ZA string(s) or number(s) to extract, e.g., ‘Pu-239’, 942390 or [‘Pu-239’, ‘Pu-240’]. If None, all ZAIDs are extracted.
g (int or list, optional) – Energy group(s) to extract, e.g., 1, 2, …, n_groups. If None, all groups are extracted.
group_order ({"ascending", "descending"}, optional) – Order used for the returned energy groups.
"ascending"preserves the internal ordering;"descending"reverses it.
- Returns:
S_avg (np.ndarray or dict) – Sensitivity profile(s).
S_rsd (np.ndarray or dict, optional) – Sensitivity RSD(s), if available.
- collapse(fewgrp, weight=None, egridname=None)[source]
Collapse sensitivity coefficients onto a coarser energy grid.
- Parameters:
fewgrp (iterable) – Few-group boundaries used for the collapse.
weight (array-like, optional) – Weighting function used for the energy collapse. If
None, a unit weighting vector is used.egridname (str, optional) – Name of the energy grid, by default
None.
- Raises:
SensitivityError – If the target grid is incompatible with the current energy grid or the weighting vector length is inconsistent.
- Returns:
The object is updated in place.
- Return type:
None