diff --git a/forward-solvers/readme.txt b/forward-solvers/readme.txt new file mode 100644 index 0000000..f62677b --- /dev/null +++ b/forward-solvers/readme.txt @@ -0,0 +1 @@ +This folder will contain the Forward Solver demos. diff --git a/inverse-solutions/readme.txt b/inverse-solutions/readme.txt new file mode 100644 index 0000000..3c6954e --- /dev/null +++ b/inverse-solutions/readme.txt @@ -0,0 +1 @@ +This folder will contain the Inverse Solution demos. diff --git a/scripting/libraries/readme.txt b/libraries/readme.txt similarity index 86% rename from scripting/libraries/readme.txt rename to libraries/readme.txt index b771629..70b8ecf 100644 --- a/scripting/libraries/readme.txt +++ b/libraries/readme.txt @@ -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 \ No newline at end of file +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 diff --git a/scripting/monte_carlo/demo_02_DAW_vs_CAW.ipynb b/monte-carlo/daw_vs_caw.ipynb similarity index 98% rename from scripting/monte_carlo/demo_02_DAW_vs_CAW.ipynb rename to monte-carlo/daw_vs_caw.ipynb index 69067f0..0986d9c 100644 --- a/scripting/monte_carlo/demo_02_DAW_vs_CAW.ipynb +++ b/monte-carlo/daw_vs_caw.ipynb @@ -27,7 +27,7 @@ "#Import the Operating System so we can access the files for the VTS library\n", "import os\n", "current_directory = os.getcwd()\n", - "library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n", + "library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n", "vts_path = os.path.join(library_directory, \"Vts.dll\")" ] }, @@ -72,7 +72,6 @@ "clr.AddReference(vts_path)\n", "import numpy as np\n", "import plotly.graph_objects as go\n", - "import plotly.express as px\n", "from Vts import *\n", "from Vts.Common import *\n", "from Vts.Extensions import *\n", diff --git a/monte-carlo/r-of-rho-impulse-beam.py b/monte-carlo/r-of-rho-impulse-beam.py new file mode 100644 index 0000000..d2d8c61 --- /dev/null +++ b/monte-carlo/r-of-rho-impulse-beam.py @@ -0,0 +1,111 @@ +# This is an example of python code using VTS to plot R(rho) using MCCL +# +# Import the Operating System so we can access the files for the VTS library +from pythonnet import load +load('coreclr') +import clr +import os +file = '../libraries/Vts.dll' +print('Does this filepath exist?', os.path.isfile(file)) +clr.AddReference(os.path.abspath(file)) + +print('Import numpy') +import numpy as np +print('Import pyplot') +import matplotlib.pyplot as plt +print('Import Vts') +from Vts import * +from Vts.Common import * +from Vts.Extensions import * +from Vts.Modeling.Optimizers import * +from Vts.Modeling.ForwardSolvers import * +from Vts.SpectralMapping import * +from Vts.Factories import * +from Vts.MonteCarlo import * +from Vts.MonteCarlo.Sources import * +from Vts.MonteCarlo.Tissues import * +from Vts.MonteCarlo.Detectors import * +from Vts.MonteCarlo.Factories import * +from Vts.MonteCarlo.PhotonData import * +from Vts.MonteCarlo.PostProcessing import * +print('Import System') +from System import Array, Double + +# SimulationInput defines the simulation. I think the default is collimated point source illumination normal to the surface. +simulationInput = SimulationInput() +simulationInput.N = 10000 + +# We add four detectors. One to monitor the reflected excitance as a function of radius, and three to monitor the overall reflection and transmission. +# add detectors to Simulation object +detectors = Array.CreateInstance(IDetectorInput, 4) + +detectors[0] = ROfRhoDetectorInput() +detectors[0].Rho = DoubleRange(start=0, stop=5, number=401) +detectors[1] = RDiffuseDetectorInput() +detectors[2] = RSpecularDetectorInput() +detectors[3] = TDiffuseDetectorInput() + +simulationInput.DetectorInputs = detectors + +# This is an index matched sample that has scattering of 0.99/mm and absorption of 0.01/mm. It is 10mm thick. +d = 10 # mm +mua = 0.01 # mm⁻¹ +musp = 0.99 # mm⁻¹ +g = 0 # scattering anisotropy +n = 1 # matched index of refraction + +regions = Array.CreateInstance(ITissueRegion, 3) + +regions[0] = LayerTissueRegion(zRange=DoubleRange(Double.NegativeInfinity, 0.0), op=OpticalProperties(mua=0.0, musp=1E-10, g=1.0, n=1.0)) +regions[1] = LayerTissueRegion(zRange=DoubleRange(0.0, d), op=OpticalProperties(mua=mua, musp=musp, g=g, n=n)) +regions[2] = LayerTissueRegion(zRange=DoubleRange(d, Double.PositiveInfinity), op=OpticalProperties(0.0, 1E-10, 1.0, 1.0)) + +simulationInput.TissueInput = MultiLayerTissueInput(regions) + +# create the simulation +simulation = MonteCarloSimulation(simulationInput) + +# run the simulation +simulationOutput = simulation.Run() + +# extract the data +rDiffuse = Array.CreateInstance(RDiffuseDetector, 1) +rDiffuse[0] = simulationOutput.ResultsDictionary["RDiffuse"] + +tDiffuse = Array.CreateInstance(TDiffuseDetector, 1) +tDiffuse[0] = simulationOutput.ResultsDictionary["TDiffuse"] + +rSpecular = Array.CreateInstance(RSpecularDetector, 1) +rSpecular[0] = simulationOutput.ResultsDictionary["RSpecular"] + +print("specular R = %.5f" % rSpecular[0].Mean) +print(" diffuse R = %.5f" % rDiffuse[0].Mean) +print(" diffuse T = %.5f" % tDiffuse[0].Mean) + +# plot the results using Pyplot +detectorResults = Array.CreateInstance(ROfRhoDetector, 1) +detectorResults[0] = simulationOutput.ResultsDictionary["ROfRho"] + +reflectance = np.array([r for r in detectorResults[0].Mean]) +edges = np.array([mp for mp in detectorResults[0].Rho])[:-1] + +plt.figure(figsize=(8,4.5)) +plt.plot(edges, reflectance, 'ob', markersize=2) +plt.plot(-edges, reflectance, 'ob', markersize=2) +plt.xlabel('ρ [mm]') +plt.ylabel('R(ρ) [W/mm²]') +plt.title('1 W Impulse Beam') + +text_args = { + 'ha': 'left', # Horizontal alignment + 'va': 'top', # Vertical alignment + 'transform': plt.gca().transAxes, # Coordinate system transformation + 'fontsize': 9 # Font size +} + +plt.text(0.8, 0.95, 'n=%.3f' % n, **text_args) +plt.text(0.8, 0.90, r'$\mu_a$=%.2f mm⁻¹' % mua, **text_args) +plt.text(0.8, 0.85, r"${\mu_s}'$=%.2f mm⁻¹" % musp, **text_args) +plt.text(0.8, 0.80, 'g=%.2f' % g, **text_args) +plt.text(0.8, 0.75, 'd=%.1f mm' % d, **text_args) +plt.show() \ No newline at end of file diff --git a/monte-carlo/r-of-rho.py b/monte-carlo/r-of-rho.py new file mode 100644 index 0000000..17e4165 --- /dev/null +++ b/monte-carlo/r-of-rho.py @@ -0,0 +1,65 @@ +# This is an example of python code using VTS to plot R(rho) using MCCL +# +# Import the Operating System so we can access the files for the VTS library +from pythonnet import load +load('coreclr') +import clr +import os +file = '../libraries/Vts.dll' +print('Does this filepath exist?', os.path.isfile(file)) +clr.AddReference(os.path.abspath(file)) + +print('Import numpy') +import numpy as np +print('Import plotly.graph') +import plotly.graph_objects as go +print('Import Vts') +from Vts import * +from Vts.Common import * +from Vts.Extensions import * +from Vts.Modeling.Optimizers import * +from Vts.Modeling.ForwardSolvers import * +from Vts.SpectralMapping import * +from Vts.Factories import * +from Vts.MonteCarlo import * +from Vts.MonteCarlo.Sources import * +from Vts.MonteCarlo.Tissues import * +from Vts.MonteCarlo.Detectors import * +from Vts.MonteCarlo.Factories import * +from Vts.MonteCarlo.PhotonData import * +from Vts.MonteCarlo.PostProcessing import * +print('Import System') +from System import Array +# Setup the values for the simulations and plot results +# create a SimulationInput object to define the simulation +detectorRange = DoubleRange(start=0, stop=40, number=201) +detectorInput = ROfRhoDetectorInput() +detectorInput.Rho = detectorRange +detectorInput.Name = "ROfRho" +detectors = Array.CreateInstance(IDetectorInput,1) +detectors[0] = detectorInput + +simulationInput = SimulationInput() +simulationInput.N = 1000 +simulationInput.DetectorInputs = detectors + +# create the simulation +simulation = MonteCarloSimulation(simulationInput) + +# run the simulation +simulationOutput = simulation.Run() + +# plot the results using Plotly +detectorResults = Array.CreateInstance(ROfRhoDetector,1) +detectorResults[0] = simulationOutput.ResultsDictionary["ROfRho"] +logReflectance = [r for r in detectorResults[0].Mean] +detectorMidpoints = [mp for mp in detectorRange] + +xLabel = "ρ [mm]" +yLabel = "log(R(ρ)) [mm-2]" + +chart = go.Figure() +chart.add_trace(go.Scatter(x=detectorMidpoints, y=logReflectance, mode='markers')) +chart.update_layout( title="log(R(ρ)) [mm-2]", xaxis_title=xLabel, yaxis_title=yLabel) +chart.update_yaxes(type="log") +chart.show(renderer="browser") \ No newline at end of file diff --git a/scripting/monte_carlo/demo_01_r_of_rho_simple.ipynb b/monte-carlo/r_of_rho.ipynb similarity index 97% rename from scripting/monte_carlo/demo_01_r_of_rho_simple.ipynb rename to monte-carlo/r_of_rho.ipynb index 5c767bc..6590b49 100644 --- a/scripting/monte_carlo/demo_01_r_of_rho_simple.ipynb +++ b/monte-carlo/r_of_rho.ipynb @@ -25,7 +25,7 @@ "#Import the Operating System so we can access the files for the VTS library\n", "import os\n", "current_directory = os.getcwd()\n", - "library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n", + "library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n", "vts_path = os.path.join(library_directory, \"Vts.dll\")" ] }, @@ -66,7 +66,6 @@ "clr.AddReference(vts_path)\n", "import numpy as np\n", "import plotly.graph_objects as go\n", - "import plotly.express as px\n", "from Vts import *\n", "from Vts.Common import *\n", "from Vts.Extensions import *\n", diff --git a/scripting/monte_carlo/vts-trial.ipynb b/monte-carlo/r_of_rho_impulse_beam.ipynb similarity index 98% rename from scripting/monte_carlo/vts-trial.ipynb rename to monte-carlo/r_of_rho_impulse_beam.ipynb index 19f8afe..d2987b1 100644 --- a/scripting/monte_carlo/vts-trial.ipynb +++ b/monte-carlo/r_of_rho_impulse_beam.ipynb @@ -37,7 +37,7 @@ "#Import the Operating System so we can get the file path for the Vts library\n", "import os\n", "current_directory = os.getcwd()\n", - "library_directory = current_directory.replace(\"monte_carlo\", \"libraries\")\n", + "library_directory = current_directory.replace(\"monte-carlo\", \"libraries\")\n", "vts_path = os.path.join(library_directory, \"Vts.dll\")\n", "clr.AddReference(vts_path)" ] @@ -260,7 +260,7 @@ "source": [ "Which should produce \n", "\n", - "" + "" ] } ], diff --git a/scripting/monte_carlo/vis-trial.svg b/monte-carlo/r_of_rho_impulse_beam.svg similarity index 100% rename from scripting/monte_carlo/vis-trial.svg rename to monte-carlo/r_of_rho_impulse_beam.svg diff --git a/scripting/runtimeconfig.json b/runtimeconfig.json similarity index 100% rename from scripting/runtimeconfig.json rename to runtimeconfig.json diff --git a/scripting/monte_carlo/example.svg b/scripting/monte_carlo/example.svg deleted file mode 100644 index 6e85a2e..0000000 --- a/scripting/monte_carlo/example.svg +++ /dev/null @@ -1,1523 +0,0 @@ - - - - - - - - 2024-04-17T17:18:46.804126 - image/svg+xml - - - Matplotlib v3.8.3, https://matplotlib.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -