public void ReadWriteFileSpecialCaseTest() { // Write to a file then read it to see if we get the same thing Histogram rTest1 = new Histogram(1, decimal.MaxValue); //Add some fake values into the mix rTest1.AddBinVal(-5); rTest1.AddBinVal(7.123); // First try it with a real file using (ITempDir tmp = TempDir.Create()) { UnitGroup ug = new UnitGroup(VolumeUnit.CubicMeter, AreaUnit.SquareMeter, LengthUnit.Meter, LengthUnit.Meter); Area cellArea = Area.From(0.2 * 0.3, ug.ArUnit); FileInfo fPath = new FileInfo(Path.Combine(tmp.Name, "myHistogram.csv")); rTest1.WriteFile(fPath, cellArea, ug); Histogram rTestRead = new Histogram(fPath); // Make sure the two histograms have the same edges and width Assert.AreEqual(rTest1.Count, rTest1.Count); Assert.AreEqual(rTest1.HistogramLower(ug).Meters, rTest1.HistogramLower(ug).Meters); Assert.AreEqual(rTest1.HistogramUpper(ug).Meters, rTest1.HistogramUpper(ug).Meters); Assert.AreEqual(rTest1._binWidth, rTest1._binWidth); // Now go bin-by-bin to make sure we end up with the same numbers everywhere for (int bid = 0; bid < rTestRead.Count; bid++) { Assert.AreEqual(rTest1.BinCounts[bid], rTestRead.BinCounts[bid]); Assert.AreEqual(rTest1.BinArea(bid, cellArea).SquareMeters, rTestRead.BinArea(bid, cellArea).SquareMeters); Assert.AreEqual(rTest1.BinLower(bid, ug).Meters, rTestRead.BinLower(bid, ug).Meters); } } }
public void BinValsTest() { Histogram rTest1 = new Histogram(20, 1); //Add some fake values into the mix for (int i = 0; i < 20; i++) { rTest1.AddBinVal((double)i - 9.9); } // Now test the values for (int i = 0; i < 20; i++) { Assert.AreEqual(rTest1.BinCount(i), 1); } // The special case Histogram rTest2 = new Histogram(1, decimal.MaxValue); //Add some fake values into the mix rTest2.AddBinVal(-1); rTest2.AddBinVal(1); rTest2.AddBinVal(1000); Assert.AreEqual(rTest2.BinCount(0), 1); Assert.AreEqual(rTest2.BinCount(1), 2); }
public void Histogram_Uniform_Raster_Test() { Raster rTempl = new Raster(new FileInfo(DirHelpers.GetTestRasterPath("const950.tif"))); Histogram theHisto = new Histogram(1, rTempl); theHisto.AddBinVal(1.0); }
/// <summary> /// The actual op on the cell /// </summary> /// <param name="data"></param> /// <param name="id"></param> /// <returns></returns> protected override void CellOp(List <double[]> data, List <double[]> outputs, int id) { // Speed things up by ignoring nodatas if (data[0][id] == inNodataVals[0]) { return; } // Pure vector method if (_hasVectorPolymask) { VectorBudgetSegCellOp(data, id); } // Rasterized vector method else if (_hasRasterizedPolymask) { RasterBudgetSegCellOp(data, id); } // Non budget seg method else { theHistogram.AddBinVal(data[0][id]); } }
public void Histogram_Equals_Test() { Histogram rTest1 = new Histogram(20, 1); // This is our control Histogram rTest2 = new Histogram(21, 1); // different number of bins Histogram rTest3 = new Histogram(20, 1); // change one value in the bins Histogram rTest4 = new Histogram(20, 2); // different bin width //Add some fake values into the mix for (int i = 0; i < 20; i++) { rTest1.AddBinVal(i - 9.9); rTest2.AddBinVal(i - 9.9); rTest3.AddBinVal(i - 9.9); } // Change one value in 2 rTest3.AddBinVal(2); Assert.IsTrue(rTest1.Equals(rTest1)); Assert.IsFalse(rTest1.Equals(rTest2)); Assert.IsFalse(rTest1.Equals(rTest3)); Assert.IsFalse(rTest1.Equals(rTest4)); Assert.IsFalse(rTest2.Equals(rTest1)); Assert.IsTrue(rTest2.Equals(rTest2)); Assert.IsFalse(rTest2.Equals(rTest3)); Assert.IsFalse(rTest2.Equals(rTest4)); Assert.IsFalse(rTest3.Equals(rTest1)); Assert.IsFalse(rTest3.Equals(rTest2)); Assert.IsTrue(rTest3.Equals(rTest3)); Assert.IsFalse(rTest3.Equals(rTest4)); Assert.IsFalse(rTest4.Equals(rTest1)); Assert.IsFalse(rTest4.Equals(rTest2)); Assert.IsFalse(rTest4.Equals(rTest3)); Assert.IsTrue(rTest4.Equals(rTest4)); }
public void BinVolumeTest() { Histogram rTest1 = new Histogram(20, 1); //Add some fake values into the mix for (int i = 0; i < 20; i++) { rTest1.AddBinVal((double)i - 9.9); } // Make sure our unit conversions are working decimal cH = -0.2m; //Foots decimal cW = 0.3m; //Foots UnitGroup ug = new UnitGroup(VolumeUnit.ImperialBeerBarrel, AreaUnit.SquareInch, LengthUnit.Foot, LengthUnit.Meter); Area cellArea = Area.From((double)Math.Abs(cH * cW), AreaUnit.SquareFoot); for (int i = 0; i < 20; i++) { // Length(m) X Width(m) X Height(ft) double manualvolume = Volume.From(cellArea.SquareMeters * Length.FromFeet(i - 9.9).Meters, VolumeUnit.CubicMeter).ImperialBeerBarrels; Assert.AreEqual(rTest1.BinVolume(i, cellArea, ug).As(ug.VolUnit), manualvolume, 0.0000001); } }
public void BinValsTest2() { Histogram rTest1 = new Histogram(4, 1); // Let's get our integers out of the way rTest1.AddBinVal(-2); Assert.AreEqual(rTest1.BinCount(0), 1); rTest1.AddBinVal(-1); Assert.AreEqual(rTest1.BinCount(1), 1); rTest1.AddBinVal(0); Assert.AreEqual(rTest1.BinCount(2), 1); rTest1.AddBinVal(1); Assert.AreEqual(rTest1.BinCount(3), 1); // Make sure the last value falls backward rTest1.AddBinVal(2); Assert.AreEqual(rTest1.BinCount(3), 2); // Now make sure everything that is supposed to fail does. List <double> badVals = new List <double>() { 3, -2.0000001, 2.0000011 }; foreach (double val in badVals) { try { rTest1.AddBinVal(val); Assert.Fail(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(ArgumentOutOfRangeException)); } } }