USGS

Isis 3.0 Application Source Code Reference

Home

ZeroBufferSmooth.h

Go to the documentation of this file.
00001 #if !defined(ZeroBufferSmooth_h)
00002 #define ZeroBufferSmooth_h
00003 /**                                                                       
00004  * @file                                                                  
00005  * $Revision: 3254 $
00006  * $Date: 2011-09-18 22:11:01 -0700 (Sun, 18 Sep 2011) $
00007  * $Id: ZeroBufferSmooth.h 3254 2011-09-19 05:11:01Z kbecker@GS.DOI.NET $
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 "LowPassFilter.h"
00040 #include "Statistics.h"
00041 #include "SpecialPixel.h"
00042 #include "iException.h"
00043 
00044 namespace Isis {
00045 
00046   /**
00047    * @brief Processes Buffer calibration data (ZeroBufferSmooth Module)
00048    * 
00049    * This class loads and processes the Buffer data from a HiRISE image for 
00050    * drift correction purposes.  The config file contains parameter 
00051    * (ZfFirstSample, ZfLastSample) that indicate which regions of the 
00052    * calibration buffer to extract/use.  This region is averaged across the line 
00053    * axis for each line resulting in a single value for each line.  The 
00054    * resulting vector is then filtered with a lowpass filter. The filter width 
00055    * (ZfFilterWidth) and number of interations (ZfFilterIterations) are 
00056    * contained within the config file. A spline fit is applied if any missing 
00057    * data remain after filtering. 
00058    *  
00059    * @ingroup Utility
00060    * 
00061    * @author 2008-06-10 Kris Becker 
00062    * @internal 
00063    *   @history 2010-04-16 Kris Becker Completed documentation
00064    *   @history 2010-10-28 Kris Becker Renamed parameters removing the "Zf"
00065    *            prefix and replacing with "ZeroBufferSmooth".
00066    */
00067   class ZeroBufferSmooth : public Module {
00068 
00069     public: 
00070       //  Constructors and Destructor
00071       ZeroBufferSmooth() : Module("ZeroBufferSmooth") { }
00072       /**
00073        * @brief Construct with data parameters
00074        *  
00075        * This constructor completely computes drift from data collected in a 
00076        * HiRISE image 
00077        * 
00078        * @param cal   Calibration data collection
00079        * @param conf  All necessary parameters for computations
00080        */
00081       ZeroBufferSmooth(HiCalData &cal, const HiCalConf &conf) : 
00082                   Module("ZeroBufferSmooth") { 
00083         init(cal, conf);
00084       }
00085 
00086       /** Destructor */
00087       virtual ~ZeroBufferSmooth() { }
00088 
00089       /** 
00090        * @brief Return statistics for filtered - raw Buffer
00091        * 
00092        * @return const Statistics&  Statistics class with all stats
00093        */
00094       const Statistics &Stats() const { return (_stats); }
00095 
00096     private:
00097       HiVector   _buffer;
00098       Statistics _stats;
00099 
00100       /**
00101        * @brief Workhorse of the zero buffer computation 
00102        *  
00103        * The default module, assumed to be the Zf module, is retrieved to 
00104        * provide parameter necessary to compute the drift correction for a 
00105        * HiRISE image. 
00106        * 
00107        * 
00108        * @param cal  Calibration data container/provider
00109        * @param conf Configuration parameter provider
00110        */
00111       void init(HiCalData &cal, const HiCalConf &conf) {
00112         DbProfile prof = conf.getMatrixProfile();
00113         _history.clear();
00114         _history.add("Profile["+ prof.Name()+"]");
00115 
00116         int samp0 = ConfKey(prof,"ZeroBufferSmoothFirstSample",0);
00117         int sampN = ConfKey(prof,"ZeroBufferSmoothLastSample",11);
00118         _buffer = averageSamples(cal.getBuffer(), samp0, sampN);
00119         _history.add("AveCols(Buffer["+ToString(samp0)+","+ToString(sampN)+"])");
00120 
00121         //  Smooth/filter the averages
00122         LowPassFilter bufter(_buffer, _history,
00123                           ConfKey(prof,"ZeroBufferSmoothFilterWidth",201),
00124                           ConfKey(prof,"ZeroBufferSmoothFilterIterations",2));
00125         //  If need be, fill the data with a cubic spline
00126         SplineFill spline(bufter);
00127         _data = spline.ref();
00128         _history = spline.History();
00129 
00130         //  Compute statistics and record to history
00131         _stats.Reset();
00132         for ( int i = 0 ; i < _data.dim() ; i++ ) {
00133           // Spline guarantees _data is non-null!
00134           if ( !IsSpecial(_buffer[i]) ) {
00135             _stats.AddData(_data[i] - _buffer[i]);
00136           }
00137         }
00138         _history.add("Statistics(Average["+ToString(_stats.Average())+
00139                      "],StdDev["+ToString(_stats.StandardDeviation())+"])"); 
00140         return;
00141       }
00142 
00143       /**
00144        * @brief Virtualized parameter reporting method 
00145        *  
00146        * This method is invoked when dumping the drift correction parameters. 
00147        * 
00148        * @param o Output stream to write results to
00149        */
00150       virtual void printOn(std::ostream &o) const {
00151         o << "#  History = " << _history << std::endl;
00152         //  Write out the header
00153         o << std::setw(_fmtWidth)   << "RawBuffer"
00154           << std::setw(_fmtWidth+1) << "Filtered\n";
00155 
00156         for (int i = 0 ; i < _data.dim() ; i++) {
00157           o << formatDbl(_buffer[i]) << " "
00158             << formatDbl(_data[i]) << std::endl;
00159         }
00160         return;
00161       }
00162 
00163   };
00164 
00165 }     // namespace Isis
00166 #endif
00167