-
Notifications
You must be signed in to change notification settings - Fork 0
Dump sources #46
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
Dump sources #46
Changes from all commits
6e893d2
9e8c7a4
6f7af2f
543a2e6
c031862
c6f3ead
4565b49
f069b6f
b99d04a
51c00fc
b5c05a6
43ecbc6
77ef8a5
e60ad1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import logging | ||
| import os | ||
| import sys | ||
| from importlib.resources import as_file, files | ||
| from math import pi | ||
| from pathlib import Path | ||
|
|
||
| from importlib.resources import files, as_file | ||
| import logging | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import pyevtk | ||
|
|
@@ -102,7 +102,6 @@ def dose_from_line_source(dose, x1, y1, z1, x2, y2, z2, x, y, z): | |
| def is_within_bounds( | ||
| x1, y1, z1, flux_grid_file, stl_files_path=None, x2=None, y2=None, z2=None | ||
| ): | ||
|
|
||
| # If a path to the STL files is provided, use it | ||
| if stl_files_path is not None: | ||
| folder_path = Path(stl_files_path) | ||
|
|
@@ -178,7 +177,6 @@ def write_vtk_file( | |
| z2=None, | ||
| output_all_vtr=False, | ||
| ): | ||
|
|
||
| # Get the bounds in which to make the plot | ||
| plot_bounds = is_within_bounds( | ||
| x1, y1, z1, flux_grid_file, stl_files_path, x2, y2, z2 | ||
|
|
@@ -227,17 +225,23 @@ def write_vtk_file( | |
| ) | ||
| dose_array[i, j, k] = dose_point | ||
|
|
||
| # Create a 3D numpy array filled with the dose values based on 1/r^2 | ||
| else: | ||
| for i in range(len(x) - 1): | ||
| for j in range(len(y) - 1): | ||
| for k in range(len(z) - 1): | ||
| else: # Point source case | ||
| # get midpoints | ||
| x_mid = (x[1:] + x[:-1]) / 2 | ||
| y_mid = (y[1:] + y[:-1]) / 2 | ||
| z_mid = (z[1:] + z[:-1]) / 2 | ||
| # Create a 3D numpy array filled with the dose values based on 1/r^2 (on middle point source model) | ||
| for i in range(len(x_mid)): | ||
| for j in range(len(y_mid)): | ||
| for k in range(len(z_mid)): | ||
| distance = np.sqrt( | ||
| (x[i] - x1) ** 2 + (y[j] - y1) ** 2 + (z[k] - z1) ** 2 | ||
| (x_mid[i] - x1) ** 2 | ||
| + (y_mid[j] - y1) ** 2 | ||
| + (z_mid[k] - z1) ** 2 | ||
| ) | ||
| # Avoid division by zero | ||
|
Member
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. I think computing the values in the center of the voxel is more correct than computing it in one of the vertex and then shift it in the center
Contributor
Author
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. If changing to middle point than the point value a 0 distance should be still divided by a distance value and not just be equal to "dose[0]" has it is now. I would suggest leave it like this; if an .stl file is not provided, I do not think 25 cm shift impact significantly, especially at several meters distances.
Contributor
Author
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. Implemented. Please note that the in case of distance==0 the dose value will be divided by 4*pi. |
||
| if distance == 0: | ||
| dose_array[i, j, k] = dose[0] | ||
| dose_array[i, j, k] = dose[0] / (4 * pi) | ||
| else: | ||
| dose_array[i, j, k] = dose[0] / (4 * pi * distance**2) | ||
|
|
||
|
|
@@ -248,7 +252,6 @@ def write_vtk_file( | |
| x_max = x[indices[0]] | ||
| y_max = y[indices[1]] | ||
| z_max = z[indices[2]] | ||
|
|
||
| # Create the output directory if it doesn't exist | ||
|
Member
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. This can probably be deleted and not just commented out |
||
| os.makedirs("output", exist_ok=True) | ||
|
|
||
|
|
@@ -265,7 +268,6 @@ def write_vtk_file( | |
|
|
||
|
|
||
| def plot_slice(dose_array, x, y, z, slice_axis, slice_location, plot_bounds): | ||
|
|
||
| # Map axis names to indices | ||
| axis_dict = {"x": 0, "y": 1, "z": 2} | ||
|
|
||
|
|
@@ -352,8 +354,9 @@ def format_func(value, tick_number): | |
| # Loop over each solid in the stl file and plot the slice | ||
| for solid in stl.solids: | ||
| slice = solid.slice(plane=slice_axis, intercept=slice_location) | ||
| pairs = getattr(slice, axis_pairs[slice_axis][0] + "_pairs"), getattr( | ||
| slice, axis_pairs[slice_axis][1] + "_pairs" | ||
| pairs = ( | ||
| getattr(slice, axis_pairs[slice_axis][0] + "_pairs"), | ||
| getattr(slice, axis_pairs[slice_axis][1] + "_pairs"), | ||
| ) | ||
| for pair in zip(*pairs): | ||
| ax.plot(*pair, color="black", linewidth=1) | ||
|
|
||
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.
This is a good addition (for what is needed). I just note that as an action for the future that in the shielding module of the code the retrieval of gamma lines was done using the API for the IAEA NDS. Just for consistency, now we have this dependency, actigamma could also be used.