diff --git a/examples/example_get_particle_data.py b/examples/example_get_particle_data.py index 868739c..aafc09d 100644 --- a/examples/example_get_particle_data.py +++ b/examples/example_get_particle_data.py @@ -1,4 +1,3 @@ - import openmc_source_plotter as osp import openmc @@ -18,7 +17,7 @@ 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' + openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", ) # gets the particle corrdiantes, energy and direction diff --git a/examples/example_plot_direction_from_initial_source.py b/examples/example_plot_direction_from_initial_source.py index 5d83c5a..5f39276 100644 --- a/examples/example_plot_direction_from_initial_source.py +++ b/examples/example_plot_direction_from_initial_source.py @@ -1,4 +1,3 @@ - import openmc_source_plotter as osp import openmc import numpy as np @@ -13,7 +12,7 @@ initial_source_filename = osp.create_initial_particles( source=my_source, number_of_particles=100, - openmc_exec='/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc' + openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", ) # plots the particle energy distribution diff --git a/examples/example_plot_energy_from_initial_source.py b/examples/example_plot_energy_from_initial_source.py index 759ec6f..ac88911 100644 --- a/examples/example_plot_energy_from_initial_source.py +++ b/examples/example_plot_energy_from_initial_source.py @@ -1,4 +1,3 @@ - import openmc_source_plotter as osp import openmc import numpy as np @@ -16,12 +15,12 @@ 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' + openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", ) # plots the particle energy distribution plot = osp.plot_energy_from_initial_source( - energy_bins=np.linspace(0, 20e6, 50), - input_filename=initial_source_filename) + energy_bins=np.linspace(0, 20e6, 50), input_filename=initial_source_filename +) plot.show() diff --git a/examples/example_plot_position_from_initial_source.py b/examples/example_plot_position_from_initial_source.py index 0feff2b..76ee303 100644 --- a/examples/example_plot_position_from_initial_source.py +++ b/examples/example_plot_position_from_initial_source.py @@ -1,4 +1,3 @@ - import openmc_source_plotter as osp import openmc import numpy as np @@ -13,17 +12,19 @@ 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., b=2* 3.14159265359) +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)) +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' + openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", ) # plots the particle energy distribution diff --git a/openmc_source_plotter/core.py b/openmc_source_plotter/core.py index b9f72dc..cd44613 100644 --- a/openmc_source_plotter/core.py +++ b/openmc_source_plotter/core.py @@ -10,10 +10,8 @@ def create_initial_particles( - source: openmc.source, - number_of_particles: int=2000, - openmc_exec='openmc' -)-> str: + source: openmc.source, number_of_particles: int = 2000, openmc_exec="openmc" +) -> str: """Accepts an openmc source and creates an initial_source.h5 file that can be used to find propties of the source particles such as initial x,y,z coordinates, direction and energy. @@ -31,7 +29,7 @@ def create_initial_particles( number_of_particles: the number of particles to sample openmc_exec: the path of openmc executable or executable name if it appears in your system $PATH. Defaults to 'openmc' which will use - the default openmc in your system $PATH environmental variable. + the default openmc in your system $PATH environmental variable. Returns: The filename of the initial source file created (initial_source.h5) """ @@ -47,7 +45,7 @@ def create_initial_particles( # Instantiate a Settings object settings = openmc.Settings() - settings.run_mode = ("fixed source") + settings.run_mode = "fixed source" settings.particles = number_of_particles settings.batches = 1 settings.inactive = 0 @@ -62,9 +60,8 @@ def create_initial_particles( return "initial_source.h5" -def get_particle_data( - input_filename: str -): + +def get_particle_data(input_filename: str): f = h5py.File(input_filename, "r") dset = f["source_bank"] @@ -83,28 +80,29 @@ def get_particle_data( z_values.append(particle[0][2]) x_dir.append(particle[1][0]) y_dir.append(particle[1][1]) - z_dir.append(particle[1][2]) + z_dir.append(particle[1][2]) e_values.append(particle[2]) - + return { - 'x_values': x_values, - 'y_values': y_values, - 'z_values': z_values, - 'x_dir': x_dir, - 'y_dir': y_dir, - 'z_dir': z_dir, - 'e_values': e_values + "x_values": x_values, + "y_values": y_values, + "z_values": z_values, + "x_dir": x_dir, + "y_dir": y_dir, + "z_dir": z_dir, + "e_values": e_values, } + def plot_energy_from_initial_source( - energy_bins: np.array=np.linspace(0, 20e6, 50), - input_filename: str = "initial_source.h5" + energy_bins: np.array = np.linspace(0, 20e6, 50), + input_filename: str = "initial_source.h5", ): """makes a plot of the energy distribution of the source""" data = get_particle_data(input_filename) - e_values = data['e_values'] + e_values = data["e_values"] # Calculate pdf for source energies probability, bin_edges = np.histogram(e_values, energy_bins, density=True) @@ -135,21 +133,21 @@ def plot_position_from_initial_source(input_filename="initial_source.h5"): data = get_particle_data(input_filename) - text = ["Energy = " + str(i) + " eV" for i in data['e_values']] + text = ["Energy = " + str(i) + " eV" for i in data["e_values"]] fig = go.Figure() fig.add_trace( go.Scatter3d( - x=data['x_values'], - y=data['y_values'], - z=data['z_values'], + x=data["x_values"], + y=data["y_values"], + z=data["z_values"], hovertext=text, text=text, mode="markers", marker={ "size": 2, - "color": data['e_values'], + "color": data["e_values"], }, ) ) @@ -170,12 +168,12 @@ def plot_direction_from_initial_source(input_filename="initial_source.h5"): { "type": "cone", "cauto": False, - "x": data['x_values'], - "y": data['y_values'], - "z": data['z_values'], - "u": data['x_dir'], - "v": data['y_dir'], - "w": data['z_dir'], + "x": data["x_values"], + "y": data["y_values"], + "z": data["z_values"], + "u": data["x_dir"], + "v": data["y_dir"], + "w": data["z_dir"], "cmin": 0, "cmax": 1, "anchor": "tail", diff --git a/setup.py b/setup.py index 7466947..e8010f4 100644 --- a/setup.py +++ b/setup.py @@ -14,19 +14,16 @@ url="https://github.com/fusion-energy/openmc_source_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', + "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', - install_requires=[ - "plotly>=5.1.0", - "numpy>=1.21.1", - "h5py" - ]) + python_requires=">=3.6", + install_requires=["plotly>=5.1.0", "numpy>=1.21.1", "h5py"], +)