Skip to content

Commit

Permalink
Merge pull request #86 from VirtualPhotonics/72-net-polyglot-notebook…
Browse files Browse the repository at this point in the history
…-and-jupyter-notebook-documentation-and-samples

72 Implement and test script-style use of the VTS
  • Loading branch information
dcuccia authored Aug 22, 2023
2 parents f2a7696 + ed11891 commit f96eec1
Show file tree
Hide file tree
Showing 52 changed files with 3,493 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "src/Vts.sln"
}
7 changes: 4 additions & 3 deletions matlab/vts_wrapper/short_course_monte_carlo_lab.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
startup();

% ======================================================================= %
%% Example 1a: run Monte Carlo simulations for fluence with increasing N photons
%% Example 01a: run Monte Carlo simulations for fluence with increasing N photons
clear;
Nphot=[10, 100, 1000, 10000]; % number of photons launched takes about 1 mins

Expand Down Expand Up @@ -129,7 +129,8 @@
save(sprintf('dawSD%d.txt',j),'-ascii','SD');
end
end
%% Example 1b: Compare standard deviation of two absorption methods

%% Example 01b: Compare standard deviation of two absorption methods
% this cell relies on above cell execution
f=figure('Position',[scrsz(3)/5 scrsz(4)/5 scrsz(3)/2 scrsz(4)/2]);
set(f,'Name','Analog relative error - DAW relative error');
Expand All @@ -156,7 +157,7 @@
end

% ======================================================================= %
%% Example 2: run Monte Carlo simulations accounting for absorption with
%% Example 02: run Monte Carlo simulations accounting for absorption with
% analog and continuous absorption weighting with 10,000 photons and compare
% time and relative error

Expand Down
20 changes: 11 additions & 9 deletions matlab/vts_wrapper/vts_mc_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
startup();

% ======================================================================= %
%% Example 1: run a simple Monte Carlo simulation with 1000 photons
%% Example 01: run a simple Monte Carlo simulation with 1000 photons

% create a default set of inputs
si = SimulationInput();
Expand All @@ -29,7 +29,7 @@
set(f,'Name','Reflectance vs Rho for N=1000');

% ======================================================================= %
%% Example 2: run Monte Carlo simulations for two absorption weighting types
%% Example 02: run Monte Carlo simulations for two absorption weighting types
% with 1000 photons each and compare computation time

% create a default set of inputs
Expand All @@ -49,7 +49,7 @@
output2 = VtsMonteCarlo.RunSimulation(si);

% ======================================================================= %
%% Example 3: run a Monte Carlo simulation with a fully-customized input
%% Example 03: run a Monte Carlo simulation with a fully-customized input
% (values used here are the class defaults)

% 1) define a source...
Expand Down Expand Up @@ -128,7 +128,7 @@
output = VtsMonteCarlo.RunSimulation(input);

% ======================================================================= %
%% Example 4: run a list of Monte Carlo simulations
%% Example 04: run a list of Monte Carlo simulations
% create a list of two default SimulationInput with different numbers of
% photons

Expand Down Expand Up @@ -156,7 +156,7 @@
set(f,'Name','Simulation 2 results');

% ======================================================================= %
% Example 5: run a Monte Carlo simulation with post-processing enabled
% Example 05: run a Monte Carlo simulation with post-processing enabled
% First run a simulation, then post-process the generated database and
% compare on-the-fly results with post-processed results
si = SimulationInput();
Expand Down Expand Up @@ -187,7 +187,7 @@
legend('on-the-fly','post-processed');

% ======================================================================= %
% Example 6: run a Monte Carlo simulation with pMC post-processing enabled
% Example 06: run a Monte Carlo simulation with pMC post-processing enabled
% First run a simulation, then post-process the generated database CA
% varying optical properties
si = SimulationInput();
Expand Down Expand Up @@ -260,7 +260,7 @@
set(f,'Name','Perturbation MC using CAW');

% ======================================================================= %
% Example 7: run a Monte Carlo simulation with pMC post-processing enabled
% Example 07: run a Monte Carlo simulation with pMC post-processing enabled
% Use generated database to solve inverse problem with measured data
% generated using Nurbs
% NOTE: convergence to measured data optical properties affected by:
Expand Down Expand Up @@ -375,7 +375,7 @@
abs(measMus-recoveredOPs(2))/measOPs(2)));

