Skip to main content
`Ctrl`+`K`

# `silx.gui.plot.stats.stats`

This module provides mechanism relative to stats calculation within a `PlotWidget`. It also include the implementation of the statistics themselves.

class Stats(statslist=None)

  Class to define a set of statistic relative to a dataset (image, curve…).

  The goal of this class is to avoid multiple recalculation of some basic operations such as filtering data area where the statistics has to be apply. Min and max are also stored because they can be used several time.

  Parameters:

    statslist (List) – List of the `Stat` object to be computed.

  calculate(item, plot, onlimits, roi, data_changed=False, roi_changed=False)

    Call all `Stat` object registered and return the result of the computation.

    Parameters:

      - item – the item for which we want statistics

      - plot – plot containing the item

      - onlimits (bool) – True if we want to apply statistic only on visible data.

      - roi (Union[None, `_RegionOfInterestBase`]) – region of interest for statistic calculation. Incompatible with the onlimits option.

      - data_changed (bool) – did the data changed since last calculation.

      - roi_changed (bool) – did the associated roi (if any) has changed since last calculation.

    Return dict:

      dictionary with `Stat` name as ket and result of the calculation as value

  add(stat)

    Add a `Stat` to the set

    Parameters:

      stat (Stat) – stat to add to the set

class StatBase(name, compatibleKinds=('curve', 'image', 'scatter', 'histogram'), description=None)

  Base class for defining a statistic.

  Parameters:

    - name (str) – the name of the statistic. Must be unique.

    - compatibleKinds (List[str]) – The kind of items (curve, scatter…) for which the statistic apply.

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

  getToolTip(kind)

    If necessary add a tooltip for a stat kind

    Parameters:

      kind (str) – the kind of item the statistic is compute for.

    Returns:

      tooltip or None if no tooltip

class Stat(name, fct, kinds=('curve', 'image', 'scatter', 'histogram'))

  Create a StatBase class based on a function pointer.

  Parameters:

    - name (str) – name of the statistic. Used as id

    - fct – function which should have as unique mandatory parameter the data. Should be able to adapt to all kinds defined as compatible

    - kinds (tuple) – the compatible item kinds of the function (curve, image…)

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

class StatMin

  Compute the minimal value on data

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

class StatMax

  Compute the maximal value on data

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

class StatDelta

  Compute the delta between minimal and maximal on data

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

class StatCoordMin

  Compute the coordinates of the first minimum value of the data

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

  getToolTip(kind)

    If necessary add a tooltip for a stat kind

    Parameters:

      kind (str) – the kind of item the statistic is compute for.

    Returns:

      tooltip or None if no tooltip

class StatCoordMax

  Compute the coordinates of the first maximum value of the data

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

  getToolTip(kind)

    If necessary add a tooltip for a stat kind

    Parameters:

      kind (str) – the kind of item the statistic is compute for.

    Returns:

      tooltip or None if no tooltip

class StatCOM

  Compute data center of mass

  calculate(context)

    compute the statistic for the given `StatsContext`

    Parameters:

      context (_StatsContext)

    Return dict:

      key is stat name, statistic computed is the dict value

  getToolTip(kind)

    If necessary add a tooltip for a stat kind

    Parameters:

      kind (str) – the kind of item the statistic is compute for.

    Returns:

      tooltip or None if no tooltip