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