casacore
Loading...
Searching...
No Matches
DirectionCoordinate.h
Go to the documentation of this file.
1//# DirectionCoordinate.h: Interconvert pixel positions and directions (e.g. RA/DEC)
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
27#ifndef COORDINATES_DIRECTIONCOORDINATE_H
28#define COORDINATES_DIRECTIONCOORDINATE_H
29
30#include <casacore/casa/aips.h>
31#include <casacore/coordinates/Coordinates/Coordinate.h>
32#include <casacore/coordinates/Coordinates/Projection.h>
33#include <casacore/casa/Arrays/Vector.h>
34#include <casacore/measures/Measures/MDirection.h>
35#include <casacore/measures/Measures/MeasConvert.h>
36#include <casacore/casa/Quanta/RotMatrix.h>
37#include <wcslib/wcs.h>
38
39struct celprm;
40struct prjprm;
41struct wcsprm;
42
43namespace casacore { //# NAMESPACE CASACORE - BEGIN
44
45class MVDirection;
46class MVAngle;
47class LogIO;
48template<class T> class Quantum;
49
50
51// <summary>
52// Interconvert pixel positions and directions (e.g. RA/DEC).
53// </summary>
54
55// <use visibility=export>
56
57// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tDirectionCoordinate">
58// </reviewed>
59
60
61// <prerequisite>
62// <li> Knowledge of astronomical coordinate conversions in general. Probably the
63// best documents are the papers by Mark Calabretta and Eric Greisen.
64// The initial draft from 1996 can be found at
65// http://www.atnf.csiro.au/~mcalabre. It is this draft that the
66// Coordinate classes are based upon. Since then, this paper has evolved
67// into three which can be found at the above address, and will be published in the
68// Astronomy and Astrophysics Supplement Series (probably in 2000).
69// The design has changed since the initial draft. When these papers
70// are finalized, and the IAU has ratified the new standards, WCSLIB
71// (Mark Calabretta's implementation of these conventions) will be
72// revised for the new designs. At that time, the Coordinate classes
73// may also be revised.
74// <li> <linkto class=Coordinate>Coordinate</linkto> defines the fundamental
75// interface to coordinate conversions.
76// <li> <linkto class=MDirection>MDirection</linkto> defines the types of
77// directions (J2000 etc.) which are defined. The measures machinery
78// also implements "astronomical" conversions which are outside the
79// scope of these coordinates (for example, <src>J2000</src> to
80// <src>B1950</src>).
81// <li> <linkto class=Projection>Projection</linkto> defines the types of
82// celestial projections which are available.
83// </prerequisite>
84//
85// <synopsis>
86// This class implements pixel to world coordinate conversions. This class
87// implements geometric conversions (e.g. SIN projection) via the WCS library
88// and also provides an interface to astronomical conversions (RA/DEC <--> l,b)
89// via the <linkto module=Measures>Measures</linkto> module.
90// </synopsis>
91//
92//
93// <note role=caution>
94// All absolute pixels coordinates are zero relative.
95// </note>
96//
97// <example>
98// Let's make a DirectionCoordinate --- used to represent a direction,
99// usually an RA/DEC, but it could also be, e.g., an AZ/EL pair.
100// <srcblock>
101// Matrix<Double> xform(2,2); // 1
102// xform = 0.0; xform.diagonal() = 1.0; // 2
103// DirectionCoordinate radec(MDirection::J2000, // 3
104// Projection(Projection::SIN), // 4
105// 135*C::pi/180.0, 60*C::pi/180.0, // 5
106// -1*C::pi/180.0, 1*C::pi/180, // 6
107// xform, // 7
108// 128, 128); // 8
109// </srcblock>
110// <ul>
111// <li> <i>1-2:</i>Here we set up a diagonal transformation matrix.
112// Normally this matrix should be diagonal, however if you wanted
113// to introduce a rotation or skew, you would do it through this
114// matrix.
115// <li> <i>3:</i>This defines the astronomical type of the world
116// coordinate. Most of the time it will probably be J2000
117// or B1950, but many other possibilities are possible as listed
118// in the <linkto class=MDirection>MDirection</linkto> class
119// header.
120// <li> <i>4:</i>The <linkto class=Projection>Projection</linkto> class
121// defines the "geometry" that is used to map <src>xy<-->world</src>. SIN
122// is the most common projection for radio interferometers. Note that
123// SIN can optionally take parameters as defined in Calabretta and Greisen.
124// If not provided, they default to 0.0, which is the "old" SIN
125// convention.
126// <li> <i>5:</i>Set the reference position to RA=135, DEC=60 degrees.
127// Note that the native units of a Direction is radians.
128// <li> <i>6:</i> Set the increments to -1 degree in RA, and +1 degree
129// in DEC.
130// <li> <i>7:</i> Set the previously defined transformation matrix.
131// <li> <i>8:</i> Set the zero-relative reference pixel. Note that it does
132// not have to be incremental. At the reference pixel, the world
133// coordinate has the reference value.
134// </ul>
135//
136// In this example is is more convenient to change the units to degrees. This can
137// be accomplished as follows:
138// <srcblock>
139// Vector<String> units(2); units = "deg"; // 9
140// radec.setWorldAxisUnits(units); // 10
141// </srcblock>
142// The increment and reference value are updated appropriately.
143//
144// Set up a couple of vectors to use the world and pixel coordinate values.
145// <srcblock>
146// Vector<Double> world(2), pixel(2); // 11
147// pixel = 138.0; // 12
148// </srcblock>
149// We use 138 as an arbitrary pixel position which is near the reference pixel
150// so we can tell if the answers look foolish or not.
151// We can actually perform a transformation like this as follows. If
152// it succeeds we print the value of the world coordinate.
153// <srcblock>
154// Bool ok = radec.toWorld(world, pixel); // 13
155// if (!ok) { // 14
156// cout << "Error: " << radec.errorMessage() << endl; // 15
157// return 1; // 16
158// } // 17
159// cout << world << " <--- " << pixel << endl; // 18
160// </srcblock>
161// There is an overloaded "toWorld" function that produces an MDirection
162// in case you want to, e.g., find out what the position in B1950 coordinates
163// would be.
164//
165// The reverse transformation takes place similarly:
166// <srcblock>
167// ok = radec.toPixel(pixel, world); // 19
168// </srcblock>
169// </example>
170//
171// <example>
172// We could also have made the above DirectionCoordinate using the Quantum-based
173// constructor, which is a little more elegant if you want to use degrees.
174//
175// Matrix<Double> xform(2,2);
176// xform = 0.0; xform.diagonal() = 1.0;
177// Quantum<Double> refLon(135.0, "deg");
178// Quantum<Double> refLat(60.0, "deg");
179// Quantum<Double> incLon(-1.0, "deg");
180// Quantum<Double> incLat(1.0, "deg");
181// DirectionCoordinate radec(MDirection::J2000,
182// Projection(Projection::SIN),
183// refLon, refLat,
184// incLon, incLat,
185// xform,
186// 128, 128);
187//
188// But note that the constructor will have converted the native units
189// of the DirectionCoordinate to radians. So the Double-based toWorld and
190// toPixel functions will be in terms of radians. If you want the native
191// units to be degrees, then again you can use
192//
193// <srcblock>
194// Vector<String> units(2); units = "deg";
195// radec.setWorldAxisUnits(units);
196// </srcblock>
197// and thereafter degrees are the native units.
198// </example>
199//
200// <motivation>
201// Directions in the sky are fundamental to astronomy.
202// </motivation>
203//
204//
205// <thrown>
206// <li> AipsError
207// </thrown>
208//
209// <todo asof="2000/01/01">
210// <li> Nothing
211// </todo>
212
213
215{
216public:
217 // The default constructor creates a J2000 DirectionCoordinate with a
218 // CARtesion projection with longitude,latitude 0,0 at pixel 0,0 and an
219 // increment of +1 radian per pixel on both axes.
221
222 // Define the DirectionCoordinate transformation. <src>refLong</src> and
223 // <src>refLat</src> will normally the the RA/DEC of the pixel described by
224 // <src>refX/refY</src>. <src>incLat/incLong</src>
225 // are the increments per pixel (RA is usually negative), and the <src>xform</src>
226 // matrix is usually the unit diagonal matrix unless you have a rotation or
227 // some other linear transformation between the pixel and world axes.
228 //
229 // Note that the units are radians initially. You can change it to degrees
230 // or something else with the <src>setWorldAxisUnits</src> method later if you want.
231 //
232 // longPole and latPole are defined by Calabretta and Greisen (these
233 // are reference points not at the native pole). In general
234 // you can leave these out and the default values will cause them
235 // to be computed appropriately. However, when reading from FITS
236 // the LONPOLE and LATPOLE keywords are passed along here.
238 const Projection &projection,
239 Double refLong, Double refLat,
240 Double incLong, Double incLat,
241 const Matrix<Double> &xform,
242 Double refX, Double refY,
243 Double longPole=999.0, Double latPole=999.0);
244
245 // Create DirectionCoordinate with Quantum-based interface.
246 // Parameters are the same as above.
247 // Regardless of the units of the quanta, the initial units
248 // of the DirectionCoordinate will be converted radians.
249 // You can change it to degrees or something else with the
250 // setWorldAxisUnits method later if you want.
251 //
252 // longPole and latPole are defined by Calabretta and Greisen (these
253 // are reference points not at the native pole). In general
254 // you can leave these out and the default values will cause them
255 // to be computed appropriately. However, when reading from FITS
256 // the LONPOLE and LATPOLE keywords are passed along here.
257 // To get the default the 999.0 value should be used (units
258 // are irrelevant in that case)
260 const Projection &projection,
261 const Quantum<Double>& refLong,
262 const Quantum<Double>& refLat,
263 const Quantum<Double>& incLong,
264 const Quantum<Double>& incLat,
265 const Matrix<Double> &xform,
266 Double refX, Double refY,
267 const Quantum<Double>& longPole=Quantum<Double>(999.0,Unit("rad")),
268 const Quantum<Double>& latPole=Quantum<Double>(999.0,Unit("rad")));
269
270 // Constructor from WCS structure; must hold ONLY a celestial wcs structure
271 // Specify whether the absolute pixel coordinates in the wcs structure
272 // are 0- or 1-relative. The coordinate is always constructed with 0-relative
273 // pixel coordinates
275 const ::wcsprm& wcs, Bool oneRel=True);
276
277 // Copy constructor (copy semantics)
279
280 // Assignment (copy semantics).
282
283 // Destructor
285
286 // Return Coordinate::DIRECTION
287 virtual Coordinate::Type type() const;
288
289 // Always returns the String "Direction".
290 virtual String showType() const;
291
292 // Always returns 2.
293 // <group>
294 virtual uInt nPixelAxes() const;
295 virtual uInt nWorldAxes() const;
296 // </group>
297
298
299 // Set extra conversion type. Whenever a conversion from pixel to world is done,
300 // the world value is then further converted to this MDirection::Types value.
301 // For example, your DirectionCoordinate may be defined in J2000.
302 // You can use this to get the world values out in say GALACTIC.
303 // Similarly, whenever you convert from world to pixel, the world
304 // value is assumed to be that appropriate to the conversionDirectionType.
305 // It is first converted to the MDirection::Types with which the
306 // DirectionCoordinate was constructed and from there to pixel.
307 // If you don't call this function, or you set the same type
308 // for which the DirectionCoordinate was constructed, no extra
309 // conversions occur. Some conversions will fail. These are the
310 // ones that require extra frame information (epoch, position) such
311 // as to AZEL from J2000 etc. This will be added later.
312 //
313 // In the mixed pixel/world conversion routine <src>toMix</src>
314 // the implementation is only partial. See the comments for this
315 // function below.
316 // <group>
320 // </group>
321
322 // Convert a pixel position to a world position or vice versa. Returns True
323 // if the conversion succeeds, otherwise it returns False and method
324 // errorMessage returns its error message.
325 // The output vectors are appropriately resized.
326 // if <src>useConversionFrame</src>, if the coordinate has a conversion
327 // layer frame, it is used. Else, the native frame is used for the conversion.
328 // <group>
329 virtual Bool toWorld(Vector<Double> &world,
330 const Vector<Double> &pixel, Bool useConversionFrame=True) const;
331
332 // <src>world</src> values must have units equivalent to the world axis
333 // units. If the coordinate has a conversion layer, the world coordinates
334 // must be supplied in the conversion frame.
335 virtual Bool toPixel(Vector<Double> &pixel,
336 const Vector<Double> &world) const;
337 // </group>
338
339 // Mixed pixel/world coordinate conversion.
340 // <src>worldIn</src> and <src>worldAxes</src> are of length
341 // nWorldAxes.
342 // <src>pixelIn</src> and <src>pixelAxes</src> are of length nPixelAxes.
343 // <src>worldAxes(i)=True</src> specifies you have given a world
344 // value in <src>worldIn(i)</src> to convert to pixel.
345 // <src>pixelAxes(i)=True</src> specifies you have given a pixel
346 // value in <src>pixelIn(i)</src> to convert to world.
347 // You cannot specify the same axis via <src>worldAxes</src>
348 // and <src>pixelAxes</src>.
349 // Values in <src>pixelIn</src> are converted to world and
350 // put into <src>worldOut</src> in the appropriate world axis
351 // location. Values in <src>worldIn</src> are copied to
352 // <src>worldOut</src>.
353 // Values in <src>worldIn</src> are converted to pixel and
354 // put into <src>pixelOut</src> in the appropriate pixel axis
355 // location. Values in <src>pixelIn</src> are copied to
356 // <src>pixelOut</src>.
357 //
358 // <src>worldMin</src> and <src>worldMax</src> specify the range of the world
359 // coordinate (in the world axis units of that world axis
360 // in the CoordinateSystem) being solved for in a mixed calculation
361 // for each world axis. Some mixed solutions can be degenerate, whereupon you
362 // you must say which one you want. Use functions <src>setWorldMixRanges</src>
363 // and <src>worldMixMin, worldMixMax</src> to set these ranges,
364 // If you don't know, use the defaults (function <src>setDefaultWorldMixRanges</src>.
365 // Removed axes are handled (for example, a removed pixel
366 // axis with remaining corresponding world axis will
367 // correctly be converted to world using the replacement
368 // value).
369 // Returns True if the conversion succeeds, otherwise it returns False and
370 // <src>errorMessage()</src> contains an error message. The output vectors
371 // are resized.
372 //
373 // If you actually request a pure pixel to world or world to pixel
374 // via <src>toMix</src>, then the functions <src>toWorld</src> or <src>toPixel</src>
375 // will be invoked directly (see above) and the extra conversion layer
376 // invoked through function <src>setReferenceConversion</src> will be active.
377 // However, if you request a true mixed pixel/world conversion,
378 // the extra conversion layer is not activated (because of the nature of mixed
379 // conversions). This situation may change in the future
380 // with a partial implementation added.
381 virtual Bool toMix(Vector<Double>& worldOut,
382 Vector<Double>& pixelOut,
383 const Vector<Double>& worldIn,
384 const Vector<Double>& pixelIn,
385 const Vector<Bool>& worldAxes,
386 const Vector<Bool>& pixelAxes,
387 const Vector<Double>& worldMin,
388 const Vector<Double>& worldMax) const;
389
390 // Compute and retrieve the world min and max ranges, for use in function <src>toMix</src>,
391 // for a lattice of the given shape (for this coordinate). Using these
392 // ranges in <src>toMix</src> should speed it up and help avoid ambiguity.
393 // If the shape is negative, that indicates that the shape is unknown
394 // for that axis. The default range is used for that axis. This situation
395 // arises in a CoordinateSystem for which a pixel, but not a world axis
396 // has been removed.
397 // The output vectors are resized. Returns False if fails (and
398 // then <src>setDefaultWorldMixRanges</src> generates the ranges)
399 // with a reason in <src>errorMessage()</src>.
400 // The <src>setDefaultWorldMixRanges</src> function
401 // just gives you [-90->90], [-180,180] (in appropriate units)
402 // <group>
405 // </group>
406
407 // Non-virtual function. When <src>which</src> is T, use the
408 // world value as the center for the mix world range.
409 void setWorldMixRanges (const Vector<Bool>& which,
410 const Vector<Double>& world);
411
412 // A convenient way to turn the world vector into an MDirection or MVDirection
413 // for further processing in the Measures system.
414 // <br>We could improve the performance of this if it would be useful. However it is
415 // expected that normally one would just call this once to get a template
416 // MDirection, and then call the vector versions.
417 // <br>In case of a failure, the versions with a Bool return value will return
418 // False. The other versions will throw an exception.
419 // <group>
420 Bool toWorld(MDirection &world, const Vector<Double> &pixel) const;
421 Bool toPixel(Vector<Double> &pixel, const MDirection &world) const;
422 Bool toWorld(MVDirection &world, const Vector<Double> &pixel) const;
423 Bool toPixel(Vector<Double> &pixel, const MVDirection &world) const;
424 MVDirection toWorld(const Vector<Double> &pixel) const;
425 Vector<Double> toPixel(const MVDirection &world) const;
426 Vector<Double> toPixel(const MDirection &world) const;
427 //</group>
428
429 // Batch up a lot of transformations. The first (most rapidly varying) axis
430 // of the matrices contain the coordinates. Returns False if any conversion
431 // failed and <src>errorMessage()</src> will hold a message.
432 // The <src>failures</src> array is the length of the number of conversions
433 // (True for failure, False for success)
434 // <group>
436 const Matrix<Double> &pixel,
437 Vector<Bool> &failures) const;
439 const Matrix<Double> &world,
440 Vector<Bool> &failures) const;
441 // </group>
442
443
444 // Make absolute world coordinates relative and vice-versa (relative to
445 // the reference value). Note that these functions are independent
446 // of the MDirection::Types (set either at construction or by function
447 // <src>setReferenceConversion</src>). The vectors must be
448 // of length <src>nWorldAxes</src> or memory access errors will occur
449 //<group>
450 virtual void makeWorldRelative (Vector<Double>& world) const;
451 virtual void makeWorldRelative (MDirection& world) const;
452 virtual void makeWorldAbsolute (Vector<Double>& world) const;
453 virtual void makeWorldAbsolute (MDirection& world) const;
454 //</group>
455
456 // Make absolute coordinates relative and vice versa with respect
457 // to the given reference value. Add the other functions in this grouping
458 // as needed.
459 //<group>
461 const Vector<Double>& refVal) const;
462 //</group>
463
464 // Recover the requested attribute.
465 // <group>
471 virtual Vector<Double> increment() const;
474 // </group>
475
476 // Set the value of the requested attribute. Note that these just
477 // change the internal values, they do not cause any recomputation.
478 // <group>
479 virtual Bool setWorldAxisNames(const Vector<String> &names);
480 virtual Bool setReferencePixel(const Vector<Double> &refPix);
482 virtual Bool setIncrement(const Vector<Double> &inc);
483 virtual Bool setReferenceValue(const Vector<Double> &refval);
484 // </group>
485
486 // Change the world axis units. Adjust the increment and
487 // reference value by the ratio of the old and new units.
488 // The units must be compatible with
489 // angle. The units are initially "rad" (radians).
490 virtual Bool setWorldAxisUnits(const Vector<String> &units);
491
492 // Return canonical axis names for the given MDirection type,
493 // giving FITS names if desired.
494 // BEG think this should be in the MDirection class, but WNB
495 // disagrees. Leave it here for now.
497 Bool FITSName = False);
498
499 // Comparison function. Any private Double data members are compared
500 // with the specified fractional tolerance. Don't compare on the specified
501 // axes in the Coordinate. If the comparison returns False, method
502 // errorMessage returns a message about why.
503 // <group>
504 virtual Bool near(const Coordinate& other,
505 Double tol=1e-6) const;
506 virtual Bool near(const Coordinate& other,
507 const Vector<Int>& excludeAxes,
508 Double tol=1e-6) const;
509 // </group>
510
511
512 // Format a DirectionCoordinate coordinate world value nicely through the
513 // common format interface. See <linkto class=Coordinate>Coordinate</linkto>
514 // for basics.
515 //
516 // Formatting types that are allowed are SCIENTIFIC, FIXED, MIXED, and TIME
517 // If you ask for format type Coordinate::DEFAULT then the
518 // selected format depends upon what the value of the enum
519 // MDirection::GlobalTypes is for this DirectionCoordinate.
520 // For example, if it is GRADEC or GHADEC you would
521 // get Coordinate::TIME style formatting (DD:MM:SS.SS), otherwise
522 // you would get Coordinate::FIXED formatting by default.
523 //
524 // <src>axis</src> says which axis in this Coordinate we are formatting.
525 // We have to know this because we may format Longitude and Latitude differently.
526 // For Coordinate::TIME style formatting, precision
527 // refers to the places after the decimal in the SS field.
528 //
529 // If you leave <src>units</src> empty, then it makes up a nice unit for you.
530 //<group>
531 virtual void getPrecision (Int& precision,
533 Bool showAsAbsolute,
534 Int defPrecScientific,
535 Int defPrecFixed,
536 Int defPrecTime) const;
537 virtual String format(String& units,
539 Double worldValue,
540 uInt axis,
541 Bool isAbsolute,
542 Bool showAsAbsolute,
543 Int precision=-1, Bool usePrecForMixed=False) const;
544 //</group>
545
546 // Fix cylindrical coordinates to put the longitude in [-180,180] range.
547 // If False returned, it failed an an error is in <src>errorMessage</src>
548 // This fix is not done automatically internally because of the dependence
549 // on the image shape. It should be called for any foreign image
550 // (such as FITS) that is imported
551 Bool cylindricalFix (Int shapeLong, Int shapeLat);
552
553 // Find the Coordinate for when we Fourier Transform ourselves. This pointer
554 // must be deleted by the caller. Axes specifies which axes of the Coordinate
555 // you wish to transform. Shape specifies the shape of the image
556 // associated with all the axes of the Coordinate. Currently the
557 // output reference pixel is always shape/2. If the pointer returned is 0,
558 // it failed with a message in <src>errorMessage</src>
560 const Vector<Int>& shape) const;
561
562 // Save the DirectionCoordinate into the supplied record using the supplied field name.
563 // The field must not exist, otherwise <src>False</src> is returned.
564 virtual Bool save(RecordInterface &container,
565 const String &fieldName) const;
566
567 // Recover the DirectionCoordinate from a record.
568 // A null pointer means that the restoration did not succeed.
570 const String &fieldName);
571
572 // Make a copy of the DirectionCoordinate using new. The caller
573 // is responsible for calling delete.
574 virtual Coordinate *clone() const;
575
576 // Fish out the ref and non-native poles (refLong, refLat, longPole, latPole)
577 // Not for general use. Units are degrees.
579
580 // get the pixel area.
582
583 // Convert this coordinate to another reference frame by rotating it about
584 // the reference pixel so the the axes of the new reference frame are
585 // aligned along the current pixel axes. The reference pixel remains the
586 // same and the conversion is exact for the reference pixel and in general
587 // becomes less accurate as distance from reference pixel increases. The
588 // latitude like and the longitude like pixel increments are preserved.
589 // Conversions which require extra information such as epoch and position
590 // are not supported. The <src>angle</src> parameter is the angle between
591 // the new coordinate and the pixel coordinate, measured clockwise from the
592 // positive y-axis of the new coordinate to the positive y-axis of the pixel
593 // coordinate; ie, it is the clockwise angle through which the current world
594 // coordinate would have to be rotated so that the new coordinate's axes
595 // would be parallel to the pixel axes. The accuracy of the returned angle
596 // is good to at least 7 digits.
599 ) const;
600
601 // Set the projection.
603
604 // Set the base (as opposed to conversion) reference frame.
606
607 // Are the pixels square?
609
610 // Is the projection equivalent to NCP?
611 Bool isNCP() const;
612
613private:
614 // Direction type
616
617 // Projection parameters
619
620 // WCS structure. This is mutable because the wcs functions
621 // that do toPixel and toWorld (which have const signature)
622 // require a non const wcs structure. so either all of these
623 // virtual functions lose their const or we use mutable...
624 mutable ::wcsprm wcs_p;
625
626 // WCS computes in degrees - use this to convert back and forth between
627 // current DirectionCoordinate units and degrees or radians
628 Vector<Double> to_degrees_p; // From current units to degrees
629 Vector<Double> to_radians_p; // From current units to radians
630
631 // Axis names.
633
634 // Current units.
636
637 // Rotation matrix used to handle relative coordinates
639
640 // Conversion machines.
641 // "To" handles type_p -> conversionType_p
642 // "From" handles conversionType_p -> type_p;
645
646 // Interconvert between the current units and wcs units (degrees)
647 // <group>
648 void toCurrent(Vector<Double>& degrees) const;
649 void fromCurrent(Vector<Double>& current) const;
650 // </group>
651
652 // Check formatting types.
654 Bool absolute) const;
655
656 // Format a latitude.
658 Bool absolute,
660 Int prec) const;
661 // Format a longitude.
664 Bool absolute,
666 Int prec) const;
667
668 // Mixed pixel/world coordinate conversion. Vector in must
669 // be length nWorldAxes (2). Specify whether longitude
670 // (in(0)) or latitude (in(1)) is the world coordinate . It is
671 // assumed that the other value is the pixel coordinate.
673 const Vector<Double>& minWorld, const Vector<Double>& maxWorld,
674 Bool longIsWorld) const;
675
676 // Initialize unit conversion vectors and units
678
679 // Helper functions interfacing to WCS.
680 // <group>
682 const Projection& proj, Double refLong, Double refLat,
683 Double incLong, Double incLat,
684 const Matrix<Double> &xform,
685 Double refX, Double refY,
686 Double longPole, Double latPole);
687//
688 void makeWCS(::wcsprm& wcs, const Matrix<Double>& xform,
690 Double refPixLong, Double refPixLat,
691 Double refLong, Double refLat,
692 Double incLong, Double incLat,
693 Double longPole, Double latPole);
694 // </group>
695
696 // Normalize each row of the PC matrix such that increment() will return the actual
697 // angular increment and any scale factors are removed from the PC matrix
698 // (modifies wcs_p.pc _and_ wcs_p.cdelt _and_ wcs_p.altlin,
699 // executes set_wcs() and hence wcsset() on the struct)
700 // See Greisen & Calabretta, A&A 395, 1061-1075 (2002), equation (4)
702
703 Double putLongInPiRange (Double lon, const String& unit) const;
704
705 // Set up conversion machine
707
708 // Convert from type_p -> conversionType_p
709 // <group>
710 virtual void convertTo (Vector<Double>& world) const;
711 virtual void convertFrom (Vector<Double>& world) const;
712 // </group>
713
714 // Copy private data
715 void copy (const DirectionCoordinate& other);
716
717 // Set up the offset coordinate rotation matrix. Units
718 // of long and lat are current world units
719 // <group>
721 void setRotationMatrix (RotMatrix& rot, Double lon, Double lat) const;
722 // </group>
723
724 // Return unit conversion vector for converting to current units
726
727};
728
729} //# NAMESPACE CASACORE - END
730
731
732#endif
733
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:141
formatType
This enum is used for formatting world values into Strings.
Definition Coordinate.h:159
void setReferenceFrame(const MDirection::Types rf)
Set the base (as opposed to conversion) reference frame.
MDirection::Types directionType(Bool showConversion=False) const
Recover the requested attribute.
virtual Matrix< Double > linearTransform() const
Quantity getPixelArea() const
get the pixel area.
Vector< String > units_p
Current units.
Vector< Double > to_degrees_p
WCS computes in degrees - use this to convert back and forth between current DirectionCoordinate unit...
virtual ~DirectionCoordinate()
Destructor.
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.
static DirectionCoordinate * restore(const RecordInterface &container, const String &fieldName)
Recover the DirectionCoordinate from a record.
virtual void setDefaultWorldMixRanges()
virtual uInt nWorldAxes() const
virtual void makeWorldRelative(Vector< Double > &world) const
Make absolute world coordinates relative and vice-versa (relative to the reference value).
virtual Bool setWorldAxisUnits(const Vector< String > &units)
Change the world axis units.
void makeConversionMachines()
Set up conversion machine.
virtual Bool toWorldMany(Matrix< Double > &world, const Matrix< Double > &pixel, Vector< Bool > &failures) const
Batch up a lot of transformations.
DirectionCoordinate & operator=(const DirectionCoordinate &other)
Assignment (copy semantics).
void toCurrent(Vector< Double > &degrees) const
Interconvert between the current units and wcs units (degrees)
virtual String format(String &units, Coordinate::formatType format, Double worldValue, uInt axis, Bool isAbsolute, Bool showAsAbsolute, Int precision=-1, Bool usePrecForMixed=False) const
virtual Bool save(RecordInterface &container, const String &fieldName) const
Save the DirectionCoordinate into the supplied record using the supplied field name.
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
void makeWCS(::wcsprm &wcs, const Matrix< Double > &xform, const Projection &proj, MDirection::Types directionType, Double refPixLong, Double refPixLat, Double refLong, Double refLat, Double incLong, Double incLat, Double longPole, Double latPole)
void makeDirectionCoordinate(MDirection::Types directionType, const Projection &proj, Double refLong, Double refLat, Double incLong, Double incLat, const Matrix< Double > &xform, Double refX, Double refY, Double longPole, Double latPole)
Helper functions interfacing to WCS.
Bool toPixel(Vector< Double > &pixel, const MDirection &world) const
virtual Vector< Double > referencePixel() const
virtual void makeWorldRelative(MDirection &world) const
DirectionCoordinate convert(Quantity &angle, MDirection::Types directionType) const
Convert this coordinate to another reference frame by rotating it about the reference pixel so the th...
virtual Bool setIncrement(const Vector< Double > &inc)
MDirection::Types type_p
Direction type.
static Vector< String > axisNames(MDirection::Types type, Bool FITSName=False)
Return canonical axis names for the given MDirection type, giving FITS names if desired.
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
world values must have units equivalent to the world axis units.
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the value of the requested attribute.
const Vector< Double > toCurrentFactors() const
Return unit conversion vector for converting to current units.
RotMatrix rot_p
Rotation matrix used to handle relative coordinates.
virtual Vector< Double > referenceValue() const
Vector< Double > longLatPoles() const
Fish out the ref and non-native poles (refLong, refLat, longPole, latPole) Not for general use.
DirectionCoordinate(MDirection::Types directionType, const ::wcsprm &wcs, Bool oneRel=True)
Constructor from WCS structure; must hold ONLY a celestial wcs structure Specify whether the absolute...
virtual Bool setReferenceValue(const Vector< Double > &refval)
void setProjection(const Projection &)
Set the projection.
Bool cylindricalFix(Int shapeLong, Int shapeLat)
Fix cylindrical coordinates to put the longitude in [-180,180] range.
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.
virtual Vector< String > worldAxisNames() const
Return the requested attributed.
Projection projection() const
Bool toWorld(MVDirection &world, const Vector< Double > &pixel) const
MVDirection toWorld(const Vector< Double > &pixel) const
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.
void setReferenceConversion(MDirection::Types type)
Set extra conversion type.
virtual Coordinate * makeFourierCoordinate(const Vector< Bool > &axes, const Vector< Int > &shape) const
Find the Coordinate for when we Fourier Transform ourselves.
virtual Coordinate * clone() const
Make a copy of the DirectionCoordinate using new.
void getReferenceConversion(MDirection::Types &type) const
virtual Vector< Double > increment() const
void setRotationMatrix()
Set up the offset coordinate rotation matrix.
void setWorldMixRanges(const Vector< Bool > &which, const Vector< Double > &world)
Non-virtual function.
Bool toMix2(Vector< Double > &out, const Vector< Double > &in, const Vector< Double > &minWorld, const Vector< Double > &maxWorld, Bool longIsWorld) const
Mixed pixel/world coordinate conversion.
Bool hasSquarePixels() const
Are the pixels square?
virtual void makeWorldAbsolute(MDirection &world) const
virtual Bool setLinearTransform(const Matrix< Double > &xform)
Double putLongInPiRange(Double lon, const String &unit) const
MDirection::Convert * pConversionMachineTo_p
Conversion machines.
Vector< String > names_p
Axis names.
virtual Coordinate::Type type() const
Return Coordinate::DIRECTION.
virtual String showType() const
Always returns the String "Direction".
DirectionCoordinate(const DirectionCoordinate &other)
Copy constructor (copy semantics)
String formatLongitude(String &units, MVAngle &mVA, MDirection::GlobalTypes gtype, Bool absolute, Coordinate::formatType form, Int prec) const
Format a longitude.
void initializeFactors()
Initialize unit conversion vectors and units.
String formatLatitude(String &units, MVAngle &mVA, Bool absolute, Coordinate::formatType form, Int prec) const
Format a latitude.
virtual void convertFrom(Vector< Double > &world) const
void checkFormat(Coordinate::formatType &format, Bool absolute) const
Check formatting types.
void fromCurrent(Vector< Double > &current) const
virtual void getPrecision(Int &precision, Coordinate::formatType &format, Bool showAsAbsolute, Int defPrecScientific, Int defPrecFixed, Int defPrecTime) const
Format a DirectionCoordinate coordinate world value nicely through the common format interface.
MDirection::Convert * pConversionMachineFrom_p
DirectionCoordinate()
The default constructor creates a J2000 DirectionCoordinate with a CARtesion projection with longitud...
Vector< Double > toPixel(const MDirection &world) const
DirectionCoordinate(MDirection::Types directionType, const Projection &projection, const Quantum< Double > &refLong, const Quantum< Double > &refLat, const Quantum< Double > &incLong, const Quantum< Double > &incLat, const Matrix< Double > &xform, Double refX, Double refY, const Quantum< Double > &longPole=Quantum< Double >(999.0, Unit("rad")), const Quantum< Double > &latPole=Quantum< Double >(999.0, Unit("rad")))
Create DirectionCoordinate with Quantum-based interface.
mutable::wcsprm wcs_p
WCS structure.
virtual void makeWorldAbsolute(Vector< Double > &world) const
virtual Bool near(const Coordinate &other, const Vector< Int > &excludeAxes, Double tol=1e-6) const
virtual Bool setReferencePixel(const Vector< Double > &refPix)
DirectionCoordinate(MDirection::Types directionType, const Projection &projection, Double refLong, Double refLat, Double incLong, Double incLat, const Matrix< Double > &xform, Double refX, Double refY, Double longPole=999.0, Double latPole=999.0)
Define the DirectionCoordinate transformation.
void copy(const DirectionCoordinate &other)
Copy private data.
void setRotationMatrix(RotMatrix &rot, Double lon, Double lat) const
Bool toPixel(Vector< Double > &pixel, const MVDirection &world) const
Projection projection_p
Projection parameters.
Bool isNCP() const
Is the projection equivalent to NCP?
virtual Bool toPixelMany(Matrix< Double > &pixel, const Matrix< Double > &world, Vector< Bool > &failures) const
Bool toWorld(MDirection &world, const Vector< Double > &pixel) const
A convenient way to turn the world vector into an MDirection or MVDirection for further processing in...
virtual Vector< String > worldAxisUnits() const
virtual void convertTo(Vector< Double > &world) const
Convert from type_p -> conversionType_p.
virtual Bool setWorldMixRanges(const IPosition &shape)
Compute and retrieve the world min and max ranges, for use in function toMix, for a lattice of the gi...
virtual uInt nPixelAxes() const
Always returns 2.
Vector< Double > toPixel(const MVDirection &world) const
void normalizePCMatrix()
Normalize each row of the PC matrix such that increment() will return the actual angular increment an...
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:185
GlobalTypes
Global types.
Definition MDirection.h:231
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
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
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