|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import os\n", |
| 10 | + "current_directory = os.getcwd()\n", |
| 11 | + "publish_local = current_directory.replace(\"monte_carlo\", \"libraries\\Vts.dll\")" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "pip install pythonnet plotly numpy" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": null, |
| 26 | + "metadata": {}, |
| 27 | + "outputs": [], |
| 28 | + "source": [ |
| 29 | + "from pythonnet import set_runtime\n", |
| 30 | + "set_runtime(\"coreclr\")\n", |
| 31 | + "import clr\n", |
| 32 | + "clr.AddReference(publish_local) # Copy the VTS dlls into the libraries folders\n", |
| 33 | + "import numpy as np\n", |
| 34 | + "import plotly.graph_objects as go\n", |
| 35 | + "from Vts import *\n", |
| 36 | + "from Vts.Common import *\n", |
| 37 | + "from Vts.Extensions import *\n", |
| 38 | + "from Vts.Modeling.Optimizers import *\n", |
| 39 | + "from Vts.Modeling.ForwardSolvers import *\n", |
| 40 | + "from Vts.SpectralMapping import *\n", |
| 41 | + "from Vts.Factories import *\n", |
| 42 | + "from Vts.MonteCarlo import *\n", |
| 43 | + "from Vts.MonteCarlo.Sources import *\n", |
| 44 | + "from Vts.MonteCarlo.Tissues import *\n", |
| 45 | + "from Vts.MonteCarlo.Detectors import *\n", |
| 46 | + "from Vts.MonteCarlo.Factories import *\n", |
| 47 | + "from Vts.MonteCarlo.PhotonData import *\n", |
| 48 | + "from Vts.MonteCarlo.PostProcessing import *\n", |
| 49 | + "from System import Array" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "# create a SimulationInput object to define the simulation\n", |
| 59 | + "detectorRange = DoubleRange(start=0, stop=40, number=201)\n", |
| 60 | + "detectorInput = ROfRhoDetectorInput()\n", |
| 61 | + "detectorInput.Rho = detectorRange\n", |
| 62 | + "detectorInput.Name = \"ROfRho\"\n", |
| 63 | + "detectors = Array.CreateInstance(IDetectorInput,1)\n", |
| 64 | + "detectors[0] = detectorInput\n", |
| 65 | + "\n", |
| 66 | + "simulationInput = SimulationInput()\n", |
| 67 | + "simulationInput.N=1000\n", |
| 68 | + "simulationInput.DetectorInputs= detectors\n", |
| 69 | + "\n", |
| 70 | + "# create the simulation\n", |
| 71 | + "simulation = MonteCarloSimulation(simulationInput)\n", |
| 72 | + "\n", |
| 73 | + "# run the simulation\n", |
| 74 | + "simulationOutput = simulation.Run()\n", |
| 75 | + "\n", |
| 76 | + "# plot the results using Plotly\n", |
| 77 | + "detectorResults = Array.CreateInstance(ROfRhoDetector,1)\n", |
| 78 | + "detectorResults[0] = simulationOutput.ResultsDictionary[\"ROfRho\"]\n", |
| 79 | + "logReflectance = [np.log(r) for r in detectorResults[0].Mean]\n", |
| 80 | + "detectorMidpoints = [mp for mp in detectorRange.AsEnumerable()]\n", |
| 81 | + "\n", |
| 82 | + "xLabel = \"ρ [mm]\"\n", |
| 83 | + "yLabel = \"log(R(ρ)) [mm-2]\"\n", |
| 84 | + "\n", |
| 85 | + "chart = go.Figure()\n", |
| 86 | + "chart.add_trace(go.Scatter(x=detectorMidpoints, y=logReflectance, mode='lines+markers'))\n", |
| 87 | + "chart.update_layout( title=\"log(R(ρ)) [mm-2]\", xaxis_title=xLabel, yaxis_title=yLabel)\n", |
| 88 | + "chart.show()\n" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "execution_count": null, |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [] |
| 97 | + } |
| 98 | + ], |
| 99 | + "metadata": { |
| 100 | + "kernelspec": { |
| 101 | + "display_name": "Python 3 (ipykernel)", |
| 102 | + "language": "python", |
| 103 | + "name": "python3" |
| 104 | + }, |
| 105 | + "language_info": { |
| 106 | + "codemirror_mode": { |
| 107 | + "name": "ipython", |
| 108 | + "version": 3 |
| 109 | + }, |
| 110 | + "file_extension": ".py", |
| 111 | + "mimetype": "text/x-python", |
| 112 | + "name": "python", |
| 113 | + "nbconvert_exporter": "python", |
| 114 | + "pygments_lexer": "ipython3", |
| 115 | + "version": "3.11.5" |
| 116 | + } |
| 117 | + }, |
| 118 | + "nbformat": 4, |
| 119 | + "nbformat_minor": 2 |
| 120 | +} |
0 commit comments