casacore
Loading...
Searching...
No Matches
CoordinateSystem.h
Go to the documentation of this file.
1// # CoordinateSystem.h: Interconvert pixel and image coordinates.
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_COORDINATESYSTEM_H
27#define COORDINATES_COORDINATESYSTEM_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/coordinates/Coordinates/Coordinate.h>
32#include <casacore/measures/Measures/MDirection.h>
33#include <casacore/measures/Measures/MFrequency.h>
34#include <casacore/coordinates/Coordinates/ObsInfo.h>
35#include <casacore/casa/Containers/Block.h>
36#include <casacore/measures/Measures/MDoppler.h>
37#include <map>
38
39namespace casacore { // # NAMESPACE CASACORE - BEGIN
40
47class IPosition;
48class LogIO;
49
50// <summary>
51// Interconvert pixel and world coordinates.
52// </summary>
53
54// <use visibility=export>
55
56// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tCoordinateSystem">
57// </reviewed>
58//
59// <prerequisite>
60// <li> <linkto class=Coordinate>Coordinate</linkto>
61// </prerequisite>
62
63// <synopsis>
64// CoordinateSystem is the normal interface to coordinate systems,
65// typically attached to an
66// <linkto class=ImageInterface>ImageInterface</linkto>, however the
67// coordinate system can be manipulated on its own. CoordinateSystem
68// is in turn composed from various classes derived from the base class
69// <linkto class=Coordinate>Coordinate</linkto>.
70// <p>
71// The fundamental operations available to the user of a
72// CoordinateSystem are:
73// <ol>
74// <li> Transform a world (physical) coordinate to a pixel coordinate
75// or vice versa via the methods toWorld and toPixel.
76// <li> Compose a CoordinateSystem from one or more independent groups,
77// typically the sky-plane transformation will be one group, and the
78// spectral axis will be another group. Each group consists of a linear
79// transformation (in FITS terms, apply <src>CRPIX, PC, CDELT</src>)
80// to turn the pixel coordinates into relative world coordinates,
81// followed by a (possibly) nonlinear projection to world coordinates
82// (i.e. apply <src>CTYPE and CRVAL</src>), typically a sky projection
83// or a frequency to velocity conversion. Note that an arbitrary rotation
84// or linear transformation can be applied by changing the
85// matrix.
86// <li> Transpose the world and/or pixel axes.
87// <li> One or more pixel or world axes may be removed. You are encouraged to
88// leave all the world axes if you remove a pixel axis.
89// Removing a world axis also removes the corresponding pixel axis.
90// <li> Calculate the CoordinateSystem that results from a subimage
91// operation.
92// </ol>
93//
94// Note that all the knowledge to do with removing and transposing axes is
95// maintained by the CoordinateSystem. The individual Coordinates, of which it
96// is made, know nothing about this.
97// <p>
98// Although the CoordinateSystem exists in the absence of an image, the usual
99// place you will find one is attached to an object derived from ImageInterface
100// such as PagedImage. When you do so, the physical (or pixel) axes in the image
101// map one to one with the pixel axes contained in the CoordinateSystem.
102// It cannot be any other way as when you create a PagedImage, it is checked
103// that there are equal numbers of image and CoordinateSystem pixel axes.
104// It is up to the creator of the PagedImage to make sure that they are
105// in the correct order.
106// <p>
107// However, the CoordinateSystem may have more world axes than pixel axes
108// because it is possible to remove a pixel axis but not its associated
109// world axis (for example for a moment image). Now, if you use
110// the CoordinateSystem functions
111// referencePixel and referenceValue, you will find the vector of reference
112// values will have more values than the vector of reference pixels,
113// if a pixel axis has been removed but not the world axis. You
114// must use the ancilliary functions provided
115// to find out what is where.
116// <p>
117// Let's consider an example where a CoordinateSystem consisted of
118// a DirectionCoordinate and a SpectralCoordinate. Let us say that
119// the first two pixel axes of the image associate (roughly of course
120// because lines of constant RA and DEC are not parallel with
121// the pixel coordinates) with the DirectionCoordinate (RA and DEC say)
122// and the third pixel axis is the SpectralCoordinate.
123// Now imagine we collapse the image along the second pixel axis (roughly,
124// the DEC axis). For the output image, we remove the second pixel axis
125// from the CoordinateSystem, but leave the world axis intact. This enables
126// us to still be able to make coordinate conversions for the first (roughly RA)
127// pixel axis. Thus, CoordinateSystem::referenceValue would return a Vector of
128// length 3 (for RA, DEC and spectral), but CoordinateSystem::referencePixel
129// would return a vector length 2 (for RA and spectral).
130// <p>
131// Now this CoordinateSystem has two Coordinates, a DirectionCoordinate and
132// a SpectralCoordinate, and let us state that that is the order in which
133// they exist in the CoordinateSystem (you can change them about if you wish);
134// they are coordinates number 0 and 1. The DirectionCoordinate has two axes
135// (RA and DEC) and the SpectralCoordinate has one axis. Only the
136// CoordinateSystem knows about removed axes, the DirectionCoordinate
137// itself is ignorant that it has been bisected. If you want to find
138// out what axis in the Coordinate system is where, you can use
139// the functions findPixelAxis or findWorldAxis.
140//
141// If we asked the former to find pixel axis 0, it would tell us that the
142// Coordinate number was 0 (the DirectionCoordinate) and that the axis in
143// that coordinate was 0 (the first axis in a DirectionCoordinate
144// is always longitude, the second always latitude). If we asked it to find
145// pixel axis 1, it would tell us that the coordinate number was 1
146// (the SpectralCoordinate) and that the axis in that coordinate was 0
147// (there is only one axis in a SpectralCoordinate). If we asked for
148// pixelAxis 2 that would generate an error because our squashed image
149// only has 2 pixel axes.
150//
151// Now, if we asked findWorldAxis similar questions,
152// it would tell us that worldAxis 0 in the CoordinateSystem can be found in
153// coordinate 0 (the DirectionCoordinate) in axis 0 of that DirectionCoordinate.
154// Similarly, worldAxis 1 in the CoordinateSystem (which has not been removed)
155// is in coordinate 0 (the DirectionCoordinate) in axis 1 of that
156// Finally, worldAxis 2 in the CoordinateSystem is in coordinate 1
157// (the SpectralCoordinate) in axis 0 of that SpectralCoordinate.
158// <p>
159// Other handy functions are pixelAxes and worldAxes.
160// These list the pixel and world axes in
161// the CoordinateSystem for the specified coordinate. Thus, if we asked
162// pixelAxes to find the pixel axes for coordinate 0 (the DirectionCoordinate)
163// in the CoordinateSystem it would return a vector [0, -1] indicating
164// the second axis of the DirectionCoordinate has been removed. However,
165// the worldAxes function would return [0,1] as no world axis has been removed.
166// Similarly, if operated on coordinate 1 (the SpectralCoordinate), pixelAxes
167// would return [1] and worldAxes would return [2].
168//
169// Because you can transpose the CoordinateSystem about, you should NEVER ASSUME
170// ANYTHING except that the pixel axes of the CoordinateSystem map to the pixel
171// axes of the image when you first construct the image.
172//
173// <p>
174// SpectralCoordinate and DirectionCoordinate both have a (non-virtual) function
175// called <src>setReferenceConversion</src>. This enables an extra conversion
176// layer so that conversion between pixel and world can go to a reference frame
177// other than the construction reference. When you use the function
178// <src>convert</src>, these layers are active, but ONLY if the
179// requested conversion is purely between pixel and world. For
180// a SpectralCoordinate this must always be true (only has one axis)
181// but for the DirectionCoordinate you might request a mixed
182// pixel/world conversion. In this case, the extra conversion layer
183// is ill-defined and not active (for the DirectionCoordinate part of it).
184// </synopsis>
185
186// <note role=caution>
187// All pixels coordinates are zero relative.
188// </note>
189
190// <example>
191// See the example in <linkto module=Coordinates>Coordinates.h</linkto>
192// and tCoordinateSystem.cc
193// </example>
194
195// <motivation>
196// Coordinate systems for images.
197// </motivation>
198//
199// <thrown>
200// <li> AipsError
201// </thrown>
202//
203// <todo asof="1997/01/13">
204// <li> Undelete individual removed axes.
205// <li> Non-integral pixel shifts/decimations in subimage operations?
206// <li> Copy-on-write for efficiency?
207// <li> Check if the classes are thread safe in general
208// </todo>
209//
210
212 public:
213 // Default constructor. This is an empty CoordinateSystem.
215
216 // Copying constructor (copy semantics)
218
219 // Assignment (copy semantics).
221
222 // Destructor
224
225 // Add another Coordinate to this CoordinateSystem. This addition is done
226 // by copying, so that if coord changes the change is NOT
227 // reflected in the CoordinateSystem.
228 void addCoordinate(const Coordinate& coord);
229
230 // Transpose the CoordinateSystem so that world axis 0 is
231 // newWorldOrder(0) and so on for all the other axes.
232 // newPixelOrder works similarly. Normally you will give the
233 // same transformation vector for both the world and pixel transformations,
234 // however this is not required.
235 void transpose(const Vector<Int>& newWorldOrder, const Vector<Int>& newPixelOrder);
236
237 // Find the world and pixel axis mappings to the supplied CoordinateSystem
238 // from the current coordinate system. <src>False</src> is
239 // returned if either the supplied or current coordinate system,
240 // has no world axes (and a message recoverable with function
241 // errorMessage indicating why). Otherwise <src>True</src> is returned.
242 // worldAxisMap(i) is the location of world axis <src>i</src> (from the
243 // supplied CoordinateSystem, cSys, in the current CoordinateSystem.
244 // worldAxisTranspose(i) is the location of world axis
245 // <src>i</src> (from the current CoordinateSystem) in the supplied
246 // CoordinateSystem, cSys. The output vectors
247 // are resized appropriately by this function. A value of -1
248 // in either vector means that the axis could not be found in the other
249 // CoordinateSystem. The vector <src>refChange</src> says
250 // if the types are the same, is there a reference type change
251 // (e.g. TOPO versus LSR for the SpectralCoordinate,
252 // or J2000 versus GALACTIC for DirectionCoordinate). Thus
253 // if refChange(i) is True, it means world axis i in the
254 // current CoordinateSystem was matched, but has a different
255 // reference type to that of the supplied CoordinateSystem.
256 // <group>
257 Bool worldMap(Vector<Int>& worldAxisMap, Vector<Int>& worldAxisTranspose, Vector<Bool>& refChange,
258 const CoordinateSystem& cSys) const;
259 Bool pixelMap(Vector<Int>& pixelAxisMap, Vector<Int>& pixelAxisTranspose,
260 const CoordinateSystem& cSys) const;
261 // </group>
262
263 // Remove a world or pixel axis. When its value is required for forward or
264 // backwards transformations, use <src>replacement</src>
265 // <br>
266 // When a world axis is removed, the corresponding pixel axis is removed
267 // too, because it makes no sense having a pixel axis without world
268 // coordinates.
269 // <br>
270 // Removing a pixel axis without removing the corresponding world axis
271 // is, however, possible and meaningful. It can be used when e.g. a
272 // frequency plane is taken from a cube. The plane has 2 pixel axes, but
273 // the 3rd world axis can still describe the frequency coordinate.
274 // See also the functions in <linkto class=CoordinateUtil>CoordinateUtil</linkto>
275 // for removing lists of pixel/world axes (tricky because they shift down)
276 //
277 // False is returned (an error in <src>errorMessage()</src> will be set)
278 // if the axis is illegal, else returns True.
279 // <group>
280 Bool removeWorldAxis(uInt axis, Double replacement);
281 Bool removePixelAxis(uInt axis, Double replacement);
282 // </group>
283
284 // Return a CoordinateSystem appropriate for a shift of origin
285 // (the shift is subtracted from the reference pixel)
286 // and change of increment (the increments are multipled
287 // by the factor). Both vectors should be of length nPixelAxes().
288 //
289 // The newShape vector is only needed for the StokesCoordinate,
290 // if any. If this vector is of length zero, the new StokesCoordinate
291 // is formed from all of the available input Stokes after application
292 // of the shift and increment factor. Otherwise,
293 // the new Stokes axis length is equal to that specified after
294 // appliction of the shift and increment and excess values
295 // discarded. In addition, for any StokesCoordinate, the
296 // shift and factor must be integer. So <src>Int(value+0.5)</src>
297 // is taken before they are used.
298 // <group>
299 CoordinateSystem subImage(const Vector<Float>& originShift, const Vector<Float>& incrFac,
300 const Vector<Int>& newShape) const;
301 void subImageInSitu(const Vector<Float>& originShift, const Vector<Float>& incrFac,
302 const Vector<Int>& newShape);
303 // </group>
304
305 // Untranspose and undelete all axes. Does not undo the effects of
306 // subimaging.
308
309 // Returns the number of Coordinates that this CoordinateSystem contains.
310 // The order might be unrelated to the axis order through the results of
311 // transposing and removing axes.
313
314 // For a given Coordinate say where its world and pixel axes are in
315 // this CoordinateSystem. The position in the returned Vector is its
316 // axis number in the Coordinate, and its value is the axis
317 // number in the CoordinateSystem. If the value is less than zero the axis
318 // has been removed from this CoordinateSystem.
319 // <group>
320 Vector<Int> worldAxes(uInt whichCoord) const;
321 Vector<Int> pixelAxes(uInt whichCoord) const;
322 // </group>
323
324 // Return the type of the given Coordinate.
325 Coordinate::Type type(uInt whichCoordinate) const;
326
327 // Returns the type of the given Coordinate as a string.
328 String showType(uInt whichCoordinate) const;
329
330 // Return the given Coordinate as a reference to the base
331 // class object.
332 const Coordinate& coordinate(uInt which) const;
333
334 // Return the given Coordinate.
335 // Throws an exception if retrieved as the wrong type.
336 // The versions which take no parameters will return the
337 // first (or in most cases only) coordinate of the requested type.
338 // If no such coordinate exists, an exception is thrown.
339 // <group>
343
347
351 // </group>
352
353 // Replace one Coordinate with another. The mapping of the coordinate axes
354 // to the CoordinateSystem axes is unchanged, therefore the number of world
355 // and pixel axes must not be changed. You can, somewhat dangerously,
356 // change the type of the coordinate however. For example, replace a
357 // SpectralCoordinate with a 1-D Linearcoordinate. It is dangerous because
358 // the world replacement values (see removeWorldAxis) have to be scaled.
359 // The algorithm tries to find a scale factor between the old and new
360 // units and applies it to the replacement values. If it can't find
361 // a scale factor (non-conformant units) then the reference value is
362 // used for any world replacement values. If the latter occurs,
363 // it returns False, else True is returned.
364 Bool replaceCoordinate(const Coordinate& newCoordinate, uInt whichCoordinate);
365
366 // Find the Coordinate number that corresponds to the given type.
367 // Since there might be more than one Coordinate of a given type you
368 // can call this multiple times setting <src>afterCoord</src> to
369 // the last value found. Returns -1 if a Coordinate of the desired
370 // type is not found.
371 Int findCoordinate(Coordinate::Type type, Int afterCoord = -1) const;
372
373 // Given an axis number (pixel or world) in the CoordinateSystem,
374 // find the corresponding coordinate number and axis in that Coordinate.
375 // The returned values are set to -1 if the axis does not exist.
376 // <group>
377 void findWorldAxis(Int& coordinate, Int& axisInCoordinate, uInt axisInCoordinateSystem) const;
378 void findPixelAxis(Int& coordinate, Int& axisInCoordinate, uInt axisInCoordinateSystem) const;
379 // </group>
380
381 // Find the world axis for the given pixel axis in a CoordinateSystem.
382 // Returns -1 if the world axis is unavailable (e.g. if it has been
383 // removed).
384 Int pixelAxisToWorldAxis(uInt pixelAxis) const;
385
386 // Find the pixel axis for the given world axis in a CoordinateSystem.
387 // Returns -1 if the pixel axis is unavailable (e.g. if it has been
388 // removed).
389 Int worldAxisToPixelAxis(uInt worldAxis) const;
390
391 // Return the name of the record field in which the coordinate is stored.
393
394 // Returns <src>Coordinate::COORDSYS</src>
395 virtual Coordinate::Type type() const;
396
397 // Always returns "System"
398 virtual String showType() const;
399
400 // Sums the number of axes in the Coordinates that the CoordinateSystem
401 // contains, allowing for removed axes.
402 // <group>
403 virtual uInt nPixelAxes() const;
404 virtual uInt nWorldAxes() const;
405 // </group>
406
407 // Convert a pixel position to a world position or vice versa. Returns True
408 // if the conversion succeeds, otherwise it returns <src>False</src> and
409 // <src>errorMessage()</src> contains an error message.
410 // The input vector must be of length <src>nPixelAxes</src> or
411 // <src>nWorldAxes</src>. The output vector is resized appropriately.
412 // if <src>useConversionFrame</src>, if the coordinate has a conversion layer frame
413 // (such as can be present in spectral and direction coordinates), it
414 // is used. Else, the native frame is used for the conversion.
415 // <group>
416 virtual Bool toWorld(Vector<Double>& world, const Vector<Double>& pixel,
417 Bool useConversionFrame = True) const;
418 // This one throws an exception rather than returning False. After all, that's
419 // what exceptions are for.
420 virtual Vector<Double> toWorld(const Vector<Double>& pixel) const;
421 virtual Bool toPixel(Vector<Double>& pixel, const Vector<Double>& world) const;
422 // This one throws an exception rather than returning False.
423 virtual Vector<Double> toPixel(const Vector<Double>& world) const;
424 // </group>
425
426 // convert a pixel "length" to a world "length"
427 virtual Quantity toWorldLength(const Double nPixels, const uInt pixelAxis) const;
428
429 // This is provided as a convenience since it is a very commonly desired
430 // operation through CoordinateSystem. The output vector is resized.
431 Bool toWorld(Vector<Double>& world, const IPosition& pixel) const;
432 Vector<Double> toWorld(const IPosition& pixel) const;
433
434 // Batch up a lot of transformations. The first (most rapidly varying) axis
435 // of the matrices contain the coordinates. Returns False if any conversion
436 // failed and <src>errorMessage()</src> will hold a message.
437 // The <src>failures</src> array (True for fail, False for success)
438 // is the length of the number of conversions and
439 // holds an error status for each conversion.
440 // <group>
441 virtual Bool toWorldMany(Matrix<Double>& world, const Matrix<Double>& pixel,
442 Vector<Bool>& failures) const;
443 virtual Bool toPixelMany(Matrix<Double>& pixel, const Matrix<Double>& world,
444 Vector<Bool>& failures) const;
445 // </group>
446
447 // Mixed pixel/world coordinate conversion.
448 // <src>worldIn</src> and <src>worldAxes</src> are of length n<src>worldAxes</src>.
449 // <src>pixelIn</src> and <src>pixelAxes</src> are of length nPixelAxes.
450 // <src>worldAxes(i)=True</src> specifies you have given a world
451 // value in <src>worldIn(i)</src> to convert to pixel.
452 // <src>pixelAxes(i)=True</src> specifies you have given a pixel
453 // value in <src>pixelIn(i)</src> to convert to world.
454 // You cannot specify the same axis via <src>worldAxes</src>
455 // and pixelAxes.
456 // Values in <src>pixelIn</src> are converted to world and
457 // put into <src>worldOut</src> in the appropriate world axis
458 // location. Values in <src>worldIn</src> are copied to
459 // <src>worldOut</src>.
460 // Values in <src>worldIn</src> are converted to pixel and
461 // put into <src>pixelOut</src> in the appropriate pixel axis
462 // location. Values in <src>pixelIn</src> are copied to
463 // <src>pixelOut</src>. Vectors
464 // <src>worldMin</src> and <src>worldMax</src> specify the range of the world
465 // coordinate (in the world axis units of that world axis
466 // in the coordinate system) being solved for in a mixed calculation
467 // for each world axis. They are only actually used for DirectionCoordinates
468 // and for all other coordinates the relevant elements are ignored.
469 // Functions <src>setWorldMixRanges, worldMixMin, worldMixMax</src> can be
470 // used to compute and recover the world ranges. If you don't know
471 // the values, use functions <src>setDefaultWorldMixRanges, worldMixMin, worldMixMax</src>.
472 // Removed axes are handled (for example, a removed pixel
473 // axis with remaining corresponding world axis will
474 // correctly be converted to world using the replacement
475 // value).
476 // Returns True if the conversion succeeds, otherwise it returns <src>False</src> and
477 // <src>errorMessage()</src> contains an error message. The output vectors
478 // are resized.
479 virtual Bool toMix(Vector<Double>& worldOut, Vector<Double>& pixelOut,
480 const Vector<Double>& worldIn, const Vector<Double>& pixelIn,
482 const Vector<Double>& worldMin, const Vector<Double>& worldMax) const;
483
484 // Compute and recover the world min and max ranges, for use in function <src>toMix</src>,
485 // for a lattice of the given shape (must be of length <src>nPixelAxes()</src>).
486 // Removed pixel axes (with remaining world axes are handled). With
487 // the retrieval functions, the output vectors are resized. They return
488 // False if they fail (and then <src>setDefaultWorldMixRanges</src> generates the ranges)
489 // with a reason in <src>errorMessage()</src>.
490 // The <src>setDefaultWorldMixRanges</src> function
491 // gives you a useful default range if you don't know the shape.
492 // The only Coordinate type for which these ranges are actually
493 // used in <src>toMix</src> is DirectionCoordinate (because its coupled). For
494 // the rest the functionality is provided but never used
495 // by toMix.
496 //<group>
501 //</group>
502
503 // Make absolute coordinates relative and vice-versa (relative
504 // to the reference pixel/value). The vectors must be of length
505 // <src>nPixelAxes()</src> or <src>nWorldAxes()</src>
506 //<group>
507 virtual void makePixelRelative(Vector<Double>& pixel) const;
508 virtual void makePixelAbsolute(Vector<Double>& pixel) const;
509 virtual void makeWorldRelative(Vector<Double>& world) const;
510 virtual void makeWorldAbsolute(Vector<Double>& world) const;
511 //</group>
512
513 // Make absolute coordinates relative and vice versa with respect
514 // to the given reference value. Add the other functions in this grouping
515 // as needed. The vectors must be of length
516 // <src>nPixelAxes()</src> or <src>nWorldAxes()</src>
517 //<group>
518 virtual void makeWorldAbsoluteRef(Vector<Double>& world, const Vector<Double>& refVal) const;
519 //</group>
520
521 // Batch up a lot of absolute/relative transformations.
522 // Parameters as above for
523 // <src>toWorldMany</src> and <src>toPixelMany</src>
524 // <group>
525 virtual void makePixelRelativeMany(Matrix<Double>& pixel) const;
526 virtual void makePixelAbsoluteMany(Matrix<Double>& pixel) const;
527 virtual void makeWorldRelativeMany(Matrix<Double>& world) const;
528 virtual void makeWorldAbsoluteMany(Matrix<Double>& world) const;
529 // </group>
530
531 // General coordinate conversion. Only works if no axes
532 // have been removed and no axis reordering has occurred.
533 // That is pixel axes and world axes are the same.
534 //
535 // Specify the input coordinate values, input units,
536 // whether value is absolute (or relative). For output
537 // specify units and abs/rel. Units may be 'pix' and velocity consistent
538 // units (e.g. m/s). Specify doppler types if velocities
539 // involved. The pixel offsets allow for the input
540 // and output pixel coordinates to be something other than 0-rel.
541 // If your pixel coordinates are 1-rel input and output, set the
542 // offsets to -1 and 1
543 //
544 // The Matrix interface lets you do many conversions efficiently.
545 // Use <src>Matrix(nAxes, nConversions) </src> and
546 // <src>Matrix.column()=coordinate</src> or
547 // <src>Matrix(axis, iConversion)</src> to get the order right.
548 //
549 // These functions invoke <src>toMix</src>
550 // so make sure you call <src>setWorldMixRanges</src>
551 // first to set up the world ranges.
552 // <group>
553 Bool convert(Vector<Double>& coordOut, const Vector<Double>& coordin, const Vector<Bool>& absIn,
554 const Vector<String>& unitsIn, MDoppler::Types dopplerIn, const Vector<Bool>& absOut,
555 const Vector<String>& unitsOut, MDoppler::Types dopplerOut, Double pixInOffset = 0.0,
556 Double pixOutOffset = 0.0);
557 Bool convert(Matrix<Double>& coordOut, const Matrix<Double>& coordIn, const Vector<Bool>& absIn,
558 const Vector<String>& unitsIn, MDoppler::Types dopplerIn, const Vector<Bool>& absOut,
559 const Vector<String>& unitsOut, MDoppler::Types dopplerOut, Double pixInOffset = 0.0,
560 Double pixOutOffset = 0.0);
561 // </group>
562
563 // Return the requested attribute.
564 // <group>
568 virtual Vector<Double> increment() const;
570 // </group>
571
572 // Set the requested attribute. Note that these just
573 // change the internal values, they do not cause any recomputation.
574 // <group>
575 virtual Bool setWorldAxisNames(const Vector<String>& names);
576 virtual Bool setReferencePixel(const Vector<Double>& refPix);
578 virtual Bool setIncrement(const Vector<Double>& inc);
579 virtual Bool setReferenceValue(const Vector<Double>& refval);
580 // </group>
581
582 // Set/get the units. Adjust the increment and
583 // reference value by the ratio of the old and new units. This implies that
584 // the units must be known <linkto class=Unit>Unit</linkto> strings, and
585 // that they must be compatible, e.g. they can't change from time to
586 // length. If <src>throwException=True</src>, throw an exception rather than
587 // returning False on failure.
588 // <group>
589 virtual Bool setWorldAxisUnits(const Vector<String>& units);
590 Bool setWorldAxisUnits(const Vector<String>& units, Bool throwException);
592 // </group>
593
594 // Comparison function. Any private Double data members are compared
595 // with the specified fractional tolerance. Don't compare on the specified
596 // pixel axes in the CoordinateSystem. If the comparison returns
597 // <src>False</src>, errorMessage() contains a message about why.
598 // <group>
599 virtual Bool near(const Coordinate& other, Double tol = 1e-6) const;
600 virtual Bool near(const Coordinate& other, const Vector<Int>& excludePixelAxes,
601 Double tol = 1e-6) const;
602 // </group>
603
604 // This function compares this and the other coordinate system,
605 // but ONLY for the non-removed pixel axes. It is less strict
606 // than near, which, for example, insists the number of coordinates
607 // is the same in each CS
608 Bool nearPixel(const CoordinateSystem& other, Double tol = 1e-6) const;
609
610 // Format a world value nicely through the
611 // common format interface. See <linkto class=Coordinate>Coordinate</linkto>
612 // for basics.
613 //
614 // You specify a world value and its corresponding world axis in
615 // the CoordinateSystem.
616 //
617 // For the specified worldAxis, the coordinate
618 // number in the CoordinateSystem is found and the actual derived Coordinate
619 // class object for that number is created. The arguments to the formatting
620 // function are then passed on to the formatter for that Coordinate. So
621 // refer to the other derived Coordinate classes for specifics on the
622 // formatting.
624 uInt worldAxis, Bool isAbsolute = True, Bool showAsAbsolute = True,
625 Int precision = -1, Bool usePrecForMixed = False) const;
626
627 // Miscellaneous information related to an observation, for example the
628 // observation date.
629 // <group>
631 void setObsInfo(const ObsInfo& obsinfo);
632 // </group>
633
634 // Find the CoordinateSystem (you can safely caste the pointer to a CoordinateSystem)
635 // for when we Fourier Transform ourselves. This pointer
636 // must be deleted by the caller. Axes specifies which pixel axes of the Coordinate
637 // System you wish to transform. Shape specifies the shape of the image
638 // associated with all the axes of the CoordinateSystem. Currently you have
639 // no control over the reference pixel, it is always shape/2.
641 const Vector<Int>& shape) const;
642
643 // Save the CoordinateSystem into the supplied record using the supplied field name.
644 // The field must not exist, otherwise <src>False</src> is returned.
645 // If the CoordinateSystem is empty <src>False</src> is also returned.
646 // If <src>False</src> is returned, errorMessage() contains a message about why.
647 virtual Bool save(RecordInterface& container, const String& fieldName) const;
648
649 // Restore the CoordinateSystem from a record. The <src>fieldName</src>
650 // can be empty, in which case the CoordinateSystem is restored
651 // directly from the Record, rather than a subrecord of it.
652 // A null pointer means that the restoration did not succeed - probably
653 // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
654 static CoordinateSystem* restore(const RecordInterface& container, const String& fieldName);
655
656 // Make a copy of the CoordinateSystem using new. The caller is responsible for calling
657 // delete.
658 virtual Coordinate* clone() const;
659
660 // Convert a CoordinateSystem to FITS, i.e. fill in ctype etc. In the record
661 // the keywords are vectors, it is expected that the actual FITS code will
662 // split them into scalars and upcase the names. Returns False if one of the
663 // keywords is already taken.
664 //
665 // If writeWCS is True, attempt to write the WCS convention (Greisen and
666 // Calabretta "Representation of celestial coordinates in FITS").
667 // Use <src>oneRelative=True</src> to convert zero-relative pixel coordinates to
668 // one-relative FITS coordinates.
669 //
670 // prefix gives the prefix for the FITS keywords. E.g.,
671 // if prefix="c" then crval, cdelt etc.
672 // if prefix="d" then drval, ddelt etc.
673 // # Much of the work in to/from fits should be moved to the individual
674 // # classes.
675 Bool toFITSHeader(RecordInterface& header, IPosition& shape, Bool oneRelative, Char prefix = 'c',
676 Bool writeWCS = True, Bool preferVelocity = True, Bool opticalVelocity = True,
677 Bool preferWavelength = False, Bool airWavelength = False) const;
678
679 // Probably even if we return False we should set up the best linear
680 // coordinate that we can.
681 // Use oneRelative=True to convert one-relative FITS pixel coordinates to
682 // zero-relative Casacore coordinates.
683 // On output, <src>stokesFITSValue</src>
684 // holds the FITS value of any unofficial Stokes (beam, optical depth,
685 // spectral index) for the last unofficial value accessed (-1 if none).
686 // The idea is that if the Stokes axis is of length one and holds an
687 // unofficial value, you should drop the STokes axis and convert that
688 // value to <src>ImageInfo::ImageTypes</src> with
689 // <src>ImageInfo::imageTypeFromFITSValue</src>.
690 // If on input, <src>stokesFITSValue</src> is positive, then a warning
691 // is issued if any unofficial values are encountered.
692 // Otherwise no warning is issued.
693 // # cf comment in toFITS.
694 static Bool fromFITSHeader(Int& stokesFITSValue, CoordinateSystem& coordsys,
695 RecordInterface& recHeader, const Vector<String>& header,
696 const IPosition& shape, uInt which = 0);
697
698 // List all header information. By default, the reference
699 // values and pixel increments are converted to a "nice" unit before
700 // formatting (e.g. RA is shown as HH:MM:SS.S).
701 // For spectral axes, both frequency and velocity information is listed. You
702 // can specify what velocity definition you want with <src>velocityType</src>
703 // If you wish, you can specify two shapes; a lattice and tile shape
704 // (perhaps an image from which the CoordinateSystem came)
705 // If you give (both of) these, they are included in the listing. If you pass
706 // in zero length <src>IPositions</src> then they are not included in
707 // the listing. If <src>postlocally=True</src> the formatted summary lines
708 // are written locally only to the sink, and then returned by the return value
709 // vector.
710 Vector<String> list(LogIO& os, MDoppler::Types doppler, const IPosition& latticeShape,
711 const IPosition& tileShape, Bool postLocally = False) const;
712
713 // Does this coordinate system have a spectral axis?
715
716 // What number is the spectral axis?
717 // If doWorld=True, the world axis number is returned.
718 // Otherwise, the pixel axis number is returned.
719 // Returns -1 if the spectral axis (world c.q. pixel) does not exist.
721
722 // what number is the spectral coordinate?
723 // Returns -1 if no spectral coordinate exists.
725
726 // does this coordinate system have a polarizaion/stokes coordinate?
729
730 // Given a stokes or polarization parameter, find the pixel location.
731 // Note the client is responsible for any boundedness checks
732 // (eg finite number of stokes in an image).
733 Int stokesPixelNumber(const String& stokesString) const;
734
735 // what is the number of the polarization/stokes coordinate?
736 // Returns -1 if no stokes coordinate exists.
738
739 // What is the number of the polarization/stokes axis?
740 // If doWorld=True, the world axis number is returned.
741 // Otherwise, the pixel axis number is returned.
742 // Returns -1 if the stokes axis (world c.q. pixel) does not exist.
744
745 // Does this coordinate system have a quality axis?
747
748 // what number is the quality axis? Returns -1 if no quality axis exists.
750
751 // what is the number of the quality coordinate?
752 // Returns -1 if no quality coordinate exists.
754
755 // Given a quality parameter, find the pixel location.
756 // Note the client is responsible for any boundedness checks
757 // (eg finite number of quality in an image).
758 Int qualityPixelNumber(const String& qualityString) const;
759
760 String qualityAtPixel(const uInt pixel) const;
761
763
765
766 // Get the pixel axis numbers of the direction coordinate in this object.
767 // The order of the returned axis numbers is always longitude axis first,
768 // latitude axis second.
770
771 String stokesAtPixel(const uInt pixel) const;
772
774
776
778
779 // Get the 0 based order of the minimal match strings specified in <src>order</src>.
780 // If <src>requireAll</src> is True, checks are done to ensure that all axes in
781 // the coordinate system are uniquely specified in <src>order</src>.
782 // If <src>allowFriendlyNames</src> is True, the following (fully specified) strings
783 // will match the specified axes:
784 // "spectral" matches both "frequency" and "velocity".
785 // "ra" matches "right ascension".
787 Bool allowFriendlyNames = False) const;
788
789 // Is the abscissa in the DirectionCoordinate the longitude axis?
790 // Throws exception if there is no DirectionCoordinate or if either of
791 // the direction pixel axes have been removed.
792 // For a normal direction coordinate, this will return True.
794
795 // Set Spectral conversion layer of SpectralCoordinate in CoordinateSystem
796 // so that pixel<->world go to the specified frequency system (a valid
797 // MFrequency::Types string). Returns False if frequency system invalid
798 // or if no DirectionCoordinate or if cant get Date/Epoch.
799 // <group>
800 Bool setSpectralConversion(String& errorMsg, const String frequencySystem);
801 // This version throws an exception rather than returning False.
802 void setSpectralConversion(const String frequencySystem);
803 //</group>
804
805 // Set rest frequency of SpectralCoordinate in CoordinateSystem.
806 // Unit must be consistent with Hz or m.
807 // Returns False if invalid inputs (and CS not changed) and an error message.
808 Bool setRestFrequency(String& errorMsg, const Quantity& freq);
809
810 private:
811 // Where we store copies of the coordinates we are created with.
813
814 // For coordinate[i] axis[j],
815 // world_maps_p[i][j], if >=0 gives the location in the
816 // input vector that maps to this coord/axis,
817 // <0 means that the axis has been removed
818 // world_tmp_p[i] a temporary vector length coord[i]->nworldAxes()
819 // replacement_values_p[i][j] value to use for this axis if removed
823
824 // Same meanings as for the world*'s above.
828
829 // These temporaries all needed for the toMix function
836
837 // Miscellaneous information about the observation associated with this
838 // Coordinate System.
840
841 const static String _class;
842 static std::mutex _mapInitMutex;
843 static std::map<String, String> _friendlyAxisMap;
844
845 static void _initFriendlyAxisMap();
846
847 // Helper functions to group common code.
848 Bool mapOne(Vector<Int>& worldAxisMap, Vector<Int>& worldAxisTranspose, Vector<Bool>& refChange,
849 const CoordinateSystem& cSys, const CoordinateSystem& cSys2, const uInt coord,
850 const uInt coord2) const;
851
852 void copy(const CoordinateSystem& other);
853 void clear();
855
856 // Delete some pointer blocks
858
859 // Delete temporary maps
860 void deleteTemps(const uInt which);
861
862 // Many abs/rel conversions
863 // <group>
866 // </group>
867
868 // Do subImage for Stokes
869 StokesCoordinate stokesSubImage(const StokesCoordinate& sc, Int originShift, Int pixincFac,
870 Int newShape) const;
871
872 // Do subImage for Quality
873 QualityCoordinate qualitySubImage(const QualityCoordinate& qc, Int originShift, Int pixincFac,
874 Int newShape) const;
875
876 // Strip out coordinates with all world and pixel axes removed
878
879 // All these functions are in support of the <src>list</src> function
880 // <group>
881 void listDirectionSystem(LogIO& os) const;
882 void listFrequencySystem(LogIO& os, MDoppler::Types velocityType) const;
883 void listPointingCenter(LogIO& os) const;
884 void getFieldWidths(LogIO& os, uInt& widthAxis, uInt& widthCoordType, uInt& widthCoordNumber,
885 uInt& widthName, uInt& widthProj, uInt& widthShape, uInt& widthTile,
886 uInt& widthRefValue, uInt& widthRefPixel, uInt& widthInc, uInt& widthUnits,
887 Int& precRefValSci, Int& precRefValFloat, Int& precRefValRADEC,
888 Int& precRefPixFloat, Int& precIncSci, String& nameAxis,
889 String& nameCoordType, String& nameCoordNumber, String& nameName,
890 String& nameProj, String& nameShape, String& nameTile, String& nameRefValue,
891 String& nameRefPixel, String& nameInc, String& nameUnits,
892 MDoppler::Types velocityType, const IPosition& latticeShape,
893 const IPosition& tileShape) const;
894
895 void listHeader(LogIO& os, Coordinate* pc, uInt& widthAxis, uInt& widthCoordType,
896 uInt& widthCoordNumber, uInt& widthName, uInt& widthProj, uInt& widthShape,
897 uInt& widthTile, uInt& widthRefValue, uInt& widthRefPixel, uInt& widthInc,
898 uInt& widthUnits, Bool findWidths, Int coordinate, Int axisInCoordinate,
899 Int pixelAxis, Int precRefValSci, Int precRefValFloat, Int precRefValRADEC,
900 Int precRefPixFloat, Int precIncSci, const IPosition& latticeShape,
901 const IPosition& tileShape) const;
902 void listVelocity(LogIO& os, Coordinate* pc, uInt widthAxis, uInt widthCoordType,
903 uInt widthCoordNumber, uInt& widthName, uInt widthProj, uInt widthShape,
904 uInt widthTile, uInt& widthRefValue, uInt widthRefPixel, uInt& widthInc,
905 uInt& widthUnits, Bool findWidths, Int axisInCoordinate, Int pixelAxis,
906 MDoppler::Types velocityType, Int precRefValSci, Int precRefValFloat,
907 Int precRefValRADEC, Int precRefPixFloat, Int precIncSci) const;
908 void clearFlags(LogIO& os) const;
910 const String& velUnits) const;
911 // </group>
912
913 void _downcase(Vector<String>& vec) const {
914 for (uInt i = 0; i < vec.size(); ++i) ToLowerCaseInPlace(vec[i]);
915 }
916};
917
918} // namespace casacore
919
920#endif
size_t size() const
Definition ArrayBase.h:99
const SpectralCoordinate & spectralCoordinate(uInt which) const
virtual void makeWorldRelative(Vector< Double > &world) const
void setObsInfo(const ObsInfo &obsinfo)
const TabularCoordinate & tabularCoordinate(uInt which) const
const DirectionCoordinate & directionCoordinate(uInt which) const
Block< Vector< Double > * > worldOut_tmps_p
String coordRecordName(uInt which) const
Return the name of the record field in which the coordinate is stored.
Block< Vector< Bool > * > pixelAxes_tmps_p
String qualityAtPixel(const uInt pixel) const
Bool mapOne(Vector< Int > &worldAxisMap, Vector< Int > &worldAxisTranspose, Vector< Bool > &refChange, const CoordinateSystem &cSys, const CoordinateSystem &cSys2, const uInt coord, const uInt coord2) const
Helper functions to group common code.
static Bool fromFITSHeader(Int &stokesFITSValue, CoordinateSystem &coordsys, RecordInterface &recHeader, const Vector< String > &header, const IPosition &shape, uInt which=0)
Probably even if we return False we should set up the best linear coordinate that we can.
Bool replaceCoordinate(const Coordinate &newCoordinate, uInt whichCoordinate)
Replace one Coordinate with another.
Vector< String > list(LogIO &os, MDoppler::Types doppler, const IPosition &latticeShape, const IPosition &tileShape, Bool postLocally=False) const
List all header information.
virtual Bool toMix(Vector< Double > &worldOut, Vector< Double > &pixelOut, const Vector< Double > &worldIn, const Vector< Double > &pixelIn, const Vector< Bool > &worldAxes, const Vector< Bool > &pixelAxes, const Vector< Double > &worldMin, const Vector< Double > &worldMax) const
Mixed pixel/world coordinate conversion.
Bool velocityIncrement(Double &velocityInc, SpectralCoordinate &sc, MDoppler::Types velocityType, const String &velUnits) const
Int qualityPixelNumber(const String &qualityString) const
Given a quality parameter, find the pixel location.
Bool hasQualityAxis() const
Does this coordinate system have a quality axis?
Bool hasLinearCoordinate() const
Block< Vector< Double > * > worldMin_tmps_p
Block< Vector< Double > * > worldMax_tmps_p
static void _initFriendlyAxisMap()
const SpectralCoordinate & spectralCoordinate() const
Int qualityCoordinateNumber() const
what is the number of the quality coordinate?
const LinearCoordinate & linearCoordinate(uInt which) const
Return the given Coordinate.
String stokesAtPixel(const uInt pixel) const
Int polarizationCoordinateNumber() const
what is the number of the polarization/stokes coordinate?
virtual Vector< Double > toPixel(const Vector< Double > &world) const
This one throws an exception rather than returning False.
void listDirectionSystem(LogIO &os) const
All these functions are in support of the list function.
virtual void makeWorldAbsolute(Vector< Double > &world) const
static CoordinateSystem * restore(const RecordInterface &container, const String &fieldName)
Restore the CoordinateSystem from a record.
virtual Bool toWorld(Vector< Double > &world, const Vector< Double > &pixel, Bool useConversionFrame=True) const
Convert a pixel position to a world position or vice versa.
void restoreOriginal()
Untranspose and undelete all axes.
virtual uInt nPixelAxes() const
Sums the number of axes in the Coordinates that the CoordinateSystem contains, allowing for removed a...
Bool removeWorldAxis(uInt axis, Double replacement)
Remove a world or pixel axis.
Int polarizationAxisNumber(Bool doWorld=False) const
What is the number of the polarization/stokes axis?
Bool convert(Vector< Double > &coordOut, const Vector< Double > &coordin, const Vector< Bool > &absIn, const Vector< String > &unitsIn, MDoppler::Types dopplerIn, const Vector< Bool > &absOut, const Vector< String > &unitsOut, MDoppler::Types dopplerOut, Double pixInOffset=0.0, Double pixOutOffset=0.0)
General coordinate conversion.
Block< Vector< Bool > * > worldAxes_tmps_p
These temporaries all needed for the toMix function.
QualityCoordinate qualitySubImage(const QualityCoordinate &qc, Int originShift, Int pixincFac, Int newShape) const
Do subImage for Quality.
void findWorldAxis(Int &coordinate, Int &axisInCoordinate, uInt axisInCoordinateSystem) const
Given an axis number (pixel or world) in the CoordinateSystem, find the corresponding coordinate numb...
StokesCoordinate stokesSubImage(const StokesCoordinate &sc, Int originShift, Int pixincFac, Int newShape) const
Do subImage for Stokes.
Block< Vector< Double > * > pixelOut_tmps_p
virtual void makePixelAbsoluteMany(Matrix< Double > &pixel) const
const QualityCoordinate & qualityCoordinate(uInt which) const
CoordinateSystem(const CoordinateSystem &other)
Copying constructor (copy semantics).
Coordinate::Type type(uInt whichCoordinate) const
Return the type of the given Coordinate.
Vector< Int > pixelAxes(uInt whichCoord) const
Int pixelAxisToWorldAxis(uInt pixelAxis) const
Find the world axis for the given pixel axis in a CoordinateSystem.
virtual Bool setWorldMixRanges(const IPosition &shape)
Compute and recover the world min and max ranges, for use in function toMix, for a lattice of the giv...
virtual Coordinate::Type type() const
Returns Coordinate::COORDSYS.
CoordinateSystem subImage(const Vector< Float > &originShift, const Vector< Float > &incrFac, const Vector< Int > &newShape) const
Return a CoordinateSystem appropriate for a shift of origin (the shift is subtracted from the referen...
void deleteTemps(const uInt which)
Delete temporary maps.
String showType(uInt whichCoordinate) const
Returns the type of the given Coordinate as a string.
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
virtual Bool setIncrement(const Vector< Double > &inc)
uInt nCoordinates() const
Returns the number of Coordinates that this CoordinateSystem contains.
Bool removePixelAxis(uInt axis, Double replacement)
Vector< Int > getWorldAxesOrder(Vector< String > &myNames, Bool requireAll, Bool allowFriendlyNames=False) const
Get the 0 based order of the minimal match strings specified in order.
virtual Bool setWorldAxisUnits(const Vector< String > &units)
Set/get the units.
virtual Vector< Double > increment() const
static std::map< String, String > _friendlyAxisMap
Bool setSpectralConversion(String &errorMsg, const String frequencySystem)
Set Spectral conversion layer of SpectralCoordinate in CoordinateSystem so that pixel<->world go to t...
Int findCoordinate(Coordinate::Type type, Int afterCoord=-1) const
Find the Coordinate number that corresponds to the given type.
const StokesCoordinate & stokesCoordinate() const
virtual Vector< Double > toWorld(const Vector< Double > &pixel) const
This one throws an exception rather than returning False.
Bool toWorld(Vector< Double > &world, const IPosition &pixel) const
This is provided as a convenience since it is a very commonly desired operation through CoordinateSys...
const StokesCoordinate & stokesCoordinate(uInt which) const
virtual void makePixelRelative(Vector< Double > &pixel) const
Make absolute coordinates relative and vice-versa (relative to the reference pixel/value).
virtual Vector< Double > referenceValue() const
Bool setWorldAxisUnits(const Vector< String > &units, Bool throwException)
void listPointingCenter(LogIO &os) const
void addCoordinate(const Coordinate &coord)
Add another Coordinate to this CoordinateSystem.
Int spectralAxisNumber(Bool doWorld=False) const
What number is the spectral axis?
void listFrequencySystem(LogIO &os, MDoppler::Types velocityType) const
virtual String showType() const
Always returns "System".
void transpose(const Vector< Int > &newWorldOrder, const Vector< Int > &newPixelOrder)
Transpose the CoordinateSystem so that world axis 0 is newWorldOrder(0) and so on for all the other a...
virtual Vector< Double > referencePixel() const
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the requested attribute.
ObsInfo obsInfo() const
Miscellaneous information related to an observation, for example the observation date.
Vector< Int > linearAxesNumbers() const
Block< Vector< Double > * > pixel_replacement_values_p
Bool checkAxesInThisCoordinate(const Vector< Bool > &axes, uInt which) const
virtual Vector< String > worldAxisUnits() const
virtual void makePixelRelativeMany(Matrix< Double > &pixel) const
Batch up a lot of absolute/relative transformations.
static std::mutex _mapInitMutex
virtual Vector< Double > worldMixMin() const
virtual void makeWorldRelativeMany(Matrix< Double > &world) const
virtual Bool setReferencePixel(const Vector< Double > &refPix)
void makePixelAbsRelMany(Matrix< Double > &value, Bool toAbs) const
virtual Bool setLinearTransform(const Matrix< Double > &xform)
Block< Block< Int > * > pixel_maps_p
Same meanings as for the world*'s above.
virtual Bool save(RecordInterface &container, const String &fieldName) const
Save the CoordinateSystem into the supplied record using the supplied field name.
Block< Coordinate * > coordinates_p
Where we store copies of the coordinates we are created with.
void _downcase(Vector< String > &vec) const
Vector< Int > worldAxes(uInt whichCoord) const
For a given Coordinate say where its world and pixel axes are in this CoordinateSystem.
virtual Coordinate * makeFourierCoordinate(const Vector< Bool > &axes, const Vector< Int > &shape) const
Find the CoordinateSystem (you can safely caste the pointer to a CoordinateSystem) for when we Fourie...
Int worldAxisToPixelAxis(uInt worldAxis) const
Find the pixel axis for the given world axis in a CoordinateSystem.
Bool pixelMap(Vector< Int > &pixelAxisMap, Vector< Int > &pixelAxisTranspose, const CoordinateSystem &cSys) const
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 world value nicely through the common format interface.
const DirectionCoordinate & directionCoordinate() const
Bool setRestFrequency(String &errorMsg, const Quantity &freq)
Set rest frequency of SpectralCoordinate in CoordinateSystem.
Block< Block< Int > * > world_maps_p
For coordinate[i] axis[j], world_maps_p[i][j], if >=0 gives the location in the input vector that map...
Bool toFITSHeader(RecordInterface &header, IPosition &shape, Bool oneRelative, Char prefix='c', Bool writeWCS=True, Bool preferVelocity=True, Bool opticalVelocity=True, Bool preferWavelength=False, Bool airWavelength=False) const
Convert a CoordinateSystem to FITS, i.e.
virtual Bool setReferenceValue(const Vector< Double > &refval)
Bool hasDirectionCoordinate() const
virtual void makePixelAbsolute(Vector< Double > &pixel) const
virtual ~CoordinateSystem()
Destructor.
Int stokesPixelNumber(const String &stokesString) const
Given a stokes or polarization parameter, find the pixel location.
virtual uInt nWorldAxes() const
Bool hasPolarizationCoordinate() const
does this coordinate system have a polarizaion/stokes coordinate?
void subImageInSitu(const Vector< Float > &originShift, const Vector< Float > &incrFac, const Vector< Int > &newShape)
Bool nearPixel(const CoordinateSystem &other, Double tol=1e-6) const
This function compares this and the other coordinate system, but ONLY for the non-removed pixel axes.
virtual Vector< String > worldAxisNames() const
Return the requested attribute.
Bool isDirectionAbscissaLongitude() const
Is the abscissa in the DirectionCoordinate the longitude axis?
void findPixelAxis(Int &coordinate, Int &axisInCoordinate, uInt axisInCoordinateSystem) const
virtual void makeWorldAbsoluteRef(Vector< Double > &world, const Vector< Double > &refVal) const
Make absolute coordinates relative and vice versa with respect to the given reference value.
void setSpectralConversion(const String frequencySystem)
This version throws an exception rather than returning False.
void listHeader(LogIO &os, Coordinate *pc, uInt &widthAxis, uInt &widthCoordType, uInt &widthCoordNumber, uInt &widthName, uInt &widthProj, uInt &widthShape, uInt &widthTile, uInt &widthRefValue, uInt &widthRefPixel, uInt &widthInc, uInt &widthUnits, Bool findWidths, Int coordinate, Int axisInCoordinate, Int pixelAxis, Int precRefValSci, Int precRefValFloat, Int precRefValRADEC, Int precRefPixFloat, Int precIncSci, const IPosition &latticeShape, const IPosition &tileShape) const
Block< Vector< Double > * > pixel_tmps_p
virtual Vector< Double > worldMixMax() const
void copy(const CoordinateSystem &other)
Int spectralCoordinateNumber() const
what number is the spectral coordinate?
Bool worldMap(Vector< Int > &worldAxisMap, Vector< Int > &worldAxisTranspose, Vector< Bool > &refChange, const CoordinateSystem &cSys) const
Find the world and pixel axis mappings to the supplied CoordinateSystem from the current coordinate s...
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
CoordinateSystem()
Default constructor.
void cleanUpSpecCoord(Block< SpectralCoordinate * > &in, Block< SpectralCoordinate * > &out)
Delete some pointer blocks.
void listVelocity(LogIO &os, Coordinate *pc, uInt widthAxis, uInt widthCoordType, uInt widthCoordNumber, uInt &widthName, uInt widthProj, uInt widthShape, uInt widthTile, uInt &widthRefValue, uInt widthRefPixel, uInt &widthInc, uInt &widthUnits, Bool findWidths, Int axisInCoordinate, Int pixelAxis, MDoppler::Types velocityType, Int precRefValSci, Int precRefValFloat, Int precRefValRADEC, Int precRefPixFloat, Int precIncSci) const
void getFieldWidths(LogIO &os, uInt &widthAxis, uInt &widthCoordType, uInt &widthCoordNumber, uInt &widthName, uInt &widthProj, uInt &widthShape, uInt &widthTile, uInt &widthRefValue, uInt &widthRefPixel, uInt &widthInc, uInt &widthUnits, Int &precRefValSci, Int &precRefValFloat, Int &precRefValRADEC, Int &precRefPixFloat, Int &precIncSci, String &nameAxis, String &nameCoordType, String &nameCoordNumber, String &nameName, String &nameProj, String &nameShape, String &nameTile, String &nameRefValue, String &nameRefPixel, String &nameInc, String &nameUnits, MDoppler::Types velocityType, const IPosition &latticeShape, const IPosition &tileShape) const
virtual Bool toPixelMany(Matrix< Double > &pixel, const Matrix< Double > &world, Vector< Bool > &failures) const
CoordinateSystem stripRemovedAxes(const CoordinateSystem &cSys) const
Strip out coordinates with all world and pixel axes removed.
Vector< Int > directionAxesNumbers() const
Get the pixel axis numbers of the direction coordinate in this object.
Block< Vector< Double > * > world_tmps_p
const Coordinate & coordinate(uInt which) const
Return the given Coordinate as a reference to the base class object.
Int directionCoordinateNumber() const
Bool convert(Matrix< Double > &coordOut, const Matrix< Double > &coordIn, const Vector< Bool > &absIn, const Vector< String > &unitsIn, MDoppler::Types dopplerIn, const Vector< Bool > &absOut, const Vector< String > &unitsOut, MDoppler::Types dopplerOut, Double pixInOffset=0.0, Double pixOutOffset=0.0)
virtual Bool near(const Coordinate &other, const Vector< Int > &excludePixelAxes, Double tol=1e-6) const
virtual Coordinate * clone() const
Make a copy of the CoordinateSystem using new.
virtual Bool toWorldMany(Matrix< Double > &world, const Matrix< Double > &pixel, Vector< Bool > &failures) const
Batch up a lot of transformations.
virtual Quantity toWorldLength(const Double nPixels, const uInt pixelAxis) const
convert a pixel "length" to a world "length"
Vector< Double > toWorld(const IPosition &pixel) const
Int linearCoordinateNumber() const
virtual void setDefaultWorldMixRanges()
virtual void makeWorldAbsoluteMany(Matrix< Double > &world) const
void makeWorldAbsRelMany(Matrix< Double > &value, Bool toAbs) const
Many abs/rel conversions.
Bool hasSpectralAxis() const
Does this coordinate system have a spectral axis?
ObsInfo obsinfo_p
Miscellaneous information about the observation associated with this Coordinate System.
CoordinateSystem & operator=(const CoordinateSystem &other)
Assignment (copy semantics).
Block< Vector< Double > * > world_replacement_values_p
Int qualityAxisNumber() const
what number is the quality axis?
void clearFlags(LogIO &os) const
virtual Matrix< Double > linearTransform() const
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
Types
Types of known MDopplers Warning: The order defines the order in the translation matrix FromTo in th...
Definition MDoppler.h:149
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
void ToLowerCaseInPlace(std::string &str)
Converts the specified string to lower case, in place.
Definition String.h:1058
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
Quantum< Double > Quantity
Definition Quantum.h:40
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44