Skip to content

Commit

Permalink
Merge pull request #30 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Patch release 0.2.3
  • Loading branch information
shimwell authored Mar 7, 2022
2 parents c5dbff2 + b3311a3 commit 1e422f2
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 123 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@ jobs:
testing:
runs-on: ubuntu-latest
container:
# image: openmc/openmc:latest-dagmc is missing the dagmc universe
image: openmc/openmc:develop-dagmc
# image: continuumio/miniconda3:4.10.3
image: ghcr.io/openmc-data-storage/miniconda3_4.9.2_endfb-7.1_nndc_tendl_2019
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: install dependancies
run: |
conda install -c conda-forge openmc
- name: install package
run: |
python setup.py install
pip install --upgrade pip
pip install .
python -c "import regular_mesh_plotter"
- name: install packages for tests
run: |
pip install -r requirements-test.txt
pip install .[tests]
- name: Run test_utils
run: |
cp tests/example.stl .
pytest tests/ -v --cov=regular_mesh_plotter --cov-append --cov-report term --cov-report xml
- name: Upload to codecov
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ manifest_processed/
# conda buid and dist dir
build/
dist/

# python package version number
_version.py
File renamed without changes.
78 changes: 18 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
pip install regular_mesh_plotter
```

Mesh results in the form of Numpy arrays or OpenMC.tally objects can be plotted
with a single API call.
Mesh results in the form of at OpenMC.tally objects can be plotted with a single API call.

A Matplotlib.pyplot object is returned by all functions so one can make changes
to the legend, axis, colour map etc. However some key options are accessible
Expand All @@ -35,82 +34,41 @@ There are additional options that allow
The resulting plots can be used to show dose maps, activation, reaction rate
and other mesh tally results.

The examples below require a mesh tally that can be read in with OpenMC in the following way.

Example 1 shows a Numpy array plotted
```python
from regular_mesh_plotter import plot_regular_mesh_values
plot_regular_mesh_values(
values: np.ndarray,
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
base_plt=None,
extent=None,
x_label="X [cm]",
y_label="Y [cm]",
rotate_plot: float = 0,
)
```
import openmc

Example 2 shows a Numpy array plotted with an underlying DAGMC geometry
```python
plot_regular_mesh_values_with_geometry(
values: np.ndarray,
dagmc_file_or_trimesh_object,
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
extent=None,
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
)
# loads in the statepoint file containing tallies
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")

