Skip to content

Commit

Permalink
Make openmc an optional dependency #24
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepettinari committed Dec 19, 2024
1 parent 25945ec commit db38601
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions libra_toolbox/neutronics/neutron_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from collections.abc import Iterable
import pandas as pd
import numpy as np
import h5py
import openmc


def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterable[openmc.IndependentSource]:
def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterable:
"""
Builds the MIT-VaultLab A-325 neutron generator in OpenMC
with data tabulated from John Ball and Shon Mackie characterization
Expand All @@ -28,15 +26,20 @@ def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterabl
Returns
-------
list of openmc neutron sources with angular and energy distribution
list of openmc neutron sources with angular and energy distribution
and total strength of 1
"""
try:
import h5py
import openmc
except ModuleNotFoundError:
raise ModuleNotFoundError("openmc and h5py are required")

filename = "A325_generator_diamond.h5"
filename = str(Path(__file__).parent) / Path(filename)

with h5py.File(filename, "r") as source:
df = pd.DataFrame(source["values/table"][()]).drop(columns='index')
df = pd.DataFrame(source["values/table"][()]).drop(columns="index")
# energy values
energies = np.array(df["Energy (MeV)"]) * 1e6
# angle column names
Expand Down

0 comments on commit db38601

Please sign in to comment.