예제 #1
0
        /// <summary>
        /// constructor that load excitation simulation AOfRhoAndZ
        /// </summary>
        public AOfRhoAndZLoader(string inputFolder, string infile, int fluorescentTissueRegionIndex)
        {
            if (infile != "")
            {
                var inputPath = "";
                if (inputFolder == "")
                {
                    inputPath = infile;
                }
                else
                {
                    inputPath = inputFolder + @"/" + infile;
                }
                var aOfRhoAndZDetector = (AOfRhoAndZDetector) DetectorIO.ReadDetectorFromFile(
                    "AOfRhoAndZ", inputFolder);
                // use DoubleRange X,Y,Z to match detector dimensions
                Rho = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Rho;
                Z = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Z;
                AOfRhoAndZ = ((AOfRhoAndZDetector) aOfRhoAndZDetector).Mean;

                var exciteInfile = SimulationInput.FromFile(inputPath);
                FluorescentTissueRegion = exciteInfile.TissueInput.Regions[fluorescentTissueRegionIndex];

                // separate setup of arrays so can unit test method
                InitializeFluorescentRegionArrays();
                SetupRegionIndices();
            }
            else
            {
                throw new ArgumentException("infile string is empty");
            }
        }
예제 #2
0
        /// <summary>
        /// method to read the simulation input from a specified or default file
        /// </summary>
        public static SimulationInput ReadSimulationInputFromFile(string inputFile)
        {
            try
            {
                if (string.IsNullOrEmpty(inputFile))
                {
                    logger.Info(" *** No input file specified ***\n\nDefine an input file using mc.exe infile=infile_name.txt");
                    return(null);
                }

                //get the full path for the input file
                var    fullFilePath = Path.GetFullPath(inputFile);
                string extension    = Path.GetExtension(inputFile);

                if (File.Exists(fullFilePath))
                {
                    return(SimulationInput.FromFile(fullFilePath));
                }

                if (File.Exists(fullFilePath + ".txt"))
                {
                    return(SimulationInput.FromFile(fullFilePath + ".txt"));
                }

                //throw a file not found exception
                throw new FileNotFoundException("\nThe following input file could not be found: " + fullFilePath + " - type mc help=infile for correct syntax");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                //Console.WriteLine(VtsJsonSerializer.TraceWriter.GetTraceMessages());
                return(null);
            }
        }
예제 #3
0
        public void validate_deserialized_class_is_correct_when_using_FileIO()
        {
            new SimulationInput {
                N = 10
            }.ToFile("test.txt");
            var iCloned = SimulationInput.FromFile("test.txt");

            Assert.AreEqual(iCloned.N, 10);
        }
예제 #4
0
        /// <summary>
        /// constructor that load excitation simulation AOfXAndYAndZ
        /// </summary>
        public AOfXAndYAndZLoader(string inputFolder, string infile, int fluorescentTissueRegionIndex)
        {
            if (infile != "")
            {
                var inputPath = "";
                if (inputFolder == "")
                {
                    inputPath = infile;
                }
                else
                {
                    inputPath = inputFolder + @"/" + infile;
                }
                var aOfXAndYAndZDetector = (AOfXAndYAndZDetector)DetectorIO.ReadDetectorFromFile(
                    "AOfXAndYAndZ", inputFolder);
                // use DoubleRange X,Y,Z to match detector dimensions
                X            = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).X;
                Y            = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Y;
                Z            = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Z;
                AOfXAndYAndZ = ((AOfXAndYAndZDetector)aOfXAndYAndZDetector).Mean;

                var exciteInfile = SimulationInput.FromFile(inputPath);

                FluorescentTissueRegion = exciteInfile.TissueInput.Regions[fluorescentTissueRegionIndex];
                BoundedTissueRegion     = null;
                // check if tissue bounded CH: can this be made more generic?
                if (exciteInfile.TissueInput.TissueType == "BoundingCylinder")
                {
                    var cylinderIndex = exciteInfile.TissueInput.Regions.Length - 1;
                    CaplessCylinderTissueRegion boundingCylinder =
                        (CaplessCylinderTissueRegion)exciteInfile.TissueInput.Regions[cylinderIndex];
                    BoundedTissueRegion = new CaplessCylinderTissueRegion(
                        boundingCylinder.Center,
                        boundingCylinder.Radius,
                        boundingCylinder.Height,
                        boundingCylinder.RegionOP);
                }

                // separate setup of arrays so can unit test method
                InitializeFluorescentRegionArrays();
                SetupRegionIndices();
            }
            else
            {
                throw new ArgumentException("infile string is empty");
            }
        }
