Skip to content

Commit

Permalink
Merge pull request #91 from VirtualPhotonics/90-rangeoft-enhancements…
Browse files Browse the repository at this point in the history
…-for-simplicity-to-consumers

Update to RangeOfT to implement IEnumerable<T> directly and simplify usage in the codebase
  • Loading branch information
dcuccia authored Aug 31, 2023
2 parents 55cc731 + 7a7b17e commit 308e706
Show file tree
Hide file tree
Showing 47 changed files with 84 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.01, musp: 1.2, g: 0.8, n: 1.4);
var rho = 10; // s-d separation, in mm
var fts = new DoubleRange(start: 0, stop: 0.5, number: 51).AsEnumerable().ToArray(); // range of temporal frequencies in GHz
var fts = new DoubleRange(start: 0, stop: 0.5, number: 51).ToArray(); // range of temporal frequencies in GHz

// predict the temporal frequency response at the specified optical properties and s-d separation
var rOfFt = solver.ROfRhoAndFt(op, rho, fts);
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo02ROfFxAndFtMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4);
var fxs = new DoubleRange(start: 0, stop: 0.1, number: 4).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var fts = new DoubleRange(start: 0, stop: 0.5, number: 51).AsEnumerable().ToArray(); // range of temporal frequencies in GHz
var fxs = new DoubleRange(start: 0, stop: 0.1, number: 4).ToArray(); // range of spatial frequencies in 1/mm
var fts = new DoubleRange(start: 0, stop: 0.5, number: 51).ToArray(); // range of temporal frequencies in GHz

// predict the temporal frequency response at each specified optical property and spatial frequency
var rOfFxAndFt = fxs.Select(fx => solver.ROfFxAndFt(op, fx, fts)).ToArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Vts.Scripting/ForwardSolvers/Demo03FluenceOfRhoAndZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var rhos = new DoubleRange(start: 0.1, stop: 10, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 10, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var rhos = new DoubleRange(start: 0.1, stop: 10, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 10, number: 100).ToArray(); // range of depths in mm

// retrieve desired optical properties, based on spectral data information

Expand All @@ -41,7 +41,7 @@ public static void RunDemo(bool showPlots = true)
var tissue = new Tissue(chromophores, scatterer, "", n: 1.4);

// predict the tissue's fluence(rho, z) for tissue optical properties spanning the visible and NIR spectral regimes
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).ToArray(); // range of wavelengths in nm
var op = tissue.GetOpticalProperties(wavelengths);
var fluenceOfRhoAndZ = solver.FluenceOfRhoAndZ(op, rhos, zs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4);
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var fts = new DoubleRange(start: 0, stop: 1, number: 2).AsEnumerable().ToArray(); // range of time frequencies in GHz
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of depths in mm
var fts = new DoubleRange(start: 0, stop: 1, number: 2).ToArray(); // range of time frequencies in GHz

// predict the tissue's fluence(rho, z, ft) for the given optical properties
var fluenceOfRhoAndZAndFt = solver.FluenceOfRhoAndZAndFt(new[]{ op }, rhos, zs, fts);
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo05PHDOfRhoAndZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4);
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of depths in mm

// predict the tissue's fluence(rho, z) for the given optical properties
var fluenceOfRhoAndZ = solver.FluenceOfRhoAndZ(new[]{ op }, rhos, zs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static void RunDemo(bool showPlots = true)
regionOP: new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4)
)
};
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of depths in mm

// predict the tissue's fluence(rho, z) for the given optical properties
var fluenceOfRhoAndZ = solver.FluenceOfRhoAndZ(new[] { opRegions }, rhos, zs );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static void RunDemo(bool showPlots = true)
regionOP: new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4)
)
};
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of depths in mm

// predict the tissue's fluence(rho, z) for the given optical properties
var fluenceOfRhoAndZ = solver.FluenceOfRhoAndZ(new[] { opRegions }, rhos, zs );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver { SourceConfiguration = SourceConfiguration.Distributed };
var op = new OpticalProperties(mua: 0.1, musp: 1, g: 0.8, n: 1.4);
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).AsEnumerable().ToArray(); // range of depths in mm
var rhos = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of s-d separations in mm
var zs = new DoubleRange(start: 0.1, stop: 19.9, number: 100).ToArray(); // range of depths in mm

