13#include <QXmlStreamWriter>
14#include <QXmlStreamReader>
18#include "IException.h"
22#include "PvlKeyword.h"
39 readStatistics(xmlReader);
42 void Statistics::readStatistics(QXmlStreamReader *xmlReader) {
43 Q_ASSERT(xmlReader->name() ==
"statistics");
44 while (xmlReader->readNextStartElement()) {
45 if (xmlReader->qualifiedName() ==
"sum") {
49 catch (IException &e) {
53 else if (xmlReader->qualifiedName() ==
"sumSquares") {
57 catch (IException &e) {
61 else if (xmlReader->qualifiedName() ==
"range") {
62 while (xmlReader->readNextStartElement()) {
63 if (xmlReader->qualifiedName() ==
"minimum") {
67 catch (IException &e) {
71 else if (xmlReader->qualifiedName() ==
"maximum") {
75 catch (IException &e) {
79 else if (xmlReader->qualifiedName() ==
"validMinimum") {
83 catch (IException &e) {
87 else if (xmlReader->qualifiedName() ==
"validMaximum") {
91 catch (IException &e) {
96 xmlReader->skipCurrentElement();
100 else if (xmlReader->qualifiedName() ==
"pixelCounts") {
101 while (xmlReader->readNextStartElement()) {
102 if (xmlReader->qualifiedName() ==
"totalPixels") {
106 catch (IException &e) {
110 else if (xmlReader->qualifiedName() ==
"validPixels") {
114 catch (IException &e) {
118 else if (xmlReader->qualifiedName() ==
"nullPixels") {
122 catch (IException &e) {
127 else if (xmlReader->qualifiedName() ==
"lisPixels") {
131 catch (IException &e) {
135 else if (xmlReader->qualifiedName() ==
"lrsPixels") {
139 catch (IException &e) {
143 else if (xmlReader->qualifiedName() ==
"hisPixels") {
147 catch (IException &e) {
151 else if (xmlReader->qualifiedName() ==
"hrsPixels") {
155 catch (IException &e) {
159 else if (xmlReader->qualifiedName() ==
"underRangePixels") {
163 catch (IException &e) {
167 else if (xmlReader->qualifiedName() ==
"overRangePixels") {
171 catch (IException &e) {
176 xmlReader->skipCurrentElement();
180 else if (xmlReader->qualifiedName() ==
"removedData") {
184 catch (IException &e) {
189 xmlReader->skipCurrentElement();
207 : m_sum(other.m_sum),
208 m_sumsum(other.m_sumsum),
209 m_minimum(other.m_minimum),
210 m_maximum(other.m_maximum),
211 m_validMinimum(other.m_validMinimum),
212 m_validMaximum(other.m_validMaximum),
213 m_totalPixels(other.m_totalPixels),
214 m_validPixels(other.m_validPixels),
215 m_nullPixels(other.m_nullPixels),
216 m_lrsPixels(other.m_lrsPixels),
217 m_lisPixels(other.m_lisPixels),
218 m_hrsPixels(other.m_hrsPixels),
219 m_hisPixels(other.m_hisPixels),
220 m_underRangePixels(other.m_underRangePixels),
221 m_overRangePixels(other.m_overRangePixels),
222 m_removedData(other.m_removedData) {
236 if (&other !=
this) {
293 for(
unsigned int i = 0; i < count; i++) {
294 double value = data[i];
327 else if (AboveRange(data)) {
330 else if (BelowRange(data)) {
359 for(
unsigned int i = 0; i < count; i++) {
360 double value = data[i];
386 else if (AboveRange(data)) {
389 else if (BelowRange(data)) {
399 QString msg =
"You are removing non-existant data in [Statistics::RemoveData]";
406 void Statistics::SetValidRange(
const double minimum,
const double maximum) {
412 QString msg =
"Invalid Range: Minimum [" +
toString(minimum)
413 +
"] must be less than the Maximum [" +
toString(maximum) +
"].";
420 double Statistics::ValidMinimum()
const {
425 double Statistics::ValidMaximum()
const {
430 bool Statistics::InRange(
const double value) {
431 return (!BelowRange(value) && !AboveRange(value));
435 bool Statistics::AboveRange(
const double value) {
440 bool Statistics::BelowRange(
const double value) {
482 if (temp < 0.0) temp = 0.0;
519 if (temp < 0.0) temp = 0.0;
535 QString msg =
"Minimum is invalid since you removed data";
556 QString msg =
"Maximum is invalid since you removed data";
676 bool Statistics::RemovedData()
const {
697 if ((percent <= 0.0) || (percent >= 100.0)) {
698 QString msg =
"Invalid value for percent";
703 double k = sqrt(1.0 / (1.0 - percent / 100.0));
724 if ((percent <= 0.0) || (percent >= 100.0)) {
725 QString msg =
"Invalid value for percent";
730 double k = sqrt(1.0 / (1.0 - percent / 100.0));
802 if (value ==
Maximum())
return 0;
804 QString msg =
"Undefined Z-score. Standard deviation is zero and the input value["
820 m_sum = inStats[
"Sum"];
847 if (name.isEmpty()) {
877 void Statistics::save(QXmlStreamWriter &stream,
const Project *project)
const {
879 stream.writeStartElement(
"statistics");
885 stream.writeStartElement(
"range");
890 stream.writeEndElement();
892 stream.writeStartElement(
"pixelCounts");
902 stream.writeEndElement();
905 stream.writeEndElement();
915 stream.setByteOrder(QDataStream::LittleEndian);
937 QDataStream &Statistics::read(QDataStream &stream) {
940 qint64 totalPixels, validPixels, nullPixels, lrsPixels, lisPixels,
941 hrsPixels, hisPixels, underRangePixels, overRangePixels;
944 stream.setByteOrder(QDataStream::LittleEndian);
982 QDataStream &
operator<<(QDataStream &stream,
const Statistics &statistics) {
983 return statistics.write(stream);
987 QDataStream &
operator>>(QDataStream &stream, Statistics &statistics) {
988 return statistics.read(stream);
@ Programmer
This error is for when a programmer made an API call that was illegal.
The main project for ipce.
Contains multiple PvlContainers.
A single keyword-value pair.
This class is used to accumulate statistics on double arrays.
BigInt m_hisPixels
Count of high instrument representation pixels processed.
BigInt NullPixels() const
Returns the total number of NULL pixels encountered.
double m_sum
The sum accumulator, i.e. the sum of added data values.
BigInt OverRangePixels() const
Returns the total number of pixels over the valid range encountered.
bool m_removedData
Indicates the RemoveData method was called which implies m_minimum and m_maximum are invalid.
double ChebyshevMinimum(const double percent=99.5) const
This method returns a minimum such that X percent of the data will fall with K standard deviations of...
BigInt m_validPixels
Count of valid pixels (non-special) processed.
double Sum() const
Returns the sum of all the data.
BigInt UnderRangePixels() const
Returns the total number of pixels under the valid range encountered.
double Average() const
Computes and returns the average.
BigInt LisPixels() const
Returns the total number of low instrument saturation (LIS) pixels encountered.
virtual ~Statistics()
Destroys the IsisStats object.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
BigInt HrsPixels() const
Returns the total number of high representation saturation (HRS) pixels encountered.
BigInt HisPixels() const
Returns the total number of high instrument saturation (HIS) pixels encountered.
double m_validMinimum
Minimum valid pixel value.
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
BigInt m_lisPixels
Count of low representation saturation pixels processed.
BigInt OutOfRangePixels() const
Returns the total number of pixels outside of the valid range encountered.
BigInt m_nullPixels
Count of null pixels processed.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
double ChebyshevMaximum(const double percent=99.5) const
This method returns a maximum such that X percent of the data will fall with K standard deviations of...
double ZScore(const double value) const
This method returns the better of the z-score of the given value.
BigInt m_totalPixels
Count of total pixels processed.
BigInt m_lrsPixels
Count of low instrument saturation pixels processed.
double SumSquare() const
Returns the sum of all the squared data.
BigInt TotalPixels() const
Returns the total number of pixels processed (valid and invalid).
QDataStream & write(QDataStream &stream) const
Order saved must match the offsets in the static compoundH5DataType() method.
PvlGroup toPvl(QString name="Statistics") const
Serialize statistics as a pvl group.
double m_minimum
Minimum double value encountered.
double m_maximum
Maximum double value encountered.
double m_validMaximum
Maximum valid pixel value.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
double Rms() const
Computes and returns the rms.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
BigInt LrsPixels() const
Returns the total number of low representation saturation (LRS) pixels encountered.
void fromPvl(const PvlGroup &inStats)
Unserializes a Statistics object from a pvl group.
void RemoveData(const double *data, const unsigned int count)
Remove an array of doubles from the accumulators and counters.
double StandardDeviation() const
Computes and returns the standard deviation.
double Variance() const
Computes and returns the variance.
BigInt m_underRangePixels
Count of pixels less than the valid range.
BigInt m_hrsPixels
Count of high instrument saturation pixels processed.
BigInt m_overRangePixels
Count of pixels greater than the valid range.
Statistics(QObject *parent=0)
Constructs an IsisStats object with accumulators and counters set to zero.
void Reset()
Reset all accumulators and counters to zero.
double m_sumsum
The sum-squared accumulator, i.e.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
const double ValidMaximum
The maximum valid double value for Isis pixels.
bool IsNullPixel(const double d)
Returns if the input pixel is null.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
long long int BigInt
Big int.
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
const double ValidMinimum
The minimum valid double value for Isis pixels.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
double toDouble(const QString &string)
Global function to convert from a string to a double.
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Namespace for the standard library.