public MorphologicalAnalysis(XmlNode nodAnalysis, BudgetSegregation bs) : base(nodAnalysis) { OutputFolder = ProjectManager.Project.GetAbsoluteDir(nodAnalysis.SelectSingleNode("Folder").InnerText); Spreadsheet = ProjectManager.Project.GetAbsolutePath(nodAnalysis.SelectSingleNode("Spreadsheet").InnerText); BS = bs; XmlNode nodDuration = nodAnalysis.SelectSingleNode("Duration"); _DisplayUnits_Duration = (UnitsNet.Units.DurationUnit)Enum.Parse(typeof(UnitsNet.Units.DurationUnit), nodDuration.Attributes["units"].InnerText); _DisplayUnits_Volume = ProjectManager.Project.Units.VolUnit; _DisplayUnits_Mass = UnitsNet.Units.MassUnit.Kilogram; _duration = Duration.From(double.Parse(nodDuration.InnerText, CultureInfo.InvariantCulture), DisplayUnits_Duration); _porosity = decimal.Parse(nodAnalysis.SelectSingleNode("Porosity").InnerText, CultureInfo.InvariantCulture); _density = decimal.Parse(nodAnalysis.SelectSingleNode("Density").InnerText, CultureInfo.InvariantCulture); _competency = decimal.Parse(nodAnalysis.SelectSingleNode("Competency").InnerText, CultureInfo.InvariantCulture); //_DataVolumeUnits = ProjectManager.Project.Units.VolUnit; double minFluxValue = double.Parse(nodAnalysis.SelectSingleNode("MinimumFluxVolume").InnerText, CultureInfo.InvariantCulture); BoundaryFlux = Volume.From(minFluxValue, ProjectManager.Project.Units.VolUnit); Units = new BindingList <MorphologicalUnit>(); LoadMorphologicalUnitData(); }
public MorphologicalAnalysis(string name, DirectoryInfo outputFolder, BudgetSegregation bs) : base(name) { OutputFolder = outputFolder; Spreadsheet = new FileInfo(Path.Combine(OutputFolder.FullName, "Morphological.xml")); BS = bs; _DisplayUnits_Duration = UnitsNet.Units.DurationUnit.Hour; _DisplayUnits_Volume = ProjectManager.Project.Units.VolUnit; _DisplayUnits_Mass = UnitsNet.Units.MassUnit.Kilogram; _duration = Duration.From(1, DisplayUnits_Duration); _porosity = 0.26m; _density = 2.65m; _competency = 1m; //_DataVolumeUnits = ProjectManager.Project.Units.VolUnit; Units = new BindingList <MorphologicalUnit>(); LoadMorphologicalUnitData(); ImposeMinimumFlux(); }
public BudgetSegregation Calculate(string dodName, DirectoryInfo analysisFolder, DoDBase dod, Project.Masks.AttributeFieldMask mask) { // Build the budget segregation result set object that will be returned. This determines paths BudgetSegregation bsResult = new BudgetSegregation(dodName, analysisFolder, mask, dod); // Retrieve the segregated statistics from the DoD rasters depending on the thresholding type used. Dictionary <string, GCDConsoleLib.GCD.DoDStats> results = null; if (dod is DoDMinLoD) { results = RasterOperators.GetStatsMinLoD(dod.RawDoD.Raster, ((DoDMinLoD)dod).Threshold, mask.Vector, mask._Field, ProjectManager.Project.Units, ProjectManager.OnProgressChange); } else { Raster propErr = ((DoDPropagated)dod).PropagatedError; if (dod is DoDProbabilistic) { results = RasterOperators.GetStatsProbalistic(dod.RawDoD.Raster, dod.ThrDoD.Raster, propErr, mask.Vector, mask._Field, ProjectManager.Project.Units, ProjectManager.OnProgressChange); } else { results = RasterOperators.GetStatsPropagated(dod.RawDoD.Raster, propErr, mask.Vector, mask._Field, ProjectManager.Project.Units, ProjectManager.OnProgressChange); } } // Retrieve the histograms for all budget segregation classes Dictionary <string, Histogram> rawHistos = RasterOperators.BinRaster(dod.RawDoD.Raster, DEFAULTHISTOGRAMNUMBER, mask.Vector, mask._Field, ProjectManager.OnProgressChange); Dictionary <string, Histogram> thrHistos = RasterOperators.BinRaster(dod.ThrDoD.Raster, DEFAULTHISTOGRAMNUMBER, mask.Vector, mask._Field, ProjectManager.OnProgressChange); decimal defaultBinWidth = 1; if (rawHistos.Count > 0) { defaultBinWidth = (decimal)rawHistos.Values.First().BinWidth(ProjectManager.Project.Units).As(ProjectManager.Project.Units.VertUnit); } // Make sure that the output folder and the folder for the figures exist analysisFolder.Create(); DoDBase.FiguresFolderPath(analysisFolder).Create(); // Build the output necessary output files int classIndex = 1; StringBuilder legendText = new StringBuilder("Class Index, Class Name"); foreach (KeyValuePair <string, GCDConsoleLib.GCD.DoDStats> segClass in results) { if (!rawHistos.ContainsKey(segClass.Key)) { rawHistos.Add(segClass.Key, new Histogram(DEFAULTHISTOGRAMNUMBER, defaultBinWidth)); } if (!thrHistos.ContainsKey(segClass.Key)) { thrHistos.Add(segClass.Key, new Histogram(DEFAULTHISTOGRAMNUMBER, defaultBinWidth)); } legendText.AppendLine(string.Format("{0},{1}", classIndex, segClass.Key)); string filePrefix = string.Format("c{0:000}", classIndex); FileInfo sumaryXML = new FileInfo(Path.Combine(analysisFolder.FullName, string.Format("{0}_summary.xml", filePrefix))); FileInfo rawHstPth = new FileInfo(Path.Combine(analysisFolder.FullName, string.Format("{0}_raw.csv", filePrefix))); FileInfo thrHstPth = new FileInfo(Path.Combine(analysisFolder.FullName, string.Format("{0}_thr.csv", filePrefix))); GenerateSummaryXML(segClass.Value, sumaryXML); GenerateChangeBarGraphicFiles(analysisFolder, segClass.Value, 600, 600, filePrefix); WriteHistogram(rawHistos[segClass.Key], rawHstPth); WriteHistogram(thrHistos[segClass.Key], thrHstPth); HistogramPair histograms = new HistogramPair(rawHistos[segClass.Key], rawHstPth, thrHistos[segClass.Key], thrHstPth); BudgetSegregationClass bsClass = new BudgetSegregationClass(segClass.Key, segClass.Value, histograms, sumaryXML); bsResult.Classes[segClass.Key] = bsClass; classIndex++; } // Generate the new inter-comparison spreadsheet FileInfo interCompare = new FileInfo(Path.Combine(analysisFolder.FullName, "InterCompare.xml")); try { InterComparison.Generate(results, interCompare); } catch (Exception ex) { // Do nothing. Essentially optional Console.WriteLine("Error generating inter-comparison as part of a budget segregation " + ex.Message); } // Write the class legend to file File.WriteAllText(bsResult.ClassLegend.FullName, legendText.ToString()); return(bsResult); }