# gets one tally from the available tallies
my_tally = statepoint.get_tally(name="neutron_effective_dose_on_2D_mesh_xy")
```

Example 3 shows a OpenMC tally plotted
Example 1 shows a OpenMC tally plotted
```python
plot_regular_mesh_tally(
tally,
dagmc_file_or_trimesh_object,

import regular_mesh_plotter as rmp

my_plot = rmp.plot_regular_mesh_tally(
tally=my_tally,
std_dev_or_tally_value="tally_value",
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units=None,
source_strength: float = None,
)

my_plot.save_fig('openmc_mesh_tally_plot.png')
```

Example 4 shows a OpenMC tally plotted with an underlying DAGMC geometry
```python
plot_regular_mesh_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
tally=my_tally,
dagmc_file_or_trimesh_object='dagmc.h5m',
std_dev_or_tally_value="tally_value",
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units=None,
source_strength: float = None,
)
```

Expand Down
1 change: 0 additions & 1 deletion examples/create_statepoint_file_with_meshes_openmc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This minimal example makes a 3D volume and exports the shape to a stp file
# A surrounding volume called a graveyard is needed for neutronics simulations

import openmc
import openmc_dagmc_wrapper as odw
Expand Down
17 changes: 10 additions & 7 deletions examples/create_statepoint_file_with_meshes_openmc_dagmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import openmc_dagmc_wrapper as odw
import openmc_plasma_source as ops
from stl_to_h5m import stl_to_h5m
from dagmc_bounding_box import DagmcBoundingBox

# code used to create example.stl
# import paramak
Expand All @@ -24,6 +25,8 @@
h5m_filename="dagmc.h5m",
)

my_corners = DagmcBoundingBox("dagmc.h5m").corners()

# makes use of the previously created neutronics geometry (h5m file) and assigns
# actual materials to the material tags. Sets simulation intensity and specifies
# the neutronics results to record (know as tallies).
Expand All @@ -40,42 +43,42 @@
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)
tally2 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="yz",
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)
tally3 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xz",
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)
tally4 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, 10),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)
tally5 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="yz",
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)
tally6 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xz",
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
bounding_box=my_corners,
)

# tally2 = odw.MeshTally3D(
# mesh_resolution=(100, 100, 100),
# bounding_box="dagmc.h5m",
# bounding_box=my_corners,
# tally_type="neutron_effective_dose",
# )

Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = [
"setuptools >= 45",
"wheel",
"setuptools_scm[toml] >= 6.2",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "regular_mesh_plotter/_version.py"
13 changes: 13 additions & 0 deletions regular_mesh_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
try:
from importlib.metadata import version, PackageNotFoundError
except (ModuleNotFoundError, ImportError):
from importlib_metadata import version, PackageNotFoundError
try:
__version__ = version("regular_mesh_plotter")
except PackageNotFoundError:
from setuptools_scm import get_version

__version__ = get_version(root="..", relative_to=__file__)

__all__ = ["__version__"]

from .core import plot_regular_mesh_values
from .core import plot_regular_mesh_values_with_geometry

Expand Down
11 changes: 9 additions & 2 deletions regular_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ def plot_regular_mesh_values(
rot = transforms.Affine2D().rotate_deg_around(x_center, y_center, rotate_plot)

image_map = plt.imshow(
values, norm=scale, vmin=vmin, extent=extent, transform=rot + base
values,
norm=scale,
vmin=vmin,
extent=extent,
transform=rot + base,
origin="lower",
)
else:
image_map = plt.imshow(values, norm=scale, vmin=vmin, extent=extent)
image_map = plt.imshow(
values, norm=scale, vmin=vmin, extent=extent, origin="lower"
)

plt.xlabel(x_label)
plt.ylabel(y_label)
Expand Down
48 changes: 48 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[metadata]
name = regular_mesh_plotter
author = The Fusion Energy Development Team
author_email = mail@jshimwell.com
description = A Python package for creating publication quality plots of regular mesh tallies with the underlying geometry
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/fusion-energy/regular_mesh_plotter
license = MIT
license_file = LICENSE.txt
classifiers =
Natural Language :: English
Topic :: Scientific/Engineering
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
License :: OSI Approved :: MIT License
Operating System :: OS Independent
project_urls =
Source = https://github.com/fusion-energy/regular_mesh_plotter
Tracker = https://github.com/fusion-energy/regular_mesh_plotter/issues

[options]
packages = find:
python_requires= >=3.6
install_requires=
numpy >= 1.21.1
matplotlib >= 3.4.2
trimesh
shapely
scipy
pandas
dagmc_geometry_slice_plotter
openmc_tally_unit_converter
setuptools_scm

[options.extras_require]
tests =
pytest >= 5.4.3
pytest-cov>=2.12.1
openmc-dagmc-wrapper
openmc_plasma_source
stl_to_h5m

[flake8]
per-file-ignores = __init__.py:F401
45 changes: 2 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="regular_mesh_plotter",
version="develop",
author="The Regular Mesh Plotter Development Team",
author_email="mail@jshimwell.com",
description="A Python package for creating publication quality plots of regular mesh tallies with the underlying geometry",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/fusion-energy/regular_mesh_plotter",
packages=setuptools.find_packages(),
classifiers=[
"Natural Language :: English",
"Topic :: Scientific/Engineering",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.6",
package_data={
"regular_mesh_plotter": [
# "requirements.txt",
"README.md",
"LICENSE",
]
},
install_requires=[
"numpy>=1.21.1",
"matplotlib>=3.4.2",
"trimesh",
"shapely",
"scipy",
"pandas",
"dagmc_geometry_slice_plotter",
"openmc_tally_unit_converter",
],
)
if __name__ == "__main__":
setuptools.setup()
5 changes: 2 additions & 3 deletions tests/create_statepoint_file_for_testing_using_dagmc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This minimal example makes a 3D volume and exports the shape to a stp file
# A surrounding volume called a graveyard is needed for neutronics simulations

import openmc
import openmc_dagmc_wrapper as odw
Expand All @@ -12,15 +11,15 @@
distance=180,
)

my_shape.export_stl("example.stl")
my_shape.export_stl("tests/example.stl")

# This script converts the CAD stl files generated into h5m files that can be
# used in DAGMC enabled codes. h5m files created in this way are imprinted,
# merged, faceted and ready for use in OpenMC. One of the key aspects of this
# is the assignment of materials to the volumes present in the CAD files.

stl_to_h5m(
files_with_tags=[("example.stl", "mat1")],
files_with_tags=[("tests/example.stl", "mat1")],
h5m_filename="dagmc.h5m",
)

Expand Down
Loading

0 comments on commit 1e422f2

Please sign in to comment.