public void validate_loading_spectral_database_from_tsv_in_resources() { Stream stream = StreamFinder.GetFileStreamFromResources("Modeling/Spectroscopy/Resources/Spectra.txt", "Vts"); List <ChromophoreSpectrum> myChromophoreList = new List <ChromophoreSpectrum>(); //create 2 sets of values for the tab delimeted file ChromophoreSpectrum c = new ChromophoreSpectrum(); c.Name = "HbO2"; c.AbsorptionCoefficientUnit = AbsorptionCoefficientUnit.InverseMillimeters; c.MolarUnit = MolarUnit.None; c.ChromophoreCoefficientType = ChromophoreCoefficientType.MolarAbsorptionCoefficient; myChromophoreList.Add(c); ChromophoreSpectrum c2 = new ChromophoreSpectrum(); c2.Name = "Hb"; c2.AbsorptionCoefficientUnit = AbsorptionCoefficientUnit.InverseMillimeters; c2.MolarUnit = MolarUnit.None; c2.ChromophoreCoefficientType = ChromophoreCoefficientType.MolarAbsorptionCoefficient; myChromophoreList.Add(c2); var testDictionary = myChromophoreList.ToDictionary(); SpectralDatabase.AppendDatabaseFromFile(testDictionary, stream); testDictionary.WriteToJson("dictionary3.txt"); Assert.IsTrue(FileIO.FileExists("dictionary3.txt")); }
/// <summary> /// /// </summary> /// <param name="importFiles">the name(s) of the file(s) to import</param> /// <param name="importPath">the path of the files to import (relative or absolute)</param> /// <param name="outname">the name of the resulting output xml spectral dictionary</param> /// <param name="outpath">the output directory of the generated xml dictionary (relative or absolute)</param> public static ChromophoreSpectrumDictionary ImportSpectraFromFile( string[] importFiles = null, string importPath = "", string outname = "SpectralDictionary", string outpath = "") { if (importFiles == null || importFiles.Length == 0 || string.IsNullOrEmpty(importFiles[0])) { importFiles = new string[] { "absorber-*.txt" }; } var allFiles = importFiles.SelectMany(file => Directory.GetFiles( importPath ?? Directory.GetCurrentDirectory(), file)); var chromophoreDictionary = new ChromophoreSpectrumDictionary(); logger.Info(() => "Importing spectral data files"); foreach (var file in allFiles) { if (File.Exists(file)) { try { logger.Info("Importing file: " + file); var stream = StreamFinder.GetFileStream(file, FileMode.Open); SpectralDatabase.AppendDatabaseFromFile(chromophoreDictionary, stream); } catch (Exception e) { logger.Info("**** An error occurred while importing file: " + file); logger.Info("Detailed error: " + e.Message); } } } return(chromophoreDictionary); }