Skip to content

Commit c2e79e6

Browse files
author
Lisa Malenfant
committed
Added a DAW vs CAW plot and inline documentation
1 parent c20c0c3 commit c2e79e6

File tree

1 file changed

+104
-1
lines changed

1 file changed

+104
-1
lines changed

scripting/monte_carlo/demo_01_r_of_rho_simple.ipynb

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"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+
},
312
{
413
"cell_type": "code",
514
"execution_count": null,
@@ -11,6 +20,13 @@
1120
"publish_local = current_directory.replace(\"monte_carlo\", \"libraries\\Vts.dll\")"
1221
]
1322
},
23+
{
24+
"cell_type": "markdown",
25+
"metadata": {},
26+
"source": [
27+
"Use pip to install PythonNet Plotly and Numpy"
28+
]
29+
},
1430
{
1531
"cell_type": "code",
1632
"execution_count": null,
@@ -20,6 +36,15 @@
2036
"pip install pythonnet plotly numpy"
2137
]
2238
},
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+
},
2348
{
2449
"cell_type": "code",
2550
"execution_count": null,
@@ -50,6 +75,15 @@
5075
"from System import Array"
5176
]
5277
},
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+
},
5387
{
5488
"cell_type": "code",
5589
"execution_count": null,
@@ -84,12 +118,81 @@
84118
"yLabel = \"log(R(ρ)) [mm-2]\"\n",
85119
"\n",
86120
"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",
88122
"chart.update_layout( title=\"log(R(ρ)) [mm-2]\", xaxis_title=xLabel, yaxis_title=yLabel)\n",
89123
"chart.update_yaxes(type=\"log\")\n",
90124
"chart.show()\n"
91125
]
92126
},
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+
},
93196
{
94197
"cell_type": "code",
95198
"execution_count": null,

0 commit comments

Comments
 (0)