% ======================================================================= %
% Example 8: run a Monte Carlo simulation and verify results with
% Example 08: run a Monte Carlo simulation and verify results with
% those in unit tests in Visual Studio
% spell out all input to ensure same settings as in unit test
si = SimulationInput();
Expand Down Expand Up @@ -422,8 +422,9 @@
(abs(d3.Mean(1,1)-95.492965855)<0.000000001))
disp('unit tests pass');
end

% ======================================================================= %
%% Example 9: run a Monte Carlo simulation for transmittance tallies with 1000 photons
%% Example 09: run a Monte Carlo simulation for transmittance tallies with 1000 photons

% create a default set of inputs
si = SimulationInput();
Expand Down Expand Up @@ -463,6 +464,7 @@
f = figure; plot(d2.Fx, abs(d2.Mean)); ylabel('T(fx) [unitless]'); xlabel('Fx (mm^-^1)');
title('Transmittance vs fx for N=1000');
set(f,'Name','Transmittance vs Fx for N=1000');

% ======================================================================= %
%% Example 10: run R(fx) detector results

Expand Down
63 changes: 33 additions & 30 deletions matlab/vts_wrapper/vts_solver_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

startup();

%% Example ROfRhoAndFt
%% Example 01: ROfRhoAndFt
% Evaluate reflectance as a function of rho and temporal-frequency with one
% set of optical properites.

Expand Down Expand Up @@ -41,7 +41,7 @@
xlabel('f_t');
set(f,'Name','Reflectance as a function of Rho and Temporal-frequency');

%% Example ROfFxAndFt
%% Example 02: ROfFxAndFt
% Evaluate reflectance as a function of spatial- and temporal- frequencies
% with one set of optical properites.

Expand All @@ -68,7 +68,7 @@
xlabel('f_t');
set(f,'Name','Reflectance as a function of Spatial- and Temporal- frequencies');

%% Example FluenceOfRhoAndZ
%% Example 03: FluenceOfRhoAndZ
% Evaluate fluence as a function of rho and z using optical properties from
% a list of chromophore absorbers with their concentrations and a power law
% scatterer for a range of wavelengths.
Expand Down Expand Up @@ -105,11 +105,11 @@
f = figure; imagesc(wv,zs,log(squeeze(test(:,1,:))));
ylabel('z [mm]');
xlabel('wavelength, \lambda [nm]');
title('Fluence of \lambda and z and \rho=0.1 mm');
set(f,'Name','Fluence as a function of Rho and z');
title('Fluence of \lambda and z at \rho=0.1 mm');
set(f,'Name','Fluence as a function of lambda and z');


%% Example FluenceOfRhoAndZAndFt
%% Example 04: FluenceOfRhoAndZAndFt
% Evaluate fluence as a function of rho and z using one set of optical
% properties and a distributed gaussian source SDA solver type.

Expand Down Expand Up @@ -148,7 +148,7 @@
ylabel('z [mm]')
set(f,'Name','Modulation of fluence (AC/DC) of Rho and z and ft (ft=1GHz)');

%% Example PHDOfRhoAndZ
%% Example 05: PHDOfRhoAndZ
% Evaluate Photon Hitting Density in cylindrical coordinates
% using one set of optical properties and a distributed gaussian source SDA
% solver type.
Expand All @@ -167,7 +167,7 @@
ylabel('z [mm]')
set(f,'Name','PHD of Rho and z');

%% Example FluenceOfRhoAndZTwoLayer
%% Example 06: FluenceOfRhoAndZTwoLayer
% Evaluate fluence in cylindrical coordinates for a two
% layer tissue with specified source-detector separation and top layer thickness
% using two sets of optical properties.
Expand All @@ -185,7 +185,7 @@
ylabel('z [mm]');
set(f,'Name','Fluence of Rho and z - Two Layer');