예제 #5
0
        public void validate_deserialization_of_infile_for_Mus_and_Musp_inconsistent_specification()
        {
            var name         = Assembly.GetExecutingAssembly().FullName;
            var assemblyName = new AssemblyName(name).Name;

            FileIO.CopyFileFromEmbeddedResources(
                assemblyName + ".Resources.infile_unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent.txt",
                "infile_unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent.txt", name);
            string[] arguments = new string[]
            { "infile=infile_unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent.txt" };
            Program.Main(arguments);
            Assert.IsTrue(Directory.Exists("unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent"));
            var writtenInfile = SimulationInput.FromFile(
                "unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent/unit_test_one_layer_ROfRho_Musp_and_Mus_inconsistent.txt");

            // infile specifies Mus=5.0 and Musp=1.2 with g=0.8
            // when there is inconsistency in Mus and Musp specification, code modifies Mus to conform to Musp
            // the following test verifies that Mus was modified accordingly
            Assert.Less(Math.Abs(writtenInfile.TissueInput.Regions[1].RegionOP.Mus - 6.0), 1e-6);
        }
예제 #6
0
        // need to work on following
        /// <summary>
        /// Runs the Monte Carlo Post-processor
        /// </summary>
        public static void RunPostProcessor(PostProcessorInput input, string outputFolderPath)
        {
            // locate root folder for output, creating it if necessary
            var path = string.IsNullOrEmpty(outputFolderPath)
                ? Path.GetFullPath(Directory.GetCurrentDirectory())
                : Path.GetFullPath(outputFolderPath);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // locate destination folder for output, creating it if necessary
            var resultsFolder = Path.Combine(path, input.OutputName);

            if (!Directory.Exists(resultsFolder))
            {
                Directory.CreateDirectory(resultsFolder);
            }

            SimulationOutput postProcessedOutput = null;

            var databaseGenerationInputFile = SimulationInput.FromFile(Path.Combine(input.InputFolder, input.DatabaseSimulationInputFilename + ".txt"));

            // check for pMC tallies first because could have ReflectanceTallies mixed in and want to load CollisionInfo

            // Why not mirror the "on-the-fly" code, and allow for all kinds of detector inputs simultaneously? (dc 12/21/2011)
            if (input.DetectorInputs.Where(di => di.TallyDetails.IspMCReflectanceTally).Any())
            {
                IList <IDetectorInput> pMCDetectorInputs;
                pMCDetectorInputs = input.DetectorInputs;
                var postProcessor = new PhotonDatabasePostProcessor(
                    VirtualBoundaryType.pMCDiffuseReflectance,
                    pMCDetectorInputs,
                    PhotonDatabaseFactory.GetpMCDatabase( // database filenames are assumed to be convention
                        VirtualBoundaryType.pMCDiffuseReflectance,
                        input.InputFolder),
                    databaseGenerationInputFile
                    );
                postProcessedOutput = postProcessor.Run();
            }
            else if (input.DetectorInputs.Where(di => di.TallyDetails.IsReflectanceTally).Any())
            {
                var postProcessor = new PhotonDatabasePostProcessor(
                    VirtualBoundaryType.DiffuseReflectance,
                    input.DetectorInputs,
                    PhotonDatabaseFactory.GetPhotonDatabase( //database filenames are assumed to be convention
                        VirtualBoundaryType.DiffuseReflectance,
                        input.InputFolder),
                    databaseGenerationInputFile
                    );
                postProcessedOutput = postProcessor.Run();
            }
            else if (input.DetectorInputs.Where(di => di.TallyDetails.IsTransmittanceTally).Any())
            {
                var postProcessor = new PhotonDatabasePostProcessor(
                    VirtualBoundaryType.DiffuseTransmittance,
                    input.DetectorInputs,
                    PhotonDatabaseFactory.GetPhotonDatabase( //database filenames are assumed to be convention
                        VirtualBoundaryType.DiffuseTransmittance,
                        input.InputFolder),
                    databaseGenerationInputFile
                    );
                postProcessedOutput = postProcessor.Run();
            }
            else if (input.DetectorInputs.Where(di => di.TallyDetails.IsSpecularReflectanceTally).Any())
            {
                var postProcessor = new PhotonDatabasePostProcessor(
                    VirtualBoundaryType.SpecularReflectance,
                    input.DetectorInputs,
                    PhotonDatabaseFactory.GetPhotonDatabase( //database filenames are assumed to be convention
                        VirtualBoundaryType.SpecularReflectance,
                        input.InputFolder),
                    databaseGenerationInputFile
                    );
                postProcessedOutput = postProcessor.Run();
            }


            var folderPath = input.OutputName;

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            // save input file to output folder with results
            input.ToFile(Path.Combine(resultsFolder, input.OutputName + ".txt"));

            // save database generation input file to output folder
            databaseGenerationInputFile.ToFile(Path.Combine(resultsFolder, input.OutputName + "_database_infile.txt"));

            if (postProcessedOutput != null)
            {
                foreach (var result in postProcessedOutput.ResultsDictionary.Values)
                {
                    // save all detector data to the specified folder
                    DetectorIO.WriteDetectorToFile(result, folderPath);
                }
            }
        }