|
1 | 1 | {
|
2 | 2 | "cells": [
|
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "Import the Operating System so we can access the files for the VTS library\n", |
| 8 | + "\n", |
| 9 | + "Before we can run the Python code we need to download the latest zip file from the downloads and put the dll files into the libraries folder." |
| 10 | + ] |
| 11 | + }, |
3 | 12 | {
|
4 | 13 | "cell_type": "code",
|
5 | 14 | "execution_count": null,
|
|
11 | 20 | "publish_local = current_directory.replace(\"monte_carlo\", \"libraries\\Vts.dll\")"
|
12 | 21 | ]
|
13 | 22 | },
|
| 23 | + { |
| 24 | + "cell_type": "markdown", |
| 25 | + "metadata": {}, |
| 26 | + "source": [ |
| 27 | + "Use pip to install PythonNet Plotly and Numpy" |
| 28 | + ] |
| 29 | + }, |
14 | 30 | {
|
15 | 31 | "cell_type": "code",
|
16 | 32 | "execution_count": null,
|
|
20 | 36 | "pip install pythonnet plotly numpy"
|
21 | 37 | ]
|
22 | 38 | },
|
| 39 | + { |
| 40 | + "cell_type": "markdown", |
| 41 | + "metadata": {}, |
| 42 | + "source": [ |
| 43 | + "Import the Core CLR runtime from PythonNet and add the reference for the VTS library and its dependencies\n", |
| 44 | + "\n", |
| 45 | + "Import the namespaces from the Python libraries and the VTS library" |
| 46 | + ] |
| 47 | + }, |
23 | 48 | {
|
24 | 49 | "cell_type": "code",
|
25 | 50 | "execution_count": null,
|
|
50 | 75 | "from System import Array"
|
51 | 76 | ]
|
52 | 77 | },
|
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "metadata": {}, |
| 81 | + "source": [ |
| 82 | + "Setup the values for the simulations and plot the results using Plotly\n", |
| 83 | + "\n", |
| 84 | + "ROfRho" |
| 85 | + ] |
| 86 | + }, |
53 | 87 | {
|
54 | 88 | "cell_type": "code",
|
55 | 89 | "execution_count": null,
|
|
84 | 118 | "yLabel = \"log(R(ρ)) [mm-2]\"\n",
|
85 | 119 | "\n",
|
86 | 120 | "chart = go.Figure()\n",
|
87 |
| - "chart.add_trace(go.Scatter(x=detectorMidpoints, y=logReflectance, mode='lines+markers'))\n", |
| 121 | + "chart.add_trace(go.Scatter(x=detectorMidpoints, y=logReflectance, mode='markers'))\n", |
88 | 122 | "chart.update_layout( title=\"log(R(ρ)) [mm-2]\", xaxis_title=xLabel, yaxis_title=yLabel)\n",
|
89 | 123 | "chart.update_yaxes(type=\"log\")\n",
|
90 | 124 | "chart.show()\n"
|
91 | 125 | ]
|
92 | 126 | },
|
| 127 | + { |
| 128 | + "cell_type": "markdown", |
| 129 | + "metadata": {}, |
| 130 | + "source": [ |
| 131 | + "DAW vs CAW" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": null, |
| 137 | + "metadata": {}, |
| 138 | + "outputs": [], |
| 139 | + "source": [ |
| 140 | + "# Setup the detector input for the simulation\n", |
| 141 | + "detectorRange = DoubleRange(start=0, stop=40, number=201)\n", |
| 142 | + "detectorInput = ROfRhoDetectorInput()\n", |
| 143 | + "detectorInput.Rho = detectorRange\n", |
| 144 | + "detectorInput.Name = \"ROfRho\"\n", |
| 145 | + "detectors = Array.CreateInstance(IDetectorInput,1)\n", |
| 146 | + "detectors[0] = detectorInput\n", |
| 147 | + "\n", |
| 148 | + "simulationOptions1 = SimulationOptions()\n", |
| 149 | + "simulationOptions1.AbsorptionWeightingType = AbsorptionWeightingType.Discrete\n", |
| 150 | + "# create a SimulationInput object to define the simulation\n", |
| 151 | + "simulationInput1 = SimulationInput()\n", |
| 152 | + "simulationInput1.N=1000\n", |
| 153 | + "simulationInput1.OutputName = \"MonteCarloROfRho-DAW\"\n", |
| 154 | + "simulationInput1.DetectorInputs= detectors\n", |
| 155 | + "simulationInput1.Options = simulationOptions1\n", |
| 156 | + "\n", |
| 157 | + "simulationOptions2 = SimulationOptions()\n", |
| 158 | + "simulationOptions2.AbsorptionWeightingType = AbsorptionWeightingType.Continuous\n", |
| 159 | + "# create a SimulationInput object to define the simulation\n", |
| 160 | + "simulationInput2 = SimulationInput()\n", |
| 161 | + "simulationInput2.N=1000\n", |
| 162 | + "simulationInput2.OutputName = \"MonteCarloROfRho-CAW\"\n", |
| 163 | + "simulationInput2.DetectorInputs = detectors\n", |
| 164 | + "simulationInput2.Options = simulationOptions2\n", |
| 165 | + "\n", |
| 166 | + "# create the simulations\n", |
| 167 | + "simulation1 = MonteCarloSimulation(simulationInput1)\n", |
| 168 | + "simulation2 = MonteCarloSimulation(simulationInput2)\n", |
| 169 | + "\n", |
| 170 | + "# run the simulations\n", |
| 171 | + "simulationOutput1 = simulation1.Run()\n", |
| 172 | + "simulationOutput2 = simulation2.Run()\n", |
| 173 | + "\n", |
| 174 | + "# plot the results using Plotly\n", |
| 175 | + "detectorResults1 = Array.CreateInstance(ROfRhoDetector,1)\n", |
| 176 | + "detectorResults1[0] = simulationOutput1.ResultsDictionary[\"ROfRho\"]\n", |
| 177 | + "logReflectance1 = [r for r in detectorResults1[0].Mean]\n", |
| 178 | + "detectorMidpoints1 = [mp for mp in detectorRange.AsEnumerable()]\n", |
| 179 | + "\n", |
| 180 | + "detectorResults2 = Array.CreateInstance(ROfRhoDetector,1)\n", |
| 181 | + "detectorResults2[0] = simulationOutput2.ResultsDictionary[\"ROfRho\"]\n", |
| 182 | + "logReflectance2 = [r for r in detectorResults[0].Mean]\n", |
| 183 | + "detectorMidpoints2 = [mp for mp in detectorRange.AsEnumerable()]\n", |
| 184 | + "\n", |
| 185 | + "xLabel = \"ρ [mm]\"\n", |
| 186 | + "yLabel = \"log(R(ρ)) [mm-2]\"\n", |
| 187 | + "\n", |
| 188 | + "chart = go.Figure()\n", |
| 189 | + "chart.add_trace(go.Scatter(x=detectorMidpoints1, y=logReflectance1, mode='markers', name='log(R(ρ)) [mm-2] - DAW'))\n", |
| 190 | + "chart.add_trace(go.Scatter(x=detectorMidpoints2, y=logReflectance2, mode='markers', name='log(R(ρ)) [mm-2] - CAW'))\n", |
| 191 | + "chart.update_layout( title=\"DAW vs CAW\", xaxis_title=xLabel, yaxis_title=yLabel)\n", |
| 192 | + "chart.update_yaxes(type=\"log\")\n", |
| 193 | + "chart.show()" |
| 194 | + ] |
| 195 | + }, |
93 | 196 | {
|
94 | 197 | "cell_type": "code",
|
95 | 198 | "execution_count": null,
|
|
0 commit comments