Line data Source code
1 : //# SingleDishSkyCal.h: Single dish sky calibration
2 : //# Copyright (C) 2014
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //# National Astronomical Observatory of Japan, Japan.
5 : //#
6 : //# This library is free software; you can redistribute it and/or modify it
7 : //# under the terms of the GNU Library General Public License as published by
8 : //# the Free Software Foundation; either version 2 of the License, or (at your
9 : //# option) any later version.
10 : //#
11 : //# This library is distributed in the hope that it will be useful, but WITHOUT
12 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 : //# License for more details.
15 : //#
16 : //# You should have received a copy of the GNU Library General Public License
17 : //# along with this library; if not, write to the Free Software Foundation,
18 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 : //#
20 : //# Correspondence concerning AIPS++ should be addressed as follows:
21 : //# Internet email: casa-feedback@nrao.edu.
22 : //# Postal address: AIPS++ Project Office
23 : //# National Radio Astronomy Observatory
24 : //# 520 Edgemont Road
25 : //# Charlottesville, VA 22903-2475 USA
26 : //#
27 : //#
28 : //# $Id$
29 :
30 : //#! Create an include 'guard', containing your class name in the all
31 : //#! upper case format implied below. This prevents multiple inclusion
32 : //#! of this header file during pre-processing.
33 : //#!
34 : //#! Note that the leading "AIPS_" identifies the package to which your class
35 : //#! belongs. Other packages include dish, vlbi, nfra, synthesis, atnf...
36 : //#! If you are contributing a new class to one of these packages, be
37 : //#! sure to replace "AIPS_" with (for instance) "DISH_" or "ATNF_".
38 :
39 : #ifndef _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
40 : #define _SYNTHESIS_SINGLEDISH_SKY_CAL_H_
41 :
42 : //#! Includes go here
43 : #include <synthesis/MeasurementComponents/SolvableVisCal.h>
44 : #include <synthesis/MeasurementComponents/SkyCal.h>
45 :
46 : namespace casa { //# NAMESPACE CASA - BEGIN
47 :
48 : //# Forward Declarations
49 :
50 : // <summary>
51 : //#! A one line summary of the class. This summary (shortened a bit
52 : //#! if necessary so that it fits along with the "ClassFileName.h" in 75
53 : //#! characters) should also appear as the first line of this file.
54 : //#! Be sure to use the word "abstract" here if this class is, indeed,
55 : //#! an abstract base class.
56 : // </summary>
57 :
58 : // <use visibility=local> or <use visibility=export>
59 : //#! If a class is intended for use by application programmers, or
60 : //#! people writing other libraries, then specify that this class
61 : //#! has an "export" visibility: it defines an interface that
62 : //#! will be seen outside of its module. On the other hand, if the
63 : //#! class has a "local" visibility, then it is known and used only
64 : //#! within its module.
65 :
66 : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
67 : //#! for example:
68 : //#! <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
69 : //#! This is a well-designed class, without any obvious problems.
70 : //#! However, the addition of several more demo programs would
71 : //#! go a *long* way towards making it more usable.
72 : //#! </reviewed>
73 : //#!
74 : //#! (In time, the documentation extractor will be able handle reviewed
75 : //#! attributes spread over more than one line.)
76 : //#!
77 : //#! see "Coding Standards and Guidelines" (AIPS++ note 167) and
78 : //#! "AIPS++ Code Review Process" (note 170) for a full explanation
79 : //#! It is up to the class author (the programmer) to fill in these fields:
80 : //#! tests, demos
81 : //#! The reviewer fills in
82 : //#! reviewer, date
83 : // </reviewed>
84 :
85 : // <prerequisite>
86 : //#! Classes or concepts you should understand before using this class.
87 : // <li> SomeClass
88 : // <li> SomeOtherClass
89 : // <li> some concept
90 : // </prerequisite>
91 : //
92 : // <etymology>
93 : //#! Except when it is obvious (e.g., "casacore::Array") explain how the class name
94 : //#! expresses the role of this class. Example: casacore::IPosition is short for
95 : //#! "Integral Position" - a specialized integer vector for specifying
96 : //#! array dimensions and indices.
97 : // </etymology>
98 : //
99 : // <synopsis>
100 : //#! What does the class do? How? For whom? This should include code
101 : //#! fragments as appropriate to support text. Code fragments shall be
102 : //#! delimited by <srcblock> </srcblock> tags. The synopsis section will
103 : //#! usually be dozens of lines long.
104 : // </synopsis>
105 : //
106 : // <example>
107 : //#! One or two concise (~10-20 lines) examples, with a modest amount of
108 : //#! text to support code fragments. Use <srcblock> and </srcblock> to
109 : //#! delimit example code.
110 : // </example>
111 : //
112 : // <motivation>
113 : //#! Insight into a class is often provided by a description of
114 : //#! the circumstances that led to its conception and design. Describe
115 : //#! them here.
116 : // </motivation>
117 : //
118 : // <templating arg=T>
119 : //#! A list of member functions that must be provided by classes that
120 : //#! appear as actual template arguments. For example: imagine that you
121 : //#! are writing a templated sort class, which does a quicksort on a
122 : //#! list of arbitrary objects. Anybody who uses your templated class
123 : //#! must make sure that the actual argument class (say, casacore::Int or
124 : //#! casacore::String or casacore::Matrix) has comparison operators defined.
125 : //#! This tag must be repeated for each template formal argument in the
126 : //#! template class definition -- that's why this tag has the "arg" attribute.
127 : //#! (Most templated classes, however, are templated on only a single
128 : //#! argument.)
129 : // <li>
130 : // <li>
131 : // </templating>
132 : //
133 : // <thrown>
134 : //#! A list of exceptions thrown if errors are discovered in the function.
135 : //#! This tag will appear in the body of the header file, preceding the
136 : //#! declaration of each function which throws an exception.
137 : // <li>
138 : // <li>
139 : // </thrown>
140 : //
141 : // <todo asof="yyyy/mm/dd">
142 : //#! A casacore::List of bugs, limitations, extensions or planned refinements.
143 : //#! The programmer should fill in a date in the "asof" field, which
144 : //#! will usually be the date at which the class is submitted for review.
145 : //#! If, during the review, new "todo" items come up, then the "asof"
146 : //#! date should be changed to the end of the review period.
147 : // <li> add this feature
148 : // <li> fix this bug
149 : // <li> start discussion of this possible extension
150 : // </todo>
151 :
152 : class SingleDishSkyCal : public SolvableVisCal
153 : {
154 : public:
155 :
156 : // Constructor
157 : SingleDishSkyCal(VisSet& vs);
158 : SingleDishSkyCal(const MSMetaInfoForCal& msmc); // preferred ctor
159 : SingleDishSkyCal(const casacore::Int& nAnt);
160 :
161 : // Destructor
162 : virtual ~SingleDishSkyCal();
163 :
164 : // Return the type of this calibration matrix (actual type of derived class).
165 : // (Must be implemented in specializations!)
166 : //
167 : // 2015/03/19 (gmoellen): Use VisCal::M here, so that it is sorted
168 : // correctly in the VisEquation relative to "B TSYS"
169 0 : virtual Type type() { return VisCal::M; }
170 :
171 : // Return type name as string (ditto)
172 0 : virtual casacore::String typeName() { return "SD SKY"; }
173 0 : virtual casacore::String longTypeName() { return "SD SKY (sky spectra)"; }
174 :
175 : // Return casacore::Matrix type
176 : // single dish calibration is antenna-based
177 0 : virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::JONES; }
178 :
179 : // Mueller matrix type (must be implemented in Mueller specializations!)
180 0 : virtual Mueller::MuellerType muellerType() { return Mueller::AddDiag2; }
181 :
182 : // Return the parameter type
183 : // so far single dish calibration is real
184 0 : virtual VisCalEnum::VCParType parType() { return VisCalEnum::REAL; }
185 :
186 : // Number of pars per ant/bln
187 : // virtual casacore::Int nPar() { return nCorr_[currSpw()]; }
188 0 : virtual casacore::Int nPar() { return 2; }
189 :
190 : // Total number of (complex) parameters per solve
191 : // (specialize to jive with ant- or bln-basedness, etc.)
192 0 : virtual casacore::Int nTotalPar() { return nPar(); }
193 :
194 : // Does normalization by MODEL_DATA commute with this VisCal?
195 : // (if so, permits pre-solve time-averaging)
196 0 : virtual casacore::Bool normalizable() { return false; }
197 :
198 : // Hazard a guess at the parameters (solveCPar) given the data
199 : virtual void guessPar(VisBuffer& vb);
200 :
201 : // Differentiate VB model w.r.t. Cal parameters (no 2nd derivative yet)
202 : virtual void differentiate(CalVisBuffer& cvb);
203 : virtual void differentiate(VisBuffer& vb,
204 : casacore::Cube<casacore::Complex>& V,
205 : casacore::Array<casacore::Complex>& dV,
206 : casacore::Matrix<casacore::Bool>& Vflg);
207 :
208 : // Differentiate VB model w.r.t. Source parameters
209 : virtual void diffSrc(VisBuffer& vb,
210 : casacore::Array<casacore::Complex>& dV);
211 :
212 : // Apply refant (implemented in SVJ)
213 0 : virtual void reReference() {}
214 :
215 : // Accumulate another VisCal onto this one
216 : virtual void accumulate(SolvableVisCal* incr,
217 : const casacore::Vector<casacore::Int>& fields);
218 :
219 : // Determine and apply flux density scaling
220 : virtual void fluxscale(const casacore::String& outfile,
221 : const casacore::Vector<casacore::Int>& refFieldIn,
222 : const casacore::Vector<casacore::Int>& tranFieldIn,
223 : const casacore::Vector<casacore::Int>& inRefSpwMap,
224 : const casacore::Vector<casacore::String>& fldNames,
225 : const casacore::Float& inGainThres,
226 : const casacore::String& antSel,
227 : const casacore::String& timerangeSel,
228 : const casacore::String& scanSel,
229 : fluxScaleStruct& oFluxScaleStruct,
230 : const casacore::String& oListFile,
231 : const casacore::Bool& incremental,
232 : const casacore::Int& fitorder,
233 : const casacore::Bool& display);
234 :
235 : // Use generic data gathering mechanism for solve
236 0 : virtual casacore::Bool useGenericGatherForSolve() { return false; }
237 :
238 : // Report state:
239 : virtual void listCal(const casacore::Vector<casacore::Int> ufldids, const casacore::Vector<casacore::Int> uantids,
240 : const casacore::Matrix<casacore::Int> uchanids, //const casacore::Int& spw, const casacore::Int& chan,
241 : const casacore::String& listfile="",const casacore::Int& pagerows=50);
242 :
243 :
244 : // Local setApply
245 : using SolvableVisCal::setApply;
246 : virtual void setApply(const casacore::Record& apply);
247 :
248 : // In general, we are freq-dep
249 0 : virtual casacore::Bool freqDepPar() { return true; }
250 :
251 : // New CalTable handling
252 : virtual void keepNCT();
253 :
254 : // Self- gather and/or solve prototypes
255 : // (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F)
256 : virtual void selfGatherAndSolve(VisSet& vs, VisEquation& ve);
257 :
258 : protected:
259 :
260 : // The number of sets of parameters under consideration
261 : // This states size of third axis of SolveAllRPar
262 0 : virtual casacore::Int& nElem() { return nAnt(); }
263 :
264 : // Number of Calibration matrices on ant/bln axis
265 0 : virtual casacore::Int nCalMat() { return nAnt(); }
266 :
267 : // Are the parameters the matrix elements?
268 : // (or is a non-trivial calculation required?)
269 : // (Must be implemented in specializations!)
270 0 : virtual casacore::Bool trivialMuellerElem() { return false; }
271 :
272 : // Initialize solve parameters (shape)
273 : virtual void initSolvePar();
274 :
275 : // Invalidate diff cal matrices generically
276 0 : inline virtual void invalidateDiffCalMat() {}
277 :
278 : // overwride syncMeta2
279 : virtual void syncMeta2(const vi::VisBuffer2& vb);
280 :
281 : // Sync matrices generically for current meta data
282 : virtual void syncCalMat(const casacore::Bool& doInv=false);
283 :
284 : // Synchronize the differentiated calibration
285 : virtual void syncDiffMat();
286 :
287 : // Synchronize weight scale factors
288 : virtual void syncWtScale();
289 :
290 : // Perform weight scale calculation (specializable)
291 : template<class ScalingScheme>
292 : void calcWtScale();
293 :
294 : // Normalize a (complex) solution array (generic)
295 : virtual casacore::Float calcPowerNorm(casacore::Array<casacore::Float>& amp, const casacore::Array<casacore::Bool>& ok);
296 :
297 : // Invalidate cal matrices generically
298 0 : virtual void invalidateCalMat() {}
299 :
300 : // Row-by-row apply to a casacore::Cube<casacore::Complex> (generic)
301 : virtual void applyCal(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false);
302 : virtual void applyCal2(vi::VisBuffer2& vb,
303 : casacore::Cube<casacore::Complex>& Vout,casacore::Cube<casacore::Float>& Wout,
304 : casacore::Bool trial=false);
305 :
306 : // Fill calibration table by processing reference data found within user selection
307 : virtual void fillCalibrationTable(casacore::MeasurementSet const &reference_data);
308 :
309 : // Fill calibration table by processing reference data found within user selection,
310 : // using DataRealComponentAccessor to access real component of data
311 : // stored either in DATA or FLOAT_DATA column
312 : template<class DataRealComponentAccessor>
313 : void fillCalibrationTable(casacore::MeasurementSet const &reference_data);
314 :
315 : // Access to current calibration data
316 0 : inline casacore::Cube<casacore::Complex> ¤tSky() { return (*currentSky_[currSpw()]); }
317 0 : inline casacore::Cube<casacore::Bool> ¤tSkyOK() { return (*currentSkyOK_[currSpw()]); }
318 0 : inline SkyCal<casacore::Complex, casacore::Complex> &engineC() { return (*engineC_[currSpw()]); }
319 : inline SkyCal<casacore::Float, casacore::Float> &engineF() { return (*engineF_[currSpw()]); }
320 :
321 : // Select reference data from user-selected data
322 : // Implementation is specific to each observing-mode
323 : virtual casacore::MeasurementSet selectReferenceData(casacore::MeasurementSet const &user_selection) = 0;
324 :
325 : // Current antenna
326 : casacore::Int currAnt_;
327 : casacore::Vector<casacore::Double> interval_;
328 :
329 : // Single Dish Calibration algebra wrapper (per Spw)
330 : casacore::PtrBlock<SkyCal<casacore::Complex, casacore::Complex> *> engineC_;
331 : casacore::PtrBlock<SkyCal<casacore::Float, casacore::Float> *> engineF_;
332 :
333 : // Current Sky spectra
334 : casacore::PtrBlock<casacore::Cube<casacore::Complex> *> currentSky_; // [nSpw]([1,2],nChanMat,nAnt)
335 : casacore::PtrBlock<casacore::Cube<casacore::Bool> *> currentSkyOK_; // [nSpw]([1,2],nChanMat,nAnt)
336 :
337 : private:
338 : void initializeSky();
339 : void finalizeSky();
340 : void updateWt2(casacore::Matrix<casacore::Float> &weight, const casacore::Int& antenna1);
341 : void initializeCorr();
342 :
343 : // number of correlations per spw
344 : casacore::Vector<casacore::Int> nCorr_;
345 :
346 : // list of timestamps and intervals for each observation, spw, and antenna
347 : // as a nested map with key obsId (outermost), spwId, antennaId (innermost)
348 : std::map<std::pair<casacore::Int, casacore::Int>, std::map<casacore::Int, casacore::Matrix<casacore::Double> > > wtScaleData_;
349 : };
350 :
351 : class SingleDishPositionSwitchCal : public SingleDishSkyCal
352 : {
353 : public:
354 :
355 : // Constructor
356 : SingleDishPositionSwitchCal(VisSet& vs);
357 : SingleDishPositionSwitchCal(const MSMetaInfoForCal& msmc); // preferred ctor
358 : SingleDishPositionSwitchCal(const casacore::Int& nAnt);
359 :
360 : // Destructor
361 : virtual ~SingleDishPositionSwitchCal();
362 :
363 : // Return type name as string (ditto)
364 0 : virtual casacore::String typeName() { return "SDSKY_PS"; }
365 0 : virtual casacore::String longTypeName() { return "SDSKY_PS (position switch sky subtraction)"; }
366 :
367 : // Select reference data on top of user-specified selection,
368 : // for Single Dish observations consisting of:
369 : // * on-the-fly mappings of science targets
370 : // * with periodic executions of atmospheric calibrations scans inserted,
371 : // * made at the reference position of the science target
372 : // Reference positions are assumed to be free of spectral-line emission
373 : virtual casacore::MeasurementSet selectReferenceData(casacore::MeasurementSet const &user_selection);
374 :
375 : // Implement fillCalibrationTable for SingleDishPositionSwitchCal
376 : virtual void fillCalibrationTable(casacore::MeasurementSet const &reference_data);
377 : private:
378 : template<class DataRealComponentAccessor>
379 : void fillCalibrationTable(casacore::MeasurementSet const &reference_data);
380 :
381 : };
382 :
383 : class SingleDishRasterCal : public SingleDishSkyCal
384 : {
385 : public:
386 :
387 : // Constructor
388 : SingleDishRasterCal(VisSet& vs);
389 : SingleDishRasterCal(const MSMetaInfoForCal& msmc); // preferred ctor
390 : SingleDishRasterCal(const casacore::Int& nAnt);
391 :
392 : // Destructor
393 : virtual ~SingleDishRasterCal();
394 :
395 : // Return type name as string (ditto)
396 0 : virtual casacore::String typeName() { return "SDSKY_RASTER"; }
397 0 : virtual casacore::String longTypeName() { return "SDSKY_RASTER (position switch sky subtraction specific to OTF raster observation)"; }
398 :
399 : // local setSolve
400 : virtual void setSolve(const casacore::Record& solve);
401 :
402 : // Reference data selection, specific to the otf raster observing mode
403 : virtual casacore::MeasurementSet selectReferenceData(casacore::MeasurementSet const &ms);
404 :
405 : private:
406 : // edge detection parameter for otfraster mode
407 : casacore::Float fraction_;
408 : casacore::Int numEdge_;
409 : };
410 :
411 : class SingleDishOtfCal : public SingleDishSkyCal
412 : {
413 : public:
414 :
415 : // Constructor
416 : SingleDishOtfCal(VisSet& vs);
417 : // SingleDishOtfCal(const MSMetaInfoForCal& msmc); // preferred ctor ****ctor needs an MS!
418 : // Renaud: disabledSingleDishOtfCal(const casacore::Int& nAnt);
419 :
420 : // Destructor
421 : virtual ~SingleDishOtfCal();
422 :
423 : // Return type name as string (ditto)
424 0 : virtual casacore::String typeName() { return "SDSKY_OTF"; }
425 0 : virtual casacore::String longTypeName() { return "SDSKY_OTF (position switch sky subtraction specific to OTF fast scan)"; }
426 :
427 : // Reference data selection, specific to the on-the-fly fast scan observing mode
428 : virtual casacore::MeasurementSet selectReferenceData(casacore::MeasurementSet const &user_selection);
429 : virtual void setSolve(const casacore::Record& solve);
430 :
431 : private:
432 : // Edge detection parameters for otf mode
433 : casacore::Float fraction_;
434 : casacore::Float pixel_scale_;
435 :
436 : // casacore::MeasurementSet filtered with user-specified selection
437 : const casacore::MeasurementSet & msSel_ ;
438 :
439 : };
440 :
441 : } //# NAMESPACE CASA - END
442 :
443 : #endif /* _SYNTHESIS_SINGLEDISH_SKY_CAL_H_ */
444 :
445 :
|