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