Skip to content

Commit 84b87a0

Browse files
authored
Merge pull request #17 from VirtualPhotonics/feature/16-rename-and-reorganize-the-demos-in-the-repo
Feature/16 rename and reorganize the demos in the repo
2 parents bd9a1eb + 5258bf6 commit 84b87a0

11 files changed

Lines changed: 183 additions & 1530 deletions

File tree

forward-solvers/readme.txt

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

inverse-solutions/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder will contain the Inverse Solution demos.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The VTS libraries should be copied into this folder. Get the latest VTS library (VTS.dll) and its dependencies from the releases section of this repository https://github.com/VirtualPhotonics/Vts.Scripting.Python/releases
1+
The VTS libraries should be copied into this folder. Get the latest VTS library (VTS.dll) and its dependencies from the releases section of this repository https://github.com/VirtualPhotonics/Vts.Scripting.Python/releases

scripting/monte_carlo/demo_02_DAW_vs_CAW.ipynb renamed to monte-carlo/daw_vs_caw.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"#Import the Operating System so we can access the files for the VTS library\n",
2828
"import os\n",
2929
"current_directory = os.getcwd()\n",
30-
"library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n",
30+
"library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n",
3131
"vts_path = os.path.join(library_directory, \"Vts.dll\")"
3232
]
3333
},
@@ -72,7 +72,6 @@
7272
"clr.AddReference(vts_path)\n",
7373
"import numpy as np\n",
7474
"import plotly.graph_objects as go\n",
75-
"import plotly.express as px\n",
7675
"from Vts import *\n",
7776
"from Vts.Common import *\n",
7877
"from Vts.Extensions import *\n",
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# This is an example of python code using VTS to plot R(rho) using MCCL
2+
#
3+
# Import the Operating System so we can access the files for the VTS library
4+
from pythonnet import load
5+
load('coreclr')
6+
import clr
7+
import os
8+
file = '../libraries/Vts.dll'
9+
print('Does this filepath exist?', os.path.isfile(file))
10+
clr.AddReference(os.path.abspath(file))
11+
12+
print('Import numpy')
13+
import numpy as np
14+
print('Import pyplot')
15+
import matplotlib.pyplot as plt
16+
print('Import Vts')
17+
from Vts import *
18+
from Vts.Common import *
19+
from Vts.Extensions import *
20+
from Vts.Modeling.Optimizers import *
21+
from Vts.Modeling.ForwardSolvers import *
22+
from Vts.SpectralMapping import *
23+
from Vts.Factories import *
24+
from Vts.MonteCarlo import *
25+
from Vts.MonteCarlo.Sources import *
26+
from Vts.MonteCarlo.Tissues import *
27+
from Vts.MonteCarlo.Detectors import *
28+
from Vts.MonteCarlo.Factories import *
29+
from Vts.MonteCarlo.PhotonData import *
30+
from Vts.MonteCarlo.PostProcessing import *
31+
print('Import System')
32+
from System import Array, Double
33+
34+
# SimulationInput defines the simulation. I think the default is collimated point source illumination normal to the surface.
35+
simulationInput = SimulationInput()
36+
simulationInput.N = 10000
37+
38+
# We add four detectors. One to monitor the reflected excitance as a function of radius, and three to monitor the overall reflection and transmission.
39+
# add detectors to Simulation object
40+
detectors = Array.CreateInstance(IDetectorInput, 4)
41+
42+
detectors[0] = ROfRhoDetectorInput()
43+
detectors[0].Rho = DoubleRange(start=0, stop=5, number=401)
44+
detectors[1] = RDiffuseDetectorInput()
45+
detectors[2] = RSpecularDetectorInput()
46+
detectors[3] = TDiffuseDetectorInput()
47+
48+
simulationInput.DetectorInputs = detectors
49+
50+
# This is an index matched sample that has scattering of 0.99/mm and absorption of 0.01/mm. It is 10mm thick.
51+
d = 10 # mm
52+
mua = 0.01 # mm⁻¹
53+
musp = 0.99 # mm⁻¹
54+
g = 0 # scattering anisotropy
55+
n = 1 # matched index of refraction
56+
57+
regions = Array.CreateInstance(ITissueRegion, 3)
58+
59+
regions[0] = LayerTissueRegion(zRange=DoubleRange(Double.NegativeInfinity, 0.0), op=OpticalProperties(mua=0.0, musp=1E-10, g=1.0, n=1.0))
60+
regions[1] = LayerTissueRegion(zRange=DoubleRange(0.0, d), op=OpticalProperties(mua=mua, musp=musp, g=g, n=n))
61+
regions[2] = LayerTissueRegion(zRange=DoubleRange(d, Double.PositiveInfinity), op=OpticalProperties(0.0, 1E-10, 1.0, 1.0))
62+
63+
simulationInput.TissueInput = MultiLayerTissueInput(regions)
64+
65+
# create the simulation
66+
simulation = MonteCarloSimulation(simulationInput)
67+
68+
# run the simulation
69+
simulationOutput = simulation.Run()
70+
71+
# extract the data
72+
rDiffuse = Array.CreateInstance(RDiffuseDetector, 1)
73+
rDiffuse[0] = simulationOutput.ResultsDictionary["RDiffuse"]
74+
75+
tDiffuse = Array.CreateInstance(TDiffuseDetector, 1)
76+
tDiffuse[0] = simulationOutput.ResultsDictionary["TDiffuse"]
77+
78+
rSpecular = Array.CreateInstance(RSpecularDetector, 1)
79+
rSpecular[0] = simulationOutput.ResultsDictionary["RSpecular"]
80+
81+
print("specular R = %.5f" % rSpecular[0].Mean)
82+
print(" diffuse R = %.5f" % rDiffuse[0].Mean)
83+
print(" diffuse T = %.5f" % tDiffuse[0].Mean)
84+
85+
# plot the results using Pyplot
86+
detectorResults = Array.CreateInstance(ROfRhoDetector, 1)
87+
detectorResults[0] = simulationOutput.ResultsDictionary["ROfRho"]
88+
89+
reflectance = np.array([r for r in detectorResults[0].Mean])
90+
edges = np.array([mp for mp in detectorResults[0].Rho])[:-1]
91+
92+
plt.figure(figsize=(8,4.5))
93+
plt.plot(edges, reflectance, 'ob', markersize=2)
94+
plt.plot(-edges, reflectance, 'ob', markersize=2)
95+
plt.xlabel('ρ [mm]')
96+
plt.ylabel('R(ρ) [W/mm²]')
97+
plt.title('1 W Impulse Beam')
98+
99+
text_args = {
100+
'ha': 'left', # Horizontal alignment
101+
'va': 'top', # Vertical alignment
102+
'transform': plt.gca().transAxes, # Coordinate system transformation
103+
'fontsize': 9 # Font size
104+
}
105+
106+
plt.text(0.8, 0.95, 'n=%.3f' % n, **text_args)
107+
plt.text(0.8, 0.90, r'$\mu_a$=%.2f mm⁻¹' % mua, **text_args)
108+
plt.text(0.8, 0.85, r"${\mu_s}'$=%.2f mm⁻¹" % musp, **text_args)
109+
plt.text(0.8, 0.80, 'g=%.2f' % g, **text_args)
110+
plt.text(0.8, 0.75, 'd=%.1f mm' % d, **text_args)
111+
plt.show()

