22 #include <QDataStream> 26 #include <QXmlStreamWriter> 35 #include "XmlStackedHandlerReader.h" 70 m_sumsum(other.m_sumsum),
71 m_minimum(other.m_minimum),
72 m_maximum(other.m_maximum),
73 m_validMinimum(other.m_validMinimum),
74 m_validMaximum(other.m_validMaximum),
75 m_totalPixels(other.m_totalPixels),
76 m_validPixels(other.m_validPixels),
77 m_nullPixels(other.m_nullPixels),
78 m_lrsPixels(other.m_lrsPixels),
79 m_lisPixels(other.m_lisPixels),
80 m_hrsPixels(other.m_hrsPixels),
81 m_hisPixels(other.m_hisPixels),
82 m_underRangePixels(other.m_underRangePixels),
83 m_overRangePixels(other.m_overRangePixels),
84 m_removedData(other.m_removedData) {
155 for(
unsigned int i = 0; i < count; i++) {
156 double value = data[i];
189 else if (AboveRange(data)) {
192 else if (BelowRange(data)) {
221 for(
unsigned int i = 0; i < count; i++) {
222 double value = data[i];
248 else if (AboveRange(data)) {
251 else if (BelowRange(data)) {
261 QString msg =
"You are removing non-existant data in [Statistics::RemoveData]";
268 void Statistics::SetValidRange(
const double minimum,
const double maximum) {
274 QString msg =
"Invalid Range: Minimum [" +
toString(minimum)
275 +
"] must be less than the Maximum [" +
toString(maximum) +
"].";
282 double Statistics::ValidMinimum()
const {
287 double Statistics::ValidMaximum()
const {
292 bool Statistics::InRange(
const double value) {
293 return (!BelowRange(value) && !AboveRange(value));
297 bool Statistics::AboveRange(
const double value) {
302 bool Statistics::BelowRange(
const double value) {
344 if (temp < 0.0) temp = 0.0;
381 if (temp < 0.0) temp = 0.0;
397 QString msg =
"Minimum is invalid since you removed data";
418 QString msg =
"Maximum is invalid since you removed data";
538 bool Statistics::RemovedData()
const {
559 if ((percent <= 0.0) || (percent >= 100.0)) {
560 QString msg =
"Invalid value for percent";
565 double k = sqrt(1.0 / (1.0 - percent / 100.0));
586 if ((percent <= 0.0) || (percent >= 100.0)) {
587 QString msg =
"Invalid value for percent";
592 double k = sqrt(1.0 / (1.0 - percent / 100.0));
656 if (value ==
Maximum())
return 0;
658 QString msg =
"Undefined Z-score. Standard deviation is zero and the input value[" 674 m_sum = inStats[
"Sum"];
701 if (name.isEmpty()) {
731 void Statistics::save(QXmlStreamWriter &stream,
const Project *project)
const {
733 stream.writeStartElement(
"statistics");
739 stream.writeStartElement(
"range");
744 stream.writeEndElement();
746 stream.writeStartElement(
"pixelCounts");
756 stream.writeEndElement();
759 stream.writeEndElement();
764 Statistics::XmlHandler::XmlHandler(Statistics *statistics, Project *project) {
765 m_xmlHandlerStatistics = statistics;
766 m_xmlHandlerProject = project;
767 m_xmlHandlerCharacters =
"";
771 Statistics::XmlHandler::~XmlHandler() {
774 m_xmlHandlerProject = NULL;
778 bool Statistics::XmlHandler::startElement(
const QString &namespaceURI,
779 const QString &localName,
780 const QString &qName,
781 const QXmlAttributes &atts) {
782 m_xmlHandlerCharacters =
"";
783 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
790 bool Statistics::XmlHandler::characters(
const QString &ch) {
791 m_xmlHandlerCharacters += ch;
792 return XmlStackedHandler::characters(ch);
796 bool Statistics::XmlHandler::endElement(
const QString &namespaceURI,
const QString &localName,
797 const QString &qName) {
798 if (!m_xmlHandlerCharacters.isEmpty()) {
799 if (localName ==
"id") {
803 if (localName ==
"sum") {
804 m_xmlHandlerStatistics->m_sum =
toDouble(m_xmlHandlerCharacters);
806 if (localName ==
"sumSquares") {
807 m_xmlHandlerStatistics->m_sumsum =
toDouble(m_xmlHandlerCharacters);
809 if (localName ==
"minimum") {
810 m_xmlHandlerStatistics->m_minimum =
toDouble(m_xmlHandlerCharacters);
812 if (localName ==
"maximum") {
813 m_xmlHandlerStatistics->m_maximum =
toDouble(m_xmlHandlerCharacters);
815 if (localName ==
"validMinimum") {
816 m_xmlHandlerStatistics->m_validMinimum =
toDouble(m_xmlHandlerCharacters);
818 if (localName ==
"validMaximum") {
819 m_xmlHandlerStatistics->m_validMaximum =
toDouble(m_xmlHandlerCharacters);
821 if (localName ==
"totalPixels") {
822 m_xmlHandlerStatistics->m_totalPixels =
toBigInt(m_xmlHandlerCharacters);
824 if (localName ==
"validPixels") {
825 m_xmlHandlerStatistics->m_validPixels =
toBigInt(m_xmlHandlerCharacters);
827 if (localName ==
"nullPixels") {
828 m_xmlHandlerStatistics->m_nullPixels =
toBigInt(m_xmlHandlerCharacters);
830 if (localName ==
"lisPixels") {
831 m_xmlHandlerStatistics->m_lisPixels =
toBigInt(m_xmlHandlerCharacters);
833 if (localName ==
"lrsPixels") {
834 m_xmlHandlerStatistics->m_lrsPixels =
toBigInt(m_xmlHandlerCharacters);
836 if (localName ==
"hisPixels") {
837 m_xmlHandlerStatistics->m_hisPixels =
toBigInt(m_xmlHandlerCharacters);
839 if (localName ==
"hrsPixels") {
840 m_xmlHandlerStatistics->m_hrsPixels =
toBigInt(m_xmlHandlerCharacters);
842 if (localName ==
"underRangePixels") {
843 m_xmlHandlerStatistics->m_underRangePixels =
toBigInt(m_xmlHandlerCharacters);
845 if (localName ==
"overRangePixels") {
846 m_xmlHandlerStatistics->m_overRangePixels =
toBigInt(m_xmlHandlerCharacters);
848 if (localName ==
"removedData") {
849 m_xmlHandlerStatistics->m_removedData =
toBool(m_xmlHandlerCharacters);
851 m_xmlHandlerCharacters =
"";
853 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
862 stream.setByteOrder(QDataStream::LittleEndian);
884 QDataStream &Statistics::read(QDataStream &stream) {
887 qint64 totalPixels, validPixels, nullPixels, lrsPixels, lisPixels,
888 hrsPixels, hisPixels, underRangePixels, overRangePixels;
891 stream.setByteOrder(QDataStream::LittleEndian);
930 return statistics.write(stream);
935 return statistics.read(stream);
long long int BigInt
Big int.
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
void RemoveData(const double *data, const unsigned int count)
Remove an array of doubles from the accumulators and counters.
BigInt m_nullPixels
Count of null pixels processed.
The main project for ipce.
double Sum() const
Returns the sum of all the data.
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
double StandardDeviation() const
Computes and returns the standard deviation.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
double SumSquare() const
Returns the sum of all the squared data.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
BigInt m_lisPixels
Count of low representation saturation pixels processed.
Namespace for the standard library.
BigInt HrsPixels() const
Returns the total number of high representation saturation (HRS) pixels encountered.
void fromPvl(const PvlGroup &inStats)
Unserializes a Statistics object from a pvl group.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
BigInt HisPixels() const
Returns the total number of high instrument saturation (HIS) pixels encountered.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
BigInt NullPixels() const
Returns the total number of NULL pixels encountered.
BigInt OverRangePixels() const
Returns the total number of pixels over the valid range encountered.
double m_sum
The sum accumulator, i.e. the sum of added data values.
BigInt TotalPixels() const
Returns the total number of pixels processed (valid and invalid).
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
BigInt m_hrsPixels
Count of high instrument saturation pixels processed.
This class is used to accumulate statistics on double arrays.
QDataStream & write(QDataStream &stream) const
Order saved must match the offsets in the static compoundH5DataType() method.
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
BigInt OutOfRangePixels() const
Returns the total number of pixels outside of the valid range encountered.
PvlGroup toPvl(QString name="Statistics") const
Serialize statistics as a pvl group.
BigInt LisPixels() const
Returns the total number of low instrument saturation (LIS) pixels encountered.
BigInt m_validPixels
Count of valid pixels (non-special) processed.
Contains multiple PvlContainers.
void Reset()
Reset all accumulators and counters to zero.
#define _FILEINFO_
Macro for the filename and line number.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
A single keyword-value pair.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
double m_sumsum
The sum-squared accumulator, i.e.
double Variance() const
Computes and returns the variance.
double m_minimum
Minimum double value encountered.
BigInt UnderRangePixels() const
Returns the total number of pixels under the valid range encountered.
Statistics(QObject *parent=0)
Constructs an IsisStats object with accumulators and counters set to zero.
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 Rms() const
Computes and returns the rms.
bool m_removedData
Indicates the RemoveData method was called which implies m_minimum and m_maximum are invalid...
BigInt LrsPixels() const
Returns the total number of low representation saturation (LRS) pixels encountered.
BigInt m_overRangePixels
Count of pixels greater than the valid range.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.
double m_maximum
Maximum double value encountered.
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_totalPixels
Count of total pixels processed.
Namespace for ISIS/Bullet specific routines.
bool IsNullPixel(const double d)
Returns if the input pixel is null.
double m_validMaximum
Maximum valid pixel value.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
double ZScore(const double value) const
This method returns the better of the z-score of the given value.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
BigInt m_hisPixels
Count of high instrument representation pixels processed.
double m_validMinimum
Minimum valid pixel value.
BigInt m_lrsPixels
Count of low instrument saturation pixels processed.
double Average() const
Computes and returns the average.
Manage a stack of content handlers for reading XML files.
virtual ~Statistics()
Destroys the IsisStats object.
BigInt m_underRangePixels
Count of pixels less than the valid range.