Package gavo :: Package stc :: Module units
[frames] | no frames]

Module units

source code

Definition and conversion of units in STC

For every physical quantity we deal with, there is a standard unit defined:

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.

Functions
 
makeConverterMaker(label, conversions)
returns a conversion function that converts between any of the units mentioned in the dict conversions.
source code
 
getDistConv(fromUnit, toUnit, reverse=False) source code
 
getAngleConv(fromUnit, toUnit, reverse=False) source code
 
getTimeConv(fromUnit, toUnit, reverse=False) source code
 
getFreqConv(fromUnit, toUnit, reverse=False) source code
 
getWlConv(fromUnit, toUnit, reverse=False) source code
 
getSpectralConv(fromUnit, toUnit, reverse=False) source code
 
getBasicConverter(*args)
returns a function converting fromUnit values to toUnit values.
source code
 
getParallaxConverter(*args)
returns a function converting distances to/from parallaxes.
source code
 
getRedshiftConverter(*args)
returns a function converting redshifts in spaceUnit/timeUnit to toSpace/toTime.
source code
 
getVectorConverter(*args)
returns a function converting from fromUnits to toUnits.
source code
 
getVelocityConverter(*args)
returns a function converting from fromSpaceUnits/fromTimeUnits to toSpace/toTime.
source code
 
getUnitConverter(*args)
returns a pair of unit info and a conversion function to take fromCoo to the units of toCoo.
source code
 
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.
source code
Variables
  toRad = 0.0174532925199
  oneAU = 1.49597870691e+11
  onePc = 3.0856775813e+16
  lightspeed = 299792458.0
  planckConstant = 4.13566733e-15
  julianYear = 31557600.0
  distFactors = {'AU': 1.49597870691e+11, 'Mpc': 3.0856775813e+2...
  angleFactors = {'arcmin': 0.0166666666667, 'arcsec': 0.0002777...
  timeFactors = {'a': 31557600.0, 'cy': 3155760000.0, 'd': 86400...
  freqFactors = {'GHz': 1000000000.0, 'GeV': 2.41798945661e+23, ...
  wlFactors = {'Angstrom': 1e-10, 'm': 1.0, 'mm': 0.001, 'nm': 1...
  distUnits = set(['AU', 'Mpc', 'km', 'kpc', 'lyr', 'm', 'mm', '...
  angleUnits = set(['arcmin', 'arcsec', 'deg', 'h', 'rad'])
  timeUnits = set(['a', 'cy', 'd', 'h', 's', 'yr'])
  spectralUnits = set(['Angstrom', 'GHz', 'GeV', 'Hz', 'MHz', 'M...
  systems = [(set(['AU', 'Mpc', 'km', 'kpc', 'lyr', 'm', 'mm', '...
  maxDistance = 10000000.0
  __package__ = 'gavo.stc'
Function Details

getBasicConverter(*args)

source code 

returns a function converting fromUnit values to toUnit values.

Decorators:
  • @memoized

getParallaxConverter(*args)

source code 

returns a function converting distances to/from parallaxes.

Decorators:
  • @memoized

getRedshiftConverter(*args)

source code 

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.

Decorators:
  • @memoized

getVectorConverter(*args)

source code 

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.

Decorators:
  • @memoized

getVelocityConverter(*args)

source code 

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.

Decorators:
  • @memoized

getUnitConverter(*args)

source code 

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().

Decorators:
  • @memoized

iterUnitAdapted(baseSTC, sysSTC, attName, dependentName)

source code 

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.


Variables Details

distFactors

Value:
{'AU': 1.49597870691e+11,
 'Mpc': 3.0856775813e+22,
 'km': 1000.0,
 'kpc': 3.0856775813e+19,
 'lyr': 9.46073047258e+15,
 'm': 1.0,
 'mm': 0.001,
 'pc': 3.0856775813e+16}

angleFactors

Value:
{'arcmin': 0.0166666666667,
 'arcsec': 0.000277777777778,
 'deg': 1.0,
 'h': 15.0,
 'rad': 57.2957795131}

timeFactors

Value:
{'a': 31557600.0,
 'cy': 3155760000.0,
 'd': 86400.0,
 'h': 3600.0,
 's': 1.0,
 'yr': 31557600.0}

freqFactors

Value:
{'GHz': 1000000000.0,
 'GeV': 2.41798945661e+23,
 'Hz': 1.0,
 'MHz': 1000000.0,
 'MeV': 2.41798945661e+20,
 'TeV': 2.41798945661e+26,
 'eV': 2.41798945661e+14,
 'kHz': 1000.0,
...

wlFactors

Value:
{'Angstrom': 1e-10, 'm': 1.0, 'mm': 0.001, 'nm': 1e-09, 'um': 1e-06}

distUnits

Value:
set(['AU', 'Mpc', 'km', 'kpc', 'lyr', 'm', 'mm', 'pc'])

spectralUnits

Value:
set(['Angstrom',
     'GHz',
     'GeV',
     'Hz',
     'MHz',
     'MeV',
     'TeV',
     'eV',
...

systems

Value:
[(set(['AU', 'Mpc', 'km', 'kpc', 'lyr', 'm', 'mm', 'pc']),
  <__builtin__.function object>),
 (set(['arcmin', 'arcsec', 'deg', 'h', 'rad']),
  <__builtin__.function object>),
 (set(['a', 'cy', 'd', 'h', 's', 'yr']),
  <__builtin__.function object>),
 (set(['Angstrom',
       'GHz',
...