monte-carlo/r-of-rho.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This is an example of python code using VTS to plot R(rho) using MCCL
2+
#
3+
# Import the Operating System so we can access the files for the VTS library
4+
from pythonnet import load
5+
load('coreclr')
6+
import clr
7+
import os
8+
file = '../libraries/Vts.dll'
9+
print('Does this filepath exist?', os.path.isfile(file))
10+
clr.AddReference(os.path.abspath(file))
11+
12+
print('Import numpy')
13+
import numpy as np
14+
print('Import plotly.graph')
15+
import plotly.graph_objects as go
16+
print('Import Vts')
17+
from Vts import *
18+
from Vts.Common import *
19+
from Vts.Extensions import *
20+
from Vts.Modeling.Optimizers import *
21+
from Vts.Modeling.ForwardSolvers import *
22+
from Vts.SpectralMapping import *
23+
from Vts.Factories import *
24+
from Vts.MonteCarlo import *
25+
from Vts.MonteCarlo.Sources import *
26+
from Vts.MonteCarlo.Tissues import *
27+
from Vts.MonteCarlo.Detectors import *
28+
from Vts.MonteCarlo.Factories import *
29+
from Vts.MonteCarlo.PhotonData import *
30+
from Vts.MonteCarlo.PostProcessing import *
31+
print('Import System')
32+
from System import Array
33+
# Setup the values for the simulations and plot results
34+
# create a SimulationInput object to define the simulation
35+
detectorRange = DoubleRange(start=0, stop=40, number=201)
36+
detectorInput = ROfRhoDetectorInput()
37+
detectorInput.Rho = detectorRange
38+
detectorInput.Name = "ROfRho"
39+
detectors = Array.CreateInstance(IDetectorInput,1)
40+
detectors[0] = detectorInput
41+
42+
simulationInput = SimulationInput()
43+
simulationInput.N = 1000
44+
simulationInput.DetectorInputs = detectors
45+
46+
# create the simulation
47+
simulation = MonteCarloSimulation(simulationInput)
48+
49+
# run the simulation
50+
simulationOutput = simulation.Run()
51+
52+
# plot the results using Plotly
53+
detectorResults = Array.CreateInstance(ROfRhoDetector,1)
54+
detectorResults[0] = simulationOutput.ResultsDictionary["ROfRho"]
55+
logReflectance = [r for r in detectorResults[0].Mean]
56+
detectorMidpoints = [mp for mp in detectorRange]
57+
58+
xLabel = "ρ [mm]"
59+
yLabel = "log(R(ρ)) [mm-2]"
60+
61+
chart = go.Figure()
62+
chart.add_trace(go.Scatter(x=detectorMidpoints, y=logReflectance, mode='markers'))
63+
chart.update_layout( title="log(R(ρ)) [mm-2]", xaxis_title=xLabel, yaxis_title=yLabel)
64+
chart.update_yaxes(type="log")
65+
chart.show(renderer="browser")

