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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 public:
00043
00044
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
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
00073
00074
00075
00076
00077
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
00085
00086 void addHistory(
00087 const LogOrigin& origin, const String& taskname,
00088 const vector<String>& paramNames, const vector<casac::variant>& paramValues
00089 ) const;
00090
00091
00092
00093 void suppressHistoryWriting(Bool b) { _suppressHistory = b; }
00094
00095
00096
00097 vector<std::pair<String, String> > getHistory() {return _newHistory;}
00098
00099 void setDropDegen(Bool d) { _dropDegen = d; }
00100
00101 protected:
00102
00103
00104
00105
00106
00107 ImageTask(
00108 const SPCIIT image,
00109 const String& region, const Record *const ®ionPtr,
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 ®ionPtr,
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
00126
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
00145
00146 virtual std::vector<Coordinate::Type> _getNecessaryCoordinates() const = 0;
00147
00148 void _removeExistingOutfileIfNecessary() const;
00149
00150
00151
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
00161
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
00180
00181
00182 virtual inline Bool _supportsMultipleBeams() const {return True;}
00183
00184
00185
00186
00187
00188
00189
00190
00191
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
00205
00206 SPIIT _prepareOutputImage(
00207 const ImageInterface<T>& image, const String& outname,
00208 Bool overwrite, Bool warnOnly
00209 ) const;
00210
00211
00212
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