Skip to content

Commit 0349a81

Browse files
authored
Merge pull request #24 from VirtualPhotonics/feature/23-create-a-separate-function-for-heat-map-so-it-can-be-referenced-from-multiple-places
2 parents 7a9990a + e76c875 commit 0349a81

File tree

9 files changed

+41
-77
lines changed

9 files changed

+41
-77
lines changed

.gitignore

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

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import clr
1212
# Import the Operating System so we can access the files for the VTS library
1313
import os
14+
import sys
15+
module_path = '../modules'
16+
sys.path.append(module_path)
1417
file = '../libraries/Vts.dll'
1518
clr.AddReference(os.path.abspath(file))
1619
import numpy as np
1720
import plotly.graph_objects as go
18-
import plotly.express as px
1921
from Vts import *
2022
from Vts.Common import *
2123
from Vts.Extensions import *
@@ -30,9 +32,8 @@
3032
from Vts.MonteCarlo.Factories import *
3133
from Vts.MonteCarlo.PhotonData import *
3234
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
35+
from System import Array, Double, Math
36+
from graph_tools import heatmap
3637

3738
solver = TwoLayerSDAForwardSolver()
3839
solver.SourceConfiguration = SourceConfiguration.Distributed
@@ -75,26 +76,6 @@
7576
# reverse and concatenate
7677
allFluenceRowsToPlot = np.concatenate((fluenceRowsToPlot[::-1], fluenceRowsToPlot))
7778

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-
9879
fluenceChart = heatmap(allFluenceRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(Φ(ρ, z) [mm-2])")
9980
fluenceChart.add_hline(y=topLayerThickness, line_dash="dash", line_color="white", line_width=2)
10081
fluenceChart.show(renderer="browser")

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import clr
1010
# Import the Operating System so we can access the files for the VTS library
1111
import os
12+
import sys
13+
module_path = '../modules'
14+
sys.path.append(module_path)
1215
file = '../libraries/Vts.dll'
1316
clr.AddReference(os.path.abspath(file))
1417
import numpy as np
1518
import plotly.graph_objects as go
16-
import plotly.express as px
1719
from Vts import *
1820
from Vts.Common import *
1921
from Vts.Extensions import *
@@ -28,9 +30,8 @@
2830
from Vts.MonteCarlo.Factories import *
2931
from Vts.MonteCarlo.PhotonData import *
3032
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
33+
from System import Array, Double, Math
34+
from graph_tools import heatmap
3435

3536
solver = DistributedPointSourceSDAForwardSolver()
3637

@@ -83,25 +84,5 @@
8384
# split into rows
8485
phdRowsToPlot = np.array([log_phd[i:i+size] for i in range(0, len(log_phd), size)])
8586

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-
10687
fluenceChart = heatmap(phdRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(phd(ρ, z) [mm-2])")
10788
fluenceChart.show(renderer="browser")

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import clr
1010
# Import the Operating System so we can access the files for the VTS library
1111
import os
12+
import sys
13+
module_path = '../modules'
14+
sys.path.append(module_path)
1215
file = '../libraries/Vts.dll'
1316
clr.AddReference(os.path.abspath(file))
1417
import numpy as np
1518
import plotly.graph_objects as go
16-
import plotly.express as px
1719
from Vts import *
1820
from Vts.Common import *
1921
from Vts.Extensions import *
@@ -28,9 +30,8 @@
2830
from Vts.MonteCarlo.Factories import *
2931
from Vts.MonteCarlo.PhotonData import *
3032
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
33+
from System import Array, Double, Math
34+
from graph_tools import heatmap
3435

3536
solver = TwoLayerSDAForwardSolver()
3637
solver.SourceConfiguration = SourceConfiguration.Distributed
@@ -77,26 +78,6 @@
7778
# split into rows
7879
fluenceRowsToPlot = np.array([log_fluence[i:i+size] for i in range(0, len(log_fluence), size)])
7980

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-
10081
fluenceChart = heatmap(fluenceRowsToPlot.tolist(), allRhos.tolist(), list(zs), "ρ [mm]", "z [mm]", "log(phd(ρ, z) [mm-2])")
10182
fluenceChart.add_hline(y=topLayerThickness, line_dash="dash", line_color="white", line_width=2)
10283
fluenceChart.show(renderer="browser")

forward-solvers/readme.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

inverse-solutions/readme.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

license.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## The MIT License (MIT)
22

3-
#### Copyright (c) 2023 Virtual Photonics Technology Initiative
3+
#### Copyright (c) 2025 Virtual Photonics Technology Initiative
44

55
### Acknowledgement
66
Use the following acknowledgement in publications or applications that make use of this open source software or underlying technology and research:

modules/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

runtimeconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"runtimeOptions": {
3-
"tfm": "net6.0",
3+
"tfm": "net8.0",
44
"framework": {
55
"name": "Microsoft.NETCore.App",
6-
"version": "6.0.0"
6+
"version": "8.0.0"
77
},
88
"configProperties": {
99
"System.GC.Server": true

0 commit comments

Comments
 (0)