-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding projection plot #4
Draft
shimwell
wants to merge
3
commits into
develop
Choose a base branch
from
adding_projection_plot
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
examples/example_plot_projected_position_from_initial_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import openmc_source_plotter as osp | ||
import openmc | ||
import numpy as np | ||
|
||
# initialises a new source object | ||
my_source = openmc.Source() | ||
|
||
# the distribution of radius is just a single value | ||
radius = openmc.stats.Discrete([10], [1]) | ||
|
||
# the distribution of source z values is just a single value | ||
z_values = openmc.stats.Discrete([0], [1]) | ||
|
||
# the distribution of source azimuthal angles values is a uniform distribution between 0 and 2 Pi | ||
angle = openmc.stats.Uniform(a=0.0, b=2 * 3.14159265359) | ||
|
||
# this makes the ring source using the three distributions and a radius | ||
my_source.space = openmc.stats.CylindricalIndependent( | ||
r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0) | ||
) | ||
|
||
|
||
# makes an initial_source.h5 file with details of the particles | ||
initial_source_filename = osp.create_initial_particles( | ||
source=my_source, | ||
number_of_particles=10, | ||
openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", | ||
) | ||
|
||
# plots the particle energy distribution | ||
plot = osp.plot_position_projected_from_initial_source( | ||
input_filename=initial_source_filename, axis="XY" | ||
) | ||
|
||
plot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .core import plot_direction_from_initial_source | ||
from .core import plot_position_from_initial_source | ||
from .core import plot_position_projected_from_initial_source | ||
from .core import plot_energy_from_initial_source | ||
from .core import get_particle_data | ||
from .core import create_initial_particles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -128,6 +128,43 @@ def plot_energy_from_initial_source( | |||||||||||||
return fig | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def plot_projected_position_from_initial_source( | ||||||||||||||
input_filename="initial_source.h5", axis="XY" | ||||||||||||||
): | ||||||||||||||
Comment on lines
+132
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
"""makes a plot of the initial creation locations of the particle source""" | ||||||||||||||
|
||||||||||||||
data = get_particle_data(input_filename) | ||||||||||||||
|
||||||||||||||
text = ["Energy = " + str(i) + " eV" for i in data["e_values"]] | ||||||||||||||
|
||||||||||||||
fig = go.Figure() | ||||||||||||||
|
||||||||||||||
if axis == "XY": | ||||||||||||||
x = data["x_values"] | ||||||||||||||
y = data["y_values"] | ||||||||||||||
if axis == "XZ": | ||||||||||||||
x = data["x_values"] | ||||||||||||||
y = data["z_values"] | ||||||||||||||
|
||||||||||||||
fig.add_trace( | ||||||||||||||
go.Scatter( | ||||||||||||||
x=x, | ||||||||||||||
y=y, | ||||||||||||||
hovertext=text, | ||||||||||||||
text=text, | ||||||||||||||
mode="markers", | ||||||||||||||
marker={ | ||||||||||||||
"size": 2, | ||||||||||||||
"color": data["e_values"], | ||||||||||||||
}, | ||||||||||||||
) | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
fig.update_layout(title="Particle production coordinates - coloured by energy") | ||||||||||||||
|
||||||||||||||
return fig | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def plot_position_from_initial_source(input_filename="initial_source.h5"): | ||||||||||||||
"""makes a plot of the initial creation locations of the particle source""" | ||||||||||||||
|
||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.