Questions on OpenMC plotting

I encountered a few problems when trying to build up a dummy model (attached).
Plotting.py (3.5 KB)

A. About Model Plotting,
I tried to plot the model with 3 approaches:

  1. plotting with the openmc.Universe.Plot (of the root universe)
  2. plotting with the openmc.Plot
  3. plotting with the openmc.Plot.from_geometry

From the plots, it seems that the first and second approach yield the same results. Unfortunately, I saw weird results from the third approach (see basis ‘yz’). I thought that perhaps there were overlapping cells but no errors found when I activated the geometry debugging. I tried a fresh install on a new conda environment and the problem still persist.
Am I doing something wrong here?

B. Plotting Source Distribution on top of the plot,
I am also interested to plot the source distribution (from the source h5 files) on top of the system plots. Are there any direct approach to do this with openmc python API? If no, how should I approach this?

Thanks.

Hi @arief.rahman ;

I checked you input file (for curiosity) and I am also working on some model these days where I need to check the geometry and to do, I tried one of the three options you did use in your example. I fixed the problem by using a line in your 3rd option:

plot_yz = openmc.Plot.from_geometry(geometry, basis=‘yz’, slice_coord=0)
plot_yz.color_by = 'material’
plot_yz.basis=‘yz’ <-------- here the line
plot_yz.colors = colors
plot_yz.to_ipython_image()

This worked for me when I was looking for a very short way to plot geometry by use of “to_ipython_image” method and I found such that way to change the basis. honestly I don’t know why it does not work with basis=‘yz’ as an argument, but it seems that it did another thing than plotting the right projection and as you notice it only shrink the xy plot!!!
For the second point I did not went so far yet in openmc, but you may get a look in the following example (at the end of the notebook):

regards

Salaheddine

Thanks @bentridisalah for trying to reproduce the behavior.

As seen above, it seems the behavior persist if we pass other basis (basis=‘yz’ or ‘xz’) as an argument on the from_geometry method. The plot object still returns as ‘xy’ if we print them. We need to set the basis again after instantiate the plot object (as you suggested).

Would you mind to clarify @paulromano if this is this a bug or it is what it is supposed to be?
Thanks a lot.

@arief.rahman Thanks for bringing this to my attention. Yes, that looks like a bug to me. It looks like we’re missing plot.basis = basis within the Plot.from_geometry method. I can get a bugfix submitted for this today, unless you or @bentridisalah are interested in submitting a pull request with a fix yourself. We always welcome new contributors :slight_smile:

1 Like

Sorry for my late reply. That’s a great idea.
I’ll try to set up my IDE to follow the contributor guidelines. Hopefully, I could submit the PR this week.

Anyway about my second question @paulromano on the post,
I have a workaround with matplotlib but I wonder, is there a direct way (with openmc python api) to plot the source distribution (from the source h5 files) on top of the plot?
Thanks.

Something like the following should work:

# You can replace this with whatever method you're using to do the geometry plot
geom = openmc.Geometry.from_xml()
geom.root_universe.plot()

with openmc.StatePoint('statepoint...h5') as sp:
    source = sp.source

# Replace 'x' and 'y' if you are using a different basis
import matplotlib.pyplot as plt
plt.scatter(source['r']['x'], source['r']['y'])
plt.show()
1 Like