Definition and conversion of units in STC
For every physical quantity we deal with, there is a standard unit defined:
angles: deg (we way want to use rad here)
We keep dictionaries of conversion factors to those units. Since turning things around, these factors give “how many bases are in the unit”, e.g. km -> 1000.
The main interface are functions returning converter functions. Pass a value in fromUnit to them and receive a value in toUnit. Simple factors unfortunately don’t cut it here since conversion from wavelength to frequency needs division of the value.
- gavo.stc.units.getAngleConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.getBasicConverter(fromUnit, toUnit, reverse=False)¶
returns a function converting fromUnit values to toUnit values.
- gavo.stc.units.getDistConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.getFreqConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.getParallaxConverter(fromUnit, toUnit, reverse=False)¶
returns a function converting distances to/from parallaxes.
- gavo.stc.units.getRedshiftConverter(spaceUnit, timeUnit, toSpace, toTime, reverse=False)¶
returns a function converting redshifts in spaceUnit/timeUnit to toSpace/toTime.
This will actually work for any unit of the form unit1/unit2 as long as unit2 is purely multiplicative.
- gavo.stc.units.getSpectralConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.getTimeConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.getUnitConverter(fromCoo, toCoo)¶
returns a pair of unit info and a conversion function to take fromCoo to the units of toCoo.
toCoo may be None, in which case the unit of fromCoo is returned together with an identity function. If the units already match, (None, None) is returned.
The unit info is a dictionary suitable for change().
- gavo.stc.units.getVectorConverter(fromUnits, toUnits, reverse=False)¶
returns a function converting from fromUnits to toUnits.
fromUnits is a tuple, toUnits is a tuple of which only the first item is interpreted. This first item must be a tuple or a single string; in the latter case, all components are supposed to be of that unit.
ToUnits may be shorter than fromUnits. In this case, the additional fromUnits are ignored. This is mainly for cases in which geometries go with SPHER3 positions.
The resulting functions accepts sequences of len(toUnits) and returns tuples of the same length.
As a special service for Geometries, these spatial converters have additional attributes fromUnit and toUnit giving what transformation they implement.
- gavo.stc.units.getVelocityConverter(fromSpaceUnits, fromTimeUnits, toSpace, toTime, reverse=False)¶
returns a function converting from fromSpaceUnits/fromTimeUnits to toSpace/toTime.
fromXUnits is a tuple, toX may either be a tuple of length fromXUnits or a a single string like in getVectorUnits.
The resulting functions accepts sequences of proper length and returns tuples.
- gavo.stc.units.getWlConv(fromUnit, toUnit, reverse=False)¶
- gavo.stc.units.iterUnitAdapted(baseSTC, sysSTC, attName, dependentName)¶
iterates over all keys that need to be changed to adapt units in baseSTC’s attName facet to conform to what sysSTC gives.
If something in baseSTC is not specified in sysSTC, it is ignored here (i.e., it will remain unchanged if the result is used in a change).
Since units are only on coordinates, and areas inherit these units, they are transformed as well, and their name is given by dependentName. See also conform.conformUnits.
- gavo.stc.units.makeConverterMaker(label, conversions)¶
returns a conversion function that converts between any of the units mentioned in the dict conversions.