From d76d416483148de9b8139c157558962ffecbb459 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Fri, 12 Jun 2020 14:00:15 -0700 Subject: [PATCH 1/3] Replaced dot operators with arrows. Added ui.interactive check --- isis/src/base/apps/hist/main.cpp | 94 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/isis/src/base/apps/hist/main.cpp b/isis/src/base/apps/hist/main.cpp index 7c3246604a..2b078ea2ee 100644 --- a/isis/src/base/apps/hist/main.cpp +++ b/isis/src/base/apps/hist/main.cpp @@ -23,7 +23,7 @@ void IsisMain() { Cube *icube = p.SetInputCube("FROM"); UserInterface &ui = Application::GetUserInterface(); - if(!ui.WasEntered("TO") && !ui.IsInteractive()) { + if (!ui.WasEntered("TO") && !ui.IsInteractive()) { QString msg = "The [TO] parameter must be entered"; throw IException(IException::User, msg, _FILEINFO_); } @@ -66,53 +66,60 @@ void IsisMain() { p.Progress()->CheckStatus(); LineManager line(*icube); - for(int i = 1; i <= icube->lineCount(); i++) { + for (int i = 1; i <= icube->lineCount(); i++) { line.SetLine(i); icube->read(line); hist->AddData(line.DoubleBuffer(), line.size()); p.Progress()->CheckStatus(); } - if(!ui.IsInteractive() || ui.WasEntered("TO") ) { + if (!ui.IsInteractive() || ui.WasEntered("TO") ) { // Write the results QString outfile = ui.GetFileName("TO"); ofstream fout; fout.open(outfile.toLatin1().data()); - fout << "Cube: " << ui.GetFileName("FROM") << endl; - fout << "Band: " << icube->bandCount() << endl; - fout << "Average: " << hist->Average() << endl; - fout << "Std Deviation: " << hist->StandardDeviation() << endl; - fout << "Variance: " << hist->Variance() << endl; - fout << "Median: " << hist->Median() << endl; - fout << "Mode: " << hist->Mode() << endl; - fout << "Skew: " << hist->Skew() << endl; - fout << "Minimum: " << hist->Minimum() << endl; - fout << "Maximum: " << hist->Maximum() << endl; + fout << "Cube: " << ui.GetFileName("FROM") << endl; + fout << "Band: " << icube->bandCount() << endl; + fout << "Average: " << hist->Average() << endl; + fout << "Std Deviation: " << hist->StandardDeviation() << endl; + fout << "Variance: " << hist->Variance() << endl; + fout << "Median: " << hist->Median() << endl; + fout << "Mode: " << hist->Mode() << endl; + fout << "Skew: " << hist->Skew() << endl; + fout << "Minimum: " << hist->Minimum() << endl; + fout << "Maximum: " << hist->Maximum() << endl; fout << endl; - fout << "Total Pixels: " << hist->TotalPixels() << endl; - fout << "Valid Pixels: " << hist->ValidPixels() << endl; - fout << "Null Pixels: " << hist->NullPixels() << endl; - fout << "Lis Pixels: " << hist->LisPixels() << endl; - fout << "Lrs Pixels: " << hist->LrsPixels() << endl; - fout << "His Pixels: " << hist->HisPixels() << endl; - fout << "Hrs Pixels: " << hist->HrsPixels() << 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; + fout << "His Pixels: " << hist->HisPixels() << endl; + fout << "Hrs Pixels: " << hist->HrsPixels() << endl; // Write histogram in tabular format fout << endl; fout << endl; - fout << "DN,Pixels,CumulativePixels,Percent,CumulativePercent" << endl; + fout << "MinInclusive,MaxExclusive,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) { + for (int i = 0; i < hist->Bins(); i++) { + if (hist->BinCount(i) > 0) { total += hist->BinCount(i); double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.; cumpct += pct; - fout << hist->BinMiddle(i) << ","; + hist->BinRange(i, low, high); + + fout << low << ","; + fout << high << ","; fout << hist->BinCount(i) << ","; fout << total << ","; fout << pct << ","; @@ -122,10 +129,10 @@ void IsisMain() { fout.close(); } // If we are in gui mode, create a histogram plot - if(ui.IsInteractive()) { + if (ui.IsInteractive()) { // Set the title for the dialog QString title; - if(ui.WasEntered("TITLE") ) { + if (ui.WasEntered("TITLE") ) { title = ui.GetString("TITLE"); } else { @@ -138,19 +145,19 @@ void IsisMain() { ui.TheGui()); // Set the xaxis title if they entered one - if(ui.WasEntered("XAXIS") ) { + if (ui.WasEntered("XAXIS") ) { QString xaxis(ui.GetString("XAXIS")); plot->setAxisLabel(QwtPlot::xBottom, xaxis.toLatin1().data()); } // Set the yLeft axis title if they entered one - if(ui.WasEntered("FREQAXIS") ) { + if (ui.WasEntered("FREQAXIS") ) { QString yaxis(ui.GetString("FREQAXIS")); plot->setAxisLabel(QwtPlot::yRight, yaxis.toLatin1().data()); } // Set the yRight axis title if they entered one - if(ui.WasEntered("PERCENTAXIS") ) { + if (ui.WasEntered("PERCENTAXIS") ) { QString y2axis(ui.GetString("PERCENTAXIS") ); plot->setAxisLabel(QwtPlot::yLeft, y2axis.toLatin1().data()); } @@ -159,13 +166,16 @@ void IsisMain() { QVector binCountData; QVector cumPctData; double cumpct = 0.0; - for(int i = 0; i < hist->Bins(); i++) { - if(hist->BinCount(i) > 0) { - binCountData.append(QPointF(hist->BinMiddle(i), hist->BinCount(i) ) ); - - double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.; + 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) ) ); + + double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.0; cumpct += pct; - cumPctData.append(QPointF(hist->BinMiddle(i), cumpct) ); + cumPctData.append(QPointF(low, cumpct) ); } } @@ -184,21 +194,13 @@ void IsisMain() { cdfCurve->setYAxis(QwtPlot::yLeft); cdfCurve->setPen(*pen); - //These are all variables needed in the following for loop. - //---------------------------------------------- QVector intervals(binCountData.size() ); -// double maxYValue = DBL_MIN; -// double minYValue = DBL_MAX; -// // --------------------------------------------- -// - for(int y = 0; y < binCountData.size(); y++) { + 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); @@ -211,10 +213,6 @@ 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' + From ee6ebceda87da1c755bef7a99de16877f0f8b793 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Fri, 12 Jun 2020 14:01:05 -0700 Subject: [PATCH 2/3] Removed code that was commented out --- isis/src/base/objs/Histogram/Histogram.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index d8d60c2638..9c29480cad 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -167,21 +167,9 @@ 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) ); From 347bc77d9f690585726df030a046d0d6656f12d2 Mon Sep 17 00:00:00 2001 From: Austin Sanders Date: Fri, 12 Jun 2020 14:16:43 -0700 Subject: [PATCH 3/3] Updated changelog --- isis/src/base/apps/hist/hist.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/isis/src/base/apps/hist/hist.xml b/isis/src/base/apps/hist/hist.xml index 39739a369b..e0d4171a04 100644 --- a/isis/src/base/apps/hist/hist.xml +++ b/isis/src/base/apps/hist/hist.xml @@ -84,6 +84,12 @@ Updated logic such that min/max values are no longer calculated from .cub if values are provided by the user. Fixes #3881. + + 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. +