22 #include <QDataStream>
26 #include <QXmlStreamWriter>
39 #include "XmlStackedHandlerReader.h"
57 xmlReader->pushContentHandler(
new XmlHandler(
this, project));
74 m_sumsum(other.m_sumsum),
75 m_minimum(other.m_minimum),
76 m_maximum(other.m_maximum),
77 m_validMinimum(other.m_validMinimum),
78 m_validMaximum(other.m_validMaximum),
79 m_totalPixels(other.m_totalPixels),
80 m_validPixels(other.m_validPixels),
81 m_nullPixels(other.m_nullPixels),
82 m_lrsPixels(other.m_lrsPixels),
83 m_lisPixels(other.m_lisPixels),
84 m_hrsPixels(other.m_hrsPixels),
85 m_hisPixels(other.m_hisPixels),
86 m_underRangePixels(other.m_underRangePixels),
87 m_overRangePixels(other.m_overRangePixels),
88 m_removedData(other.m_removedData) {
102 if (&other !=
this) {
159 for(
unsigned int i = 0; i < count; i++) {
160 double value = data[i];
193 else if (AboveRange(data)) {
196 else if (BelowRange(data)) {
225 for(
unsigned int i = 0; i < count; i++) {
226 double value = data[i];
252 else if (AboveRange(data)) {
255 else if (BelowRange(data)) {
265 QString msg =
"You are removing non-existant data in [Statistics::RemoveData]";
272 void Statistics::SetValidRange(
const double minimum,
const double maximum) {
278 QString msg =
"Invalid Range: Minimum [" +
toString(minimum)
279 +
"] must be less than the Maximum [" +
toString(maximum) +
"].";
286 double Statistics::ValidMinimum()
const {
291 double Statistics::ValidMaximum()
const {
296 bool Statistics::InRange(
const double value) {
297 return (!BelowRange(value) && !AboveRange(value));
301 bool Statistics::AboveRange(
const double value) {
306 bool Statistics::BelowRange(
const double value) {
348 if (temp < 0.0) temp = 0.0;
385 if (temp < 0.0) temp = 0.0;
401 QString msg =
"Minimum is invalid since you removed data";
422 QString msg =
"Maximum is invalid since you removed data";
542 bool Statistics::RemovedData()
const {
563 if ((percent <= 0.0) || (percent >= 100.0)) {
564 QString msg =
"Invalid value for percent";
569 double k = sqrt(1.0 / (1.0 - percent / 100.0));
590 if ((percent <= 0.0) || (percent >= 100.0)) {
591 QString msg =
"Invalid value for percent";
596 double k = sqrt(1.0 / (1.0 - percent / 100.0));
660 if (value ==
Maximum())
return 0;
662 QString msg =
"Undefined Z-score. Standard deviation is zero and the input value["
678 m_sum = inStats[
"Sum"];
705 if (name.isEmpty()) {
735 void Statistics::save(QXmlStreamWriter &stream,
const Project *project)
const {
737 stream.writeStartElement(
"statistics");
743 stream.writeStartElement(
"range");
748 stream.writeEndElement();
750 stream.writeStartElement(
"pixelCounts");
760 stream.writeEndElement();
763 stream.writeEndElement();
768 Statistics::XmlHandler::XmlHandler(Statistics *statistics, Project *project) {
769 m_xmlHandlerStatistics = statistics;
770 m_xmlHandlerProject = project;
771 m_xmlHandlerCharacters =
"";
775 Statistics::XmlHandler::~XmlHandler() {
778 m_xmlHandlerProject = NULL;
782 bool Statistics::XmlHandler::startElement(
const QString &namespaceURI,
783 const QString &localName,
784 const QString &qName,
785 const QXmlAttributes &atts) {
786 m_xmlHandlerCharacters =
"";
787 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
794 bool Statistics::XmlHandler::characters(
const QString &ch) {
795 m_xmlHandlerCharacters += ch;
796 return XmlStackedHandler::characters(ch);
800 bool Statistics::XmlHandler::endElement(
const QString &namespaceURI,
const QString &localName,
801 const QString &qName) {
802 if (!m_xmlHandlerCharacters.isEmpty()) {
803 if (localName ==
"id") {
807 if (localName ==
"sum") {
808 m_xmlHandlerStatistics->m_sum =
toDouble(m_xmlHandlerCharacters);
810 if (localName ==
"sumSquares") {
811 m_xmlHandlerStatistics->m_sumsum =
toDouble(m_xmlHandlerCharacters);
813 if (localName ==
"minimum") {
814 m_xmlHandlerStatistics->m_minimum =
toDouble(m_xmlHandlerCharacters);
816 if (localName ==
"maximum") {
817 m_xmlHandlerStatistics->m_maximum =
toDouble(m_xmlHandlerCharacters);
819 if (localName ==
"validMinimum") {
820 m_xmlHandlerStatistics->m_validMinimum =
toDouble(m_xmlHandlerCharacters);
822 if (localName ==
"validMaximum") {
823 m_xmlHandlerStatistics->m_validMaximum =
toDouble(m_xmlHandlerCharacters);
825 if (localName ==
"totalPixels") {
826 m_xmlHandlerStatistics->m_totalPixels =
toBigInt(m_xmlHandlerCharacters);
828 if (localName ==
"validPixels") {
829 m_xmlHandlerStatistics->m_validPixels =
toBigInt(m_xmlHandlerCharacters);
831 if (localName ==
"nullPixels") {
832 m_xmlHandlerStatistics->m_nullPixels =
toBigInt(m_xmlHandlerCharacters);
834 if (localName ==
"lisPixels") {
835 m_xmlHandlerStatistics->m_lisPixels =
toBigInt(m_xmlHandlerCharacters);
837 if (localName ==
"lrsPixels") {
838 m_xmlHandlerStatistics->m_lrsPixels =
toBigInt(m_xmlHandlerCharacters);
840 if (localName ==
"hisPixels") {
841 m_xmlHandlerStatistics->m_hisPixels =
toBigInt(m_xmlHandlerCharacters);
843 if (localName ==
"hrsPixels") {
844 m_xmlHandlerStatistics->m_hrsPixels =
toBigInt(m_xmlHandlerCharacters);
846 if (localName ==
"underRangePixels") {
847 m_xmlHandlerStatistics->m_underRangePixels =
toBigInt(m_xmlHandlerCharacters);
849 if (localName ==
"overRangePixels") {
850 m_xmlHandlerStatistics->m_overRangePixels =
toBigInt(m_xmlHandlerCharacters);
852 if (localName ==
"removedData") {
853 m_xmlHandlerStatistics->m_removedData =
toBool(m_xmlHandlerCharacters);
855 m_xmlHandlerCharacters =
"";
857 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
866 stream.setByteOrder(QDataStream::LittleEndian);
888 QDataStream &Statistics::read(QDataStream &stream) {
891 qint64 totalPixels, validPixels, nullPixels, lrsPixels, lisPixels,
892 hrsPixels, hisPixels, underRangePixels, overRangePixels;
895 stream.setByteOrder(QDataStream::LittleEndian);
934 return statistics.write(stream);
939 return statistics.read(stream);
954 H5::CompType compoundDataType((
size_t)124);
957 compoundDataType.insertMember(
"Sum", offset, H5::PredType::NATIVE_DOUBLE);
960 offset +=
sizeof(double);
961 compoundDataType.insertMember(
"SumSquared", offset, H5::PredType::NATIVE_DOUBLE);
964 offset +=
sizeof(double);
965 compoundDataType.insertMember(
"Minimum", offset, H5::PredType::NATIVE_DOUBLE);
968 offset +=
sizeof(double);
969 compoundDataType.insertMember(
"Maximum", offset, H5::PredType::NATIVE_DOUBLE);
972 offset +=
sizeof(double);
973 compoundDataType.insertMember(
"ValidMinimum", offset, H5::PredType::NATIVE_DOUBLE);
976 offset +=
sizeof(double);
977 compoundDataType.insertMember(
"ValidMaximum", offset, H5::PredType::NATIVE_DOUBLE);
980 offset +=
sizeof(double);
981 compoundDataType.insertMember(
"TotalPixels", offset, H5::PredType::NATIVE_INT64);
984 offset +=
sizeof(BigInt);
985 compoundDataType.insertMember(
"ValidPixels", offset, H5::PredType::NATIVE_INT64);
988 offset +=
sizeof(BigInt);
989 compoundDataType.insertMember(
"NullPixels", offset, H5::PredType::NATIVE_INT64);
992 offset +=
sizeof(BigInt);
993 compoundDataType.insertMember(
"LRSPixels", offset, H5::PredType::NATIVE_INT64);
996 offset +=
sizeof(BigInt);
997 compoundDataType.insertMember(
"LISPixels", offset, H5::PredType::NATIVE_INT64);
1000 offset +=
sizeof(BigInt);
1001 compoundDataType.insertMember(
"HRSPixels", offset, H5::PredType::NATIVE_INT64);
1004 offset +=
sizeof(BigInt);
1005 compoundDataType.insertMember(
"HISPixels", offset, H5::PredType::NATIVE_INT64);
1008 offset +=
sizeof(BigInt);
1009 compoundDataType.insertMember(
"UnderRangePixels", offset, H5::PredType::NATIVE_INT64);
1012 offset +=
sizeof(BigInt);
1013 compoundDataType.insertMember(
"OverRangePixels", offset, H5::PredType::NATIVE_INT64);
1016 offset +=
sizeof(BigInt);
1017 compoundDataType.insertMember(
"RemovedData", offset, H5::PredType::NATIVE_HBOOL);
1021 return compoundDataType;
BigInt LisPixels() const
Returns the total number of low instrument saturation (LIS) pixels encountered.
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
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...
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 cnetsuite.
QDataStream & write(QDataStream &stream) const
Order saved must match the offsets in the static compoundH5DataType() method.
BigInt NullPixels() const
Returns the total number of NULL pixels encountered.
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
static H5::CompType compoundH5DataType()
H5 compound data type uses the offesets from the QDataStream returned by the write(QDataStream &strea...
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
double BestMaximum(const double percent=99.5) const
This method returns the better of the absolute maximum or the Chebyshev maximum.
double Rms() const
Computes and returns the rms.
BigInt m_lisPixels
Count of low representation saturation pixels processed.
BigInt HisPixels() const
Returns the total number of high instrument saturation (HIS) 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.
PvlGroup toPvl(QString name="Statistics") const
Serialize statistics as a pvl group.
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.
double Variance() const
Computes and returns the variance.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
double m_sum
The sum accumulator, i.e. the sum of added data values.
double StandardDeviation() const
Computes and returns the standard deviation.
double Sum() const
Returns the sum of all the data.
double ZScore(const double value) const
This method returns the better of the z-score of the given value.
BigInt m_hrsPixels
Count of high instrument saturation pixels processed.
This class is used to accumulate statistics on double arrays.
BigInt HrsPixels() const
Returns the total number of high representation saturation (HRS) pixels encountered.
BigInt TotalPixels() const
Returns the total number of pixels processed (valid and invalid).
BigInt m_validPixels
Count of valid pixels (non-special) processed.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
Contains multiple PvlContainers.
double Average() const
Computes and returns the average.
void Reset()
Reset all accumulators and counters to zero.
#define _FILEINFO_
Macro for the filename and line number.
BigInt LrsPixels() const
Returns the total number of low representation saturation (LRS) pixels encountered.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
A single keyword-value pair.
double m_sumsum
The sum-squared accumulator, i.e.
double m_minimum
Minimum double value encountered.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
BigInt OutOfRangePixels() const
Returns the total number of pixels outside of the valid range encountered.
Statistics(QObject *parent=0)
Constructs an IsisStats object with accumulators and counters set to zero.
bool m_removedData
Indicates the RemoveData method was called which implies m_minimum and m_maximum are invalid...
BigInt UnderRangePixels() const
Returns the total number of pixels under the valid range encountered.
double SumSquare() const
Returns the sum of all the squared data.
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.
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.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
double BestMinimum(const double percent=99.5) const
This method returns the better of the absolute minimum or the Chebyshev minimum.
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.
his enables stack-based XML parsing of XML files.
virtual ~Statistics()
Destroys the IsisStats object.
BigInt m_underRangePixels
Count of pixels less than the valid range.
BigInt OverRangePixels() const
Returns the total number of pixels over the valid range encountered.