From 214ce8071a465dbfa5bcc366248c4cfdcc9497ec Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 29 Jul 2022 12:33:32 +0100 Subject: [PATCH 1/3] added three badges --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0c50e2c..22f5055 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![CI with install](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/ci_with_install.yml/badge.svg)](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/ci_with_install.yml) + +[![Python Flake8 Lint](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/lint.yaml/badge.svg)](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/lint.yaml) + +[![Upload Python Package](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/python-publish.yml/badge.svg)](https://github.com/fusion-energy/openmc_source_plotter/actions/workflows/python-publish.yml) A Python package for plotting the locations, directions or energy distributions of OpenMC sources. From 3bb75dd1f7539b86d26c3ed08eed9d687cd32aa6 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 29 Jul 2022 12:48:31 +0100 Subject: [PATCH 2/3] implemented flake8 suggestions --- examples/example_plot_source_energy.py | 1 - examples/example_plot_source_position.py | 3 ++- examples/example_plot_two_source_energies.py | 6 +++-- openmc_source_plotter/core.py | 24 ++++++++++++-------- tests/test_core.py | 2 -- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/example_plot_source_energy.py b/examples/example_plot_source_energy.py index ea8aa4e..a5be58d 100644 --- a/examples/example_plot_source_energy.py +++ b/examples/example_plot_source_energy.py @@ -1,6 +1,5 @@ import openmc_source_plotter as osp import openmc -import numpy as np # initialises a new source object my_source = openmc.Source() diff --git a/examples/example_plot_source_position.py b/examples/example_plot_source_position.py index 0ffda4b..d395691 100644 --- a/examples/example_plot_source_position.py +++ b/examples/example_plot_source_position.py @@ -10,7 +10,8 @@ # 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 +# 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 diff --git a/examples/example_plot_two_source_energies.py b/examples/example_plot_two_source_energies.py index c97c443..e2aa5c6 100644 --- a/examples/example_plot_two_source_energies.py +++ b/examples/example_plot_two_source_energies.py @@ -1,6 +1,5 @@ import openmc_source_plotter as osp import openmc -import numpy as np # initialises a new source object my_dt_source = openmc.Source() @@ -14,6 +13,9 @@ my_dd_source.energy = openmc.stats.Muir(e0=2080000.0, m_rat=2.0, kt=20000.0) # plots the particle energy distribution -plot = osp.plot_source_energy(source=[my_dt_source, my_dd_source], n_samples=10000) +plot = osp.plot_source_energy( + source=[my_dt_source, my_dd_source], + n_samples=10000 +) plot.show() diff --git a/openmc_source_plotter/core.py b/openmc_source_plotter/core.py index 64c5c70..b954163 100644 --- a/openmc_source_plotter/core.py +++ b/openmc_source_plotter/core.py @@ -2,7 +2,6 @@ """Provides functions for plotting source information""" -import tempfile from typing import List, Union import numpy as np @@ -47,12 +46,13 @@ def plot_source_energy( """makes a plot of the initial creation postions of an OpenMC source(s) Args: - source: The openmc.Source object or list of openmc.Source objects to plot. + source: The openmc.Source object or list of openmc.Source objects to + plot. n_samples: The number of source samples to obtain. prn_seed: The pseudorandom number seed - energy_bins: Defaults to 'auto' which uses inbuilt auto binning in Numpy - bins can also be manually set by passing in a numpy array of bin - edges. + energy_bins: Defaults to 'auto' which uses inbuilt auto binning in + Numpy bins can also be manually set by passing in a numpy array of + bin edges. """ figure = go.Figure() @@ -67,7 +67,9 @@ def plot_source_energy( e_values = [particle.E for particle in data] # Calculate pdf for source energies - probability, bin_edges = np.histogram(e_values, bins=energy_bins, density=True) + probability, bin_edges = np.histogram( + e_values, bins=energy_bins, density=True + ) # Plot source energy histogram figure.add_trace( @@ -97,7 +99,8 @@ def plot_source_position( """makes a plot of the initial creation postions of an OpenMC source(s) Args: - source: The openmc.Source object or list of openmc.Source objects to plot. + source: The openmc.Source object or list of openmc.Source objects to + plot. n_samples: The number of source samples to obtain. prn_seed: The pseudorandom number seed """ @@ -127,8 +130,8 @@ def plot_source_position( }, ) ) - - figure.update_layout(title="Particle production coordinates - coloured by energy") + title = "Particle production coordinates coloured by energy" + figure.update_layout(title=title) return figure @@ -141,7 +144,8 @@ def plot_source_direction( """makes a plot of the initial creation postions of an OpenMC source(s) Args: - source: The openmc.Source object or list of openmc.Source objects to plot. + source: The openmc.Source object or list of openmc.Source objects to + plot. n_samples: The number of source samples to obtain. prn_seed: The pseudorandom number seed """ diff --git a/tests/test_core.py b/tests/test_core.py index 776d97b..e932190 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,8 +1,6 @@ -from numpy import isin import openmc_source_plotter as osp import openmc import unittest -from pathlib import Path import numpy as np import plotly.graph_objects as go From 1dc44112cb8d8eef24af35f35efc2aafd7c37e98 Mon Sep 17 00:00:00 2001 From: shimwell Date: Fri, 29 Jul 2022 11:49:20 +0000 Subject: [PATCH 3/3] [skip ci] Apply formatting changes --- examples/example_plot_two_source_energies.py | 5 +---- openmc_source_plotter/core.py | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/example_plot_two_source_energies.py b/examples/example_plot_two_source_energies.py index e2aa5c6..82c6b50 100644 --- a/examples/example_plot_two_source_energies.py +++ b/examples/example_plot_two_source_energies.py @@ -13,9 +13,6 @@ my_dd_source.energy = openmc.stats.Muir(e0=2080000.0, m_rat=2.0, kt=20000.0) # plots the particle energy distribution -plot = osp.plot_source_energy( - source=[my_dt_source, my_dd_source], - n_samples=10000 -) +plot = osp.plot_source_energy(source=[my_dt_source, my_dd_source], n_samples=10000) plot.show() diff --git a/openmc_source_plotter/core.py b/openmc_source_plotter/core.py index b954163..714ddb0 100644 --- a/openmc_source_plotter/core.py +++ b/openmc_source_plotter/core.py @@ -67,9 +67,7 @@ def plot_source_energy( e_values = [particle.E for particle in data] # Calculate pdf for source energies - probability, bin_edges = np.histogram( - e_values, bins=energy_bins, density=True - ) + probability, bin_edges = np.histogram(e_values, bins=energy_bins, density=True) # Plot source energy histogram figure.add_trace(