casacore
|
a module for units and quantities More...
Modules | |
Quanta_module_internal_classes | |
Internal Quanta_module classes and functions. | |
Classes | |
class | casacore::MeasValue |
Base class for values in a Measure. More... | |
struct | casacore::MeasValue_global_functions_Output |
Global functions. More... | |
class | casacore::MVAngle |
Class to handle angle type conversions and I/O. More... | |
struct | casacore::MVAngle_global_functions_output |
Global functions. More... | |
class | casacore::MVBaseline |
A 3D vector on Earth. More... | |
class | casacore::MVDirection |
Vector of three direction cosines. More... | |
class | casacore::MVDoppler |
Internal value for MDoppler. More... | |
class | casacore::MVDouble |
Class to distinguish external and Measure internal Double. More... | |
class | casacore::MVEpoch |
A class for high precision time. More... | |
class | casacore::MVFrequency |
Internal value for MFrequency. More... | |
class | casacore::MVPosition |
A 3D vector in space. More... | |
class | casacore::MVRadialVelocity |
Internal value for MRadialVelocity. More... | |
class | casacore::MVTime |
Class to handle date/time type conversions and I/O. More... | |
class | casacore::MVuvw |
A 3D vector on Earth. More... | |
class | casacore::QBase |
Base for Quantities (i.e. dimensioned values) More... | |
struct | casacore::QBase_global_functions_Output |
Global functions. More... | |
class | casacore::QC |
Physical constants (i.e. dimensioned values) More... | |
struct | casacore::QLogical_global_functions_Quantum_logical_operations |
Logical operations for the Quantum class. More... | |
struct | casacore::QMath_global_functions_Quantum_mathematical_operations |
Mathematical operations for the Quantum class. More... | |
class | casacore::Quantum< Qtype > |
Quantities (i.e. dimensioned values) More... | |
struct | casacore::Quantum_global_functions_output |
Global functions. More... | |
class | casacore::QuantumHolder |
A holder for Quantums to enable record conversions. More... | |
struct | casacore::QuantumType_global_functions_QuantumType |
Get an integer type for a Qunatum<T> More... | |
class | casacore::QVector< T > |
Specialization for Quantum<Vector<T> > More... | |
class | casacore::Unit |
defines physical units More... | |
class | casacore::UnitDim |
describes a unit in basic SI unit dimensions More... | |
class | casacore::UnitMap |
contains all simple known physical units More... | |
class | casacore::UnitName |
handles physical units More... | |
class | casacore::UnitVal |
describes any valid unit as a factor and a dimenion of SI units More... | |
struct | casacore::UnitVal_global_functions_output |
Global output function. More... | |
class | casacore::UnitVal_static_initializer |
Static initialisation of UnitVal constants. More... | |
Variables | |
static class casacore::UnitVal_static_initializer | casacore::unitval_static_initializer |
a module for units and quantities
See below for an overview of the classes in this module.
Public interface
The name Quanta derives from a physical quantity, i.e. a value with units attached.
The Quanta model deals with units and physical quantities (i.e. values with a unit). Units are handled in the Unit section (see Unit.h). Quantities are handled in the Quantum section (see Quantum.h). In addition the module contains some more general support classes (Euler angles, rotation matrix, pointed string), formatting for time and angle classes and classes containing information for Measures (MeasValue and the derived MV classes like MVEpoch). See the MeasValue section.
Including the casa/Quanta.h
will take care of all includes necessary for the handling of pure Units and Quantities.
Physical units are basically used in quantities (see Quantum), i.e. a value and a dimension. The Unit class, or one of its subsidiaries, will in general not be called separately. The only reason to make use of these classes is to generate additional 'tagged' units, i.e. units with a special name, e.g. 'beam' for a telescope beam, or 'JY', a non-SI name for Jy.
A Unit is in principle specified as a String (or directly as "string"), and can be defined as either a Unit or a String. If defined as a Unit, the format of the string will be checked for a legal definition and relevant information (e.g. scale, dimension type) is cached in the Unit object, leading to (much) faster use; if defined as a String, the checking will be postponed until any use is made of the information in the string.
A unit is a string of one or more fields separated by 'space' or '.' (to indicate multiply) or '/' (to indicate divide). Multiple separators are acted upon (i.e. m//s == m.s
). Separators are acted upon left-to-right (i.e. m/s/A == (m/s)/A
; use () to indicate otherwise (e.g. m/(s/A)
)).
A field is a name, or a unit enclosed in (), optionally followed by an, optionally signed, decimal constant. E.g. m.(m/s)-2 == m-1.s2
)
Note that a 'space' or '.' before an opening '(' can be omitted.
A name can consist of case-sensitive letters, '_', ''', ':', '"' and '0' ('0' not as first character). Digits 1-9 are allowed if preceded with an '_'. Possible legal names are e.g. Jy, R0, R_1, "_2.
Tip:
'
is used for arcmin ''
or "
for arcsec
Tip: The standard naming conventions for SI units are that they are all in lowercase, unless derived from a person's name, when they start with a capital letter; Notable exceptions are some of the astronomical SI related units (e;g; AU);
A name can be preceded by a (standard) decimal prefix.
A name must be defined in a Unit map before it can be used.
All SI units and some customary units are part of the classes. User defined names can be added by the UnitMap::putUser() function (see UnitMap). A special set of FITS related units can be added by the UnitMap::addFITS()
function. For details, see UnitMap.
Example:
There are 5 name lists in the UnitMap, which are searched in reverse order:
All known names can be viewed by running the tUnit test program, or using the MapUnit::list() routine.
The definitions that were current on 990915 are given at end of this file
Caution: There is a difference between units without a dimension (non-dimensioned I will call them), and undimensioned units; Non-dimensioned examples are "", "%"; undimensioned examples: "beam", "pixel";
In general units are not used explicitly, but are embedded in quantities and coordinates.
Explicit use of units is only necessary if:
For these cases a Unit can be defined as either a String or a Unit. If specified as a Unit an automatic check (with exception if illegal) of the format of the unit string is performed
Tip: UnitVal has the following special constants to easily check unit dimensions (note that they can be combined to e;g; generate velocity as 'UnitVal::LENGTH/UnitVal::TIME')
See the UnitVal for details of calculating with units. See the UnitMap for the details of defining/viewing named units.
A Quantum is a value with a unit. Quantums are templated on their value type (e.g. Float
, Vector<Double>
). Quantity is a typedef for the (probably most common) Quantum<Double>
. The basic specification of a Quantum is:
E.g.
Quantity(5.,"m");
Quantum<Double> (5.,"m"); // identical to previous
Vector<Int> a(3); a(3) = 5; Quantum<Vector<Int> >(a,"Jy");
The following list of constructors is available.
Tip: In the following 'Unit' can be replaced by 'String' (or "string" everywhere; The only difference being a check for a legitimate unit string being executed if Unit specified (with exception if error), and a much faster execution of the Unit is used repeatedly; Quantum<Type>
can, if Type equals Double, be replaced with Quantity
Quantum<Type>() value 0 generated
Quantum<Type>(Quantum<Type>) copy constructor
Quantum<Type>(Type factor) value factor generated
Quantum<Type>(Type factor, Unit unit) specified quantity
Quantum<Type>(Type factor, Quantum<any> quant) specified factor, the unit from the quant
The following operators and functions are defined on Quantums. They are, of course, only available if the template Type supports them (e.g. / will not be defined for a Quantum<String>
(whatever that may mean)).
= assignment of identical <type>
* *= multiply two Quantums of same <type>
/ /= divide two Quantums of same <type>
+ += add two Quantums of same <type> and same unit dimensions
(else exception) - -= subtract two Quantums of same <type> and same unit dimensions
(else exception) == != compare unit dimensions and value of same <type>
. They will be unequal if the unit dimensions do not match or the values (converted to common base units) are unequal < > compare unit dimensions of same <type>
. Exception if no match, else compare the values <= >=
ibid Quanta can be converted to other units by the following set of member functions:
convert(Quantum<any> quant)
will convert the quantum to the units of the specified quant with the same conversion rules as the previous one get(Quantum<any> quant) will return the converted quantum
Quanta can be checked for having the correct unit dimensions (e.g. before addition or comparing) by the following two member functions, which will return a Bool value or raise an exception:
Bool isConform(Unit)
Bool isConform(Quantum<any>)
Bool check(UnitVal)
void assure(UnitVal)
The value and units of a quantum can be set or retrieved separately by the following member functions:
Type getValue()
return the value (as Type) of the quantum Type getValue(Unit)
return the value in specified units Type getBaseValue()
return the value in canonical units String getUnit()
return the units of the quantum void setValue(Type val)
replace the value of the quantum with val, leaving the units the same void scale(Type)
scale the value (leaving units same) by multiplying with the specified value void setUnit(Unit)
replace the units of the quantum, leaving the value the same. void setUnit(Quantum<any>)
ibid The output operator ('<<') will produce the value of the quantum and its units. Given Quantity myval(5.,"mJy");
, cout << myval;
will produce: "5.0 mJy"; while cout << myval.get("yW/m2")
will produce: ".00005 yW/m2.s"
In parallel with the 'C' class of undimensioned constants, the QC class contains dimensioned constants. On 960509 the following were defined:
Quantum<Double> c; // vel of light
Quantum<Double> G; // Gravitational constant
Quantum<Double> h; // Planck
Quantum<Double> HI; // Frequency HI line
Quantum<Double> R; // Gas constant
Quantum<Double> NA; // Avogadro
Quantum<Double> e; // electron charge
Quantum<Double> mp; // proton mass
Quantum<Double> mp_me; // mp/me
Quantum<Double> mu0; // permeability vacuum
Quantum<Double> epsilon0; // permittivity vacuum
Quantum<Double> k; // Boltzmann
Quantum<Double> F; // Faraday
Quantum<Double> me; // mass electron
Quantum<Double> re; // radius electron
Quantum<Double> a0; // Bohr's radius
Quantum<Double> R0; // Solar radius
Quantum<Double> k2; // IAU Gaussian grav. const **2
The MeasValue class derivatives are all named MVmeasure, e.g. MVFrequency, and represent the internal representation of the specific measure class. There main use is for the Measures module, but they can be used alone, e.g. for the conversion to formatted times, or the conversion of frequencies from say wavelength to frequency. They all have at least the following constructors:
But most have also constructors like:
The actual interpretation is class dependent: see the individual MV classes like MVEpoch, MVDirection, MVPosition, MVFrequency, MVDouble, MVRadialVelocity. MVBaseline, MVuvw, MVEarthMagnetic, A few examples:
All MVs have the +=, -=, ==, !=, <<
operators, and near()
, nearAbs()
, print()
and adjust()
and readjust()
(which in general normalise to a value of 1 (e.g. MVDirection), or recalculates high precision values (e.g. MVEpoch) functions.
Information can be viewed with many get functions. In most cases getValue() will return the internal value as either Double or Vector<Double>; get() will return the same, or converted values (e.g. a vector of length, angle, angle for MVPosition; while special one like getAngle() or getAngle(unit), getTime() etc will return Quantums (with optional conversion to specified units).
In general the Measure classes can be used without worrying about the MeasValues, since most Measure constructors have enough flexibility (and their own get()'s) to be able to use them independently).
Special cases are MVAngle and MVTime, which can do special formatting for time and angles (in earlier documentation they were called HMS etc.).
The Quanta model originated to handle physical quantities independent of their units. Units were introduced in the described way to be able to handle any possible physical unit.
|
static |