casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SkyCal.h
Go to the documentation of this file.
1 //# SkyCal.h: this defines <ClassName>, which ...
2 //# Copyright (C) 2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef _SYNTHESIS_SKY_CAL_H_
30 #define _SYNTHESIS_SKY_CAL_H_
31 
32 #include <casa/Arrays/Matrix.h>
33 #include <casa/Exceptions/Error.h>
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 //#! A one line summary of the class. This summary (shortened a bit
39 //#! if necessary so that it fits along with the "ClassFileName.h" in 75
40 //#! characters) should also appear as the first line of this file.
41 //#! Be sure to use the word "abstract" here if this class is, indeed,
42 //#! an abstract base class.
43 // </summary>
44 
45 // <use visibility=local> or <use visibility=export>
46 //#! If a class is intended for use by application programmers, or
47 //#! people writing other libraries, then specify that this class
48 //#! has an "export" visibility: it defines an interface that
49 //#! will be seen outside of its module. On the other hand, if the
50 //#! class has a "local" visibility, then it is known and used only
51 //#! within its module.
52 
53 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
54 //#! for example:
55 //#! <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
56 //#! This is a well-designed class, without any obvious problems.
57 //#! However, the addition of several more demo programs would
58 //#! go a *long* way towards making it more usable.
59 //#! </reviewed>
60 //#!
61 //#! (In time, the documentation extractor will be able handle reviewed
62 //#! attributes spread over more than one line.)
63 //#!
64 //#! see "Coding Standards and Guidelines" (AIPS++ note 167) and
65 //#! "AIPS++ Code Review Process" (note 170) for a full explanation
66 //#! It is up to the class author (the programmer) to fill in these fields:
67 //#! tests, demos
68 //#! The reviewer fills in
69 //#! reviewer, date
70 // </reviewed>
71 
72 // <prerequisite>
73 //#! Classes or concepts you should understand before using this class.
74 // <li> SomeClass
75 // <li> SomeOtherClass
76 // <li> some concept
77 // </prerequisite>
78 //
79 // <etymology>
80 //#! Except when it is obvious (e.g., "casacore::Array") explain how the class name
81 //#! expresses the role of this class. Example: casacore::IPosition is short for
82 //#! "Integral Position" - a specialized integer vector for specifying
83 //#! array dimensions and indices.
84 // </etymology>
85 //
86 // <synopsis>
87 //#! What does the class do? How? For whom? This should include code
88 //#! fragments as appropriate to support text. Code fragments shall be
89 //#! delimited by <srcblock> </srcblock> tags. The synopsis section will
90 //#! usually be dozens of lines long.
91 // </synopsis>
92 //
93 // <example>
94 //#! One or two concise (~10-20 lines) examples, with a modest amount of
95 //#! text to support code fragments. Use <srcblock> and </srcblock> to
96 //#! delimit example code.
97 // </example>
98 //
99 // <motivation>
100 //#! Insight into a class is often provided by a description of
101 //#! the circumstances that led to its conception and design. Describe
102 //#! them here.
103 // </motivation>
104 //
105 // <templating arg=T>
106 //#! A list of member functions that must be provided by classes that
107 //#! appear as actual template arguments. For example: imagine that you
108 //#! are writing a templated sort class, which does a quicksort on a
109 //#! list of arbitrary objects. Anybody who uses your templated class
110 //#! must make sure that the actual argument class (say, casacore::Int or
111 //#! casacore::String or casacore::Matrix) has comparison operators defined.
112 //#! This tag must be repeated for each template formal argument in the
113 //#! template class definition -- that's why this tag has the "arg" attribute.
114 //#! (Most templated classes, however, are templated on only a single
115 //#! argument.)
116 // <li>
117 // <li>
118 // </templating>
119 //
120 // <thrown>
121 //#! A list of exceptions thrown if errors are discovered in the function.
122 //#! This tag will appear in the body of the header file, preceding the
123 //#! declaration of each function which throws an exception.
124 // <li>
125 // <li>
126 // </thrown>
127 //
128 // <todo asof="yyyy/mm/dd">
129 //#! A casacore::List of bugs, limitations, extensions or planned refinements.
130 //#! The programmer should fill in a date in the "asof" field, which
131 //#! will usually be the date at which the class is submitted for review.
132 //#! If, during the review, new "todo" items come up, then the "asof"
133 //#! date should be changed to the end of the review period.
134 // <li> add this feature
135 // <li> fix this bug
136 // <li> start discussion of this possible extension
137 // </todo>
138 
139 template<class DataType, class CalDataType>
140 class SkyCal
141 {
142  // all the member functions are inline
143 public:
145  : npol_(2),
146  nchan_(1),
147  m0_(NULL),
148  ok0_(NULL),
149  m_(NULL),
150  mi_(NULL),
151  ok_(NULL),
152  oki_(NULL),
153  cOne_(1.0),
154  cZero_(0.0),
155  scalardata_(false)
156  {}
157 
158  virtual ~SkyCal() {}
159 
160  // stride
161  // In Mueller series, typesize is defined as "number of polarizations"
162  // while SkyCal definition is "number of elements in the DATA cell",
163  // which is npol * nchan in practice.
164  casacore::uInt typesize() const { return npol_ * nchan_; }
167 
168  // Set scalardata_
169  // TBD: Handle this better; for now, we need to set this from
170  // an external call so we handle single-corr data properly
171  // when setting non-corr-dep flags
172  void setScalarData(casacore::Bool scalardata) const { scalardata_=scalardata; }
173 
174  // Synchronize with leading element in external array
175  void sync(CalDataType& mat) { m0_=&mat; origin(); }
176  void sync(CalDataType& mat, casacore::Bool& ok) { m0_=&mat; ok0_=&ok; origin(); }
177 
178  // Reset to origin
179  void origin() {m_=m0_;ok_=ok0_;}
180 
181  // Increment to next vector (according to len)
182  // In practice, this operator increments row index
183  void operator++() { m_+=typesize(); if (ok_) ok_+=typesize();}
184  void operator++(int) { m_+=typesize(); if (ok_) ok_+=typesize();}
185 
186  // Advance step matrices forward (according to len)
187  void advance(const casacore::Int& step) { m_+=(step*typesize()); if (ok_) ok_+=(step*typesize());}
188 
189  // In-place invert
190  void invert() {}
191 
192  // Set matrix elements according to ok flag
193  // (so we don't have to check ok flags atomically in apply)
194  void setMatByOk()
195  {
196  throw(casacore::AipsError("Illegal use of SkyCal::setMatByOk"));
197  }
198 
199  // In-place multiply onto a data with flag information
200  // apply implements position switch calibration: (ON - OFF)/OFF
201  //
202  // This processes the data corresponding to each DATA cell
203  // (npol * nchan) together in contrast to Mueller series, which
204  // processes one casacore::Stokes vector, i.e., process each channel
205  // individually.
207  {
208  if (f.shape() == v.shape()) {
209  flag(f);
210  }
211 
212  constexpr size_t nPolCal = 2;
213 
214  casacore::Bool deleteIt;
215  DataType *data = v.getStorage(deleteIt);
216  for (size_t i = 0; i < nchan_; ++i) {
217  auto const iData = i * npol_;
218  auto const iMat = i * nPolCal;
219  for (size_t j = 0; j < npol_; ++j) {
220  // (ON - OFF) / OFF
221  data[iData+j] = (data[iData+j] - m_[iMat+j]) / m_[iMat+j];
222  }
223  }
224  v.putStorage(data, deleteIt);
225  }
226 
228  {
229  if (!ok_) throw(casacore::AipsError("Illegal use of SkyCal::applyFlag."));
230 
231  applyFlag(vflag);
232  apply(v, f);
233  }
234 
235  // Apply only flags according to cal flags
236  //
237  // Similar to apply, flagging also processes each DATA cell together.
239  {
240  if (!ok_) throw(casacore::AipsError("Illegal use of SkyCal::applyFlag(vflag)."));
241 
242  constexpr size_t nPolCal = 2;
243 
244  if (scalardata_) {
245  for (size_t i = 0; i < nchan_; ++i) {
246  vflag[i] |= (!ok_[i*nPolCal]);
247  }
248  }
249  else {
250  for (size_t i = 0; i < nchan_; ++i) {
251  for (size_t j = 0; j < npol_; ++j) {
252  vflag[i] |= !(ok_[i*nPolCal + j]);
253  }
254  }
255  }
256  }
257 
259  {
260  constexpr size_t nPolCal = 2;
261 
262  casacore::Bool deleteIt;
263  casacore::Bool *data = v.getStorage(deleteIt);
264  for (size_t i = 0; i < nchan_; ++i) {
265  auto const iData = i * npol_;
266  auto const iMat = i * nPolCal;
267  for (size_t j = 0; j < npol_; ++j) {
268  data[iData+j] |= (!ok_[iMat+j]); // data: false is valid, ok_: true is valid
269  }
270  }
271  v.putStorage(data, deleteIt);
272  }
273 
274  // Multiply onto a vis VisVector, preserving input (copy then in-place apply)
277  {
278  out = in;
279  outFlag = inFlag;
280  apply(out, outFlag);
281  }
282 
283  // print it out
284  // unused
285  /*
286  friend std::ostream& operator<<(std::ostream& os, const SkyCal<DataType, CalDataType>& mat)
287  {
288  return os;
289  }
290  */
291 
292 protected:
293 
294 private:
297 
298  // Pointer to origin
299  CalDataType *m0_;
301 
302  // Moving pointer
303  CalDataType *m_, *mi_;
305 
306  // casacore::Complex unity, zero (for use in invert and similar methods)
307  const CalDataType cOne_,cZero_;
308 
310 
311  // Copy ctor protected
313 };
314 
315 } //# NAMESPACE CASA - END
316 
317 //#include <synthesis/MeasurementComponents/SkyCal.tcc>
318 
319 #endif /* _SYNTHESIS_SKY_CAL_H_ */
320 
321 
322 
CalDataType * m0_
Pointer to origin.
Definition: SkyCal.h:299
void operator++()
Increment to next vector (according to len) In practice, this operator increments row index...
Definition: SkyCal.h:183
casacore::Bool scalardata_
Definition: SkyCal.h:309
const CalDataType cOne_
casacore::Complex unity, zero (for use in invert and similar methods)
Definition: SkyCal.h:307
int Int
Definition: aipstype.h:50
void putStorage(T *&storage, Bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
const CalDataType cZero_
Definition: SkyCal.h:307
casacore::Bool * ok_
Definition: SkyCal.h:304
const IPosition & shape() const
The length of each axis of the Matrix.
Definition: Matrix.h:295
void apply(casacore::Matrix< DataType > &out, casacore::Matrix< casacore::Bool > &outFlag, const casacore::Matrix< DataType > &in, const casacore::Matrix< casacore::Bool > &inFlag)
Multiply onto a vis VisVector, preserving input (copy then in-place apply)
Definition: SkyCal.h:275
void setNumChannel(casacore::uInt n)
Definition: SkyCal.h:165
virtual ~SkyCal()
Definition: SkyCal.h:158
casacore::Bool * ok0_
Definition: SkyCal.h:300
void flag(casacore::Matrix< casacore::Bool > &v)
Definition: SkyCal.h:258
void invert()
In-place invert.
Definition: SkyCal.h:190
void setNumPolarization(casacore::uInt n)
Definition: SkyCal.h:166
A 2-D Specialization of the Array class.
SkyCal()
all the member functions are inline
Definition: SkyCal.h:144
casacore::uInt typesize() const
stride In Mueller series, typesize is defined as &quot;number of polarizations&quot; while SkyCal definition is...
Definition: SkyCal.h:164
casacore::Bool * oki_
Definition: SkyCal.h:304
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
T * getStorage(Bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar...
void sync(CalDataType &mat, casacore::Bool &ok)
Definition: SkyCal.h:176
void applyFlag(casacore::Vector< casacore::Bool > &vflag)
Apply only flags according to cal flags.
Definition: SkyCal.h:238
void apply(casacore::Matrix< DataType > &v, casacore::Matrix< casacore::Bool > &f, casacore::Vector< casacore::Bool > &vflag)
Definition: SkyCal.h:227
casacore::uInt npol_
print it out unused
Definition: SkyCal.h:295
void apply(casacore::Matrix< DataType > &v, casacore::Matrix< casacore::Bool > &f)
In-place multiply onto a data with flag information apply implements position switch calibration: (ON...
Definition: SkyCal.h:206
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
CalDataType * m_
Moving pointer.
Definition: SkyCal.h:303
void setScalarData(casacore::Bool scalardata) const
Set scalardata_ TBD: Handle this better; for now, we need to set this from an external call so we han...
Definition: SkyCal.h:172
void operator++(int)
Definition: SkyCal.h:184
Base class for all Casacore library errors.
Definition: Error.h:134
void sync(CalDataType &mat)
Synchronize with leading element in external array.
Definition: SkyCal.h:175
void advance(const casacore::Int &step)
Advance step matrices forward (according to len)
Definition: SkyCal.h:187
void origin()
Reset to origin.
Definition: SkyCal.h:179
CalDataType * mi_
Definition: SkyCal.h:303
unsigned int uInt
Definition: aipstype.h:51
casacore::uInt nchan_
Definition: SkyCal.h:296
void setMatByOk()
Set matrix elements according to ok flag (so we don&#39;t have to check ok flags atomically in apply) ...
Definition: SkyCal.h:194