%% Example PHDOfRhoAndZTwoLayer
%% Example 07: PHDOfRhoAndZTwoLayer
% Evaluate Photon Hitting Density in cylindrical coordinates for a two
% layer tissue with specified source-detector separation and top layer thickness
% using two sets of optical properties.
Expand All @@ -204,7 +204,7 @@
ylabel('z [mm]');
set(f,'Name','PHD of Rho and z - Two Layer');

%% Example AbsorbedEnergyOfRhoAndZ
%% Example 08: AbsorbedEnergyOfRhoAndZ
% Evaluate Absorbed Energy of rho and z using one set of optical properties
% and a point source SDA solver type.

Expand All @@ -225,7 +225,7 @@
ylabel('z [mm]');
set(f,'Name','Absorbed Energy of Rho and z');

%% Example ROfRho
%% Example 09: ROfRho
% Evaluate reflectance as a function of rho with three sets
% of optical properites.

Expand All @@ -242,7 +242,7 @@
ylabel('R(\rho)');
xlabel('\rho');

%% Example ROfRhoAndT
%% Example 10: ROfRhoAndTime
% Evaluate reflectance of rho and t at one s-d separation and
% two sets of optical properites.

Expand All @@ -259,7 +259,7 @@
ylabel('R(t)');
xlabel('Time, t [ns]');

%% Example ROfFxAndT
%% Example 11: ROfFxAndTime
% Evaluate reflectance as a function of spacial-frequency and t using one
% set of optical properites.

Expand Down Expand Up @@ -291,7 +291,7 @@
end
legend(l2, 'FontSize', 12);

%% Example ROfFx (single set of optical properties)
%% Example 12: ROfFx (single set of optical properties)
% Evaluate reflectance as a function of spacial-frequency with a single set
% of optical properties.

Expand All @@ -304,7 +304,7 @@
ylabel('R(f_x)');
xlabel('Spatial frequency, f_x [mm^-^1]');

%% Example ROfFx (multiple sets of optical properties)
%% Example 13: ROfFx (multiple sets of optical properties)
% Evaluate reflectance as a function of spacial-frequency
% with multiple sets of optical properties, varying mua linearly.

Expand All @@ -323,8 +323,7 @@
ylabel('R(f_x)');
xlabel('Spatial frequency, f_x [mm^-^1]');


