Skip to content

Commit

Permalink
Merge pull request #44 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Develop refactor
  • Loading branch information
shimwell authored Feb 1, 2023
2 parents d5208e1 + 95f2f4d commit eebba75
Show file tree
Hide file tree
Showing 21 changed files with 297 additions and 1,154 deletions.
122 changes: 17 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,122 +6,34 @@

[![codecov](https://codecov.io/gh/fusion-energy/regular_mesh_plotter/branch/main/graph/badge.svg)](https://codecov.io/gh/fusion-energy/regular_mesh_plotter)

## A minimal Python package that plots 2D mesh tally results with the underlying DAGMC geometry
## A minimal Python package that extracts 2D mesh tally results for plotting convenience.

# Installation
This package is deployed on [xsplot.com](https://www.xsplot.com) as part of the ```openmc_plot``` suite of plotting apps

```bash
pip install regular_mesh_plotter
```

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
in the function call directly.

There are additional options that allow

- rotation of the mesh tally results
- rotation of the DAGMC geometry slice
- saving the plot as an image file
- specifying contour lines TODO
- changing axis and colour bar labels
- changing colour scale applied
- truncation of values
- The plane_normal of the DAGMC geometry

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.

```python
import openmc

# loads in the statepoint file containing tallies
statepoint = openmc.StatePoint(filepath="statepoint.2.h5")
# Local install

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

Example 1 shows a OpenMC tally plotted
```python

import regular_mesh_plotter as rmp
import matplotlib.pyplot as plt
First you will need openmc installed, then you can install this package with pip

rmp.plot_regular_mesh_tally(
tally=my_tally,
std_dev_or_tally_value="tally_value",
x_label="X [cm]",
y_label="Y [cm]",
)

plt.savefig('openmc_mesh_tally_plot.png')
```bash
pip install regular_mesh_plotter
```
# Usage

Example 4 shows a OpenMC tally plotted with an underlying DAGMC geometry
```python
plot_regular_mesh_tally_with_geometry(
tally=my_tally,
dagmc_file_or_trimesh_object='dagmc.h5m',
std_dev_or_tally_value="tally_value",
x_label="X [cm]",
y_label="Y [cm]",
)
```
The package can be used from within your own python script to make plots or via a GUI that is also bundled into the package install.

Example 5 shows how to rotate the underlying DAGMC geometry and mesh tally.
This is sometimes necessary as the slice and mesh can get out of alignment
when changing the plane normal
```python
plot_regular_mesh_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
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,
)
```
## Python API script usage

Example 6 shows how to plot a dose tally with the underlying DAGMC geometry.
This also includes unit conversion from the base tally units to the requested
units.
```python
plot_regular_mesh_dose_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
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="picosievert / source_particle",
source_strength: float = None,
std_dev_or_tally_value: str = "tally_value",
):
```
See the [examples folder](https://github.com/fusion-energy/regular_mesh_plotter/tree/master/examples) for example scripts

Additional examples can be found in the [examples folder in the GitHub repository](https://github.com/fusion-energy/regular_mesh_plotter/tree/main/examples)
## Graphical User Interface (GUI) usage

After installing run ```openmc_mesh_plotter``` command from the terminal and the GUI should launch in a new browser window.
# Related packages

[openmc_plot](https://github.com/fusion-energy/openmc_plot)A single package that includes all the various plotters.

If you want to plot the DAGMC geometry without a mesh tally then take a look at
the [dagmc_geometry_slice_plotter](https://github.com/fusion-energy/dagmc_geometry_slice_plotter) package

If you want to plot the Native CSG geometry without a mesh tally then take a look at
the [dagmc_geometry_slice_plotter](https://github.com/fusion-energy/openmc_geometry_plot) package
93 changes: 0 additions & 93 deletions examples/create_statepoint_file_with_meshes_openmc.py

This file was deleted.

107 changes: 0 additions & 107 deletions examples/create_statepoint_file_with_meshes_openmc_dagmc.py

This file was deleted.

Loading

0 comments on commit eebba75

Please sign in to comment.