Skip to content

Commit 8073072

Browse files
committed
Moved the heatmap function into a separate file, added the libraries and the pycache folders to the .gitignore
1 parent 11c6a40 commit 8073072

6 files changed

Lines changed: 30 additions & 73 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
**/.ipynb_checkpoints/
2+
forward-solvers/__pycache__/
3+
libraries/

forward-solvers/fluence-of-rho-and-z-two-layer.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
clr.AddReference(os.path.abspath(file))
1616
import numpy as np
1717
import plotly.graph_objects as go
18-
import plotly.express as px
1918
from Vts import *
2019
from Vts.Common import *
2120
from Vts.Extensions import *
@@ -30,9 +29,8 @@
3029
from Vts.MonteCarlo.Factories import *
3130
from Vts.MonteCarlo.PhotonData import *
3231
from Vts.MonteCarlo.PostProcessing import *
33-
from System import Array, Double, Object, Func, Math
34-
clr.AddReference("System.Core")
35-
from System.Linq import Enumerable
32+
from System import Array, Double, Math
33+
from graph_tools import heatmap
3634

3735
solver = TwoLayerSDAForwardSolver()
3836
solver.SourceConfiguration = SourceConfiguration.Distributed
@@ -75,26 +73,6 @@
7573
# reverse and concatenate
7674
allFluenceRowsToPlot = np.concatenate((fluenceRowsToPlot[::-1], fluenceRowsToPlot))
7775

78-
# Heatmap function to convert the data into a heat map
79-
def heatmap(values, x, y, x_label="", y_label="", title=""):
80-
"""Create a heatmap chart."""
81-
# values should be a 2D array-like (list of lists or 2D numpy array)
82-
fig = go.Figure(data=go.Heatmap(
83-
z=values,
84-
x=x,
85-
y=y,
86-
transpose=True,
87-
colorscale='Hot',
88-
colorbar=dict(title=title)
89-
))
90-
fig.update_layout(
91-
title=title,
92-
xaxis_title=x_label,
93-
yaxis_title=y_label,
94-
yaxis_autorange='reversed'
95-
)
96-
return fig
97-
9876
fluenceChart = heatmap(allFluenceRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(Φ(ρ, z) [mm-2])")
9977
fluenceChart.add_hline(y=topLayerThickness, line_dash="dash", line_color="white", line_width=2)
10078
fluenceChart.show(renderer="browser")

forward-solvers/graph_tools.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import plotly.graph_objects as go
2+
3+
# Heatmap function to convert the data into a heat map
4+
def heatmap(values, x, y, x_label="", y_label="", title=""):
5+
"""Create a heatmap chart."""
6+
# values should be a 2D array-like (list of lists or 2D numpy array)
7+
fig = go.Figure(data=go.Heatmap(
8+
z=values,
9+
x=x,
10+
y=y,
11+
transpose=True,
12+
colorscale='Hot',
13+
colorbar=dict(title=title)
14+
))
15+
fig.update_layout(
16+
title=title,
17+
xaxis_title=x_label,
18+
yaxis_title=y_label,
19+
yaxis_autorange='reversed'
20+
)
21+
return fig

forward-solvers/phd-of-rho-and-z-compute-fluence.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
clr.AddReference(os.path.abspath(file))
1414
import numpy as np
1515
import plotly.graph_objects as go
16-
import plotly.express as px
1716
from Vts import *
1817
from Vts.Common import *
1918
from Vts.Extensions import *
@@ -28,9 +27,8 @@
2827
from Vts.MonteCarlo.Factories import *
2928
from Vts.MonteCarlo.PhotonData import *
3029
from Vts.MonteCarlo.PostProcessing import *
31-
from System import Array, Double, Object, Func, Math
32-
clr.AddReference("System.Core")
33-
from System.Linq import Enumerable
30+
from System import Array, Double, Math
31+
from graph_tools import heatmap
3432

3533
solver = DistributedPointSourceSDAForwardSolver()
3634

@@ -83,25 +81,5 @@
8381
# split into rows
8482
phdRowsToPlot = np.array([log_phd[i:i+size] for i in range(0, len(log_phd), size)])
8583

86-
# Heatmap function to convert the data into a heat map
87-
def heatmap(values, x, y, x_label="", y_label="", title=""):
88-
"""Create a heatmap chart."""
89-
# values should be a 2D array-like (list of lists or 2D numpy array)
90-
fig = go.Figure(data=go.Heatmap(
91-
z=values,
92-
x=x,
93-
y=y,
94-
transpose=True,
95-
colorscale='Hot',
96-
colorbar=dict(title=title)
97-
))
98-
fig.update_layout(
99-
title=title,
100-
xaxis_title=x_label,
101-
yaxis_title=y_label,
102-
yaxis_autorange='reversed'
103-
)
104-
return fig
105-
10684
fluenceChart = heatmap(phdRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(phd(ρ, z) [mm-2])")
10785
fluenceChart.show(renderer="browser")

forward-solvers/phd-of-rho-and-z-two-layer.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
clr.AddReference(os.path.abspath(file))
1414
import numpy as np
1515
import plotly.graph_objects as go
16-
import plotly.express as px
1716
from Vts import *
1817
from Vts.Common import *
1918
from Vts.Extensions import *
@@ -28,9 +27,8 @@
2827
from Vts.MonteCarlo.Factories import *
2928
from Vts.MonteCarlo.PhotonData import *
3029
from Vts.MonteCarlo.PostProcessing import *
31-
from System import Array, Double, Object, Func, Math
32-
clr.AddReference("System.Core")
33-
from System.Linq import Enumerable
30+
from System import Array, Double, Math
31+
from graph_tools import heatmap
3432

3533
solver = TwoLayerSDAForwardSolver()
3634
solver.SourceConfiguration = SourceConfiguration.Distributed
@@ -77,26 +75,6 @@
7775
# split into rows
7876
fluenceRowsToPlot = np.array([log_fluence[i:i+size] for i in range(0, len(log_fluence), size)])
7977

80-
# Heatmap function to convert the data into a heat map
81-
def heatmap(values, x, y, x_label="", y_label="", title=""):
82-
"""Create a heatmap chart."""
83-
# values should be a 2D array-like (list of lists or 2D numpy array)
84-
fig = go.Figure(data=go.Heatmap(
85-
z=values,
86-
x=x,
87-
y=y,
88-
transpose=True,
89-
colorscale='Hot',
90-
colorbar=dict(title=title)
91-
))
92-
fig.update_layout(
93-
title=title,
94-
xaxis_title=x_label,
95-
yaxis_title=y_label,
96-
yaxis_autorange='reversed'
97-
)
98-
return fig
99-
10078
fluenceChart = heatmap(fluenceRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(phd(ρ, z) [mm-2])")
10179
fluenceChart.add_hline(y=topLayerThickness, line_dash="dash", line_color="white", line_width=2)
10280
fluenceChart.show(renderer="browser")

forward-solvers/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This folder will contain the Forward Solver demos.
1+
This folder contains the Forward Solver demos.

0 commit comments

Comments
 (0)