casacore
Loading...
Searching...
No Matches
SpectralCoordinate.h
Go to the documentation of this file.
1//# SpectralCoordinate.h: Interconvert between pixel and frequency.
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_SPECTRALCOORDINATE_H
28#define COORDINATES_SPECTRALCOORDINATE_H
29
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/coordinates/Coordinates/Coordinate.h>
33#include <casacore/coordinates/Coordinates/ObsInfo.h>
34#include <casacore/measures/Measures/MFrequency.h>
35#include <casacore/measures/Measures/MDoppler.h>
36#include <casacore/measures/Measures/MDirection.h>
37#include <casacore/measures/Measures/MPosition.h>
38#include <casacore/measures/Measures/MEpoch.h>
39#include <casacore/casa/Quanta/Quantum.h>
40#include <memory>
41
42#include <wcslib/wcs.h>
43
44
45namespace casacore { //# NAMESPACE CASACORE - BEGIN
46
47
48class TabularCoordinate;
49class LogIO;
50class MVFrequency;
51class VelocityMachine;
52template<class T> class Quantum;
53
54
55// <summary>
56// Interconvert pixel and frequency values.
57// </summary>
58
59// <use visibility=export>
60
61// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tSpectralCoordinate">
62// </reviewed>
63//
64// <prerequisite>
65// <li> <linkto class=Coordinate>Coordinate</linkto>
66// <li> <linkto class=MFrequency>MFrequency</linkto>,
67// <linkto class=MDoppler>MDoppler</linkto> and
68// <linkto class=VelocityMachine>VelocityMachine</linkto>
69// classes if you want radial velocities.
70// </prerequisite>
71//
72// <synopsis>
73// This class performs the mapping from pixel to frequency.
74// This can be done via a Tabular lookup or via an algorithmic
75// implementation which may be linear or non-linear. The latter
76// is implemented via the WCS library.
77//
78// </synopsis>
79//
80
81// <note role=caution>
82// All pixels coordinates are zero relative.
83// </note>
84//
85// <example>
86// Let us make a linear SpectralCoordinate first
87// <srcblock>
88// Double restfreq = 1.420405752E9;
89// Double crpix = 10.0;
90// Double crval = 1.4e9;
91// Double cdelt = 1.0e6;
92// SpectralCoordinate sc(MFrequency::TOPO, crval, cdelt, crpix, restfreq);
93//
94// Double world, pixel;
95// pixel = 12.1;
96// if (!sc.toWorld(world, pixel)) {
97// cerr << "Error : " << sc.errorMessage() << endl;
98// } else {
99// cerr << "pixel, world = " << pixel << ", " << world << endl;
100// }
101//
102// </srcblock>
103// </example>
104//
105// <example>
106// Now we make a non-linear SpectralCoordinate
107// <srcblock>
108// Vector<Double> freqs(5);
109// freqs(0) = 1.4e9; freqs(1) = 1.41e9;
110// freqs(2) = 1.43e9; freqs(3) = 1.44e9;
111// freqs(4) = 1.47e9;
112// SpectralCoordinate sc(MFrequency::LSRK, freqs, restfreq);
113//
114// Double world, pixel;
115// world = 1.42e9;
116// if (!sc.toPixel(pixel, world)) {
117// cerr << "Error : " << sc.errorMessage() << endl;
118// } else {
119// cerr << "world, pixel = " << world << ", " << pixel << endl;
120// }
121//
122// </srcblock>
123// </example>
124//
125// <motivation>
126// Spectral-line astronomy requires a specialized SpectralCoordinate.
127// </motivation>
128
129// <todo asof="2000/01/01">
130// <li> Allow other than linear interpolations for frequency lookup.
131// </todo>
132//
133
135{
136public:
137 enum SpecType { // taken from the FITS spectral coordinate type codes
143 AWAV
144 };
145
146 // Default constructor. It is equivalent to doing
147 // SpectralCoordinate(MFrequency::TOPO, 0.0, 1.0, 0.0)
149
150 // Create a linear frequency axis SpectralCoordinate
151 // <src>f0</src> is the frequency of the reference pixel, <src>inc</src> is the pixel increment,
152 // <src>refPix</src> is the reference pixel. You can
153 // optionally store the rest frequency for later use in calculating radial
154 // velocities. Use 0 for restFrequency if continuum.
155 //
156 // Frequencies and increments initially in Hz.
158 Double refPix, Double restFrequency = 0.0);
159
160 // Create linear frequency axis SpectralCoordinate with Quantum-based interface.
161 // Parameters are the same as above.
162 // Regardless of the units of the Quanta, the initial units
163 // of the SpectralCoordinate will be Hz. You can change it to
164 // something else with the setWorldAxisUnits method later if you want.
165 // Use 0 for restFrequency if continuum.
167 const Quantum<Double>& inc, Double refPix,
169
170 // Construct a SpectralCoordinate with the specified frequencies (in Hz).
171 // This axis can be nonlinear; the increments and related
172 // functions return the <src>average</src> values
173 // (calculated from the first and last pixel's frequencies).
174 //
175 // A linear interpolation/extrapolation is used for pixels which are
176 // not supplied. The reference pixel is chosen to be 0.
177 // The frequencies must increase or decrease monotonically (otherwise
178 // the toPixel lookup would not be possible).
179 // Use 0 for restFrequency if continuum.
181 Double restFrequency = 0.0);
182
183 // Construct a SpectralCoordinate with the specified frequencies
184 // with Quantum-based interface.
185 // Parameters are the same as above.
186 // Regardless of the units of the Quanta, the initial units
187 // of the SpectralCoordinate will be Hz.
188 // Use 0 for restFrequency if continuum.
191
192 // Construct a SpectralCoordinate with the specified velocities (in km/s).
193 // They will be converted to Hz and the SpectralCoordinate constructed.
194 // This axis can be nonlinear; the increments and related
195 // functions return the <src>average</src> values
196 // (calculated from the first and last pixel's frequencies).
197 //
198 // A linear interpolation/extrapolation is used for pixels which are
199 // not supplied. The reference pixel is chosen to be 0.
200 // The velocities must increase or decrease monotonically (otherwise
201 // the toPixel lookup would not be possible).
203 const Vector<Double>& velocities, const String& velUnit,
204 Double restFrequency = 0.0);
205
206 // Construct a SpectralCoordinate with the specified wavelengths (in mm).
207 // They will be converted to Hz and the SpectralCoordinate constructed.
208 // This axis can be nonlinear; the increments and related
209 // functions return the <src>average</src> values
210 // (calculated from the first and last pixel's frequencies).
211 // If inAir is True, the input wavelengths are assumed to be Air Wavelengths.
212 // They are converted to vacuum frequency using the refractive index
213 // which is calculated based on the mean input air wavelength.
214 //
215 // A linear interpolation/extrapolation is used for pixels which are
216 // not supplied. The reference pixel is chosen to be 0.
217 // The wavelengths must increase or decrease monotonically (otherwise
218 // the toPixel lookup would not be possible).
220 const Vector<Double>& wavelengths, const String& waveUnit,
221 Double restFrequency = 0.0, Bool inAir = False);
222
223 // Construct from wcs structure. Must hold only a spectral wcs structure
224 // Specify whether the absolute pixel coordinates in the wcs structure
225 // are 0- or 1-relative. The coordinate is always constructed with 0-relative
226 // pixel coordinates
227 SpectralCoordinate(MFrequency::Types freqType, const ::wcsprm& wcs, Bool oneRel=True);
228
229 // Copy constructor (copy semantics).
231
232 // Assignment (copy semantics).
234
235 // Destructor.
237
238 // Always returns Coordinate::SPECTRAL.
239 virtual Coordinate::Type type() const;
240
241 // Always returns the String "Spectral".
242 virtual String showType() const;
243
244 // Always returns 1.
245 // <group>
246 virtual uInt nPixelAxes() const;
247 virtual uInt nWorldAxes() const;
248 // </group>
249
250 // Set extra conversion layer. Whenever a conversion from pixel to world is done,
251 // the world value is then further converted to this MFrequency::Types value.
252 // For example, your SpectralCoordinate may be defined in LSRK.
253 // You can use this to get the world values out in say BARY. You must
254 // specify the position on earth, the epoch and the direction for the conversions
255 // and it is your responsibility to ensure they are viable.
256 // Similarly, whenever you convert from world to pixel, the world
257 // value is assumed to be that appropriate to the setReferenceConversion type.
258 // It is first converted to the MFrequency::Types with which the
259 // SpectralCoordinate was constructed and from there to pixel.
260 // If you don't call this function, or you set the same type
261 // for which the SpectralCoordinate was constructed, no extra
262 // conversions occur. Some conversions will fail. These are the
263 // ones that require extra frame information (radial velocity) such
264 // as to REST. This will be added later. In this case this function
265 // returns False (and the conversion parameters are all left as they were),
266 // else it returns True.
267 // <group>
269 const MEpoch& epoch, const MPosition& position,
270 const MDirection& direction);
272 MEpoch& epoch, MPosition& position,
273 MDirection& direction) const
274 {type = conversionType_p; epoch=epoch_p;
275 position=position_p; direction=direction_p;};
276 // </group>
277
278 // Convert a pixel to a world coordinate or vice versa. Returns True
279 // if the conversion succeeds, otherwise it returns False and
280 // <src>errorMessage()</src> contains an error message. The input vectors
281 // must be of length one and the output vectors are resized if they are not
282 // already of length one.
283 // if <src>useConversionFrame</src>, if the coordinate has a conversion
284 // layer frame, it is used. Else, the native frame is used for the conversion.
285 // <group>
286 virtual Bool toWorld(Vector<Double> &world,
287 const Vector<Double> &pixel, Bool useConversionFrame=True) const;
288 virtual Bool toPixel(Vector<Double> &pixel,
289 const Vector<Double> &world) const;
290 Bool toWorld(Double& world, const Double& pixel) const;
291 Bool toPixel(Double& pixel, const Double& world) const;
292 // </group>
293
294 // Convert a pixel (channel number) into an MFrequency or MVFrequency and vice
295 // versa. Usually you will do
296 // this for calculating velocities or converting frequencies from one frame
297 // to another.
298 // <group>
300 Double pixel) const;
301 Bool toPixel(Double& pixel, const MFrequency &world) const;
303 Double pixel) const;
304 Bool toPixel(Double& pixel, const MVFrequency &world) const;
305 // </group>
306
307 // Batch up a lot of transformations. The first (most rapidly varying) axis
308 // of the matrices contain the coordinates. Returns False if any conversion
309 // failed and <src>errorMessage()</src> will hold a message.
310 // The <src>failures</src> array (True for fail, False for success)
311 // is the length of the number of conversions and
312 // holds an error status for each conversion.
313 // <group>
315 const Matrix<Double>& pixel,
316 Vector<Bool>& failures) const;
318 const Matrix<Double>& world,
319 Vector<Bool>& failures) const;
320 // </group>
321
322 // Set the state that is used for conversions from pixel and frequency to velocity
323 // or wavelength. The SpectralCoordinate is constructed with
324 // <src>MDoppler::RADIO</src> and <src>km/s</src> as the velocity conversion state
325 // and <src>mm</src> as the wavelength conversion state.
326 // The functions in this class which use this state are those that convert
327 // to or from velocity. Also, function <src>format</src> uses the Doppler
328 // state set here. If the function returns False it means the unit was
329 // not valid. There will be an error message in function <src>errorMessage</src>
330 // <group>
331 Bool setVelocity (const String& velUnit=String("km/s"),
333
335 String velocityUnit () const {return velUnit_p;};
336 //
337 Bool setWavelengthUnit (const String& waveUnit=String("mm"));
338 String wavelengthUnit () const {return waveUnit_p;};
339 //
342
343 // </group>
344 // Functions to convert to velocity (uses the current active
345 // rest frequency) or wavelength. There is no reference frame
346 // change but you can specify the velocity Doppler and the output
347 // units of the velocity with function <src>setVelocity</src>
348 // or <src>setWavelength</src> respectively. When the input is a frequency stored
349 // as a Double it must be in the current units of the SpectralCoordinate.
350 //
351 // Note that the extra conversion layer (see function <src>setReferenceConversion</src>)
352 // is active in the <src>pixelToVelocity</src> functions (because internally
353 // the use <src>toWorld</src>) but not in the <src>frequencyToVelocity</src>
354 // or <src>frequencyToWavelength</src> functions.
355 // <group>
356 Bool pixelToVelocity (Quantum<Double>& velocity, Double pixel) const;
357 Bool pixelToVelocity (Double& velocity, Double pixel) const;
358 Bool pixelToVelocity (Vector<Double>& velocity, const Vector<Double>& pixel) const;
359 //
360 Bool frequencyToVelocity (Quantum<Double>& velocity, Double frequency) const;
361 Bool frequencyToVelocity (Quantum<Double>& velocity, const MFrequency& frequency) const;
362 Bool frequencyToVelocity (Quantum<Double>& velocity, const MVFrequency& frequency) const;
363 Bool frequencyToVelocity (Double& velocity, Double frequency) const;
364 Bool frequencyToVelocity (Vector<Double>& velocity, const Vector<Double>& frequency) const;
365 //
366 Bool frequencyToWavelength (Vector<Double>& wavelength, const Vector<Double>& frequency) const;
367 Bool frequencyToAirWavelength (Vector<Double>& wavelength, const Vector<Double>& frequency) const;
368 // The refractive index of air (argument can be wavelength or airwavelength)
369 // according to Greisen et al., 2006, A&A, 464, 746.
370 // If airwavelength is used there is an error of the order of 1E-9.
371 // Argument must be in micrometers!
372 //static Double refractiveIndex(const Double& lambda_um);
373 // </group>
374
375 // Functions to convert from velocity (uses the current active
376 // rest frequency) or wavelength. There is no reference frame
377 // change but you can specify the velocity Doppler and the output
378 // units of the velocity with function <src>setVelocity</src>
379 // and those of the wavelength with <src>setWavelength</src>.
380 // When the input is a frequency stored
381 // as a Double it must be in the current units of the SpectralCoordinate.
382 //
383 // Note that the extra conversion layer (see function <src>setReferenceConversion</src>)
384 // is active in the <src>pixelToVelocity</src> functions (because internally
385 // the use <src>toPixel</src>) but not in the <src>frequencyToVelocity</src> functions.
386 // <group>
387 Bool velocityToPixel (Double& pixel, Double velocity) const;
388 Bool velocityToPixel (Vector<Double>& pixel, const Vector<Double>& velocity) const;
389 //
390 Bool velocityToFrequency (Double& frequency, Double velocity) const;
391 Bool velocityToFrequency (Vector<Double>& frequency, const Vector<Double>& velocity) const;
392 //
393 Bool wavelengthToFrequency (Vector<Double>& frequency, const Vector<Double>& wavelength) const;
394 Bool airWavelengthToFrequency (Vector<Double>& frequency, const Vector<Double>& wavelength) const;
395 // </group>
396
397 // The SpectralCoordinate can maintain a list of rest frequencies
398 // (e.g. multiple lines within a band). However, only
399 // one of them is active (e.g. for velocity conversions) at any
400 // one time. Function <src>restFrequency</src> returns that
401 // frequency. Function <src>restFrequencies</src> returns
402 // all of the possible restfrequencies.
403 //
404 // When you construct the SpectralCoordinate, you give it one rest frequency
405 // and it is the active one. Thereafter you can add a new restfrequency
406 // with function <src>setRestFrequency</src> (<src>append=True</src>) and
407 // that frequency will become the active one. With this function
408 // and <src>append=False</src>, the current active restfrequency will
409 // be replaced by the one you give.
410 //
411 // You can change the list of
412 // restfrequencies with function <src>setRestFrequencies</src>. When
413 // you do so, you can either replace the list of rest frequencies or append to it.
414 // You specify which frequency of the new (appended) list
415 // becomes active.
416 //
417 // You can also select the active rest frequency either by an index into
418 // the current list (exception if out of range) given by
419 // <src>restFrequencies()</src> or by the value in the list
420 // nearest to the frequency you give.
421 //
422 // Whenever you change the active rest frequency, the class internals
423 // are adjusted (e.g. the velocity machine is updated).
424 // <group>
427 Bool setRestFrequency(Double newFrequency, Bool append=False);
428 void setRestFrequencies(const Vector<Double>& newFrequencies, uInt which=0,
429 Bool append=False);
433 // </group>
434
435 // Retrieve/set the frequency system. Note that setting the
436 // frequency system just changes the internal value of the
437 // frequency system. In addition, it will reset the internal
438 // conversion frequency system to the new type and delete any
439 // conversion machines.
440 // <group>
443
444 // Transform the SpectralCoordinate to a different native reference frame
445 // keeping the conversion layer as is
447 const MEpoch& epoch,
448 const MPosition& position,
449 const MDirection& direction);
450 // </group>
451
452 // Report the value of the requested attribute.
453 // <group>
457 virtual Vector<Double> increment() const;
459 // </group>
460
461 // Set the value of the requested attribute. Note that these just
462 // change the internal values, they do not cause any recomputation.
463 // <group>
464 virtual Bool setWorldAxisNames(const Vector<String> &names);
465 virtual Bool setReferencePixel(const Vector<Double> &refPix);
467 virtual Bool setIncrement(const Vector<Double> &inc) ;
468 virtual Bool setReferenceValue(const Vector<Double> &refval);
469 // </group>
470
471 // Get the table, i.e. the pixel and world values. The length of these
472 // Vectors will be zero if this axis is pure linear (i.e. if the
473 // channel and frequencies are related through an increment and offset).
474 // <group>
477 // </group>
478
479 // Set/get the unit. Adjust the increment and
480 // reference value by the ratio of the old and new units.
481 // The unit must be compatible with frequency.
482 //<group>
483 virtual Bool setWorldAxisUnits(const Vector<String> &units);
485 //</group>
486
487 // Comparison function. Any private Double data members are compared
488 // with the specified fractional tolerance. Don't compare on the specified
489 // axes in the Coordinate. If the comparison returns False,
490 // <src>errorMessage()</src> contains a message about why.
491 // <group>
492 virtual Bool near(const Coordinate& other,
493 Double tol=1e-6) const;
494 virtual Bool near(const Coordinate& other,
495 const Vector<Int>& excludeAxes,
496 Double tol=1e-6) const;
497 // </group>
498
499
500 // Find the Coordinate for when we Fourier Transform ourselves. This pointer
501 // must be deleted by the caller. Axes specifies which axes of the Coordinate
502 // you wish to transform. Shape specifies the shape of the image
503 // associated with all the axes of the Coordinate. Currently the
504 // output reference pixel is always shape/2. Cannot transform tabular
505 // coordinates. If the pointer returned is 0, it failed with a message
506 // in <src>errorMessage</src>
508 const Vector<Int>& shape) const;
509
510
511 // Format a SpectralCoordinate coordinate world value nicely through the
512 // common format interface. See <linkto class=Coordinate>Coordinate</linkto>
513 // for basics.
514 //
515 // Format types SCIENTIFIC, FIXED, MIXED and DEFAULT are supported.
516 // DEFAULT will use MIXED.
517 //
518 // The world value must always be given in native frequency units.
519 // Use argument <src>unit</src> to determine what it will be
520 // converted to for formatting. If <src>unit</src> is given, it
521 // must be dimensionally consistent with Hz, m, or m/s.
522 // If you give a unit consistent with m/s then the
523 // appropriate velocity Doppler type is taken from that set by
524 // function <src>setVelocity</src>. There is no frame conversion.
525 // If <src>unit</src> is empty, the unit given by <src>setFormatUnit</src>
526 // is used. If this is turn empty, then native units are used.
527 virtual String format(String& unit,
529 Double worldValue,
530 uInt worldAxis,
531 Bool isAbsolute=True,
532 Bool showAsAbsolute=True,
533 Int precision=-1, Bool usePrecForFixed=False) const;
534
535 // Set the default formatter unit (which is initialized to empty). Must
536 // be consistent with Hz or km/s.
537 // If the given unit is illegal, False is returned and the internal state unchanged.
538 // This unit is used by the function <src>format</src> when the given
539 // unit is empty.
540 // <group>
541 String formatUnit () const {return formatUnit_p;}
542 Bool setFormatUnit (const String& unit);
543 // </group>
544
545 // Convert to FITS header record. When writing the FITS record,
546 // the fields "ctype, crval, crpix", and "cdelt" must already be created. Other header
547 // words are created as needed. Use <src>oneRelative=True</src> to
548 // convert zero-relative SpectralCoordinate pixel coordinates to
549 // one-relative FITS coordinates, and vice-versa. If <src>preferVelocity=True</src>
550 // the primary axis type will be velocity, if <src>preferWavelength=True</src> it will
551 // be wavelength, else frequency. For a velocity axis, if <src>opticalVelDef=False</src>,
552 // the radio velocity definition will be used, else optical definition. Similarly for a
553 // wavelength axis, if <src>airWaveDef=True</src> air wavelength will be used, the
554 // default is vacuum wavelength.
555 //<group>
556 void toFITS(RecordInterface &header, uInt whichAxis,
557 LogIO &logger, Bool oneRelative=True,
558 Bool preferVelocity=True, Bool opticalVelDef=True,
559 Bool preferWavelength=False, Bool airWaveDef=False) const;
560
561// Old interface. Handled by wcs in new interface in FITSCoordinateUtil.cc
562// static Bool fromFITSOld(SpectralCoordinate &out, String &error,
563// const RecordInterface &header,
564// uInt whichAxis,
565// LogIO &logger, Bool oneRelative=True);
566 //</group>
567
568 // Save the SpectralCoordinate into the supplied record using the supplied field name.
569 // The field must not exist, otherwise <src>False</src> is returned.
570 virtual Bool save(RecordInterface &container,
571 const String &fieldName) const;
572
573 // Recover the SpectralCoordinate from a record.
574 // A null pointer means that the restoration did not succeed.
576 const String &fieldName);
577
578 // Convert from String to spectral type and vice versa.
579 static Bool specTypetoString(String &stypeString, const SpecType &specType);
580 static Bool stringtoSpecType(SpecType &specType, const String &stypeString);
581
582 // Make a copy of the SpectralCoordinate using new. The caller is responsible for calling
583 // delete.
584 virtual Coordinate* clone() const;
585
586 ostream& print(ostream& os) const;
587
588 // is this a tabular coordinate?
590
591private:
592
593 std::unique_ptr<TabularCoordinate> _tabular; // Tabular coordinate OR
594 mutable ::wcsprm wcs_p; // wcs structure is used
595 Double to_hz_p; // Convert from current world units to Hz
596 Double to_m_p; // Convert from current wavelength units to m
597//
598 MFrequency::Types type_p, conversionType_p; // Frequency system and conversion system
599 Vector<Double> restfreqs_p; // List of possible rest frequencies
600 uInt restfreqIdx_p; // Current active rest frequency index
601
602 // Conversion machines; for pixel<->world conversions only.
603 mutable MFrequency::Convert* pConversionMachineTo_p; // For type_p -> conversionType_p
604 mutable MFrequency::Convert* pConversionMachineFrom_p; // For conversionType_p -> type_p
605
606 VelocityMachine* pVelocityMachine_p; // The velocity machine does all conversions between world & velocity.
607 MDoppler::Types velType_p; // Velocity Doppler
608 String velUnit_p; // Velocity unit
609//
610 String waveUnit_p; // Wavelength unit for conversions between world & wavelength
611 SpectralCoordinate::SpecType nativeType_p; // The native spectral type
612//
613 Unit unit_p; // World axis unit
614 String axisName_p; // The axis name
615 String formatUnit_p; // The default unit for the format function
616//
617 MDirection direction_p; // These are a part of the frame set for
618 MPosition position_p; // the reference conversions machines
619 MEpoch epoch_p; // They are only private so we can save their state
620
621// Format checker
623 const Bool ) const;
624
625// Copy private data
626 void copy (const SpectralCoordinate& other);
627
628// Convert to and from conversion reference type
629 virtual void convertTo (Vector<Double>& world) const;
630 virtual void convertFrom (Vector<Double>& world) const;
631
632// Deletes and sets pointer to 0
634
635// Deletes and sets pointers to 0
637
638// Set up pixel<->world conversion machines
639// Returns: 3 (machines were noOPs, machines deleted)
640// 2 (types the same, machines deleted),
641// 1 (machines created and functioning)
642// -1 (machines could not make trial conversion, machines deleted)
644 const MEpoch& epoch,
645 const MPosition& position,
646 const MDirection& direction);
647
648// Create velocity<->frequency machine
649 void makeVelocityMachine (const String& velUnit,
650 MDoppler::Types velType,
651 const Unit& freqUnit,
652 MFrequency::Types freqType,
653 Double restFreq);
654
655// Make spectral wcs structure (items in Hz)
656 static void makeWCS(wcsprm& wcs, const String& ctype, Double refPix, Double refVal,
657 Double inc, Double pc, Double restFreq);
658
659// Record restoration handling
660// <group>
663 static void restoreVelocity (SpectralCoordinate*& pSpectral,
664 const RecordInterface& subrec);
666 const RecordInterface& subrec,
667 Double restFreq);
668 static void restoreConversion (SpectralCoordinate*& pSpectral,
669 const RecordInterface& subrec);
670
671// </group>
672
673// Interconvert between the current units and wcs units (Hz)
674// <group>
677// </group>
678
679// Return unit conversion vector for converting to current units
681
682// Update Velocity Machine
683 void updateVelocityMachine (const String& velUnit,
684 MDoppler::Types velType);
685// Restore wcs stuff from Record
686 static Bool wcsRestore (Double& crval, Double& crpix, Double& cdelt,
687 Double& pc, String& ctype,
688 const RecordInterface& rec);
689
690// Save wcs stuff into Record
691 Bool wcsSave (RecordInterface& rec, const wcsprm& wcs,
692 const String& fieldName) const;
693
695
696};
697
698ostream &operator<<(ostream &os, const SpectralCoordinate& spcoord);
699
700} //# NAMESPACE CASACORE - END
701
702
703#endif
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
Types
Types of known MDopplers Warning: The order defines the order in the translation matrix FromTo in th...
Definition MDoppler.h:146
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:173
static void makeWCS(wcsprm &wcs, const String &ctype, Double refPix, Double refVal, Double inc, Double pc, Double restFreq)
Make spectral wcs structure (items in Hz)
Bool velocityToFrequency(Vector< Double > &frequency, const Vector< Double > &velocity) const
static SpectralCoordinate * restoreVersion1(const RecordInterface &container)
Record restoration handling.
Bool frequencyToAirWavelength(Vector< Double > &wavelength, const Vector< Double > &frequency) const
SpectralCoordinate(MFrequency::Types freqType, const Vector< Double > &wavelengths, const String &waveUnit, Double restFrequency=0.0, Bool inAir=False)
Construct a SpectralCoordinate with the specified wavelengths (in mm).
virtual void convertTo(Vector< Double > &world) const
Convert to and from conversion reference type.
virtual Vector< Double > referenceValue() const
SpectralCoordinate(MFrequency::Types type, const Vector< Double > &freqs, Double restFrequency=0.0)
Construct a SpectralCoordinate with the specified frequencies (in Hz).
Bool wcsSave(RecordInterface &rec, const wcsprm &wcs, const String &fieldName) const
Save wcs stuff into Record.
static SpectralCoordinate * restore(const RecordInterface &container, const String &fieldName)
Recover the SpectralCoordinate from a record.
virtual void convertFrom(Vector< Double > &world) const
Bool velocityToPixel(Vector< Double > &pixel, const Vector< Double > &velocity) const
SpectralCoordinate(const SpectralCoordinate &other)
Copy constructor (copy semantics).
SpectralCoordinate(MFrequency::Types type, const Quantum< Double > &f0, const Quantum< Double > &inc, Double refPix, const Quantum< Double > &restFrequency=Quantum< Double >(0.0,"Hz"))
Create linear frequency axis SpectralCoordinate with Quantum-based interface.
Bool transformFrequencySystem(MFrequency::Types type, const MEpoch &epoch, const MPosition &position, const MDirection &direction)
Transform the SpectralCoordinate to a different native reference frame keeping the conversion layer a...
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the value of the requested attribute.
Bool toWorld(MFrequency &world, Double pixel) const
Convert a pixel (channel number) into an MFrequency or MVFrequency and vice versa.
Bool pixelToVelocity(Quantum< Double > &velocity, Double pixel) const
Functions to convert to velocity (uses the current active rest frequency) or wavelength.
virtual Bool toWorldMany(Matrix< Double > &world, const Matrix< Double > &pixel, Vector< Bool > &failures) const
Batch up a lot of transformations.
virtual Coordinate::Type type() const
Always returns Coordinate::SPECTRAL.
std::unique_ptr< TabularCoordinate > _tabular
const Vector< Double > toCurrentFactors() const
Return unit conversion vector for converting to current units.
Bool frequencyToVelocity(Quantum< Double > &velocity, Double frequency) const
static void restoreVelocity(SpectralCoordinate *&pSpectral, const RecordInterface &subrec)
static void restoreRestFrequencies(SpectralCoordinate *&pSpectral, const RecordInterface &subrec, Double restFreq)
Bool frequencyToVelocity(Double &velocity, Double frequency) const
Bool pixelToVelocity(Vector< Double > &velocity, const Vector< Double > &pixel) const
String formatUnit() const
Set the default formatter unit (which is initialized to empty).
MFrequency::Convert * pConversionMachineTo_p
Conversion machines; for pixel<->world conversions only.
virtual Vector< Double > increment() const
Bool wavelengthToFrequency(Vector< Double > &frequency, const Vector< Double > &wavelength) const
Bool toPixel(Double &pixel, const Double &world) const
SpectralCoordinate()
Default constructor.
virtual Vector< String > worldAxisNames() const
Report the value of the requested attribute.
Bool toPixel(Double &pixel, const MVFrequency &world) const
Vector< Double > pixelValues() const
Get the table, i.e.
Double restFrequency() const
The SpectralCoordinate can maintain a list of rest frequencies (e.g.
void selectRestFrequency(Double frequency)
virtual Bool setReferencePixel(const Vector< Double > &refPix)
SpectralCoordinate(MFrequency::Types type, Double f0, Double inc, Double refPix, Double restFrequency=0.0)
Create a linear frequency axis SpectralCoordinate f0 is the frequency of the reference pixel,...
static Bool stringtoSpecType(SpecType &specType, const String &stypeString)
virtual Vector< String > worldAxisUnits() const
Bool frequencyToVelocity(Quantum< Double > &velocity, const MVFrequency &frequency) const
virtual Bool toPixelMany(Matrix< Double > &pixel, const Matrix< Double > &world, Vector< Bool > &failures) const
Vector< Double > worldValues() const
void toCurrent(Vector< Double > &value) const
Interconvert between the current units and wcs units (Hz)
static Bool specTypetoString(String &stypeString, const SpecType &specType)
Convert from String to spectral type and vice versa.
void setRestFrequencies(const Vector< Double > &newFrequencies, uInt which=0, Bool append=False)
SpectralCoordinate(MFrequency::Types freqType, MDoppler::Types velType, const Vector< Double > &velocities, const String &velUnit, Double restFrequency=0.0)
Construct a SpectralCoordinate with the specified velocities (in km/s).
String formatRestFrequencies() const
SpectralCoordinate(MFrequency::Types type, const Quantum< Vector< Double > > &freqs, const Quantum< Double > &restFrequency=Quantum< Double >(0.0,"Hz"))
Construct a SpectralCoordinate with the specified frequencies with Quantum-based interface.
Bool setFormatUnit(const String &unit)
virtual String format(String &unit, Coordinate::formatType format, Double worldValue, uInt worldAxis, Bool isAbsolute=True, Bool showAsAbsolute=True, Int precision=-1, Bool usePrecForFixed=False) const
Format a SpectralCoordinate coordinate world value nicely through the common format interface.
void _setTabulatedFrequencies(const Vector< Double > &freqs)
Bool setWavelengthUnit(const String &waveUnit=String("mm"))
void makeVelocityMachine(const String &velUnit, MDoppler::Types velType, const Unit &freqUnit, MFrequency::Types freqType, Double restFreq)
Create velocity<->frequency machine
virtual Matrix< Double > linearTransform() const
virtual Bool save(RecordInterface &container, const String &fieldName) const
Old interface.
void setFrequencySystem(MFrequency::Types type, Bool verbose=True)
static void restoreConversion(SpectralCoordinate *&pSpectral, const RecordInterface &subrec)
Bool airWavelengthToFrequency(Vector< Double > &frequency, const Vector< Double > &wavelength) const
Int makeConversionMachines(MFrequency::Types type, MFrequency::Types conversionType, const MEpoch &epoch, const MPosition &position, const MDirection &direction)
Set up pixel<->world conversion machines Returns: 3 (machines were noOPs, machines deleted) 2 (types ...
virtual uInt nWorldAxes() const
virtual Coordinate * clone() const
Make a copy of the SpectralCoordinate using new.
virtual String showType() const
Always returns the String "Spectral".
static Bool wcsRestore(Double &crval, Double &crpix, Double &cdelt, Double &pc, String &ctype, const RecordInterface &rec)
Restore wcs stuff from Record.
virtual Bool setReferenceValue(const Vector< Double > &refval)
SpectralCoordinate & operator=(const SpectralCoordinate &other)
Assignment (copy semantics).
SpectralCoordinate::SpecType nativeType() const
Bool frequencyToWavelength(Vector< Double > &wavelength, const Vector< Double > &frequency) const
Bool frequencyToVelocity(Vector< Double > &velocity, const Vector< Double > &frequency) const
Bool velocityToFrequency(Double &frequency, Double velocity) const
void getReferenceConversion(MFrequency::Types &type, MEpoch &epoch, MPosition &position, MDirection &direction) const
virtual Bool toWorld(Vector< Double > &world, const Vector< Double > &pixel, Bool useConversionFrame=True) const
Convert a pixel to a world coordinate or vice versa.
MFrequency::Types frequencySystem(Bool showConversion=False) const
Retrieve/set the frequency system.
virtual Bool setWorldAxisUnits(const Vector< String > &units)
Set/get the unit.
void selectRestFrequency(uInt which)
void deleteConversionMachines()
Deletes and sets pointers to 0.
Bool setRestFrequency(Double newFrequency, Bool append=False)
Bool setVelocity(const String &velUnit=String("km/s"), MDoppler::Types velType=MDoppler::RADIO)
Set the state that is used for conversions from pixel and frequency to velocity or wavelength.
Bool pixelToVelocity(Double &velocity, Double pixel) const
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
static SpectralCoordinate * restoreVersion2(const RecordInterface &container)
virtual Bool setIncrement(const Vector< Double > &inc)
Bool isTabular() const
is this a tabular coordinate?
void toFITS(RecordInterface &header, uInt whichAxis, LogIO &logger, Bool oneRelative=True, Bool preferVelocity=True, Bool opticalVelDef=True, Bool preferWavelength=False, Bool airWaveDef=False) const
Convert to FITS header record.
virtual ~SpectralCoordinate()
Destructor.
void checkFormat(Coordinate::formatType &format, const Bool) const
Format checker.
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
Bool setNativeType(const SpectralCoordinate::SpecType spcType)
Bool toWorld(MVFrequency &world, Double pixel) const
SpectralCoordinate(MFrequency::Types freqType, const ::wcsprm &wcs, Bool oneRel=True)
Construct from wcs structure.
Bool velocityToPixel(Double &pixel, Double velocity) const
The refractive index of air (argument can be wavelength or airwavelength) according to Greisen et al....
void fromCurrent(Vector< Double > &value) const
virtual Bool near(const Coordinate &other, const Vector< Int > &excludeAxes, Double tol=1e-6) const
MDoppler::Types velocityDoppler() const
Bool setReferenceConversion(MFrequency::Types type, const MEpoch &epoch, const MPosition &position, const MDirection &direction)
Set extra conversion layer.
void updateVelocityMachine(const String &velUnit, MDoppler::Types velType)
Update Velocity Machine.
virtual Coordinate * makeFourierCoordinate(const Vector< Bool > &axes, const Vector< Int > &shape) const
Find the Coordinate for when we Fourier Transform ourselves.
SpectralCoordinate::SpecType nativeType_p
void deleteVelocityMachine()
Deletes and sets pointer to 0.
Bool toPixel(Double &pixel, const MFrequency &world) const
const Vector< Double > & restFrequencies() const
virtual Bool setLinearTransform(const Matrix< Double > &xform)
virtual Vector< Double > referencePixel() const
ostream & print(ostream &os) const
Bool toWorld(Double &world, const Double &pixel) const
void copy(const SpectralCoordinate &other)
Copy private data.
virtual uInt nPixelAxes() const
Always returns 1.
Bool frequencyToVelocity(Quantum< Double > &velocity, const MFrequency &frequency) const
MFrequency::Convert * pConversionMachineFrom_p
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
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53