casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointingDirectionCalculator.h
Go to the documentation of this file.
1 //# PointingDirectionCalculator.h: Does for MSes various fixes which do not involve calibrating.
2 //# Copyright (C) 2008
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 //# $Id$
27 //#
28 
29 #ifndef _SYNTHESIS_POINTING_DIRECTION_CALCULATOR_H_
30 #define _SYNTHESIS_POINTING_DIRECTION_CALCULATOR_H_
31 
32 #include <casa/aipstype.h>
33 #include <casa/BasicSL/String.h>
34 #include <casa/Arrays/Matrix.h>
35 #include <casa/Arrays/Vector.h>
49 // CAS-8418 //
51 #include <memory> // for unique_ptr<>
52 #include <utility> // for std::pair
53 
54 namespace casa {
55 
57 // <summary>Calculates Pointing Direction Efficiently</summary>
58 //
59 //<use visibility=export>
60 //
61 // <reviewed reviewer="UNKNOWN" date="before2018/05/22" tests="" demos="">
62 // </reviewed>
63 //
64 // The PointingDirectionCalculator calculates pointing directions for selected MS rows.
65 // The calculation is based on the information recorded in MS POINTING table.
66 // In general, sampling intervals for spectral (autocorrelation) data (MS MAIN table)
67 // and pointing direction information (MS POINTING table) are independent. Thus,
68 // any interpolation in time domain should be necessary to calculate the pointing
69 // direction from the MS POINTING table. In addition, a direction reference frame
70 // in MS POINTING table may be different from the desired one. In that case,
71 // the frame conversion is also required. The class is intended to automate those
72 // complicated calculation. User can obtain a list of pointing directions by
73 // calling a few configuration method to select data and/or specify output direction
74 // reference frame. The class supports pointing direction calculation for moving
75 // objects. If the flag for moving source is turn on, returned direction will be
76 // shifted to the first timestamp.
77 //
78 // <prerequisite>
79 // </prerequisite>
80 //
81 // <etymology>
82 // </etymology>
83 //
84 // <synopsis>
85 // The PointingDirectionCalculator calculates pointing directions for selected
86 // MS rows. The calculation is based on the information recorded in MS POINTING
87 // table.
88 // </synopsis>
89 //
90 // <example>
91 // Here is a typical example for ALMA data. In ALMA, POINTING information is
92 // recorded in AZELGEO reference. However, there is a case that we need
93 // pointing direction in celestial coordinate such as J2000. In such case,
94 // the code will look like the following.
95 // <srcblock>
96 // MeasurementSet ms; // any MS
97 // PointingDirectionCalculator calculator(ms);
98 // calculator.setDirectionListMatrixShape(PointingDirectionCalculator::ROW_MAJOR);
99 // calculator.selectData(spw="19", antenna="PM01&&&"); // select spw 19 and antnena PM01
100 // calculator.setDirectionColumn("DIRECTION");
101 // calculator.setFrame("J2000");
102 // Matrix directions = calculator.getDirection();
103 // </srcblock>
104 // </example>
105 //
106 // <motivation>
107 // Pointing direction is one of the crucial information on single-dish data
108 // reduction. However, such information is not directly associated with
109 // spectral (autocorrelation) data. Instead, pointing directions must be
110 // calculated from the records in MS POINTING table. That calculation is
111 // sometimes complicated. It may contain an interpolation in time as well
112 // as a conversion to desired direction reference frame. This class is
113 // designed to automate such calculation. The implementation is somewhat
114 // specialized for the usecase of single-dish data reduction.
115 // </motivation>
116 //
117 //#! <templating arg=T>
118 //#! </templating>
119 //
120 // <thrown>
121 // </thrown>
122 //
123 // <todo asof="before2018/05/22">
124 // <li> Define unit test
125 // <li> Implement more sophisticated interpolation method such as cubic spline
126 // </todo>
128 
129 class SplineInterpolation; // CAS-8418 Forward Reference //
130 
132 public:
133 
134  //+
135  // CAS-8418: typedef of accessor_ and Direction column types.
136  //-
137  typedef
139  casacore::uInt rownr);
140  typedef
142 
145 
146  // Enumerations for memory layout of the output pointing direction array.
147  // User should select the layout according to an usercase of this class.
148  enum MatrixShape {
149  // Memory layout is "column major"
151  // Memory layout is "row major"
153  };
154 
155  //+
156  // Constructor
157  //-
158 
159 //+
160 
161 // Create Spline five Objects on PointingDirectionCalculator.
162 //
163 // - The setDirectionColumn(name) performs all the initialization and make Coefficient table.
164 // - In this constructor, init() and setDirectionColumn("DIRECTION") are called,
165 // soon or later, setDirectionColumn will be called, whenever new Direction column is used
166 // and interporation is made.
167 // - The spline object is created by a column, which contains all antenna_Id.
168 // - Cofficient table is obtained from SDPosInterpolation.
169 // - SplineInterpolation class in this file provides calculation but it is sort of customize
170 // for PoinitngDirectionCalculator.
171 // - To see the initialization, please start from setDirectionColumn().
172 //-
173 
175 
176  // Destructor
178 
179  // Select data in the given MS.
180  // Each selection parameters accept MS data selection syntax.
181  void selectData(casacore::String const &antenna = "",
182  casacore::String const &spw ="",
183  casacore::String const &field = "",
184  casacore::String const &time = "",
185  casacore::String const &scan = "",
186  casacore::String const &feed = "",
187  casacore::String const &intent = "",
188  casacore::String const &observation = "",
189  casacore::String const &uvrange = "",
190  casacore::String const &msselect = "");
191 
192  //+
193  // Select which POINTING column to use for pointing direction calculation.
194  // Possible values are "DIRECTION" (default), "TARGET", "POINTING_OFFSET",
195  // "SOURCE_OFFSET", and "ENCODER". These values are all case-sensitive.
196  //
197  // CAS-8418 Update
198  // Spline-Interpolation initialization is inserted for each POINTING Column.
199  // Once this is done, the object will be reused.
200  //-
201 
202  void setDirectionColumn(casacore::String const &columnName = "DIRECTION");
203 
204  //+
205  // Set output direction reference frame. This accepts reference strings which
206  // <linkto class=MDirection>MDirection</linkto> can recognize.
207  // If given string is invalid, the frame will be set to "J2000".
208  //-
209 
210  void setFrame(casacore::String const frameType);
211 
212  //+
213  // Set output direction matrix shape. If "ROW_MAJOR" is given, the shape will be
214  // (2, nrow) where nrow is a number of selected rows in MS. If "COLUMN_MAJOR" is
215  // set, the shape will be (nrow, 2). User can choose appropriate shape according
216  // to the access pattern for the output direction matrix.
217  //-
218 
221 
222  //+
223  // <group>
224  // Set source name for the moving source.
225  // The method accepts source names which <linkto class=MDirection>MDirection</linkto>
226  // can recognize (e.g. "Moon", "Jupiter").
227  // If given string is invalid, exception will be thrown. User can specify the moving source
228  // using a string or the MDirection instance.
229 
230  void setMovingSource(casacore::String const sourceName);
231  void setMovingSource(casacore::MDirection const &sourceDirection);
232 
233  // </group>
234 
235  //+
236  // Clear the moving source setting.
237  //-
238 
239  void unsetMovingSource();
240 
241  //+
242  // Return number of rows for selected MS.
243  //-
244 
246 
247  //+
248  // Return direction type as a <linkto class=MDirection>MDirection::Types</linkto>
249  // enum.
250  //-
251 
253 
254  //+
255  // Return an information on the moving source as a <linkto class=MDirection>MDirection</linkto>
256  // instance.
257  //-
258 
260 
261  //+
262  // Return pointing direction matrix. Its shape depends on the user set the shape to
263  // "ROW_MAJOR" or "COLUMN_MAJOR". Returned directions are interpolated to timestamps
264  // recorded in the selected MS, and are converted to desired direction reference
265  // frame if necessary.
266  //-
267 
269 
270  //+
271  // Return pointing direction for specified row.
272  // If irow is larger than or equal to the number of rows for selected MS,
273  // exception will be thrown.
274  //-
275 
277 
278  // <group>
279  // Return a list of row ids for selected rows. The getRowId will return the ids
280  // in selected MS. On the other hand, the getRowIdForOriginalMS will return
281  // the ids in original MS.
282 
285 
286  // </group>
287 
288  //+
289  // Return a row id for specified row.
290  // If irow is larger than or equal to the number of rows for selected MS,
291  // exception will be thrown.
292  //-
293 
295 
296  //***************************************
297  // CAS-8418 Spline Interpolation API
298  //***************************************
299 
300  // Spline interpolation Enable/Disable (true=ENABLE)
301 
302  inline void setSplineInterpolation(bool mode) {useSplineInterpolation_ = mode;};
303 
304  // Curret Direction column (=accessor in this source) (for UT)
305 
306  inline PtColID getCurretAccessorId() { return accessorId_ ; };
307 
308  // Exporting COEFF table. //
309 
310  bool isCoefficientReady(); // true if current COEFF is availabe
311  COEFF exportCoeff(); // returns copy of COEFF
312 
313 private:
314 
315  void init();
316  void initPointingTable(casacore::Int const antennaId);
317  void resetAntennaPosition(casacore::Int const antennaId);
318  void resetTime(casacore::Double const timestamp);
319  void inspectAntenna();
321 
324 
325  // table access stuff
326 
335 
337  casacore::uInt rownr);
338  // conversion stuff
339 
347 
352 
353  // other
354 
362 
363  // privatize default constructor
364 
366 
367  //**********************************************
368  // CAS-8418 Spline Extended
369  // (Initial values on the top of Constructor)
370  //**********************************************
371 
372  // Spline Type , Initialized in Constructor. 'true' enables Spline Interpoation. //
374 
375  // Current Spline Object (become active with specified Direction Column)
377 
378  // Spline Object for each Direction-Column
379  casacore::vector<std::unique_ptr<casa::SplineInterpolation> > splineObj_;
380 
381  // Internal conditions to check limitted service.
384 
385  // Accessor ID (See typedef above. )
387 
388  // check specified Column when creating Spline-Object.
389 
390  bool checkColumn(casacore::MeasurementSet const &ms,
391  casacore::String const &columnName );
392 
393  // Initialize Coefficient table.
395 
396  // Current Spline-Object handle. (only available SplineInterpolation class)
398 
399 };
400 
401 //+
402 // CAS-8418
403 // Spline Interpolation Class
404 //-
405 
407 public:
408  // Coefficient table typedef //
411 
412  // Constructor
414 
416 
417  // Calculating Function //
418 
420  casacore::Double dt,
421  casacore::uInt AntennaID =0);
422  // Spline-Obj coefficient status //
423 
425 
426  // Programmers API:: for Coefficient Table access //
427 
428  COEFF getCoeff() { return coeff_; }
429 
430  // CAS-8418 Time Gap
432  { return tmp_timegap[ant][index]; }
433 
434 private:
435  // default constructor
436 
438 
439  // constructor sub.
440 
441  void init( casacore::MeasurementSet const &ms,
442  PointingDirectionCalculator::ACCESSOR const my_accessor);
443 
444  // Coefficient (set up by SDPosInterpolator)
445 
447 
448  // Interal Staus (one Spline status)//
449 
450  bool stsCofficientReady = false;
451 
452  // Coeff debug in csv. //
453  void dumpCsvCoeff();
454 
455  //*
456  // CAS-8418 Time Gap
457  // (relocated and new )
458  //*
459 
464 
465 };
466 
467 
468 } //# NAMESPACE CASA - END
469 
470 #endif /* _SYNTHESIS_POINTING_DIRECTION_CALCULATOR_H_ */
void setFrame(casacore::String const frameType)
Set output direction reference frame.
void unsetMovingSource()
Clear the moving source setting.
casa::SplineInterpolation * currSpline_
Current Spline Object (become active with specified Direction Column)
A Measure: astronomical direction.
Definition: MDirection.h:174
bool checkColumn(casacore::MeasurementSet const &ms, casacore::String const &columnName)
check specified Column when creating Spline-Object.
A 1-D Specialization of the Array class.
Memory layout is &quot;row major&quot;.
A Measure: position on Earth.
Definition: MPosition.h:79
int Int
Definition: aipstype.h:50
casacore::Vector< casacore::Vector< bool > > tmp_timegap
SplineInterpolation()
default constructor
casacore::ScalarColumn< casacore::Int > antennaColumn_
PtColID accessorId_
Accessor ID (See typedef above.)
casacore::Vector< casacore::Vector< casacore::Vector< casacore::Double > > > tmp_dir
casa::SplineInterpolation * getCurrentSplineObj()
Current Spline-Object handle.
casacore::MPosition antennaPosition_
conversion stuff
casacore::Vector< bool > initializeReady_
Internal conditions to check limitted service.
casacore::CountedPtr< casacore::MDirection::Convert > movingSourceConvert_
~PointingDirectionCalculator()
Destructor.
bool initializeSplinefromPointingColumn(casacore::MeasurementSet const &ms, PtColID colNo)
Initialize Coefficient table.
casacore::CountedPtr< casacore::MDirection::Convert > directionConvert_
void initPointingTable(casacore::Int const antennaId)
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
Container for Measure frame.
Definition: MeasFrame.h:137
A class to provide easy read-write access to MSPointing columns.
casacore::MDirection const & getMovingSourceDirection()
Return an information on the moving source as a MDirection instance.
casacore::Vector< casacore::Double > calculate(casacore::uInt row, casacore::Double dt, casacore::uInt AntennaID=0)
Calculating Function //.
casacore::ScalarMeasColumn< casacore::MEpoch > timeColumn_
A Measure: instant in time.
Definition: MEpoch.h:104
casacore::Vector< casacore::Vector< casacore::Double > > tmp_time
void dumpCsvCoeff()
Coeff debug in csv.
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
Memory layout is &quot;column major&quot;.
casacore::Matrix< casacore::Double > getDirection()
Return pointing direction matrix.
void init(casacore::MeasurementSet const &ms, PointingDirectionCalculator::ACCESSOR const my_accessor)
constructor sub.
casacore::MDirection(* accessor_)(casacore::MSPointingColumns &pointingColumns, casacore::uInt rownr)
void selectData(casacore::String const &antenna="", casacore::String const &spw="", casacore::String const &field="", casacore::String const &time="", casacore::String const &scan="", casacore::String const &feed="", casacore::String const &intent="", casacore::String const &observation="", casacore::String const &uvrange="", casacore::String const &msselect="")
Select data in the given MS.
void setMovingSource(casacore::String const sourceName)
double Double
Definition: aipstype.h:55
casacore::CountedPtr< casacore::MeasurementSet > originalMS_
table access stuff
bool stsCofficientReady
Interal Staus (one Spline status)//.
enum casa::PointingDirectionCalculator::DC_ PtColID
casacore::ScalarColumn< casacore::Double > intervalColumn_
casacore::Vector< casacore::uInt > getRowId()
Return a list of row ids for selected rows.
casacore::MDirection::Types const & getDirectionType()
Return direction type as a MDirection::Types enum.
casacore::CountedPtr< casacore::MSPointingColumns > pointingColumns_
casacore::CountedPtr< casacore::MDirection > movingSource_
void(* movingSourceCorrection_)(casacore::CountedPtr< casacore::MDirection::Convert > &convertToAzel, casacore::CountedPtr< casacore::MDirection::Convert > &convertToCelestial, casacore::Vector< casacore::Double > &direction)
casacore::Vector< casacore::Double > doGetDirection(casacore::uInt irow)
MatrixShape
Enumerations for memory layout of the output pointing direction array.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
casacore::CountedPtr< casacore::MeasurementSet > selectedMS_
A Table intended to hold astronomical data (a set of Measurements).
casacore::Vector< casacore::uInt > getRowIdForOriginalMS()
CAS-8418 Spline Interpolation Class
casacore::Vector< casacore::Vector< casacore::Vector< casacore::Vector< casacore::Double > > > > COEFF
Coefficient table typedef //.
casacore::Vector< casacore::Double > pointingTimeUTC_
casacore::vector< std::unique_ptr< casa::SplineInterpolation > > splineObj_
Spline Object for each Direction-Column.
casacore::uInt getNrowForSelectedMS()
Return number of rows for selected MS.
void setDirectionListMatrixShape(PointingDirectionCalculator::MatrixShape const shape)
Set output direction matrix shape.
casacore::Vector< casacore::Vector< casacore::Double > > tmp_dtime
PtColID getCurretAccessorId()
Curret Direction column (=accessor in this source) (for UT)
void setDirectionColumn(casacore::String const &columnName="DIRECTION")
Select which POINTING column to use for pointing direction calculation.
void resetAntennaPosition(casacore::Int const antennaId)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
PointingDirectionCalculator()
privatize default constructor
bool isTimeGap(casacore::uInt ant, casacore::uInt index)
CAS-8418 Time Gap.
bool isCoefficientReady()
Spline-Obj coefficient status //.
casacore::MDirection(* ACCESSOR)(casacore::MSPointingColumns &pointingColumns, casacore::uInt rownr)
CAS-8418: typedef of accessor_ and Direction column types.
void resetTime(casacore::Double const timestamp)
casacore::CountedPtr< casacore::MSPointing > pointingTable_
COEFF getCoeff()
Programmers API:: for Coefficient Table access //.
COEFF coeff_
Coefficient (set up by SDPosInterpolator)
casacore::Vector< casacore::uInt > antennaBoundary_
other
bool isCoefficientReady()
Exporting COEFF table.
casacore::Vector< casacore::Vector< casacore::Vector< casacore::Vector< casacore::Double > > > > COEFF
unsigned int uInt
Definition: aipstype.h:51
PointingDirectionCalculator::MatrixShape shape_