Skip to content

Commit

Permalink
MC/PP: added validation to MCCL and MCPP to check that tissue OPs (e.…
Browse files Browse the repository at this point in the history
…g. mua, musp, n) are non-negative. Found out that MCLL and MCPP run with negative values! So fixed that with input validation check. Also corrected headers of some tests because summary was confusing.
  • Loading branch information
hayakawa16 committed Jul 13, 2020
1 parent 919bc10 commit 82fdc44
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Vts.Desktop.Test/Vts.Desktop.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
<Compile Include="..\Vts.Test\MonteCarlo\DataStructuresValidation\DetectorInputs\dMCdROfRhodMusDetectorInputValidationTests.cs">
<Link>MonteCarlo\DataStructuresValidation\DetectorInputs\dMCdROfRhodMusDetectorInputValidationTests.cs</Link>
</Compile>
<Compile Include="..\Vts.Test\MonteCarlo\DataStructuresValidation\PostProcessorInputs\PostProcessorInputValidationTests.cs">
<Link>MonteCarlo\DataStructuresValidation\PostProcessorInputs\PostProcessorInputValidationTests.cs</Link>
</Compile>
<Compile Include="..\Vts.Test\MonteCarlo\DataStructuresValidation\SimulationInputValidationTests.cs">
<Link>MonteCarlo\DataStructuresValidation\SimulationInputValidationTests.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Vts.Test.MonteCarlo.DataStructuresValidation.DetectorInputs
public class dMCdROfRhodMuaDetectorInputValidationTests
{
/// <summary>
/// Test to check that layers that overlap.
/// Can only run dMC with one tissue region at the present.
/// Check that detector input does not specify more than 1 region
/// </summary>
[Test]
public void validate_only_one_perturbed_region_index_specified()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Vts.Test.MonteCarlo.DataStructuresValidation.DetectorInputs
public class dMCdROfRhodMusDetectorInputValidationTests
{
/// <summary>
/// Test to check that layers that overlap.
/// Can only run dMC with one tissue region at the present.
/// Check that detector input does not specify more than 1 region
/// </summary>
[Test]
public void validate_only_one_perturbed_region_index_specified()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using NUnit.Framework;
using Vts.Common;
using Vts.MonteCarlo;
using Vts.MonteCarlo.Detectors;
using Vts.MonteCarlo.Tissues;

namespace Vts.Test.MonteCarlo.DataStructuresValidation.PostProcessorInputs
{
[TestFixture]
public class PostProcessorInputValidationTests
{
/// <summary>
/// Test to check that post-processor perturbed OPs are not negative
/// </summary>
[Test]
public void validate_tissue_optical_properties_are_non_negative()
{
var tissueInput = new MultiLayerTissueInput(
new ITissueRegion[]
{
new LayerTissueRegion(
new DoubleRange(double.NegativeInfinity, 0.0),
new OpticalProperties( 0.0, 1e-10, 1.0, 1.0)),
new LayerTissueRegion(
new DoubleRange(0.0, 100.0),
new OpticalProperties(-1.0, 1.0, 0.8, 1.4)), // make mua negative
new LayerTissueRegion(
new DoubleRange(100.0, double.PositiveInfinity),
new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
});
var input = new PostProcessorInput(
new List<IDetectorInput>()
{
new pMCROfRhoDetectorInput()
{
Rho=new DoubleRange(0.0, 100.0),
// set perturbed ops to reference ops
PerturbedOps = new List<OpticalProperties>()
{
tissueInput.Regions[0].RegionOP,
tissueInput.Regions[1].RegionOP,
tissueInput.Regions[2].RegionOP
},
PerturbedRegionsIndices = new List<int>() { 1 }
}
},
"","",""
);
var result = PostProcessorInputValidation.ValidateInput(input,"");
Assert.IsFalse(result.IsValid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,28 @@ public void validate_voxel_tissue_and_ROfFx_detectors_are_not_defined_together()
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
}
[Test]
public void validate_tissue_optical_properties_are_non_negative()
{
// generate input embedded ellipsoid tissue and cylindrical detector
var input = new SimulationInput()
{
TissueInput = new MultiLayerTissueInput(
new ITissueRegion[]
{
new LayerTissueRegion(
new DoubleRange(double.NegativeInfinity, 0.0),
new OpticalProperties( 0.0, 1e-10, 1.0, 1.0)),
new LayerTissueRegion(
new DoubleRange(0.0, 100.0),
new OpticalProperties(-1.0, 1.0, 0.8, 1.4)), // make mua negative
new LayerTissueRegion(
new DoubleRange(100.0, double.PositiveInfinity),
new OpticalProperties(0.0, 1e-10, 1.0, 1.0))
})
};
var result = SimulationInputValidation.ValidateInput(input);
Assert.IsFalse(result.IsValid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Linq;
using Vts.MonteCarlo.DataStructuresValidation;
using Vts.MonteCarlo.Extensions;

namespace Vts.MonteCarlo
{
Expand All @@ -21,6 +20,12 @@ public class PostProcessorInputValidation
public static ValidationResult ValidateInput(PostProcessorInput input, string inpath)
{
ValidationResult tempResult;
tempResult = ValidateTissueOpticalProperties(input.DetectorInputs);
if (!tempResult.IsValid)

{
return tempResult;
}

tempResult = ValidateInputFolderExistence(Path.Combine(inpath, input.InputFolder));
if (!tempResult.IsValid)
Expand Down Expand Up @@ -97,5 +102,31 @@ private static ValidationResult ValidateSimulationInputExistence(
"PostProcessorInput: SimulationInput filename does not exist",
"check that a SimulationInput file exists in inputFolder");
}
private static ValidationResult ValidateTissueOpticalProperties(
IList<IDetectorInput> detectorInputs)
{
// for all pMC detectors, check that perturbed OPs are non-negative (g could be neg)
foreach (var detectorInput in detectorInputs)
{
if (detectorInput.TallyDetails.IspMCReflectanceTally)
{
var ops = ((dynamic)detectorInput).PerturbedOps;
foreach (var op in ops)
{
if ((op.Mua < 0.0) || (op.Musp < 0.0) || (op.N < 0.0))
{

return new ValidationResult(
false,
"Tissue optical properties mua, mus', n need to be non-negative",
"Please check optical properties");
}
}
}
}
return new ValidationResult(
true,
"PostProcessorInput: perturbed optical properties are all non-negative");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ private static ValidationResult ValidateSourceInput(ISourceInput sourceInput, IT

private static ValidationResult ValidateTissueInput(ITissueInput tissueInput)
{
// for all types of tissues, check that OPs are non-negative (g could be neg)
if (tissueInput.Regions.Any(r => r.RegionOP.Mua < 0.0) ||
tissueInput.Regions.Any(r => r.RegionOP.Musp < 0.0) ||
tissueInput.Regions.Any(r => r.RegionOP.N < 0.0))
{
return new ValidationResult(
false,
"Tissue optical properties mua, mus', n need to be non-negative",
"Please check optical properties");
}
if (tissueInput is MultiLayerTissueInput)
{
return MultiLayerTissueInputValidation.ValidateInput(tissueInput);
Expand Down

0 comments on commit 82fdc44

Please sign in to comment.