%% Example ROfFx (multiple optical properties, varying mua as a function of wavelength, mus' as intralipid scatterer)
%% Example 14: ROfFx (multiple optical properties, varying mua as a function of wavelength, mus' as intralipid scatterer)
% Evaluate reflectance as a function of spacial-frequency with multiple
% sets of optical properties, varying mua as a function of wavelength.

Expand All @@ -343,14 +342,14 @@

% % or
scatterer.Type = 'Intralipid';
scatterer.vol_frac = 0.5;
scatterer.vol_frac = 0.01;

% % or
% scatterer.Type = 'Mie';
% scatterer.radius = 0.5;
% scatterer.n = 1.4;
% scatterer.nMedium = 1.0;
% scatterer.vol_frac = 0.5;
% scatterer.vol_frac = 0.001;

op = VtsSpectroscopy.GetOP(absorbers, scatterer, wv);

Expand Down Expand Up @@ -384,7 +383,8 @@
xlabel('Wavelength, \lambda [nm]');
options = [{'Location', 'NorthWest'}; {'FontSize', 12}; {'Box', 'on'}];
PlotHelper.CreateLegend(fx, 'f_x = ', 'mm^-^1', options);
%% Example ROfFx (multiple optical properties, varying mua as a function of wavelength, mus' as mie scatterer)

%% Example 15: ROfFx (multiple optical properties, varying mua as a function of wavelength, mus' as mie scatterer)
% Evaluate reflectance as a function of spacial-frequency with multiple
% sets of optical properties, varying mua as a function of wavelength.

Expand All @@ -403,14 +403,14 @@

% % or
% scatterer.Type = 'Intralipid';
% scatterer.vol_frac = 0.5;
% scatterer.vol_frac = 0.01;

% % or
scatterer.Type = 'Mie';
scatterer.radius = 0.5;
scatterer.n = 1.4;
scatterer.nMedium = 1.0;
scatterer.vol_frac = 0.5;
scatterer.vol_frac = 0.001;

op = VtsSpectroscopy.GetOP(absorbers, scatterer, wv);

Expand Down Expand Up @@ -445,7 +445,7 @@
options = [{'Location', 'NorthWest'}; {'FontSize', 12}; {'Box', 'on'}];
PlotHelper.CreateLegend(fx, 'f_x = ', 'mm^-^1', options);

%% Example ROfFx
%% Example 16: ROfFx
% Call planar reflectance with multiple sets of optical
% properties, varying the scattering prefactor as a function of wavelength.

Expand Down Expand Up @@ -478,7 +478,7 @@
options = [{'Location', 'NorthWest'}; {'FontSize', 12}; {'Box', 'on'}];
PlotHelper.CreateLegend(A, '\mu_s''(1000nm) = ', 'mm^-^1', options);

%% Example ROfRho (multiple wavelengths, multiple rho)
%% Example 17: ROfRho (multiple wavelengths, multiple rho)
% Call reflectance varying the wavelength.

VtsSolvers.SetSolverType('PointSourceSDA');
Expand Down Expand Up @@ -508,7 +508,7 @@
xlabel('Wavelength, \lambda [nm]');
options = [{'Location', 'NorthEast'}; {'FontSize', 12}; {'Box', 'on'}];
PlotHelper.CreateLegend(rho,'\rho = ', 'mm',options);
%% Example ROfRho (inverse solution for chromophore concentrations for multiple wavelengths, single rho)
%% Example 18: ROfRho (inverse solution for chromophore concentrations for multiple wavelengths, single rho)

rho = 1; % source-detector separation in mm
wv = 400:50:1000;
Expand Down Expand Up @@ -571,7 +571,8 @@
(measData-recovered)*(measData-recovered)'));
disp(sprintf('error = [%5.3f %5.3f %5.3f]',abs(measData(1)-recovered(1))/measData(1),...
abs(measData(2)-recovered(2))/measData(2),abs(measData(3)-recovered(3))/measData(3)));
%% Example ROfRho for a two-layer tissue (multiple optical properties and rhos)

%% Example 19: ROfRho for a two-layer tissue (multiple optical properties and rhos)
clear op
topLayerThickness = 2; % units: mm

Expand All @@ -592,7 +593,8 @@
title('2-Layer Reflectance vs \rho for various top Layer OPs');
ylabel('R(\rho)');
xlabel('\rho');
%% Example ROfFx for a two-layer tissue (multiple optical properties and fxs)

%% Example 20: ROfFx for a two-layer tissue (multiple optical properties and fxs)
clear op
topLayerThickness = 2; % units: mm

Expand All @@ -605,15 +607,16 @@

fx = 0:0.01:0.5; % range of spatial frequencies in 1/mm
test = VtsSolvers.ROfFxTwoLayer(op, topLayerThickness, fx);
f = figure; semilogy(fx, test);
f = figure; plot(fx, test);
set(f,'Name','2-Layer Reflectance vs Fx for various top Layer Optical Properties');
% create the legend with just the mua value from the top layer optical properties
options = [{'FontSize', 12}; {'Location', 'NorthEast'}];
PlotHelper.CreateLegend(op(:,1), 'top \mu_a: ', 'mm^-^1', options);
title('2-Layer Reflectance vs fx for various top Layer OPs');
ylabel('R(fx)');
xlabel('fx');
%% Example ROfRhoAndTime for a two-layer tissue (multiple optical properties and times)

%% Example 21: ROfRhoAndTime for a two-layer tissue (multiple optical properties and times)
clear op
topLayerThickness = 2; % units: mm
%
Expand Down Expand Up @@ -662,7 +665,7 @@
ylabel('R(t)');
xlabel('Time, t [ns]');

%% Example ROfRhoAndFt for a two-layer tissue (multiple optical properties and fts)
%% Example 22: ROfRhoAndFt for a two-layer tissue (multiple optical properties and fts)
% Evaluate reflectance as a function of rho and temporal-frequency with one
% set of optical properites.
clear op
Expand Down
1 change: 1 addition & 0 deletions src/Vts.Scripting.Test/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
Loading

0 comments on commit f96eec1

Please sign in to comment.