ImageTask.h

Go to the documentation of this file.
00001 #ifndef IMAGEANALYSIS_IMAGETASK_H
00002 #define IMAGEANALYSIS_IMAGETASK_H
00003 
00004 #include <casa/Containers/Record.h>
00005 
00006 #include <imageanalysis/ImageTypedefs.h>
00007 #include <imageanalysis/IO/OutputDestinationChecker.h>
00008 #include <imageanalysis/Regions/CasacRegionManager.h>
00009 
00010 #include <memory>
00011 
00012 #include <components/ComponentModels/C11Timer.h>
00013 
00014 namespace casac {
00015 class variant;
00016 }
00017 
00018 namespace casa {
00019 class LogFile;
00020 template <class T> class ArrayLattice;
00021 
00022 template <class T> class ImageTask {
00023 
00024     // <summary>
00025     // Virtual base class for image analysis tasks.
00026     // </summary>
00027 
00028     // <reviewed reviewer="" date="" tests="" demos="">
00029     // </reviewed>
00030 
00031     // <prerequisite>
00032     // </prerequisite>
00033 
00034     // <etymology>
00035     // Image tasking
00036     // </etymology>
00037 
00038     // <synopsis>
00039     // Virtual base class for image tasking.
00040     // </synopsis>
00041 
00042 public:
00043 
00044     // verbosity levels
00045     enum Verbosity {
00046         QUIET,
00047         WHISPER,
00048         LOW,
00049         NORMAL,
00050         HIGH,
00051         NOISY,
00052         DEAFENING
00053     };
00054 
00055     virtual ~ImageTask();
00056 
00057     virtual String getClass() const = 0;
00058 
00059     inline void setStretch(const Bool stretch) { _stretch = stretch;}
00060 
00061     // tacitly does nothing if <src>lf</src> is the empty string.
00062     void setLogfile(const String& lf);
00063 
00064     void setLogfileAppend(const Bool a);
00065 
00066     void setRegion(const Record& region);
00067 
00068     void setMask(const String& mask) { _mask = mask; }
00069 
00070     void setVerbosity(Verbosity verbosity) { _verbosity = verbosity; }
00071 
00072     // These messages will appear in the product image history upon the call to
00073     // _prepareOutputImage(). They will be located immediately after the input
00074     // image's copied history. The first value in the pair is the log origin.
00075     // The second is the associated message. If this method is called more than once
00076     // on the same object, messages from subsequent calls are appended to the
00077     // end of messages set in prior calls.
00078     void addHistory(const vector<std::pair<String, String> >& msgs) const;
00079 
00080     void addHistory(const LogOrigin& origin, const String& msg) const;
00081 
00082     void addHistory(const LogOrigin& origin, const vector<String>& msgs) const;
00083 
00084     // This adds standard history messages regarding the task that was run and
00085     // input parameters used. The vectors must have the same length
00086     void addHistory(
00087         const LogOrigin& origin, const String& taskname,
00088         const vector<String>& paramNames, const vector<casac::variant>& paramValues
00089     ) const;
00090 
00091     // suppress writing the history on _prepareOutputImage() call. Useful for
00092     // not writing history to intermediate image products.
00093     void suppressHistoryWriting(Bool b) { _suppressHistory = b; }
00094 
00095     // get the history associated with the task. Does not include the
00096     // history of the input image.
00097     vector<std::pair<String, String> > getHistory() {return _newHistory;}
00098 
00099     void setDropDegen(Bool d) { _dropDegen = d; }
00100 
00101 protected:
00102 
00103     // if <src>outname</src> is empty, no image will be written
00104      // if <src>overwrite</src> is True, if image already exists it will be removed
00105       // if <src>overwrite</src> is False, if image already exists exception will be thrown
00106 
00107        ImageTask(
00108            const SPCIIT image,
00109         const String& region, const Record *const &regionPtr,
00110         const String& box, const String& chanInp,
00111         const String& stokes, const String& maskInp,
00112         const String& outname, Bool overwrite
00113     );
00114 
00115        ImageTask(
00116            const SPCIIT image, const Record *const &regionPtr,
00117         const String& mask,
00118         const String& outname, Bool overwrite
00119     );
00120 
00121        virtual CasacRegionManager::StokesControl _getStokesControl() const = 0;
00122 
00123     virtual std::vector<OutputDestinationChecker::OutputStruct> _getOutputStruct();
00124 
00125     // does the lion's share of constructing the object, ie checks validity of
00126     // inputs, etc.
00127 
00128     virtual void _construct(Bool verbose=True);
00129 
00130     inline const SPCIIT _getImage() const {return _image;}
00131 
00132     inline const String& _getMask() const {return _mask;}
00133 
00134     inline const Record* _getRegion() const {return &_regionRecord;}
00135 
00136     inline void _setStokes(const String& stokes) { _stokesString = stokes; }
00137 
00138     inline const String& _getStokes() const {return _stokesString;}
00139 
00140     inline const String& _getChans() const {return _chan;}
00141 
00142     inline const String& _getOutname() const {return _outname; }
00143 
00144     // Represents the minimum set of coordinates necessary for the
00145     // task to function.
00146     virtual std::vector<Coordinate::Type> _getNecessaryCoordinates() const = 0;
00147 
00148     void _removeExistingOutfileIfNecessary() const;
00149 
00150     // if warnOnly is True, log a warning message if file exists and
00151     // overwrite is True, else throw an exception.
00152     void _removeExistingFileIfNecessary(
00153         const String& filename, const Bool overwrite, Bool warnOnly=False
00154     ) const;
00155 
00156     String _summaryHeader() const;
00157 
00158     inline const SHARED_PTR<LogIO> _getLog() const {return _log;}
00159 
00160     // by default, derived classes are configured to have no log file
00161     // support.
00162     virtual Bool _hasLogfileSupport() const {return False;}
00163 
00164     inline Bool _getStretch() const {return _stretch;}
00165 
00166     const SHARED_PTR<LogFile> _getLogFile() const;
00167 
00168     Bool _writeLogfile(
00169         const String& output, const Bool open=True,
00170         const Bool close=True
00171     );
00172 
00173     Bool _openLogfile();
00174 
00175     void _closeLogfile() const;
00176 
00177     virtual inline Bool _supportsMultipleRegions() const {return False;}
00178 
00179     // does this task support images with multiple beams? False means it never does.
00180     // True means it does, but not necessarily in all cases (in which case, the
00181     // derived class is responsible for checking for and throwing exceptions in those cases).
00182     virtual inline Bool _supportsMultipleBeams() const {return True;}
00183 
00184     // If outname != NULL, use the value supplied. If is NULL, use the value of _outname.
00185     // Create a TempImage or PagedImage depending if outname/_outname is empty or not. Generally meant
00186     // for the image to be returned to the UI or the final image product that the user will want.
00187     // values=0 => the pixel values from the image will be used
00188     // mask=0 => the mask attached to the image, if any will be used, outShape=0 => use image shape, coordsys=0 => use image coordinate
00189     // system. overwrite is only used if outname != NULL.
00190 
00191     //SPIIT _prepareOutputImage(const ImageInterface<T>& image) const;
00192 
00193     SPIIT _prepareOutputImage(
00194         const ImageInterface<T>& image, const Array<T> *const values,
00195         const ArrayLattice<Bool> *const mask=nullptr,
00196         const IPosition *const outShape=nullptr, const CoordinateSystem *const coordsys=nullptr,
00197         const String *const outname=nullptr, Bool overwrite=False, Bool dropDegen=False
00198     ) const;
00199 
00200     SPIIT _prepareOutputImage(
00201         const ImageInterface<T>& image, Bool dropDegen=False
00202     ) const;
00203 
00204     // if warnOnly is True, only log a warning message if the file exists and
00205     // overwrite is True, else throw an excepction
00206     SPIIT _prepareOutputImage(
00207         const ImageInterface<T>& image, const String& outname,
00208         Bool overwrite, Bool warnOnly
00209     ) const;
00210 
00211     // data are copied to the output image from the <src>data</src>
00212     // lattice. The mask is copied from the input image.
00213     SPIIT _prepareOutputImage(
00214         const ImageInterface<T>& image, const Lattice<T>& data
00215     ) const;
00216 
00217     Verbosity _getVerbosity() const { return _verbosity; }
00218 
00219     Bool _getOverwrite() const { return _overwrite; }
00220 
00221     virtual Bool _mustHaveSquareDirectionPixels() const {return False;}
00222 
00223     Bool _getDropDegen() const { return _dropDegen; }
00224 
00225     static void _copyMask(Lattice<Bool>& mask, const ImageInterface<T>& image);
00226 
00227     static void _copyData(Lattice<T>& data, const ImageInterface<T>& image);
00228 
00229     template <class U> void _doHistory(SHARED_PTR<ImageInterface<U>>& image) const;
00230 
00231 private:
00232     const SPCIIT _image;
00233     mutable SHARED_PTR<LogIO> _log = SHARED_PTR<LogIO>(new LogIO());
00234     const Record *const _regionPtr;
00235     Record _regionRecord;
00236     String _region = "";
00237     String _box = "";
00238     String _chan = "";
00239     String _stokesString = "";
00240     String _mask = "";
00241     String _outname = "";
00242     Bool _overwrite = False;
00243     Bool _stretch = False;
00244     Bool _logfileAppend = False;
00245     Bool _suppressHistory = False;
00246     Bool _dropDegen = False;
00247     std::unique_ptr<FiledesIO> _logFileIO;
00248     Verbosity _verbosity = NORMAL;
00249     SHARED_PTR<LogFile> _logfile;
00250     mutable vector<std::pair<String, String> > _newHistory;
00251 
00252     mutable C11Timer _timer;
00253 };
00254 
00255 }
00256 
00257 #ifndef AIPS_NO_TEMPLATE_SRC
00258 #include <imageanalysis/ImageAnalysis/ImageTask.tcc>
00259 #endif
00260 
00261 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1