bins

mdtools.check.bins(start, stop, step=None, num=None, amin=0, amax=None, precision=9, verbose=True)[source]

Check if start point, end point and step width or number of bins are chosen properly for creating bin edges.

start, stop, step and num must meet the following requirements:

  • start must not be less than amin (if supplied).

  • stop must be greater than start, but not greater than amax (if supplied).

  • step must be greater than zero, but not greater than stop - start.

  • num must be an integer and greater than zero.

Parameters:
  • start (scalar) – Start of interval. The interval includes this value.

  • stop (scalar) – End of interval. The interval includes(!) this value.

  • step (scalar, optional) – Step width.

  • num (int, optional) – Number of steps between start and stop. Note that either step or num or both of them must be given.

  • amin (scalar, optional) – A minimum value that start must not undermine.

  • amax (scalar, optional) – A maximum value that stop must not exceed. If given, amax must be greater than amin.

  • precision (int, optional) – Precision to use for floating point arithmetics. Default is 9 decimal places.

  • verbose (bool, optional) – If True (default), any changes of the input parameters are printed to standard output.

Returns:

  • start (float) – The input or a corrected start point.

  • stop (float) – The input or a corrected end point.

  • step (float) – The input or a corrected step width.

  • num (int) – The input or a corrected number of bins. Note: If both, step and num, are given, step is tried to be kept fixed while num is changed according to stop - start == num * step.

Raises:

ValueError – If a corrected value cannot be inferred from the given input.

See also

mdtools.check.distance_bins()

Check if the input is appropriate for binning distances that obey the minimum image convention

mdtools.check.bin_edges()

Check if bin edges are chosen properly for binning a given interval

Notes

To check whether the binning also fulfills the minimum image convention, use mdtools.check.distance_bins().

If you want to ensure that all bins are equidistant, do not parse step but only num. If you parse step, this function tries to keep the input step fixed, even if this requires that the last bin is smaller than all other bins.