astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- World Coordinate System (`astropy.wcs`) »
- UnitConverter

# UnitConverter

`astropy.wcs.``UnitConverter`(*args, **kwargs)

  Deprecated since version 0.2: Use astropy.units instead.

  UnitConverter(have, want, translate_units=’‘)

  An object for converting from one system of units to another.

  Use the returned object’s `convert` method to convert values from have to want.

  This function is permissive in accepting whitespace in all contexts in a units specification where it does not create ambiguity (e.g. not between a metric prefix and a basic unit string), including in strings like `"log (m ** 2)"` which is formally disallowed.

  Note

  Deprecated in Astropy 0.2

  `UnitConverter` will be removed in a future version of astropy. The `astropy.units` package should be used instead.

  Parameters:

  have : str

  > FITS unit string to convert from, with or without surrounding square brackets (for inline specifications); text following the closing bracket is ignored.

  want : str

  > FITS unit string to convert to, with or without surrounding square brackets (for inline specifications); text following the closing bracket is ignored.

  ctrl : str, optional

  > Do potentially unsafe translations of non-standard unit strings.

  > Although `"S"` is commonly used to represent seconds, its recognizes `"S"` formally as Siemens, however rarely that may be translation to `"s"` is potentially unsafe since the standard used. The same applies to `"H"` for hours (Henry), and `"D"` for days (Debye).

  > This string controls what to do in such cases, and is case-insensitive.

  > - If the string contains `"s"`, translate `"S"` to `"s"`.
  > - If the string contains `"h"`, translate `"H"` to `"h"`.
  > - If the string contains `"d"`, translate `"D"` to `"d"`.

  > Thus `''` doesn’t do any unsafe translations, whereas `'shd'` does all of them.

  Raises:

  ValueError :

  > Invalid numeric multiplier.

  SyntaxError :

  > Dangling binary operator.

  SyntaxError :

  > Invalid symbol in INITIAL context.

  SyntaxError :

  > Function in invalid context.

  SyntaxError :

  > Invalid symbol in EXPON context.

  SyntaxError :

  > Unbalanced bracket.

  SyntaxError :

  > Unbalanced parenthesis.

  SyntaxError :

  > Consecutive binary operators.

  SyntaxError :

  > Internal parser error.

  SyntaxError :

  > Non-conformant unit specifications.

  SyntaxError :

  > Non-conformant functions.

  ValueError :

  > Potentially unsafe translation.