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