Skip to main content
`Ctrl`+`K`

# Parameter

class astropy.cosmology.Parameter(*, default=<MISSING>, derived=False, unit=None, equivalencies=<factory>, fvalidate='default', doc=None)

  Bases: `object`

  Cosmological parameter (descriptor).

  Should only be used with a `Cosmology` subclass.

  Parameters:
    default `Any` (optional, keyword-only)

      Default value of the Parameter. If not given the Parameter must be set when initializing the cosmology.

    derived bool (optional, keyword-only)

      Whether the Parameter is ‘derived’, default `False`. Derived parameters behave similarly to normal parameters, but are not sorted by the |Cosmology| signature (probably not there) and are not included in all methods. For reference, see `Ode0` in `FlatFLRWMixin`, which removes \(\Omega_{de,0}`\) as an independent parameter (\(\Omega_{de,0} \equiv 1 - \Omega_{tot}\)).

    unit astropy:unit-like or `python:None` (optional, keyword-only)

      The `Unit` for the Parameter. If None (default) no unit as assumed.

    equivalencies `Equivalency` or python:sequence thereof

      Unit equivalencies for this Parameter.

    fvalidate `python:callable()`[[`object`, `object`, `Any`], `Any`] or `python:str` (optional, keyword-only)

      Function to validate the Parameter value from instances of the cosmology class. If “default”, uses default validator to assign units (with equivalencies), if Parameter has units. For other valid string options, see `Parameter._registry_validators`. ‘fvalidate’ can also be set through a decorator with `validator()`.

    doc `python:str` or `python:None` (optional, keyword-only)

      Parameter description.

  Examples

  For worked examples see `FLRW`.

  Attributes Summary

  `default` | Default value of the Parameter.
  `derived` | Whether the Parameter can be set, or is derived, on the cosmology.
  `doc` | Parameter description.
  `fvalidate` | Function to validate/convert values when setting the Parameter.
  `name` | The name of the Parameter on the Cosmology.
  `unit` | The unit of the Parameter (can be `None` for unitless).

  Methods Summary

  `clone`(**kw) | Clone this `Parameter`, changing any constructor argument.
  `register_validator`(key[, fvalidate]) | Decorator to register a new kind of validator function.
  `validate`(cosmology, value) | Run the validator on this Parameter.
  `validator`(fvalidate) | Make new Parameter with custom `fvalidate`.

  Attributes Documentation

  default = 1

    Default value of the Parameter.

    By default set to `MISSING`, which indicates the parameter must be set when initializing the cosmology.

  derived = False

    Whether the Parameter can be set, or is derived, on the cosmology.

  doc = None

    Parameter description.

  fvalidate = 'default'

    Function to validate/convert values when setting the Parameter.

  name = None

    The name of the Parameter on the Cosmology.

    Cannot be set directly.

  unit = None

    The unit of the Parameter (can be `None` for unitless).

  Methods Documentation

  clone(**kw)

    Clone this `Parameter`, changing any constructor argument.

    Parameters:
      **kw

        Passed to constructor. The current values, eg. `fvalidate` are used as the default values, so an empty `**kw` is an exact copy.

    Examples

        >>> p = Parameter()
        >>> p
        Parameter(derived=False, unit=None, equivalencies=[],
                  fvalidate='default', doc=None)

        >>> p.clone(unit="km")
        Parameter(derived=False, unit=Unit("km"), equivalencies=[],
                  fvalidate='default', doc=None)

  static register_validator(key, fvalidate=None)

    Decorator to register a new kind of validator function.

    Parameters:
      key `python:str`
      fvalidate `python:callable()`[[`object`, `object`, `Any`], `Any`] or `python:None`, optional

        Value validation function.

    Returns:
      `validator` or `python:callable()`[`validator`]

        if validator is None returns a function that takes and registers a validator. This allows `register_validator` to be used as a decorator.

  validate(cosmology, value)

    Run the validator on this Parameter.

    Parameters:
      cosmology `Cosmology` instance
      value `Any`

        The object to validate.

    Returns:
      `Any`

        The output of calling `fvalidate(cosmology, self, value)` (yes, that parameter order).

  validator(fvalidate)

    Make new Parameter with custom `fvalidate`.

    Note: `Parameter.fvalidator` must be the top-most descriptor decorator.

    Parameters:
      fvalidate `python:callable()`[[type, type, `Any`], `Any`]
    Returns:
      `Parameter`

        Copy of this Parameter but with custom `fvalidate`.