// predict the tissue's AbsorbedEnergy(rho, z) for the given optical properties
var fluenceOfRhoAndZ = solver.FluenceOfRhoAndZ(new[] { op }, rhos, zs );
Expand Down
2 changes: 1 addition & 1 deletion src/Vts.Scripting/ForwardSolvers/Demo09ROfRhoMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void RunDemo(bool showPlots = true)
new OpticalProperties(mua: 0.1, musp: 1, g: 0.8, n: 1.4),
new OpticalProperties(mua: 1, musp: 1, g: 0.8, n: 1.4)
};
var rhos = new DoubleRange(start: 0.5, stop: 9.5, number: 19).AsEnumerable().ToArray(); // range of radial detector locations in mm
var rhos = new DoubleRange(start: 0.5, stop: 9.5, number: 19).ToArray(); // range of radial detector locations in mm

// predict the reflectance at each specified optical property and source-detector separation
var allROfRho = solver.ROfRho(ops, rhos).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void RunDemo(bool showPlots = true)
new OpticalProperties(mua: 0.2, musp: 1, g: 0.8, n: 1.4)
};
var rho = 10; // radial detector location in mm
var ts = new DoubleRange(start: 0, stop: 0.5, number: 501).AsEnumerable().ToArray(); // range of times in ns
var ts = new DoubleRange(start: 0, stop: 0.5, number: 501).ToArray(); // range of times in ns

// predict the reflectance at each specified optical property and source-detector separation
var allROfRho = solver.ROfRhoAndTime(ops, rho, ts).ToArray();
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo11ROfFxAndTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4);
var fxs = new DoubleRange(start: 0, stop: 0.5, number: 11).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var ts = new DoubleRange(start: 0, stop: 0.5, number: 501).AsEnumerable().ToArray(); // range of times in ns
var fxs = new DoubleRange(start: 0, stop: 0.5, number: 11).ToArray(); // range of spatial frequencies in 1/mm
var ts = new DoubleRange(start: 0, stop: 0.5, number: 501).ToArray(); // range of times in ns

// predict the temporal response at each specified optical property and spatial frequency
var rOfFxAndTime = solver.ROfFxAndTime(op, fxs, ts).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Vts.Scripting/ForwardSolvers/Demo12ROfFxSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void RunDemo(bool showPlots = true)
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var op = new OpticalProperties(mua: 0.1, musp: 1.2, g: 0.8, n: 1.4);
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 201).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 201).ToArray(); // range of spatial frequencies in 1/mm

// predict the spatial frequency response at each specified optical properties
var rOfFx = solver.ROfFx(op, fxs);
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo13ROfFxMultiOpProp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 201).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var muas = new DoubleRange(start: 0, stop: 0.1, number: 11).AsEnumerable().ToArray(); // range of absorption values in 1/mm
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 201).ToArray(); // range of spatial frequencies in 1/mm
var muas = new DoubleRange(start: 0, stop: 0.1, number: 11).ToArray(); // range of absorption values in 1/mm
var ops = muas.Select(mua => new OpticalProperties(mua: mua, musp: 1.2, g: 0.8, n: 1.4)).ToArray();

// predict the spatial frequency response at each specified optical properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 5).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 5).ToArray(); // range of spatial frequencies in 1/mm

// retrieve desired optical properties, based on spectral data information

Expand All @@ -39,7 +39,7 @@ public static void RunDemo(bool showPlots = true)
var tissue = new Tissue(chromophores, scatterer, "", n: 1.4);

// predict the tissue's optical properties spanning the visible and NIR spectral regimes
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).ToArray(); // range of wavelengths in nm
var ops = tissue.GetOpticalProperties(wavelengths);

// predict the spatial frequency response at each specified optical properties
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo15ROfFxMultiOpPropMie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 5).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var fxs = new DoubleRange(start: 0, stop: 0.2, number: 5).ToArray(); // range of spatial frequencies in 1/mm

// retrieve desired optical properties, based on spectral data information

Expand All @@ -39,7 +39,7 @@ public static void RunDemo(bool showPlots = true)
var tissue = new Tissue(chromophores, scatterer, "", n: 1.4);

// predict the tissue's optical properties spanning the visible and NIR spectral regimes
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).ToArray(); // range of wavelengths in nm
var ops = tissue.GetOpticalProperties(wavelengths);

// predict the spatial frequency response at each specified optical properties
Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo16ROfFxMultiPowerLaw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static void RunDemo(bool showPlots = true)
var fx = 0; // spatial frequency in 1/mm

// predict the tissue's optical properties spanning the visible and NIR spectral regimes
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).ToArray(); // range of wavelengths in nm

