casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageTask.h
Go to the documentation of this file.
1 #ifndef IMAGEANALYSIS_IMAGETASK_H
2 #define IMAGEANALYSIS_IMAGETASK_H
3 
5 
9 
10 #include <memory>
11 
13 
14 namespace casacore{
15 
16 template <class T> class ArrayLattice;
17 }
18 
19 namespace casac {
20 class variant;
21 }
22 
23 namespace casa {
24 
25 class LogFile;
26 
27 template <class T> class ImageTask {
28 
29  // <summary>
30  // Virtual base class for image analysis tasks.
31  // </summary>
32 
33  // <reviewed reviewer="" date="" tests="" demos="">
34  // </reviewed>
35 
36  // <prerequisite>
37  // </prerequisite>
38 
39  // <etymology>
40  // Image tasking
41  // </etymology>
42 
43  // <synopsis>
44  // Virtual base class for image tasking.
45  // </synopsis>
46 
47 public:
48 
49  // verbosity levels
50  enum Verbosity {
53  LOW,
58  };
59 
60  virtual ~ImageTask();
61 
62  virtual casacore::String getClass() const = 0;
63 
64  inline void setStretch(const casacore::Bool stretch) { _stretch = stretch;}
65 
66  // tacitly does nothing if <src>lf</src> is the empty string.
67  void setLogfile(const casacore::String& lf);
68 
69  void setLogfileAppend(const casacore::Bool a);
70 
71  void setRegion(const casacore::Record& region);
72 
73  void setMask(const casacore::String& mask) { _mask = mask; }
74 
75  void setVerbosity(Verbosity verbosity) { _verbosity = verbosity; }
76 
77  // <group>
78  // These messages will appear in the product image history upon the call to
79  // _prepareOutputImage(). They will be located immediately after the input
80  // image's copied history. The first value in the pair is the log origin.
81  // The second is the associated message. If this method is called more than once
82  // on the same object, messages from subsequent calls are appended to the
83  // end of messages set in prior calls.
84  void addHistory(const std::vector<std::pair<casacore::String, casacore::String> >& msgs) const;
85 
86  void addHistory(const casacore::LogOrigin& origin, const casacore::String& msg) const;
87 
88  void addHistory(const casacore::LogOrigin& origin, const std::vector<casacore::String>& msgs) const;
89 
90  // This adds standard history messages regarding the task that was run and
91  // input parameters used. The vectors must have the same length
92  void addHistory(
93  const casacore::LogOrigin& origin, const casacore::String& taskname,
94  const std::vector<casacore::String>& paramNames, const std::vector<casac::variant>& paramValues
95  ) const;
96  // </group>
97 
98  // suppress writing the history on _prepareOutputImage() call. Useful for
99  // not writing history to intermediate image products.
101 
102  // get the history associated with the task. Does not include the
103  // history of the input image.
104  std::vector<std::pair<casacore::String, casacore::String> > getHistory() {return _newHistory;}
105 
107 
108 protected:
109 
110  // if <src>outname</src> is empty, no image will be written
111  // if <src>overwrite</src> is True, if image already exists it will be removed
112  // if <src>overwrite</src> is False, if image already exists exception will be thrown
113  ImageTask(
114  const SPCIIT image,
115  const casacore::String& region, const casacore::Record *const &regionPtr,
116  const casacore::String& box, const casacore::String& chanInp,
117  const casacore::String& stokes, const casacore::String& maskInp,
118  const casacore::String& outname, casacore::Bool overwrite
119  );
120 
121  ImageTask(
122  const SPCIIT image, const casacore::Record *const &regionPtr,
123  const casacore::String& mask,
124  const casacore::String& outname, casacore::Bool overwrite
125  );
126 
128 
129  virtual std::vector<OutputDestinationChecker::OutputStruct> _getOutputStruct();
130 
131  // does the lion's share of constructing the object, ie checks validity of
132  // inputs, etc.
133 
134  virtual void _construct(casacore::Bool verbose=true);
135 
136  inline const SPCIIT _getImage() const {return _image;}
137 
138  inline const casacore::String& _getMask() const {return _mask;}
139 
140  inline const casacore::Record* _getRegion() const {return &_regionRecord;}
141 
142  inline void _setStokes(const casacore::String& stokes) { _stokesString = stokes; }
143 
144  inline const casacore::String& _getStokes() const {return _stokesString;}
145 
146  inline const casacore::String& _getChans() const {return _chan;}
147 
148  inline const casacore::String& _getOutname() const {return _outname; }
149 
150  // Represents the minimum set of coordinates necessary for the
151  // task to function.
152  virtual std::vector<casacore::Coordinate::Type> _getNecessaryCoordinates() const = 0;
153 
154  // Is the attached image a position-velocity (PV) image?
155  casacore::Bool _isPVImage() const;
156 
158 
159  // if warnOnly is true, log a warning message if file exists and
160  // overwrite is true, else throw an exception.
162  const casacore::String& filename, const casacore::Bool overwrite, casacore::Bool warnOnly=false
163  ) const;
164 
166 
167  inline const std::shared_ptr<casacore::LogIO> _getLog() const {return _log;}
168 
169  // by default, derived classes are configured to have no log file
170  // support.
171  virtual casacore::Bool _hasLogfileSupport() const {return false;}
172 
173  inline casacore::Bool _getStretch() const {return _stretch;}
174 
176 
177  const std::shared_ptr<LogFile> _getLogFile() const;
178 
180  const casacore::String& output, const casacore::Bool open=true,
181  const casacore::Bool close=true
182  );
183 
185 
186  void _closeLogfile() const;
187 
188  virtual inline casacore::Bool _supportsMultipleRegions() const {return false;}
189 
190  // does this task support images with multiple beams? false means it never does.
191  // true means it does, but not necessarily in all cases (in which case, the
192  // derived class is responsible for checking for and throwing exceptions in those cases).
193  virtual inline casacore::Bool _supportsMultipleBeams() const {return true;}
194 
195  // If outname != NULL, use the value supplied. If is NULL, use the value of _outname.
196  // Create a casacore::TempImage or casacore::PagedImage depending if outname/_outname is empty or not. Generally meant
197  // for the image to be returned to the UI or the final image product that the user will want.
198  // values=0 => the pixel values from the image will be used
199  // mask=0 => the mask attached to the image, if any will be used, outShape=0 => use image shape, coordsys=0 => use image coordinate
200  // system. overwrite is only used if outname != NULL.
201 
203  const casacore::ImageInterface<T>& image, const casacore::Array<T> *const values,
204  const casacore::ArrayLattice<casacore::Bool> *const mask=nullptr,
205  const casacore::IPosition *const outShape=nullptr, const casacore::CoordinateSystem *const coordsys=nullptr,
206  const casacore::String *const outname=nullptr, casacore::Bool overwrite=false, casacore::Bool dropDegen=false
207  ) const;
208 
210  const casacore::ImageInterface<T>& image, casacore::Bool dropDegen=false
211  ) const;
212 
213  // if warnOnly is true, only log a warning message if the file exists and
214  // overwrite is true, else throw an excepction
216  const casacore::ImageInterface<T>& image, const casacore::String& outname,
217  casacore::Bool overwrite, casacore::Bool warnOnly
218  ) const;
219 
220  // data are copied to the output image from the <src>data</src>
221  // lattice. The mask is copied from the input image.
224  ) const;
225 
226  Verbosity _getVerbosity() const { return _verbosity; }
227 
229 
230  virtual casacore::Bool _mustHaveSquareDirectionPixels() const {return false;}
231 
233 
235 
236  static void _copyData(casacore::Lattice<T>& data, const casacore::Lattice<T>& image);
237 
238  template <class U> void _doHistory(std::shared_ptr<casacore::ImageInterface<U>>& image) const;
239 
240  void _reportOldNewImageShapes(const ImageInterface<T>& out) const;
241 
242  void _reportOldNewImageShapes(const IPosition& outShape) const;
243 
244 private:
245  const SPCIIT _image;
246  mutable std::shared_ptr<casacore::LogIO> _log = std::shared_ptr<casacore::LogIO>(new casacore::LogIO());
260  std::unique_ptr<casacore::FiledesIO> _logFileIO;
262  std::shared_ptr<LogFile> _logfile;
263  mutable std::vector<std::pair<casacore::String, casacore::String> > _newHistory;
264 
265  mutable C11Timer _timer;
266 };
267 
268 }
269 
270 #ifndef AIPS_NO_TEMPLATE_SRC
271 #include <imageanalysis/ImageAnalysis/ImageTask.tcc>
272 #endif
273 
274 #endif
Verbosity
Virtual base class for image analysis tasks.
Definition: ImageTask.h:50
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
casacore::String _region
Definition: ImageTask.h:249
virtual CasacRegionManager::StokesControl _getStokesControl() const =0
virtual casacore::Bool _hasLogfileSupport() const
by default, derived classes are configured to have no log file support.
Definition: ImageTask.h:171
casacore::Bool _dropDegen
Definition: ImageTask.h:259
void _removeExistingFileIfNecessary(const casacore::String &filename, const casacore::Bool overwrite, casacore::Bool warnOnly=false) const
if warnOnly is true, log a warning message if file exists and overwrite is true, else throw an except...
std::unique_ptr< casacore::FiledesIO > _logFileIO
Definition: ImageTask.h:260
const casacore::String & _getChans() const
Definition: ImageTask.h:146
casacore::String _chan
Definition: ImageTask.h:251
void _reportOldNewImageShapes(const ImageInterface< T > &out) const
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
std::vector< std::pair< casacore::String, casacore::String > > _newHistory
Definition: ImageTask.h:263
std::vector< std::pair< casacore::String, casacore::String > > getHistory()
get the history associated with the task.
Definition: ImageTask.h:104
void suppressHistoryWriting(casacore::Bool b)
suppress writing the history on _prepareOutputImage() call.
Definition: ImageTask.h:100
casacore::String _stokesString
Definition: ImageTask.h:252
const casacore::Record * _getRegion() const
Definition: ImageTask.h:140
virtual void _construct(casacore::Bool verbose=true)
does the lion&#39;s share of constructing the object, ie checks validity of inputs, etc.
casacore::Bool _logfileAppend
Definition: ImageTask.h:257
virtual casacore::String getClass() const =0
void _removeExistingOutfileIfNecessary() const
ostream-like interface to creating log messages.
Definition: LogIO.h:167
void setLogfileAppend(const casacore::Bool a)
void setMask(const casacore::String &mask)
Definition: ImageTask.h:73
void _doHistory(std::shared_ptr< casacore::ImageInterface< U >> &image) const
Verbosity _verbosity
Definition: ImageTask.h:261
virtual std::vector< OutputDestinationChecker::OutputStruct > _getOutputStruct()
casacore::Bool _overwrite
Definition: ImageTask.h:255
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
virtual casacore::Bool _mustHaveSquareDirectionPixels() const
Definition: ImageTask.h:230
const std::shared_ptr< LogFile > _getLogFile() const
casacore::Bool _isPVImage() const
Is the attached image a position-velocity (PV) image?
const casacore::String & _getOutname() const
Definition: ImageTask.h:148
const casacore::String & _getMask() const
Definition: ImageTask.h:138
void setStretch(const casacore::Bool stretch)
Definition: ImageTask.h:64
const casacore::String & _getStokes() const
Definition: ImageTask.h:144
A templated, abstract base class for array-like objects.
A base class for astronomical images.
casacore::Bool _suppressHistory
Definition: ImageTask.h:258
#define SPIIT
Definition: ImageTypedefs.h:34
void _setStokes(const casacore::String &stokes)
Definition: ImageTask.h:142
virtual casacore::Bool _supportsMultipleRegions() const
Definition: ImageTask.h:188
void _closeLogfile() const
static void _copyMask(casacore::Lattice< casacore::Bool > &mask, const casacore::ImageInterface< T > &image)
virtual std::vector< casacore::Coordinate::Type > _getNecessaryCoordinates() const =0
Represents the minimum set of coordinates necessary for the task to function.
ImageTask(const SPCIIT image, const casacore::String &region, const casacore::Record *const &regionPtr, const casacore::String &box, const casacore::String &chanInp, const casacore::String &stokes, const casacore::String &maskInp, const casacore::String &outname, casacore::Bool overwrite)
if outname is empty, no image will be written if overwrite is True, if image already exists it will b...
casacore::Bool _stretch
Definition: ImageTask.h:256
void setLogfile(const casacore::String &lf)
tacitly does nothing if lf is the empty string.
casacore::Bool _getStretch() const
Definition: ImageTask.h:173
casacore::Bool _getDropDegen() const
Definition: ImageTask.h:232
casacore::Bool _writeLogfile(const casacore::String &output, const casacore::Bool open=true, const casacore::Bool close=true)
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual casacore::Bool _supportsMultipleBeams() const
does this task support images with multiple beams? false means it never does.
Definition: ImageTask.h:193
void setRegion(const casacore::Record &region)
Verbosity _getVerbosity() const
Definition: ImageTask.h:226
const casacore::Record *const _regionPtr
Definition: ImageTask.h:247
casacore::String _summaryHeader() const
casacore::Bool _openLogfile()
#define SPCIIT
Definition: ImageTypedefs.h:35
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
void addHistory(const std::vector< std::pair< casacore::String, casacore::String > > &msgs) const
These messages will appear in the product image history upon the call to _prepareOutputImage().
casacore::String _mask
Definition: ImageTask.h:253
virtual Origin origin() const =0
ABSTRACT METHODS //.
casacore::String _box
Definition: ImageTask.h:250
LogOrigin: The source code location of the originator of a LogMessage.
Definition: LogOrigin.h:94
const SPCIIT _image
Definition: ImageTask.h:245
C11Timer _timer
Definition: ImageTask.h:265
const SPCIIT _getImage() const
Definition: ImageTask.h:136
casacore::Record _regionRecord
Definition: ImageTask.h:248
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void setDropDegen(casacore::Bool d)
Definition: ImageTask.h:106
void setVerbosity(Verbosity verbosity)
Definition: ImageTask.h:75
std::shared_ptr< casacore::LogIO > _log
Definition: ImageTask.h:246
std::shared_ptr< LogFile > _logfile
Definition: ImageTask.h:262
SPIIT _prepareOutputImage(const casacore::ImageInterface< T > &image, const casacore::Array< T > *const values, const casacore::ArrayLattice< casacore::Bool > *const mask=nullptr, const casacore::IPosition *const outShape=nullptr, const casacore::CoordinateSystem *const coordsys=nullptr, const casacore::String *const outname=nullptr, casacore::Bool overwrite=false, casacore::Bool dropDegen=false) const
If outname != NULL, use the value supplied.
A memory resident Lattice.
Definition: ImageTask.h:16
casacore::Bool _getOverwrite() const
Definition: ImageTask.h:228
static void _copyData(casacore::Lattice< T > &data, const casacore::Lattice< T > &image)
casacore::String _outname
Definition: ImageTask.h:254
const std::shared_ptr< casacore::LogIO > _getLog() const
Definition: ImageTask.h:167
Bool _getSuppressHistory() const
Definition: ImageTask.h:175
Interconvert pixel and world coordinates.
virtual ~ImageTask()
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42