casacore
Loading...
Searching...
No Matches
DirectionEngine.h
Go to the documentation of this file.
1// # DirectionEngine.h: Engine for TaQL UDF Direction conversions
2// # Copyright (C) 2011
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: casa-feedback@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#ifndef MEAS_DIRECTIONENGINE_H
27#define MEAS_DIRECTIONENGINE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/meas/MeasUDF/MeasEngine.h>
32#include <casacore/measures/Measures/MDirection.h>
33#include <casacore/measures/Measures/MCDirection.h>
34#include <casacore/measures/Measures/MeasConvert.h>
35
36namespace casacore {
37
38// # Forward declarations
39class EpochEngine;
40class PositionEngine;
41
42// <summary>
43// Engine for TaQL UDF Direction conversions
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="" date="" tests="tMeas.cc">
49// </reviewed>
50
51// <prerequisite>
52// # Classes you should understand before using this one.
53// <li> EngineBase
54// </prerequisite>
55
56// <synopsis>
57// DirectionEngine defines Engines (user defined functions) that can be
58// used in TaQL to convert Measures for directions.
59// In this way such derived values appear to be ordinary TaQL functions.
60//
61// In TaQL these functions can be called like:
62// <srcblock>
63// meas.dir (toref, directions, epochs, positions)
64// meas.j2000 (directions, epochs, positions)
65// meas.dircos (toref, directions, epochs, positions)
66// meas.riset (directions, epochs, positions)
67// </srcblock>
68// The first two result in angles, the third in direction cosines, while
69// the fourth returns the rise/set time of sources as datetimes.
70// Note that the second form is a shorthand for
71// <src>meas.dir('j2000', ...)</src>. There are more such functions.
72// The exact number of arguments depends on how they are specified.
73// <ul>
74// <li> <src>toref</src> is a single constant string defining the
75// reference frame to convert to. Note it should be omitted for
76// the functions (e.g., meas.j2000) with an implicit destination
77// reference frame.
78// <li> <src>directions</src> is one or more directions which can be
79// given in several ways.
80// <ul>
81// <li> An array of directions, each 2 angles or 3 directions cosines.
82// It can be given as a single list or a multi-dim array. The choice
83// between angles and direction cosines is based on the size of the
84// first dimension. If divisible by 2, it is angles, by 3 is
85// direction cosines, otherwise an error. Thus a list of 6 elements
86// defines 3 directions with 2 angles each (default in radians).
87// <br>It can be followed by a string defining the source
88// reference frame. It defaults to 'J2000'.
89// <li> If a single constant direction is used, it can be given as
90// 2 (for angles) or 3 (for direction cosines) scalar values,
91// followed by the optional source reference frame.
92// <li> The name of a column in a table or a subset of it such as
93// <src>DELAY_DIR[0,]</src>. Often this is a TableMeasures column
94// which is recognized as such, also its source reference frame.
95// If such a column is given as part of an expression, it will not
96// be recognized as a TableMeasures column and its reference frame
97// should be given.
98// <li> As a list of (case-insensitive) names of known sources
99// such as 'CasA' or 'SUN'.
100// </ul>
101// <li> <src>epochs</src> can be given as shown in class EpochEngine.
102// <li> <src>positions</src> can be given as shown in class PositionEngine.
103// </ul>
104// Note that epochs and positions are only needed if required by the
105// conversion from source reference frame to destination reference frame.
106// For example, J2000 to/from APP needs them, but not J2000 to/from B1950.
107//
108// The result of the function is an array with shape [2|3,dir,epoch,pos]
109// where the last 3 elements are the shapes of these arguments. They are
110// omitted if all of them have length 1.
111//
112// Futhermore, it is possible to get the rise/set date/time of a source
113// given the source direction, date and position on earth. These functions
114// return data with type double and unit d (day).
115// If the source is visible all day, the rise time is 0 and set time 1.
116// If the source is not visible at all, the rise time is 1 and set time 0.
117// For the sun and the moon it is possible to add a suffix to the name
118// telling if and which edge and twilight should be used. For the sun and
119// moon the default is -UR (the upper edge with refraction correction).
120// </synopsis>
121
122// <example>
123// <srcblock>
124// // Get rise/set time of the upper edge of the sun in the coming month
125// // at the WSRT site.
126// meas.riseset ('SUN', date()+[0:31], 'WSRT')
127// // Get the apparent coordinates of CasA for the given date and position.
128// meas.dircos ('APP', 'CasA', 12mar2015, [52deg,5deg])
129// // Get the J2000 coordinates (in degrees) of CygA.
130// meas.j2000 ('cyga') deg
131// </srcblock>
132// </example>
133
134// <motivation>
135// It makes it possible to easily handle measures in TaQL.
136// </motivation>
137
138class DirectionEngine : public MeasEngine<MDirection> {
139 public:
141
143
144 // Get the values.
145 // The first Bool tells if rise/set times have to be calculated.
146 // The second Bool tells if direction cosines have to be calculated.
147 Array<Double> getArrayDouble(const TableExprId& id, Bool riseSet, Bool asDirCos);
148
149 // Get the directions.
151
152 // Handle the argument(s) giving the input directions and reference type.
153 // The direction can be a column in a table.
154 void handleDirection(const std::vector<TENShPtr>& args, uInt& argnr, Bool riseSet, Bool asDirCos);
155
156 // Set the MeasConvert object.
158
159 // Set the possible epoch engine.
160 // It can be done only once.
162
163 // Set the possible position engine.
164 // It can be done only once.
166
167 private:
168 void handleScalars(const TENShPtr& e1, const TENShPtr& e2, const TENShPtr& e3);
169 void handleNames(const TENShPtr& operand);
170 virtual void handleValues(TableExprNode& operand, const TableExprId& id,
171 Array<MDirection>& directions);
172
173 // Calucate the rise and set time of a source for a given position and
174 // epoch. Argument <src>h</src> defines the possible edge of sun/moon.
175 void calcRiseSet(const MDirection& dir, const MPosition& pos, const MEpoch& epoch, double h,
176 double& rise, double& set);
177 int fillRiseSet(double epoch, const MDirection& dir, double lat, double h, const MEpoch& off,
178 double* rise, double* set);
179
180 // # Data members.
181 MeasFrame itsFrame; // # frame used by converter
183 Vector<Double> itsH; // # diff for sun or moon
186};
187
188} // namespace casacore
189
190#endif
Array< Double > getArrayDouble(const TableExprId &id, Bool riseSet, Bool asDirCos)
Get the values.
void calcRiseSet(const MDirection &dir, const MPosition &pos, const MEpoch &epoch, double h, double &rise, double &set)
Calucate the rise and set time of a source for a given position and epoch.
void setEpochEngine(EpochEngine &engine)
Set the possible epoch engine.
void handleDirection(const std::vector< TENShPtr > &args, uInt &argnr, Bool riseSet, Bool asDirCos)
Handle the argument(s) giving the input directions and reference type.
MDirection::Convert itsConverter
PositionEngine * itsPositionEngine
void handleScalars(const TENShPtr &e1, const TENShPtr &e2, const TENShPtr &e3)
Array< MDirection > getDirections(const TableExprId &id)
Get the directions.
void setConverter(MDirection::Types toType)
Set the MeasConvert object.
int fillRiseSet(double epoch, const MDirection &dir, double lat, double h, const MEpoch &off, double *rise, double *set)
void handleNames(const TENShPtr &operand)
void setPositionEngine(PositionEngine &engine)
Set the possible position engine.
virtual void handleValues(TableExprNode &operand, const TableExprId &id, Array< MDirection > &directions)
Let a derive class handle the values.
MeasConvert< MDirection > Convert
Measure Convert (i.e.
Definition MDirection.h:244
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:187
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
void set(const T &val)
Definition Block.h:541
unsigned int uInt
Definition aipstype.h:49
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:56
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40