var prefactorAs = new DoubleRange(start: 0.5, stop: 2.5, number: 9).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var prefactorAs = new DoubleRange(start: 0.5, stop: 2.5, number: 9).ToArray(); // range of spatial frequencies in 1/mm
var opsForMultipleA = prefactorAs.Select(prefactorA =>
new Tissue(chromophores, new PowerLawScatterer(a: prefactorA, b: 1.42), "", n: 1.4).GetOpticalProperties(wavelengths)).ToArray();

Expand Down
4 changes: 2 additions & 2 deletions src/Vts.Scripting/ForwardSolvers/Demo17ROfRhoMultiOpProp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new PointSourceSDAForwardSolver();
var rhos = new DoubleRange(start: 0.2, stop: 1, number: 5).AsEnumerable().ToArray(); // range of source-detector separations in mm
var rhos = new DoubleRange(start: 0.2, stop: 1, number: 5).ToArray(); // range of source-detector separations in mm

// create an array of chromophore absorbers, each with a given concentrations
var chromophores = new IChromophoreAbsorber[]
Expand All @@ -34,7 +34,7 @@ public static void RunDemo(bool showPlots = true)
var tissue = new Tissue(chromophores, scatterer, "", n: 1.4);

// predict the tissue's optical properties spanning the visible and NIR spectral regimes
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 450, stop: 1000, number: 1101).ToArray(); // range of wavelengths in nm
var ops = tissue.GetOpticalProperties(wavelengths);

// predict the radial reflectance response across the spectrum of optical properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void RunDemo(bool showPlots = true)

// predict the tissue's optical properties spanning the visible and NIR spectral regimes
//var wavelengths = new DoubleRange(start: 400, stop: 1000, number: 13).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 400, stop: 1000, number: 601).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 400, stop: 1000, number: 601).ToArray(); // range of wavelengths in nm
var measuredOPs = tissue.GetOpticalProperties(wavelengths);

// Create some measurements, based on a Nurbs-based White Monte Carlo forward solver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new TwoLayerSDAForwardSolver();
var rhos = new DoubleRange(start: 0.5, stop: 9.5, number: 19).AsEnumerable().ToArray(); // range of radial distances in 1/mm
var rhos = new DoubleRange(start: 0.5, stop: 9.5, number: 19).ToArray(); // range of radial distances in 1/mm
var op1 = new IOpticalPropertyRegion[]
{
new LayerOpticalPropertyRegion(zRange: new DoubleRange(0, 2, 2), regionOP: new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new TwoLayerSDAForwardSolver();
var fxs = new DoubleRange(start: 0, stop: 0.5, number: 51).AsEnumerable().ToArray(); // range of spatial frequencies in 1/mm
var fxs = new DoubleRange(start: 0, stop: 0.5, number: 51).ToArray(); // range of spatial frequencies in 1/mm
var op1 = new IOpticalPropertyRegion[]
{
new LayerOpticalPropertyRegion(zRange: new DoubleRange(0, 2, 2), regionOP: new OpticalProperties(mua: 0.01, musp: 1, g: 0.8, n: 1.4)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RunDemo(bool showPlots = true)
// PointSourceSDA,DistributedGaussianSourceSDA, DistributedPointSourceSDA,
// MonteCarlo(basic scaled), Nurbs(scaled with smoothing and adaptive binning)
var solver = new TwoLayerSDAForwardSolver();
var ts = new DoubleRange(start: 0, stop: 0.5, number: 51).AsEnumerable().ToArray(); // range of times in 1/mm
var ts = new DoubleRange(start: 0, stop: 0.5, number: 51).ToArray(); // range of times in 1/mm

// create an array of chromophore absorbers, each with a given concentrations
var chromophores = new IChromophoreAbsorber[]
Expand All @@ -35,7 +35,7 @@ public static void RunDemo(bool showPlots = true)
var tissue = new Tissue(chromophores, scatterer, "", n: 1.4);

// predict the bulk tissue's NIR optical properties
var wavelengths = new DoubleRange(start: 650, stop: 850, number: 3).AsEnumerable().ToArray(); // range of wavelengths in nm
var wavelengths = new DoubleRange(start: 650, stop: 850, number: 3).ToArray(); // range of wavelengths in nm
var opsBottomLayer = tissue.GetOpticalProperties(wavelengths);

// perturb the top layer's mua by a multiplicative factor
Expand Down
Loading

0 comments on commit 308e706

Please sign in to comment.