casacore
Loading...
Searching...
No Matches
EarthMagneticEngine.h
Go to the documentation of this file.
1// # EarthMagneticEngine.h: Engine for TaQL UDF EarthMagnetic conversions
2// # Copyright (C) 2016
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_EARTHMAGNETICENGINE_H
27#define MEAS_EARTHMAGNETICENGINE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/meas/MeasUDF/MeasEngine.h>
32#include <casacore/measures/Measures/EarthMagneticMachine.h>
33#include <casacore/measures/Measures/MEarthMagnetic.h>
34#include <casacore/measures/Measures/MCEarthMagnetic.h>
35#include <casacore/measures/Measures/MeasConvert.h>
36
37namespace casacore {
38
39// # Forward declarations
40class DirectionEngine;
41class EpochEngine;
42class PositionEngine;
43
44// <summary>
45// Engine for TaQL UDF EarthMagnetic conversions
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="" date="" tests="tMeas.cc">
51// </reviewed>
52
53// <prerequisite>
54// # Classes you should understand before using this one.
55// <li> EngineBase
56// </prerequisite>
57
58// <synopsis>
59// EarthMagneticEngine defines Engines (user defined functions) that can be
60// used in TaQL to convert EarthMagnetic values from one frame to another
61// or to calculate them from the IGRF model.
62// In this way such derived values appear to be ordinary TaQL functions.
63//
64// In TaQL these functions can be called like:
65// <srcblock>
66// meas.em (toref, emvalues, epochs, positions)
67// meas.igrf (toref, heights, directions, epochs, positions)
68// meas.igrflos (heights, directions, epochs, positions)
69// meas.igrflong (heights, directions, epochs, positions)
70// </srcblock>
71// The first one converts the given EarthMagnetic values to the 'toref'
72// frame for all epoch and positions (their Cartesian product).
73// The second one calculates the IGRF model values in the 'toref' frame
74// for all heights, directions, epochs and positions.
75// The 3rd and 4th return the model value along the line-of-sight cq. as
76// longitude for all heights, directions, epochs and positions.
77// The first two function names can be followed by XYZ, ANGLES or LENGTH
78// to return the values according to the suffix.
79// <ul>
80// <li> <src>toref</src> is a single constant string.
81// If not given, it defaults to ITRF. Note that 'toref' can also be
82// given for function IGRFLOS and IGRFLONG, but is neglected.
83// <li> <src>emvalues</src> gives the EarthMagnetic values to be converted.
84// They can be given in various forms.
85// <ul>
86// <li> An array of positions given as xyz or as lon-lat-flux
87// Note that specifying as lon-lat-flux precludes use of units
88// (angle and length units cannot be mixed in a TaQL value),
89// while xyz must have a flux unit (e.g., nT). It means that the
90// unit determines if xyz or lon-lat-flux is given.
91// It can be given as a single list or a multi-dim array.
92// It can be followed by a string defining the source
93// reference type, which defaults to ITRF.
94// <li> If a single constant position is used, it can be given as
95// 3 scalar values, optionally followed by the source
96// reference type. The unit defines iff x,y,z or lon-lat-flux is
97// given.
98// <li> The name of a column in a table or a subset of it such as
99// <src>EMVAL[0,]</src>. Often this is a TableMeasures column
100// which is recognized as such, also its source reference frame.
101// If such a column is used in a expression, it will not be
102// recognized as a TableMeasures column and its reference frame
103// should be given.
104// </ul>
105// <li> <src>heights</src> is one or more real values giving the heights
106// above the earth at which the model has to be calculated.
107// Default unit is m.
108// <li> <src>directions</src> defines the directions in which the model
109// has to be calculated. They can be given in all forms as described
110// in class DirectionEngine.
111// <li> <src>epochs</src> can be given as shown in class EpochEngine.
112// <li> <src>positions</src> can be given as shown in class PositionEngine.
113// </ul>
114// All functions return data with type double and unit nT. Unit rad is
115// returned for functions with the ANGLES suffix.
116//
117// The result of a conversion is an array with shape [1|2|3,em,epoch,pos].
118// The model calculations result has shape [1|2|3,h,dir,epoch,pos]
119// The last 3 or 4 elements are the shapes of these arguments. They are
120// omitted if all of them have length 1.
121// </synopsis>
122
123// <example>
124// <srcblock>
125// // Get IGRF model value for today at the WSRT at 200 km height
126// // in the direction of the SUN.
127// meas.igrf (200km, 'SUN', date(), 'WSRT')
128// // Similar, but the flux along the line of sight.
129// meas.igrflos (200km, 'SUN', date(), 'WSRT')
130// // Convert an earthmagnetic value from ITRF to J2000 angles.
131// meas.emang ('J2000', 677, 45441, 29517, date(), 'WSRT')
132// </srcblock>
133// </example>
134
135// <motivation>
136// It makes it possible to handle measures in TaQL.
137// </motivation>
138
139class EarthMagneticEngine : public MeasEngine<MEarthMagnetic> {
140 public:
142
144
145 // Get the value type. It also gives the nr of output values per position.
146 // 0=default, 1=length (in tesla), 2=angles (in radians)
147 Int valueType() const { return itsValueType; }
148
149 // Get the values.
151
152 // Handle the argument(s) giving the input earthMagnetics or direction
153 // and reference type. The earthMagnetic can be a column in a table.
154 // Note that direction (or height) can only be given for reftype IGRF.
155 void handleEarthMagnetic(std::vector<TENShPtr>& args, uInt& argnr);
156
157 // Handle the heights argument.
158 void handleHeight(TENShPtr& operand);
159
160 // Set the MeasConvert object.
161 // Set the possible epoch engine.
162 // It can be done only once.
164
165 // Set the possible position engine.
166 // It can be done only once.
168
169 // Set the possible direction engine.
170 // It can be done only once.
172
173 // Set the types of the result.
174 void set(MEarthMagnetic::Types toRefType, Int toValueType, Bool asLOS, Bool asLong,
175 Bool useModel);
176
177 private:
178 // Strip a possible suffix from the reference type.
180 virtual void deriveAttr(const Unit& unit, Int nval);
182 // Make an MEarthMagnetic from xyz or length,angles.
184 const Quantity& q2) const;
185 void handleScalars(const TENShPtr& e1, const TENShPtr& e2, const TENShPtr& e3);
186 virtual void handleValues(TableExprNode& operand, const TableExprId& id,
187 Array<MEarthMagnetic>& earthMagnetics);
190 void copyEM(const MVEarthMagnetic& em, double*& outPtr);
191 void copyLLEM(EarthMagneticMachine& emm, double*& outPtr);
192
193 // # Data members.
194 MeasFrame itsFrame; // # frame used by converter
195 EarthMagneticMachine itsMachine; // # model calculations
198 // # 3=xyz flux, -3=angle,flux
200 Bool itsAsLOS; // # get as line-of-sight?
201 Bool itsAsLong; // # get as longitude?
202 Bool itsUseModel; // # use model calculation?
203 Bool itsConvertModel; // # model to non-ITRF?
207};
208
209} // namespace casacore
210
211#endif
const Unit & unit() const
Get the unit of the function's result.
Definition BaseEngine.h:115
virtual void deriveAttr(const Unit &unit, Int nval)
Let a derived class derive its attributes.
MEarthMagnetic makeEarthMagnetic(const Quantity &qh, const Quantity &q1, const Quantity &q2) const
Make an MEarthMagnetic from xyz or length,angles.
void set(MEarthMagnetic::Types toRefType, Int toValueType, Bool asLOS, Bool asLong, Bool useModel)
Set the types of the result.
void setPositionEngine(PositionEngine &engine)
Set the possible position engine.
Array< Double > getHeights(const TableExprId &id)
MEarthMagnetic::Convert itsConverter
Array< MEarthMagnetic > getEarthMagnetics(const TableExprId &id)
virtual String stripMeasType(const String &type)
Strip a possible suffix from the reference type.
Int valueType() const
Get the value type.
void handleHeight(TENShPtr &operand)
Handle the heights argument.
void handleScalars(const TENShPtr &e1, const TENShPtr &e2, const TENShPtr &e3)
virtual void handleValues(TableExprNode &operand, const TableExprId &id, Array< MEarthMagnetic > &earthMagnetics)
Let a derive class handle the values.
void handleEarthMagnetic(std::vector< TENShPtr > &args, uInt &argnr)
Handle the argument(s) giving the input earthMagnetics or direction and reference type.
Array< Double > getArrayDouble(const TableExprId &id)
Get the values.
void copyLLEM(EarthMagneticMachine &emm, double *&outPtr)
virtual void setValueType(Int valueType)
Let a derived class set its value type.
void setDirectionEngine(DirectionEngine &engine)
Set the possible direction engine.
void setEpochEngine(EpochEngine &engine)
Set the MeasConvert object.
void copyEM(const MVEarthMagnetic &em, double *&outPtr)
MeasConvert< MEarthMagnetic > Convert
Measure Convert (i.e.
Types
Types of known MEarthMagnetics Tip: The order defines the order in the translation matrix FromTo in ...
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:56
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
Quantum< Double > Quantity
Definition Quantum.h:40