private void cboBudgetClass_SelectedIndexChanged(object sender, EventArgs e) { if (cboBudgetClass.SelectedItem == null) { return; } BudgetSegregationClass classResult = (BudgetSegregationClass)cboBudgetClass.SelectedItem; List <GCDConsoleLib.GCD.DoDStats> allStats = BudgetSeg.Classes.Values.Select(x => x.Statistics).ToList <GCDConsoleLib.GCD.DoDStats>(); ucSummary.RefreshDisplay(classResult.Statistics, allStats, SelectedRawRepresents, m_Options); ucBars.ChangeStats = classResult.Statistics; // Incorporate the class name into the proposed image file name if the user attempts to save the chart image cmsChart.DefaultFileName = string.Format("budget_seg_{0}", classResult.Name); // The raw histogram is either that for the whole DoD or just the budget seg class GCDConsoleLib.Histogram rawHist; switch (SelectedRawRepresents) { case RawRepresents.RawDoDAreaOfInterest: rawHist = BudgetSeg.DoD.Histograms.Raw.Data; break; case RawRepresents.ThrDoDAreaDetectableChange: rawHist = BudgetSeg.DoD.Histograms.Thr.Data; break; case RawRepresents.RawClassAreaOfInterest: rawHist = classResult.Histograms.Raw.Data; break; case RawRepresents.ThrClassAreaDetectableChange: rawHist = classResult.Histograms.Thr.Data; break; default: throw new Exception("Unhandled raw represents type"); } ucHistogram.LoadHistograms(rawHist, classResult.Histograms.Thr.Data); }
public void LoadMorphologicalUnitData() { Units.Clear(); // Loop over the sorted list of mask values IN ASCENDING DIRECTIONAL ORDER foreach (KeyValuePair <int, Tuple <string, string> > maskValue in ((GCDCore.Project.Masks.DirectionalMask)BS.Mask).SortedFieldValues) { // Only able to create a morphological unit if this mask item appears in budget seg if (BS.Classes.ContainsKey(maskValue.Value.Item1)) { BudgetSegregationClass bsc = BS.Classes[maskValue.Value.Item1]; MorphologicalUnit mu = new MorphologicalUnit(bsc.Name); mu.VolErosion = bsc.Statistics.ErosionThr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units); mu.VolErosionErr = bsc.Statistics.ErosionErr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units); mu.VolDeposition = bsc.Statistics.DepositionThr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units); mu.VolDepositionErr = bsc.Statistics.DepositionErr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units); Units.Add(mu); } } //////////////////////////////////////////////////////////////////////////////////////////////////// // Uncomment next line to clear the morph unit data and load the debug data #if DEBUG LoadFeshieData(); #endif //////////////////////////////////////////////////////////////////////////////////////////////////// // Add the total row Units.Add(new MorphologicalUnit("Reach Total", true)); }
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); }