casacore
Loading...
Searching...
No Matches
StokesCoordinate.h
Go to the documentation of this file.
1// # StokesCoordinate.h: Interconvert between pixel number and Stokes value.
2// # Copyright (C) 1997,1998,1999,2000,2001,2002,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_STOKESCOORDINATE_H
27#define COORDINATES_STOKESCOORDINATE_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/coordinates/Coordinates/Coordinate.h>
31#include <casacore/measures/Measures/Stokes.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/casa/Arrays/Vector.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Interconvert between pixel and Stokes value.
39// </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tStokesCoordinate">
44// </reviewed>
45//
46// <prerequisite>
47// <li> <linkto class=Coordinate>Coordinate</linkto>
48// <li> <linkto class=Stokes>Stokes</linkto>
49// </prerequisite>
50//
51// <synopsis>
52// Although not really a "coordinate", an axis where pixel numbers are used
53// for different Stokes values is in wide use. The StokesCoordinate
54// is a poor fit to the Coordinate polymorphic model.
55// You will probably find that if you try to use the Coordinate
56// classes polymorphically, that StokesCoordinate will cause you
57// to break the polymorphism. I.e. you may have to deal with
58// a specific StokesCoordinate)
59//
60// The StokesCoordinate just maintains a list (given in the constructor) of
61// possibly non-monotonic Stokes values. The values of the list are the
62// world values (they are values from the Stokes::StokesTypes enum).
63// Thus world = list[pixel] where pixel is the pixel coordinate (0,1, ...)
64//
65// This means that concepts such as reference pixel, reference value,
66// increment etc are meaningless for StokesCoordinate. You can recover these
67// these attributes, but the functions to set these attributes have no effect.
68//
69// Note also that for the StokesCoordinate relative world coordinates are defined to be the
70// as absolute, since there is no meaning for a relative Stokes world value (e.g.
71// what is XX -RL ?? Relative pixel coordinates are defined.
72//
73// </synopsis>
74//
75// <note role=caution>
76// All pixel coordinates are zero relative.
77// </note>
78//
79// <example>
80// In this example we create a StokesCoordinate housing IQUV
81// <srcblock>
82// Vector<Int> iquv(4);
83// iquv(0) = Stokes::I; iquv(1) = Stokes::Q;
84// iquv(2) = Stokes::U; iquv(3) = Stokes::V;
85// StokesCoordinate stokes(iquv);
86// </srcblock>
87// </example>
88//
89// <motivation>
90// It is conventional to make a pseudo-axis of Stokes parameters.
91// Another approach is to make an image type called Stokes.
92// </motivation>
93//
94// <todo asof="1997/1/14">
95// <li> This could probably be generalized into an "enumeration axis" class.
96// </todo>
97//
98
100 public:
101 // The length of whichStokes is the length of the axis, and the values
102 // define which stokes are in which axis value. Often the vector will be of
103 // length 4 and will contain Stokes::I, Q, U and V, however any valid value
104 // from the stokes enum may be used. The values may not repeat however, e.g.
105 // only one axis position may contain "I".
106 explicit StokesCoordinate(const Vector<Int> &whichStokes);
107
108 // Copy constructor (copy semantics)
110
111 // Assignment (copy semantics)
113
114 // Destructor.
116
117 // Returns Coordinates::STOKES.
118 virtual Coordinate::Type type() const;
119
120 // Always returns the String "Stokes".
121 virtual String showType() const;
122
123 // Always returns 1.
124 // <group>
125 virtual uInt nPixelAxes() const;
126 virtual uInt nWorldAxes() const;
127 // </group>
128
129 // Convert a pixel to a world coordinate or vice versa. Returns True
130 // if the conversion succeeds, otherwise it returns False and method
131 // <src>errorMessage</src> returns an error message.
132 // The output vectors are appropriately resized before use.
133 // The Bool parameter in toWorld() is ignored as this coordinate does not
134 // support a conversion layer frame.
135 // <group>
136 virtual Bool toWorld(Vector<Double> &world, const Vector<Double> &pixel, Bool = True) const;
137 virtual Bool toPixel(Vector<Double> &pixel, const Vector<Double> &world) const;
138 // </group>
139
140 // Interconvert between pixel and world as a Stokes type.
141 // It returns False if no conversion could be done.
142 // <group>
145 // </group>
146
147 // Interconvert between world stored as a Double and world stored as
148 // a Stokes type. Since these functions are static, any valid
149 // Stokes type can be used. The second function returns
150 // Stokes::Undefined if world is illegal.
151 // <group>
154 // </group>
155
156 // Make absolute coordinates relative and vice-versa.
157 // For the StokesCoordinate relative world coordinates are defined to be the
158 // same as absolute world coordinates. Relative pixels do have meaning
159 // and are implemented (rel = abs - refPix)
160 // <group>
161 virtual void makePixelRelative(Vector<Double> &pixel) const;
162 virtual void makePixelAbsolute(Vector<Double> &pixel) const;
163 virtual void makeWorldRelative(Vector<Double> &world) const;
164 virtual void makeWorldAbsolute(Vector<Double> &world) const;
165 // </group>
166
167 // Get the Stokes values (Stokes::StokesType) that we constructed
168 // with into a vector
170
171 // Get the stokes string representations
173
174 // Set a new vector of Stokes values (a vector of Stokes::StokesType)
175 void setStokes(const Vector<Int> &whichStokes);
176
177 // Report the value of the requested attribute.
178 // <group>
182 virtual Vector<Double> increment() const;
184 // </group>
185
186 // Set the value of the requested attribute. For the StokesCoordinate,
187 // these have no effect (always return True) except for setWorldAxisNames.
188 // <group>
189 virtual Bool setWorldAxisNames(const Vector<String> &names);
190 virtual Bool setReferencePixel(const Vector<Double> &refPix);
192 virtual Bool setIncrement(const Vector<Double> &inc);
193 virtual Bool setReferenceValue(const Vector<Double> &refval);
194 // </group>
195
196 // The set function has no effect as the units must be empty for a StokesCoordinate
197 // Always returns True
198 // <group>
199 virtual Bool setWorldAxisUnits(const Vector<String> &units);
201 // </group>
202
203 // Set the world min and max ranges, for use in function <src>toMix</src>,
204 // for a lattice of the given shape (for this coordinate).
205 // The implementation here gives world coordinates at the start
206 // and end of the Stokes axis.
207 // The output vectors are resized. Returns False if fails (and
208 // then <src>setDefaultWorldMixRanges</src> generates the ranges)
209 // with a reason in <src>errorMessage()</src>.
210 // The <src>setDefaultWorldMixRanges</src> function
211 // gives you [-1e99->1e99].
212 // <group>
215 //</group>
216
217 // Format a StokesCoordinate world value with the common format
218 // interface (refer to the base class <linkto class=Coordinate>Coordinate</linkto>
219 // for basics.
220 //
221 // A StokesCoordinate is formatted differently from other Coordinate
222 // types. The world value is converted to the character representation
223 // as defined by the enum <src>StokesTypes</src> in the class
224 // <linkto class=Stokes>Stokes</linkto>.
225 //
226 // Thus, all other arguments to do with formatting and precision are ignored.
228 uInt worldAxis, Bool isAbsolute = True, Bool showAsAbsolute = True,
229 Int precision = -1, Bool usePrecForMixed = False) const;
230
231 // Comparison function. Any private Double data members are compared
232 // with the specified fractional tolerance. Don't compare on the specified
233 // axes in the Coordinate. If the comparison returns False, method
234 // errorMessage returns a message about why.
235 // <group>
236 virtual Bool near(const Coordinate &other, Double tol = 1e-6) const;
237 virtual Bool near(const Coordinate &other, const Vector<Int> &excludeAxes,
238 Double tol = 1e-6) const;
239 // </group>
240
241 // Save the StokesCoordinate into the supplied record using the supplied field name.
242 // The field must not exist, otherwise <src>False</src> is returned.
243 virtual Bool save(RecordInterface &container, const String &fieldName) const;
244
245 // Recover the StokesCoordinate from a record.
246 // A null pointer means that the restoration did not succeed - probably
247 // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
248 static StokesCoordinate *restore(const RecordInterface &container, const String &fieldName);
249
250 // Make a copy of the StokesCoordinate using new. The caller is responsible for calling
251 // delete.
252 virtual Coordinate *clone() const;
253
254 // Comparison only made for specified axes in this and other Coordinate
255 virtual Bool doNearPixel(const Coordinate &other, const Vector<Bool> &thisAxes,
256 const Vector<Bool> &otherAxes, Double tol = 1.0e-6) const;
257
258 private:
259 Bool toWorld(Double &world, const Double pixel) const;
260 Bool toPixel(Double &pixel, const Double world) const;
261 //
263
264 // Keep these for subimaging purposes.
269
270 // Undefined and inaccessible
272};
273
274} // namespace casacore
275
276#endif
Coordinate()
Default constructor.
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:139
formatType
This enum is used for formatting world values into Strings.
Definition Coordinate.h:158
void setStokes(const Vector< Int > &whichStokes)
Set a new vector of Stokes values (a vector of Stokes::StokesType).
static StokesCoordinate * restore(const RecordInterface &container, const String &fieldName)
Recover the StokesCoordinate from a record.
virtual Bool setReferencePixel(const Vector< Double > &refPix)
virtual void makeWorldRelative(Vector< Double > &world) const
virtual Coordinate * clone() const
Make a copy of the StokesCoordinate using new.
virtual uInt nPixelAxes() const
Always returns 1.
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the value of the requested attribute.
virtual Matrix< Double > linearTransform() const
Bool toWorld(Stokes::StokesTypes &stokes, Int pixel) const
virtual String showType() const
Always returns the String "Stokes".
Vector< Int > stokes() const
Get the Stokes values (Stokes::StokesType) that we constructed with into a vector.
virtual void setDefaultWorldMixRanges()
virtual Bool setWorldAxisUnits(const Vector< String > &units)
The set function has no effect as the units must be empty for a StokesCoordinate Always returns True.
Vector< String > stokesStrings() const
Get the stokes string representations.
virtual void makePixelAbsolute(Vector< Double > &pixel) const
StokesCoordinate()
Undefined and inaccessible.
virtual Bool setWorldMixRanges(const IPosition &shape)
Set the world min and max ranges, for use in function toMix, for a lattice of the given shape (for th...
virtual Vector< Double > increment() const
static Stokes::StokesTypes toWorld(Double world)
static Double toWorld(Stokes::StokesTypes stokes)
Interconvert between world stored as a Double and world stored as a Stokes type.
virtual String format(String &units, Coordinate::formatType format, Double worldValue, uInt worldAxis, Bool isAbsolute=True, Bool showAsAbsolute=True, Int precision=-1, Bool usePrecForMixed=False) const
Format a StokesCoordinate world value with the common format interface (refer to the base class Coord...
StokesCoordinate(const Vector< Int > &whichStokes)
The length of whichStokes is the length of the axis, and the values define which stokes are in which ...
Bool toPixel(Int &pixel, Stokes::StokesTypes stokes) const
Interconvert between pixel and world as a Stokes type.
virtual Vector< Double > referenceValue() const
Bool toPixel(Double &pixel, const Double world) const
virtual ~StokesCoordinate()
Destructor.
virtual Bool setIncrement(const Vector< Double > &inc)
virtual Vector< Double > referencePixel() const
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
virtual Vector< String > worldAxisUnits() const
virtual Vector< String > worldAxisNames() const
Report the value of the requested attribute.
virtual void makeWorldAbsolute(Vector< Double > &world) const
virtual Coordinate::Type type() const
Returns Coordinates::STOKES.
virtual Bool save(RecordInterface &container, const String &fieldName) const
Save the StokesCoordinate into the supplied record using the supplied field name.
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
virtual uInt nWorldAxes() const
virtual void makePixelRelative(Vector< Double > &pixel) const
Make absolute coordinates relative and vice-versa.
StokesCoordinate(const StokesCoordinate &other)
Copy constructor (copy semantics).
virtual Bool setReferenceValue(const Vector< Double > &refval)
virtual Bool setLinearTransform(const Matrix< Double > &xform)
virtual Bool doNearPixel(const Coordinate &other, const Vector< Bool > &thisAxes, const Vector< Bool > &otherAxes, Double tol=1.0e-6) const
Comparison only made for specified axes in this and other Coordinate.
virtual Bool near(const Coordinate &other, const Vector< Int > &excludeAxes, Double tol=1e-6) const
Bool toWorld(Double &world, const Double pixel) const
StokesCoordinate & operator=(const StokesCoordinate &other)
Assignment (copy semantics).
virtual Bool toWorld(Vector< Double > &world, const Vector< Double > &pixel, Bool=True) const
Convert a pixel to a world coordinate or vice versa.
Double crval_p
Keep these for subimaging purposes.
StokesTypes
The Stokes types are defined by this enum.
Definition Stokes.h:64
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
const Bool False
Definition aipstype.h:42
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.
int Int
Definition aipstype.h:48
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