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