scripting/monte_carlo/demo_01_r_of_rho_simple.ipynb renamed to monte-carlo/r_of_rho.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"#Import the Operating System so we can access the files for the VTS library\n",
2626
"import os\n",
2727
"current_directory = os.getcwd()\n",
28-
"library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n",
28+
"library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n",
2929
"vts_path = os.path.join(library_directory, \"Vts.dll\")"
3030
]
3131
},
@@ -66,7 +66,6 @@
6666
"clr.AddReference(vts_path)\n",
6767
"import numpy as np\n",
6868
"import plotly.graph_objects as go\n",
69-
"import plotly.express as px\n",
7069
"from Vts import *\n",
7170
"from Vts.Common import *\n",
7271
"from Vts.Extensions import *\n",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"#Import the Operating System so we can get the file path for the Vts library\n",
3838
"import os\n",
3939
"current_directory = os.getcwd()\n",
40-
"library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n",
40+
"library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n",
4141
"vts_path = os.path.join(library_directory, \"Vts.dll\")\n",
4242
"clr.AddReference(vts_path)"
4343
]
@@ -260,7 +260,7 @@
260260
"source": [
261261
"Which should produce \n",
262262
"\n",
263-
"<img src='example.svg'>"
263+
"<img src='r_of_rho_impulse_beam.svg'>"
264264
]
265265
}
266266
],

0 commit comments

Comments
 (0)