Commit f7aea713 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

Preliminary hdf serialization for Bundle classes.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@6344 41f8697f-d340-4b68-9986-7bafba869bb8
parent 52c3f433
Loading
Loading
Loading
Loading
+131 −63
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@

#include <float.h>

#include <H5Cpp.h>
#include <hdf5_hl.h>
#include <hdf5.h>

#include "IException.h"
#include "IString.h"
#include "Project.h"
@@ -37,27 +41,23 @@ using namespace std;
namespace Isis {
  //! Constructs an IsisStats object with accumulators and counters set to zero.
  Statistics::Statistics(QObject *parent) : QObject(parent) {
    m_id = NULL;
    m_id = new QUuid(QUuid::createUuid());
//    m_id = NULL;
//    m_id = new QUuid(QUuid::createUuid());
    SetValidRange();
    Reset(); // initialize
  }



  Statistics::Statistics(Project *project, XmlStackedHandlerReader *xmlReader, QObject *parent) {   // TODO: does xml stuff need project???
    m_id = NULL;
//    m_id = NULL;
    SetValidRange();
    Reset(); // initialize
    xmlReader->pushContentHandler(new XmlHandler(this, project));   // TODO: does xml stuff need project???
  }




  Statistics::Statistics(const Statistics &other)
    : m_id(new QUuid(other.m_id->toString())),
      m_sum(other.m_sum),
    : m_sum(other.m_sum),
      m_sumsum(other.m_sumsum),
      m_minimum(other.m_minimum),
      m_maximum(other.m_maximum),
@@ -74,23 +74,22 @@ namespace Isis {
      m_overRangePixels(other.m_overRangePixels),
      m_removedData(other.m_removedData) {
  }

   // : m_id(new QUuid(other.m_id->toString())),


  //! Destroys the IsisStats object.
  Statistics::~Statistics() {
    delete m_id;
    m_id = NULL;
//    delete m_id;
//    m_id = NULL;
  }



  Statistics &Statistics::operator=(const Statistics &other) {

    if (&other != this) {
      delete m_id;
      m_id = NULL;
      m_id = new QUuid(other.m_id->toString());
//      delete m_id;
//      m_id = NULL;
//      m_id = new QUuid(other.m_id->toString());

      m_sum = other.m_sum;
      m_sumsum = other.m_sumsum;
@@ -114,7 +113,6 @@ namespace Isis {
  }



  //! Reset all accumulators and counters to zero.
  void Statistics::Reset() {
    m_sum = 0.0;
@@ -134,7 +132,6 @@ namespace Isis {
  }



  /**
   * Add an array of doubles to the accumulators and counters.
   * This method can be invoked multiple times (for example: once
@@ -153,7 +150,6 @@ namespace Isis {
  }



  /**
   * Add a double to the accumulators and counters. This method
   * can be invoked multiple times (for example: once for each
@@ -198,7 +194,6 @@ namespace Isis {
  }



  /**
   * Remove an array of doubles from the accumulators and counters.
   * Note that is invalidates the absolute minimum and maximum. They
@@ -213,7 +208,6 @@ namespace Isis {
   *    doesn't exist.
   */
  void Statistics::RemoveData(const double *data, const unsigned int count) {
    m_removedData = true;

    for(unsigned int i = 0; i < count; i++) {
      double value = data[i];
@@ -222,7 +216,9 @@ namespace Isis {

  }


  void Statistics::RemoveData(const double data) {
    m_removedData = true;
    m_totalPixels--;

    if (Isis::IsNullPixel(data)) {
@@ -256,8 +252,10 @@ namespace Isis {
      QString msg = "You are removing non-existant data in [Statistics::RemoveData]";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    // what happens to saved off min/max???
  }


  void Statistics::SetValidRange(const double minimum, const double maximum) {
    m_validMinimum = minimum;
    m_validMaximum = maximum;
@@ -268,40 +266,35 @@ namespace Isis {
                    + "] must be less than the Maximum [" + toString(maximum) + "].";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    //??? throw exception if data has already been added???
  }



  double Statistics::ValidMinimum() const {
    return m_validMinimum;
  }



  double Statistics::ValidMaximum() const {
    return m_validMaximum;
  }



  bool Statistics::InRange(const double value) {
    return (!BelowRange(value) && !AboveRange(value));
  }



  bool Statistics::AboveRange(const double value) {
    return (value > m_validMaximum);
  }



  bool Statistics::BelowRange(const double value) {
    return (value < m_validMinimum);
  }



  /**
   * Computes and returns the average.
   * If there are no valid pixels, then NULL8 is returned.
@@ -313,6 +306,7 @@ namespace Isis {
    return m_sum / m_validPixels;
  }


  /**
   * Computes and returns the standard deviation.
   * If there are no valid pixels, then NULL8 is returned.
@@ -324,6 +318,7 @@ namespace Isis {
    return sqrt(Variance());
  }


  /**
   * Computes and returns the variance.
   * If there are no valid pixels, then NULL8 is returned.
@@ -342,7 +337,6 @@ namespace Isis {
  }



  /**
   * Returns the sum of all the data
   *
@@ -353,7 +347,6 @@ namespace Isis {
  }



  /**
   * Returns the sum of all the squared data
   *
@@ -364,7 +357,6 @@ namespace Isis {
  }



  /**
   * Computes and returns the rms.
   * If there are no valid pixels, then NULL8 is returned.
@@ -381,6 +373,7 @@ namespace Isis {
    return sqrt(temp);
  }


  /**
   * Returns the absolute minimum double found in all data passed through the
   * AddData method. If there are no valid pixels, then NULL8 is returned.
@@ -400,6 +393,7 @@ namespace Isis {
    return m_minimum;
  }


  /**
   * Returns the absolute maximum double found in all
   * data passed through the AddData method. If there
@@ -420,6 +414,7 @@ namespace Isis {
    return m_maximum;
  }


  /**
   * Returns the total number of pixels processed
   * (valid and invalid).
@@ -430,6 +425,7 @@ namespace Isis {
    return m_totalPixels;
  }


  /**
   * Returns the total number of valid pixels processed.
   * Only valid pixels are utilized when computing the
@@ -442,6 +438,7 @@ namespace Isis {
    return m_validPixels;
  }


  /**
   * Returns the total number of pixels over the valid range
   *   encountered.
@@ -452,6 +449,7 @@ namespace Isis {
    return m_overRangePixels;
  }


  /**
   * Returns the total number of pixels under the valid range
   *   encountered.
@@ -462,6 +460,7 @@ namespace Isis {
    return m_underRangePixels;
  }


  /**
   * Returns the total number of NULL pixels encountered.
   *
@@ -471,6 +470,7 @@ namespace Isis {
    return m_nullPixels;
  }


  /**
   * Returns the total number of low instrument
   * saturation (LIS) pixels encountered.
@@ -481,6 +481,7 @@ namespace Isis {
    return m_lisPixels;
  }


  /**
   * Returns the total number of low representation
   * saturation (LRS) pixels encountered.
@@ -491,6 +492,7 @@ namespace Isis {
    return m_lrsPixels;
  }


  /**
   * Returns the total number of high instrument
   * saturation (HIS) pixels encountered.
@@ -501,6 +503,7 @@ namespace Isis {
    return m_hisPixels;
  }


  /**
   * Returns the total number of high representation
   * saturation (HRS) pixels encountered.
@@ -511,6 +514,7 @@ namespace Isis {
    return m_hrsPixels;
  }


  /**
   * Returns the total number of pixels outside of
   * the valid range encountered.
@@ -521,9 +525,12 @@ namespace Isis {
    return m_overRangePixels + m_underRangePixels;
  }


  bool Statistics::RemovedData() const {
    return m_removedData;
  }


  /**
   * This method returns a minimum such that X percent
   * of the data will fall with K standard deviations
@@ -550,6 +557,7 @@ namespace Isis {
    return Average() - k * StandardDeviation();
  }


  /**
   * This method returns a maximum such that
   * X percent of the data will fall with K
@@ -576,6 +584,7 @@ namespace Isis {
    return Average() + k * StandardDeviation();
  }


  /**
   * This method returns the better of the absolute
   * minimum or the Chebyshev minimum. The better
@@ -597,6 +606,7 @@ namespace Isis {
    return min;
  }


  /**
   *
   * This method returns the better of the absolute
@@ -619,6 +629,7 @@ namespace Isis {
    return max;
  }


  /**
   *
   * This method returns the better of the z-score
@@ -644,11 +655,10 @@ namespace Isis {
  }



  void Statistics::save(QXmlStreamWriter &stream, const Project *project) const {   // TODO: does xml stuff need project???

    stream.writeStartElement("statistics");
    stream.writeTextElement("id", m_id->toString());
//    stream.writeTextElement("id", m_id->toString());
 
    stream.writeTextElement("sum", toString(m_sum));
    stream.writeTextElement("sumSquares", toString(m_sumsum));
@@ -678,7 +688,6 @@ namespace Isis {
  }



  Statistics::XmlHandler::XmlHandler(Statistics *statistics, Project *project) {   // TODO: does xml stuff need project???
    m_xmlHandlerStatistics = statistics;
    m_xmlHandlerProject = project;   // TODO: does xml stuff need project???
@@ -686,7 +695,6 @@ namespace Isis {
  }



  Statistics::XmlHandler::~XmlHandler() {
    // do not delete this pointer... we don't own it, do we??? passed into StatCumProbDistDynCalc constructor as pointer
    // delete m_xmlHandlerProject;    // TODO: does xml stuff need project???
@@ -694,7 +702,6 @@ namespace Isis {
  }



  bool Statistics::XmlHandler::startElement(const QString &namespaceURI, 
                                                                const QString &localName,
                                                                const QString &qName,
@@ -707,20 +714,18 @@ namespace Isis {
  }



  bool Statistics::XmlHandler::characters(const QString &ch) {
    m_xmlHandlerCharacters += ch;
    return XmlStackedHandler::characters(ch);
  }



  bool Statistics::XmlHandler::endElement(const QString &namespaceURI, const QString &localName,
                                     const QString &qName) {
    if (!m_xmlHandlerCharacters.isEmpty()) {
      if (localName == "id") {
        m_xmlHandlerStatistics->m_id = NULL;
        m_xmlHandlerStatistics->m_id = new QUuid(m_xmlHandlerCharacters);
//        m_xmlHandlerStatistics->m_id = NULL;
//        m_xmlHandlerStatistics->m_id = new QUuid(m_xmlHandlerCharacters);
      }
      if (localName == "sum") {
        m_xmlHandlerStatistics->m_sum = toDouble(m_xmlHandlerCharacters);
@@ -776,38 +781,43 @@ namespace Isis {
  }



  /** 
   * Order saved must match the offsets in the static compoundH5DataType() 
   * method. 
   */ 
  QDataStream &Statistics::write(QDataStream &stream) const {
    stream << m_id->toString()
           << m_sum
    stream.setByteOrder(QDataStream::LittleEndian);
    stream << m_sum
           << m_sumsum
           << m_minimum
           << m_maximum
           << m_validMinimum
           << m_validMaximum
           << (qint32)m_totalPixels
           << (qint32)m_validPixels
           << (qint32)m_nullPixels
           << (qint32)m_lrsPixels
           << (qint32)m_lisPixels
           << (qint32)m_hrsPixels
           << (qint32)m_hisPixels
           << (qint32)m_underRangePixels
           << (qint32)m_overRangePixels
           << m_removedData;
           << (qint64)m_totalPixels
           << (qint64)m_validPixels
           << (qint64)m_nullPixels
           << (qint64)m_lrsPixels
           << (qint64)m_lisPixels
           << (qint64)m_hrsPixels
           << (qint64)m_hisPixels
           << (qint64)m_underRangePixels
           << (qint64)m_overRangePixels
           << (qint32)m_removedData;
    return stream;
//    stream << m_id->toString()
  }



  QDataStream &Statistics::read(QDataStream &stream) {

    QString id;
    qint32 totalPixels, validPixels, nullPixels, lrsPixels, lisPixels,
//    QString id;
    qint64 totalPixels, validPixels, nullPixels, lrsPixels, lisPixels,
           hrsPixels, hisPixels, underRangePixels, overRangePixels;
    qint32 removedData;

    stream >> id
           >> m_sum
    stream.setByteOrder(QDataStream::LittleEndian);
//    stream >> id
    stream >> m_sum
           >> m_sumsum
           >> m_minimum
           >> m_maximum
@@ -822,11 +832,11 @@ namespace Isis {
           >> hisPixels
           >> underRangePixels
           >> overRangePixels
           >> m_removedData;
           >> removedData;

    delete m_id;
    m_id = NULL;
    m_id = new QUuid(id);
//    delete m_id;
//    m_id = NULL;
//    m_id = new QUuid(id);

    m_totalPixels      = (BigInt)totalPixels;
    m_validPixels      = (BigInt)validPixels;
@@ -837,20 +847,78 @@ namespace Isis {
    m_hisPixels        = (BigInt)hisPixels;
    m_underRangePixels = (BigInt)underRangePixels;
    m_overRangePixels  = (BigInt)overRangePixels;
    
    m_removedData      = (bool)removedData;
    
    return stream;
  }



  QDataStream &operator<<(QDataStream &stream, const Statistics &statistics) {
    return statistics.write(stream);
  }



  QDataStream &operator>>(QDataStream &stream, Statistics &statistics) {
    return statistics.read(stream);
  }


  /** 
   *  H5 compound data type uses the offesets from the QDataStream returned by
   *  the write(QDataStream &stream) method.
   */
  H5::CompType Statistics::compoundH5DataType() {

    H5::CompType compoundDataType((size_t)124);

    size_t offset = 0;
    compoundDataType.insertMember("Sum", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_sum);
    compoundDataType.insertMember("SumSquared", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_sumsum);
    compoundDataType.insertMember("Minimum", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_minimum);
    compoundDataType.insertMember("Maximum", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_maximum);
    compoundDataType.insertMember("ValidMinimum", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_validMinimum);
    compoundDataType.insertMember("ValidMaximum", offset, H5::PredType::NATIVE_DOUBLE);

    offset += sizeof(m_validMaximum);
    compoundDataType.insertMember("TotalPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_totalPixels);
    compoundDataType.insertMember("ValidPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_validPixels);
    compoundDataType.insertMember("NullPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_nullPixels);
    compoundDataType.insertMember("LRSPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_lrsPixels);
    compoundDataType.insertMember("LISPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_lisPixels);
    compoundDataType.insertMember("HRSPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_hrsPixels);
    compoundDataType.insertMember("HISPixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_hisPixels);
    compoundDataType.insertMember("UnderRangePixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_underRangePixels);
    compoundDataType.insertMember("OverRangePixels", offset, H5::PredType::NATIVE_INT64);

    offset += sizeof(m_overRangePixels);
    compoundDataType.insertMember("RemovedData", offset, H5::PredType::NATIVE_HBOOL);

    return compoundDataType;
  }
} // end namespace isis
+17 −5
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@

#include <QObject>

#include <H5Cpp.h>
#include <hdf5_hl.h>
#include <hdf5.h>

#include "Constants.h"
#include "SpecialPixel.h"
#include "XmlStackedHandler.h"
@@ -74,15 +78,20 @@ namespace Isis {
   *   @history 2006-03-10 Jacob Danton - Added Z-score method
   *   @history 2007-01-18 Robert Sucharski - Added AddData method for a single double value
   *   @history 2008-05-06 Steven Lambright - Added AboveRange, BelowRange methods
  *   @history 2010-03-18 Sharmila Prasad  - Error message more meaningful for SetValidRange function
   *   @history 2010-03-18 Sharmila Prasad  - Error message more meaningful for SetValidRange
   *                           function
   *   @history 2011-06-13 Ken Edmundson - Added Rms method.
   *   @history 2011-06-23 Jeannie Backer - Added QDataStream read(), write() methods and added
   *                           QDataStream >> and << operators. Replaced std strings with QStrings.
   *   @history 2014-09-05 Jeannie Backer - Added xml read/write capabilities.  Moved method
   *                           implementation to cpp file. Improved coverage of unitTest. Brought
   *                           code closer to standards.
   *   @history 2015-09-03 Jeannie Backer - Added hdf5 read/write capabilities by adding
   *                           compoundH5DataType() static method.
   *
   *   @todo 2005-02-07 Deborah Lee Soltesz - add example using cube data to the class documentation
   *   @todo 2015-08-13 Jeannie Backer - Clean up header and implementation files once
   *                        serialization is implemented. (Remove xml, data stream, hdf, etc)
   *
   */
  class Statistics : public QObject {
@@ -145,6 +154,8 @@ namespace Isis {
      QDataStream &write(QDataStream &stream) const;
      QDataStream &read(QDataStream &stream);

      static H5::CompType compoundH5DataType();

    private:
      /**
       *
@@ -173,10 +184,11 @@ namespace Isis {
          QString m_xmlHandlerCharacters;
      };

      QUuid *m_id; /**< A unique ID for this object (useful for others to reference
                        this object when saving to disk).*/
      double m_sum;              //!< Sum accumulator.
      double m_sumsum;           //!< Sum-squared accumulator.
//      QUuid *m_id; /**< A unique ID for this object (useful for others to reference
//                        this object when saving to disk).*/
      double m_sum;              //!< The sum accumulator, i.e. the sum of added data values.
      double m_sumsum;           /**< The sum-squared accumulator, i.e. the sum of the squares
                                      of the  data values.*/
      double m_minimum;          //!< Minimum double value encountered.
      double m_maximum;          //!< Maximum double value encountered.
      double m_validMinimum;     //!< Minimum valid pixel value
+57 −37

File changed.

Preview size limit exceeded, changes collapsed.

+10 −2
Original line number Diff line number Diff line
@@ -196,6 +196,12 @@ namespace Isis {
   *                           users to use the outputFilePrefix to specify a file path without
   *                           adding an underscore to the file name. If the underscore is wanted,
   *                           it should be added to the prefix when entered by the user.
   *   @history 2015-09-03 Jeannie Backer - Changed the name of the output correlation matrix file
   *                           from ["inverseMatrix" + random unique code + ".dat"] to
   *                           [BundleSettings::outputFilePrefix() + "inverseMatrix.dat"]. So that
   *                           the prefix can be used to specify the path of the location where the
   *                           matrix file should be written. Some improvements made to comply with
   *                           coding standards.
   */
  class BundleAdjust : public QObject {
      Q_OBJECT
@@ -495,6 +501,10 @@ namespace Isis {

      BundleSettings m_bundleSettings; // pointer ??? then bundle settings method needs copy constructor ???
                                       // or constructors here take a const ref ???
      BundleResults  m_bundleResults;
//    BundleSolutionInfo m_bundleSolveInformation;


// unused variable ???      int m_nHeldPoints;                                     //!< number of 'held' points (define)
// unused variable ???      int m_nHeldObservations;                               //!< number of 'held' observations (define)
// ??? moved to bundle stats class    //!< vectors for statistical computations...
@@ -503,8 +513,6 @@ Statistics m_Statsy; //!< y errors
Statistics m_Statsrx;                      //!<  x residuals
Statistics m_Statsry;                      //!<  y residuals
Statistics m_Statsrxy;                     //!< xy residuals
    BundleResults m_bundleResults;
//    BundleSolutionInfo m_bundleSolveInformation;
  };
}

+625 −254

File changed.

Preview size limit exceeded, changes collapsed.

Loading