USGS

Isis 3.0 Application Source Code Reference

Home

ZeroReverse.h

Go to the documentation of this file.
00001 #ifndef ZeroReverse_h
00002 #define ZeroReverse_h
00003 /**                                                                       
00004  * @file                                                                  
00005  * $Revision: 1.3 $
00006  * $Date: 2008/11/18 07:29:12 $
00007  * $Id: ZeroReverse.h,v 1.3 2008/11/18 07:29:12 kbecker Exp $
00008  * 
00009  *   Unless noted otherwise, the portions of Isis written by the USGS are 
00010  *   public domain. See individual third-party library and package descriptions 
00011  *   for intellectual property information, user agreements, and related  
00012  *   information.                                                         
00013  *                                                                        
00014  *   Although Isis has been used by the USGS, no warranty, expressed or   
00015  *   implied, is made by the USGS as to the accuracy and functioning of such 
00016  *   software and related material nor shall the fact of distribution     
00017  *   constitute any such warranty, and no responsibility is assumed by the
00018  *   USGS in connection therewith.                                        
00019  *                                                                        
00020  *   For additional information, launch                                   
00021  *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html                
00022  *   in a browser or see the Privacy & Disclaimers page on the Isis website,
00023  *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
00024  *   http://www.usgs.gov/privacy.html.                                    
00025  */                                                                       
00026 #include <cmath>
00027 #include <string>
00028 #include <vector>
00029 #include <iostream>
00030 #include <sstream>
00031 
00032 
00033 #include "IString.h"
00034 #include "HiCalTypes.h"
00035 #include "HiCalUtil.h"
00036 #include "HiCalConf.h"
00037 #include "Module.h"
00038 #include "SplineFill.h"
00039 #include "Statistics.h"
00040 #include "SpecialPixel.h"
00041 #include "IException.h"
00042 
00043 namespace Isis {
00044 
00045   /**
00046    * @brief Processes Reverse Clock calibration data (ZeroReverse Module)
00047    * 
00048    * This class loads and processes the Reverse Clock data from a  HiRISE image
00049    * for offset correction purposes.   Additional processing may occur in 
00050    * subsequent modules. 
00051    *  
00052    * @ingroup Utility
00053    * 
00054    * @author 2008-06-13 Kris Becker 
00055    * @internal 
00056    *   @history 2010-04-16 Kris Becker Renamed from Zf to ZeroReverse
00057    *   @history 2010-10-28 Kris Becker Renamed parameters replacing "Zz" with
00058    *            "ZeroReverse".
00059    */
00060   class ZeroReverse : public Module {
00061 
00062     public: 
00063       //  Constructors and Destructor
00064       ZeroReverse() : Module("ZeroReverse") { }
00065       ZeroReverse(HiCalData &cal, const HiCalConf &conf) : 
00066                   Module("ZeroReverse") { 
00067         init(cal, conf);
00068       }
00069 
00070       /** Destructor */
00071       virtual ~ZeroReverse() { }
00072 
00073       /** 
00074        * @brief Return statistics for raw Reverse Clock buffer
00075        * 
00076        * @return const Statistics&  Statistics class with all stats
00077        */
00078       const Statistics &Stats() const { return (_stats); }
00079 
00080       /**
00081        * @brief Specifies if the input trigger conditions were met
00082        *  
00083        * If trigger conditions where met, the reverse clock correction becomes a 
00084        * constant as opposed to processed reverse clock pixels. 
00085        * 
00086        * @return bool True if triggered, false otherwise
00087        */
00088       bool wasTriggered() const { return (_triggered); }
00089 
00090     private:
00091       HiVector   _revClock;
00092       Statistics _stats;
00093       bool       _triggered;
00094 
00095 
00096       /**
00097        * @brief Initialize and compute data solution 
00098        *  
00099        * 
00100        * @author Kris Becker - 4/16/2010
00101        * 
00102        * @param cal  HiRISE calibration data provided 
00103        * @param conf Configuration data provider
00104        */
00105       void init(HiCalData &cal, const HiCalConf &conf) {
00106         DbProfile prof = conf.getMatrixProfile();
00107         _history.clear();
00108         _history.add("Profile["+ prof.Name()+"]");
00109 
00110         int line0 = toInt(ConfKey(prof,"ZeroReverseFirstLine",QString("0")));
00111         int lineN = toInt(ConfKey(prof,"ZeroReverseLastLine",QString("19")));
00112         QString tfile= conf.getMatrixSource("ReverseClockStatistics",prof);
00113 
00114         HiMatrix revclk = cropLines(cal.getReverseClock(), line0, lineN);
00115         _stats.Reset();
00116         _stats.AddData(revclk[0], revclk.dim1()*revclk.dim2());
00117 
00118         _revClock = averageLines(revclk);
00119        _history.add("RevClock(CropLines["+ToString(line0)+","+ToString(lineN) +
00120                     "],Mean["+ToString(_stats.Average()) + 
00121                      "],StdDev["+ToString(_stats.StandardDeviation()) +
00122                      "],LisPixels["+ToString(_stats.LisPixels())+
00123                      "],HisPixels["+ToString(_stats.HisPixels()) +
00124                      "],NulPixels["+ToString(_stats.NullPixels())+ "])");
00125 
00126        DbAccess triggers(Pvl(tfile).FindObject("ReverseClockStatistics"));
00127        QString tprofName = conf.resolve("{FILTER}{CCD}_{CHANNEL}_{BIN}",prof); 
00128        _history.add("ReverseClockStatistics(File["+tfile+
00129                     "],Profile["+tprofName+"])");
00130 
00131        _triggered= false;
00132        if (triggers.profileExists(tprofName)) {
00133          DbProfile tprof(prof, triggers.getProfile(tprofName), tprofName);
00134          double revmean = toDouble(ConfKey(tprof,"RevMeanTrigger", toString(_stats.Average())));
00135          double revstddev = toDouble(ConfKey(tprof,"RevStdDevTrigger", toString(DBL_MAX)));
00136          int lisTol = toInt(ConfKey(tprof, "RevLisTolerance", toString(1)));
00137          int hisTol = toInt(ConfKey(tprof, "RevHisTolerance", toString(1)));
00138          int nulTol = toInt(ConfKey(tprof, "RevNulTolerance", toString(1)));
00139 
00140          _history.add("TriggerLimits(RevMeanTrigger["+ToString(revmean) +
00141                       "],RevStdDevTrigger["+ToString(revstddev)+
00142                       "],RevLisTolerance["+ToString(lisTol)+
00143                       "],RevHisTolerance["+ToString(hisTol)+
00144                       "],RevNulTolerance["+ToString(nulTol)+ "])");
00145 
00146          if ((_stats.LisPixels() > lisTol) || (_stats.HisPixels() > hisTol) ||
00147              (_stats.NullPixels() > nulTol) || 
00148              (_stats.StandardDeviation() > revstddev)) { 
00149            _triggered = true;
00150            _data = HiVector(_revClock.dim1(), revmean);
00151            _history.add("Trigger(True - Reverse Clock set to constant,"
00152                         "ReverseClock["+ToString(revmean)+"])"); 
00153          }
00154          else {
00155            _history.add("Trigger(False - Reverse Clock processing invoked)");
00156            _triggered = false;
00157          }
00158        }
00159        else {
00160          _history.add("Trigger(Profile["+tprofName+"],NotFound!)");
00161          _triggered = false;
00162        }
00163 
00164        if (!_triggered) {
00165         SplineFill spline(_revClock, _history);
00166         _data = spline.ref();
00167         _history = spline.History();
00168        }
00169 
00170         return;
00171       }
00172 
00173       /** Virtual dump of data processing vectors */
00174       virtual void printOn(std::ostream &o) const {
00175         o << "#  History = " << _history << std::endl;
00176         //  Write out the header
00177         o << std::setw(_fmtWidth)   << "RevClock"
00178           << std::setw(_fmtWidth+1) << "Applied\n";
00179 
00180         for (int i = 0 ; i < _data.dim() ; i++) {
00181           o << formatDbl(_revClock[i]) << " "
00182             << formatDbl(_data[i]) << std::endl;
00183         }
00184         return;
00185       }
00186 
00187   };
00188 
00189 }     // namespace Isis
00190 #endif
00191