astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Units and Quantities (`astropy.units`) »
- FunctionUnitBase

# FunctionUnitBase

class astropy.units.FunctionUnitBase(physical_unit=None, function_unit=None)

  Bases: `object`

  Abstract base class for function units.

  Function units are functions containing a physical unit, such as dB(mW). Most of the arithmetic operations on function units are defined in this base class.

  While instantiation is defined, this class should not be used directly. Rather, subclasses should be used that override the abstract properties `_default_function_unit` and `_quantity_class`, and the abstract methods `from_physical`, and `to_physical`.

  Parameters:
    physical_unit `Unit` or `string`

      Unit that is encapsulated within the function unit. If not given, dimensionless.

    function_unit `Unit` or `string`

      By default, the same as the function unit set by the subclass.

  Attributes Summary

  `cgs` | Copy the current function unit with the physical unit in CGS.
  `equivalencies` | List of equivalencies between function and physical units.
  `function_unit` |
  `physical_type` | Return the physical type of the physical unit (e.g., 'length').
  `physical_unit` |
  `si` | Copy the current function unit with the physical unit in SI.

  Methods Summary

  `decompose`([bases]) | Copy the current unit with the physical unit decomposed.
  `from_physical`(x) | Transformation from value in physical to value in function units.
  `is_equivalent`(other[, equivalencies]) | Returns `True` if this unit is equivalent to `other`.
  `is_unity`() |
  `to`(other[, value, equivalencies]) | Return the converted values in the specified unit.
  `to_physical`(x) | Transformation from value in function to value in physical units.
  `to_string`([format]) | Output the unit in the given format as a string.

  Attributes Documentation

  cgs

    Copy the current function unit with the physical unit in CGS.

  equivalencies

    List of equivalencies between function and physical units.

    Uses the `from_physical` and `to_physical` methods.

  function_unit
  physical_type

    Return the physical type of the physical unit (e.g., ‘length’).

  physical_unit
  si

    Copy the current function unit with the physical unit in SI.

  Methods Documentation

  decompose(bases={})

    Copy the current unit with the physical unit decomposed.

    For details, see `decompose`.

  abstract from_physical(x)

    Transformation from value in physical to value in function units.

    This method should be overridden by subclasses. It is used to provide automatic transformations using an equivalency.

  is_equivalent(other, equivalencies=[])

    Returns `True` if this unit is equivalent to `other`.

    Parameters:
      other `Unit`, `python:str`, or `python:tuple`

        The unit to convert to. If a tuple of units is specified, this method returns true if the unit matches any of those in the tuple.

      equivalencies `python:list` of `python:tuple`

        A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. This list is in addition to the built-in equivalencies between the function unit and the physical one, as well as possible global defaults set by, e.g., `set_enabled_equivalencies`. Use `None` to turn off any global equivalencies.

    Returns:
      bool
  is_unity()
  to(other, value=1.0, equivalencies=[])

    Return the converted values in the specified unit.

    Parameters:
      other `Unit`, `FunctionUnitBase`, or `python:str`

        The unit to convert to.

      value `python:int`, `python:float`, or scalar numpy:array_like, optional

        Value(s) in the current unit to be converted to the specified unit. If not provided, defaults to 1.0.

      equivalencies `python:list` of `python:tuple`

        A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. This list is in meant to treat only equivalencies between different physical units; the built-in equivalency between the function unit and the physical one is automatically taken into account.

    Returns:
      values scalar or `array`

        Converted value(s). Input value sequences are returned as numpy arrays.

    Raises:
      `UnitsError`

        If units are inconsistent.

  abstract to_physical(x)

    Transformation from value in function to value in physical units.

    This method should be overridden by subclasses. It is used to provide automatic transformations using an equivalency.

  to_string(format='generic')

    Output the unit in the given format as a string.

    The physical unit is appended, within parentheses, to the function unit, as in “dB(mW)”, with both units set using the given format

    Parameters:
      format `astropy.units.format.Base` instance or `python:str`

        The name of a format or a formatter object. If not provided, defaults to the generic format.