Unverified Commit ad037e65 authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Revert "Changed histogram binning logic (#3918)" (#3922)

This reverts commit 92296341.
parent ceaf6b0b
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -84,12 +84,6 @@
      Updated logic such that min/max values are no longer calculated from .cub
      if values are provided by the user.  Fixes #3881.
    </change>
    <change name="Kaitlyn Lee" date="2020-06-11">
      Added "Pixels Below Min" and "Pixels Above Max" to the CSV output and changed how the data is
      outputted. Originally, the CSV output and the GUI histogram would use the DN value in the
      middle of a bin to represent that bin. That is, the CSV output used to have a "DN" value that
      was the bin's middle pixel DN. This was not intuitive to users. Removed the "DN" value and added "MinInclusive" and "MaxExclusive" to the CSV so that bins are represented by their min/max values. These changes were also reflected in the histrogram creation. The x-axis is now based off of the min value of a bin instead of the middle value. These changes were made alongside changes made to Histogram and cnethist.
    </change>
  </history>

  <oldName>
+48 −46
Original line number Diff line number Diff line
@@ -92,8 +92,6 @@ void IsisMain() {
    fout << endl;
    fout << "Total Pixels:    " << hist->TotalPixels() << endl;
    fout << "Valid Pixels:    " << hist->ValidPixels() << endl;
    fout << "Pixels Below Min:  " << hist->UnderRangePixels() << endl;
    fout << "Pixels Above Max:  " << hist->OverRangePixels() << endl;
    fout << "Null Pixels:     " << hist->NullPixels() << endl;
    fout << "Lis Pixels:      " << hist->LisPixels() << endl;
    fout << "Lrs Pixels:      " << hist->LrsPixels() << endl;
@@ -103,12 +101,10 @@ void IsisMain() {
    //  Write histogram in tabular format
    fout << endl;
    fout << endl;
    fout << "MinInclusive,MaxExclusive,Pixels,CumulativePixels,Percent,CumulativePercent" << endl;
    fout << "DN,Pixels,CumulativePixels,Percent,CumulativePercent" << endl;

    Isis::BigInt total = 0;
    double cumpct = 0.0;
    double low;
    double high;

    for(int i = 0; i < hist->Bins(); i++) {
      if(hist->BinCount(i) > 0) {
@@ -116,10 +112,7 @@ void IsisMain() {
        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.;
        cumpct += pct;

        hist->BinRange(i, low, high);

        fout << low << ",";
        fout << high << ",";
        fout << hist->BinMiddle(i) << ",";
        fout << hist->BinCount(i) << ",";
        fout << total << ",";
        fout << pct << ",";
@@ -166,16 +159,13 @@ void IsisMain() {
    QVector<QPointF> binCountData;
    QVector<QPointF> cumPctData;
    double cumpct = 0.0;
    double low;
    double high;
    for(int i = 0; i < hist->Bins(); i++) {
      if(hist->BinCount(i) > 0) {
        hist->BinRange(i, low, high);
        binCountData.append(QPointF(low, hist->BinCount(i) ) );
        binCountData.append(QPointF(hist->BinMiddle(i), hist->BinCount(i) ) );

        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.0;
        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.;
        cumpct += pct;
        cumPctData.append(QPointF(low, cumpct) );
        cumPctData.append(QPointF(hist->BinMiddle(i), cumpct) );
      }
    }

@@ -194,13 +184,21 @@ void IsisMain() {
    cdfCurve->setYAxis(QwtPlot::yLeft);
    cdfCurve->setPen(*pen);

    //These are all variables needed in the following for loop.
    //----------------------------------------------
    QVector<QwtIntervalSample> intervals(binCountData.size() );
//     double maxYValue = DBL_MIN;
//     double minYValue = DBL_MAX;
//     // ---------------------------------------------
//
    for(int y = 0; y < binCountData.size(); y++) {

      intervals[y].interval = QwtInterval(binCountData[y].x(),
                                          binCountData[y].x() + hist->BinSize());

      intervals[y].value = binCountData[y].y();
//       if(values[y] > maxYValue) maxYValue = values[y];
//       if(values[y] < minYValue) minYValue = values[y];
    }

    QPen percentagePen(Qt::red);
@@ -213,6 +211,10 @@ void IsisMain() {

    plot->add(histCurve);
    plot->add(cdfCurve);
//     plot->fillTable();

//     plot->setScale(QwtPlot::yLeft, 0, maxYValue);
//     plot->setScale(QwtPlot::xBottom, hist.Minimum(), hist.Maximum());

    QLabel *label = new QLabel("  Average = " + QString::number(hist->Average()) + '\n' +
           "\n  Minimum = " + QString::number(hist->Minimum()) + '\n' +
+24 −10
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ namespace Isis {
  Histogram::Histogram(double minimum, double maximum, int nbins) {

    SetValidRange(minimum, maximum);
    //SetBinRange(minimum, maximum);
    SetBins(nbins);
  }

@@ -166,9 +167,21 @@ namespace Isis {

   rangesFromNet(net,statFunc);


   //stretch the domain so that it is an even multiple of binWidth
   //for some reason Histogram makes the end points of the bin range be at the center of
   //bins.  Thus the +/-0.5 forces it to point the bin range at the ends of the bins.
   //SetBinRange(binWidth*( floor(this->ValidMinimum()/binWidth )+0.5),
   //            binWidth*(ceil( this->ValidMaximum()/binWidth )-0.5) );


   //Keep an eye on this to see if it breaks anything.  Also, I need to create
   //a dataset to give this constructor for the unit test.

    //tjw:  SetValidRange is moved into SetBinRange
   //SetValidRange(binWidth*floor(this->ValidMinimum()/binWidth),
   //              binWidth*ceil(this->ValidMaximum()/binWidth));

   //from the domain of the data and the requested bin width calculate the number of bins
   double domain = this->ValidMaximum() - this->ValidMinimum();
   int nBins = int ( ceil(domain/binWidth) );
@@ -253,6 +266,7 @@ namespace Isis {
    //set up the histogram ranges

    SetValidRange(min, max);
    //SetBinRange(min, max);
  }


@@ -382,7 +396,7 @@ namespace Isis {
  Histogram::~Histogram() {
  }

  //2015-08-24,  Tyler Wilson:  Added Statistics::SetValidRange call to SetValidRange
  //2015-08-24,  Tyler Wilson:  Added Statistics::SetValidRange call to SetBinRange
  //So the two functions do not have to be called together when setting
  //up a histogram

@@ -448,8 +462,8 @@ namespace Isis {
          index = 0;
        }
        else {
          index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) *
                              (data[i] - BinRangeStart()) );
          index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
                              (data[i] - BinRangeStart() ) + 0.5);
        }
        if (index < 0) index = 0;
        if (index >= nbins) index = nbins - 1;
@@ -476,8 +490,8 @@ namespace Isis {
        index = 0;
      }
      else {
        index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) *
                              (data - BinRangeStart()) );
        index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart() ) *
                            (data - BinRangeStart() ) + 0.5);
      }
      if (index < 0) index = 0;
      if (index >= nbins) index = nbins - 1;
@@ -508,8 +522,8 @@ namespace Isis {
          index = 0;
        }
        else {
          index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) *
                              (data[i] - BinRangeStart()) );
          index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
                              (data[i] - BinRangeStart()) + 0.5);
        }
        if (index < 0) index = 0;
        if (index >= nbins) index = nbins - 1;
@@ -639,8 +653,8 @@ namespace Isis {
      throw IException(IException::Programmer, message, _FILEINFO_);
    }

    double binSize = (BinRangeEnd() - BinRangeStart()) / (double) p_bins.size();
    low = BinRangeStart() + binSize * (double) index;
    double binSize = (BinRangeEnd() - BinRangeStart()) / (double)(p_bins.size() - 1);
    low = BinRangeStart() - binSize / 2.0 + binSize * (double) index;
    high = low + binSize;
  }

+0 −5
Original line number Diff line number Diff line
@@ -81,11 +81,6 @@ namespace Isis {
   *                            #1673.
   *   @history 2018-07-27 Jesse Mapel - Added support for initializing a histogram from
   *                           signed and unsigned word cubes. References #971.
   *   @history 2020-06-11 Kaitlyn Lee - Changed how to detemine which bin a pixel/measure falls
   *                           into in AddData(). Changed how the bin range is calculated in
   *                           BinRange(). The math for these functions were incorrect and not
   *                           intuitive. These changes were made alongside changes made
   *                           to cnethist and hist.
   */

  class Histogram : public Statistics {
+0 −5
Original line number Diff line number Diff line
@@ -17,11 +17,6 @@
    <change name="Orrin Thomas" date="2012-04-19">
      Original version
    </change>
    <change name="Kaitlyn Lee" date="2020-06-11">
      Removed "ResidualMagnitude" from the CSV output and added "ResidualMagnitudeMin" and "ResidualMagnitudeMax". This way, the bins are represented by the min/max values of the
      bins instead of the DN of the pixel in the middle of the bin. These changes were also
      reflected in the histrogram creation. The x-axis is now based off of the min value of a bin instead of the middle value. These changes were made alongside changes made to Histogram and hist.
    </change>
  </history>

  <groups>
Loading