casacore
Loading...
Searching...
No Matches
TabularCoordinate.h
Go to the documentation of this file.
1//# TabularCoordinate.h: Table lookup 1-D coordinate, with interpolation
2//# Copyright (C) 1997,1998,1999,2000,2001,2003,2004
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
27#ifndef COORDINATES_TABULARCOORDINATE_H
28#define COORDINATES_TABULARCOORDINATE_H
29
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayMath.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/coordinates/Coordinates/Coordinate.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37template<class Domain, class Range> class Interpolate1D;
38template<class T> class Quantum;
39class LogIO;
40
41
42
43// <summary>
44// Table lookup 1-D coordinate, with interpolation.
45// </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tTabularCoordinate">
50// </reviewed>
51
52// <prerequisite>
53// <li> <linkto class=Coordinate>Coordinate</linkto>
54// </prerequisite>
55//
56// <synopsis>
57// This class is used where the world and pixel values are determined by a
58// lookup table. For fractional pixel values, a linear interpolation is used.
59// The values returned for, e.g., the increment, are based on
60// the average of the whole table. At present,
61// the values must either increase or decrease monotonically.
62// </synopsis>
63//
64// <note role=caution>
65// All pixels coordinates are zero relative.
66// </note>
67//
68// <example>
69// Let's make a non-linear TabularCoordinate and convert a pixel
70// value to world (which will use linear interpolation)
71// <srcblock>
72// Vector<Double> pixelValues(3);
73// Vector<Double> worldValues(3);
74// pixelValues(0) = 122.0;
75// pixelValues(1) = 300.0;
76// pixelValues(2) = 6524.0;
77// worldValues(0) = 1.1e6;
78// worldValues(1) = 2.1e6;
79// worldValues(2) = 2.2e6;
80//
81// String unit("km");
82// String axisName("length");
83//
84// TabularCoordinate tc(pixelValues, worldValues, unit, axisName);
85//
86// Double world, pixel;
87// pixel = 200.12;
88// if (!tc.toWorld(world, pixel)) {
89// cerr << "Error : " << tc.errorMessage() << endl;
90// } else {
91// cerr << "pixel, world = " << pixel << ", " << world << endl;
92// }
93// </srcblock>
94// </example>
95//
96// <motivation>
97// This class was motivated by the need for an irregular axis, such as a collection
98// of frequencies. For example, the SpectralCoordinate class contains a TabularCoordinate.
99// </motivation>
100//
101//
102// <thrown>
103// <li> AipsError
104// </thrown>
105//
106// <todo asof="1997/07/12">
107// <li> Allow interpolations other than linear.
108// </todo>
109
110
112{
113public:
114 // Default constructor. It is equivalent to
115 // TabularCoordinate(0,1,0, "", "Tabular");
117
118 // Create a linear TabularCoordinate where
119 // <src>world = refval + inc*(pixel-refpix)</src>
121 const String &unit, const String &axisName);
122
123 // Create a linear TabularCoordinate with a Quantum-based interface where
124 // <src>world = refval + inc*(pixel-refpix)</src>. The units of the
125 // increment (<src>inc</src>) will be converted to
126 // those of the reference value (<src>refVal</src>) which will
127 // then serve as the units of the Coordinate.
129 const Quantum<Double>& inc,
130 Double refpix, const String& axisName);
131
132 // Construct a TabularCoordinate with the specified world values. The
133 // increments and related functions return the average values
134 // calculated from the first and last world values. The number of pixel
135 // and world values must be the same. Normally the pixel values will be
136 // 0,1,2,..., but this is not required.
137 //
138 // A linear interpolation/extrapolation is used for channels which are not
139 // supplied. The reference channel (pixel) is chosen to be 0. The
140 // frequencies must increase or decrease monotonically (otherwise the
141 // toPixel lookup would not be possible).
144 const String &unit, const String &axisName);
145
146 // Construct a TabularCoordinate with the specified world values
147 // via the Quantum-based interface. All comments for the
148 // previous constructor apply
151 const String &axisName);
152
153 // Copy constructor (copy semantics).
155
156 // Assignment (copy semantics).
158
159 // Destructor.
161
162 // Returns Coordinate::TABULAR.
163 virtual Coordinate::Type type() const;
164
165 // Always returns the String "Tabular".
166 virtual String showType() const;
167
168 // Always returns 1.
169 // <group>
170 virtual uInt nPixelAxes() const;
171 virtual uInt nWorldAxes() const;
172 // </group>
173
174 // Convert a pixel position to a world position or vice versa. Returns True
175 // if the conversion succeeds, otherwise it returns False and method
176 // errorMessage contains an error message. The output
177 // vectors are appropriately resized.
178 // The Bool parameter in toWorld() has no effect as this coordinate does
179 // not support a conversion layer frame.
180 // <group>
181 virtual Bool toWorld(Vector<Double> &world,
182 const Vector<Double> &pixel, Bool=True) const;
183 virtual Bool toPixel(Vector<Double> &pixel,
184 const Vector<Double> &world) const;
185 Bool toWorld(Double &world, Double pixel) const;
186 Bool toPixel(Double &pixel, Double world) const;
187 // </group>
188
189 // Batch up a lot of transformations. The first (most rapidly varying) axis
190 // of the matrices contain the coordinates. Returns False if any conversion
191 // failed and <src>errorMessage()</src> will hold a message.
192 // The <src>failures</src> array (True for fail, False for success)
193 // is the length of the number of conversions and
194 // holds an error status for each conversion.
195 // <group>
197 const Matrix<Double> &pixel,
198 Vector<Bool>& failures) const;
200 const Matrix<Double>& world,
201 Vector<Bool>& failures) const;
202 // </group>
203
204
205 // Make absolute coordinates relative and vice-versa (with
206 // respect to the referencfe value).
207 // Vectors must be length <src>nPixelAxes()</src> or
208 // <src>nWorldAxes()</src> or memory access errors will occur
209 // <group>
210 virtual void makePixelRelative (Vector<Double>& pixel) const {pixel -= crpix_p;};
211 virtual void makePixelAbsolute (Vector<Double>& pixel) const {pixel += crpix_p;};
212 virtual void makeWorldRelative (Vector<Double>& world) const {world -= crval_p;};
213 virtual void makeWorldAbsolute (Vector<Double>& world) const {world += crval_p;};
214 // </group>
215
216 // Return the requested attribute.
217 // <group>
221 virtual Vector<Double> increment() const;
223 // </group>
224
225 // Set the value of the requested attribute. Note that these just
226 // change the internal values, they do not cause any recomputation.
227 // <group>
228 virtual Bool setWorldAxisNames(const Vector<String> &names);
229 virtual Bool setReferencePixel(const Vector<Double> &refPix);
231 virtual Bool setIncrement(const Vector<Double> &inc) ;
232 virtual Bool setReferenceValue(const Vector<Double> &refval);
233 // </group>
234
235 // Set/get the axis unit. Adjust the increment and
236 // reference value by the ratio of the old and new units.
237 // The unit must be compatible with the current units.
238 // <group>
239 virtual Bool setWorldAxisUnits(const Vector<String> &units);
241 // </group>
242
243 // Overwrite the world axis units with no compatibility
244 // checks or adjustment.
246
247 // Get the table, i.e. the pixel and world values. The length of these
248 // Vectors will be zero if this axis is pure linear.
249 // <group>
252 // </group>
253
254 // Comparison function. Any private Double data members are compared
255 // with the specified fractional tolerance. Don't compare on the specified
256 // axes in the Coordinate. If the comparison returns False, method
257 // errorMessage() contains a message about why.
258 // <group>
259 virtual Bool near(const Coordinate& other,
260 Double tol=1e-6) const;
261 virtual Bool near(const Coordinate& other,
262 const Vector<Int>& excludeAxes,
263 Double tol=1e-6) const;
264 // </group>
265
266 // Find the Coordinate for when we Fourier Transform ourselves. This pointer
267 // must be deleted by the caller. Axes specifies which axes of the Coordinate
268 // you wish to transform. Shape specifies the shape of the image
269 // associated with all the axes of the Coordinate. Currently the
270 // output reference pixel is always shape/2. If the pointer returned is 0,
271 // it failed with a message in <src>errorMessage</src>
273 const Vector<Int>& shape) const;
274
275 // Save the TabularCoordinate into the supplied record using the supplied field name.
276 // The field must not exist, otherwise <src>False</src> is returned.
277 virtual Bool save(RecordInterface &container, const String &fieldName) const;
278
279 // Recover the TabularCoordinate from a record.
280 // A null pointer means that the restoration did not succeed - probably
281 // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
282 static TabularCoordinate *restore(const RecordInterface &container,
283 const String &fieldName);
284
285 // Make a copy of the TabularCoordinate using new. The caller is responsible for calling
286 // delete.
287 virtual Coordinate *clone() const;
288
289private:
294
295 // Channel_True = channel_corrections_p(Channel_average).
296 // <group>
299 // </group>
300
301 // Common for assignment operator and destructor.
303
304 // Common code for copy ctor and assignment operator.
305 void copy(const TabularCoordinate &other);
306
309};
310
311} //# NAMESPACE CASACORE - END
312
313
314#endif
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:141
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual Vector< String > worldAxisUnits() const
virtual Matrix< Double > linearTransform() const
static TabularCoordinate * restore(const RecordInterface &container, const String &fieldName)
Recover the TabularCoordinate from a record.
virtual Coordinate * makeFourierCoordinate(const Vector< Bool > &axes, const Vector< Int > &shape) const
Find the Coordinate for when we Fourier Transform ourselves.
Vector< Double > worldValues() const
virtual Coordinate * clone() const
Make a copy of the TabularCoordinate using new.
Bool overwriteWorldAxisUnits(const Vector< String > &units)
Overwrite the world axis units with no compatibility checks or adjustment.
Interpolate1D< Double, Double > * channel_corrector_rev_p
virtual Coordinate::Type type() const
Returns Coordinate::TABULAR.
TabularCoordinate(const Vector< Double > &pixelValues, const Vector< Double > &worldValues, const String &unit, const String &axisName)
Construct a TabularCoordinate with the specified world values.
virtual String showType() const
Always returns the String "Tabular".
virtual void makePixelAbsolute(Vector< Double > &pixel) const
Bool toPixel(Double &pixel, Double world) const
virtual void makeWorldRelative(Vector< Double > &world) const
virtual Vector< Double > referencePixel() const
void copy(const TabularCoordinate &other)
Common code for copy ctor and assignment operator.
Interpolate1D< Double, Double > * channel_corrector_p
Channel_True = channel_corrections_p(Channel_average).
Vector< Double > pixelValues() const
Get the table, i.e.
virtual Bool setIncrement(const Vector< Double > &inc)
virtual Vector< String > worldAxisNames() const
Return the requested attribute.
virtual Bool setReferenceValue(const Vector< Double > &refval)
virtual void makeWorldAbsolute(Vector< Double > &world) const
TabularCoordinate(const Vector< Double > &pixelValues, const Quantum< Vector< Double > > &worldValues, const String &axisName)
Construct a TabularCoordinate with the specified world values via the Quantum-based interface.
TabularCoordinate()
Default constructor.
virtual ~TabularCoordinate()
Destructor.
virtual Vector< Double > increment() const
virtual Bool toPixelMany(Matrix< Double > &pixel, const Matrix< Double > &world, Vector< Bool > &failures) const
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
virtual Vector< Double > referenceValue() const
TabularCoordinate & operator=(const TabularCoordinate &other)
Assignment (copy semantics).
Bool toWorld(Double &world, Double pixel) const
TabularCoordinate(const TabularCoordinate &other)
Copy constructor (copy semantics).
virtual Bool setWorldAxisUnits(const Vector< String > &units)
Set/get the axis unit.
virtual void makePixelRelative(Vector< Double > &pixel) const
Make absolute coordinates relative and vice-versa (with respect to the referencfe value).
virtual Bool save(RecordInterface &container, const String &fieldName) const
Save the TabularCoordinate into the supplied record using the supplied field name.
virtual uInt nPixelAxes() const
Always returns 1.
virtual Bool near(const Coordinate &other, const Vector< Int > &excludeAxes, Double tol=1e-6) const
virtual uInt nWorldAxes() const
TabularCoordinate(Double refval, Double inc, Double refpix, const String &unit, const String &axisName)
Create a linear TabularCoordinate where world = refval + inc*(pixel-refpix)
virtual Bool toWorldMany(Matrix< Double > &world, const Matrix< Double > &pixel, Vector< Bool > &failures) const
Batch up a lot of transformations.
virtual Bool setReferencePixel(const Vector< Double > &refPix)
virtual Bool toWorld(Vector< Double > &world, const Vector< Double > &pixel, Bool=True) const
Convert a pixel position to a world position or vice versa.
void makeNonLinearTabularCoordinate(const Vector< Double > &pixelValues, const Vector< Double > &worldValues)
void clear_self()
Common for assignment operator and destructor.
TabularCoordinate(const Quantum< Double > &refval, const Quantum< Double > &inc, Double refpix, const String &axisName)
Create a linear TabularCoordinate with a Quantum-based interface where world = refval + inc*(pixel-re...
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the value of the requested attribute.
virtual Bool setLinearTransform(const Matrix< Double > &xform)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53