atomica.utils.format_duration(t, pluralize=False)[source]

User-friendly string format of a duration

This helper function is used when displaying durations in plots. It takes in a duration in units of years, and returns a string representation in user-friendly units. This function is mainly intended to be used to format denominators e.g., going from ‘probability’ and ‘1/365’ to ‘probability/day’

  • t (float) – A duration in units of years

  • pluralize – Always return a plural suffix

Return type:



A string

Example usage:

>>> format_duration(1)
>>> format_duration(1, pluralize=True)
>>> format_duration(1/365)
>>> format_duration(2/365)
'2 days'
>>> format_duration(1.5/52)
'1.5 weeks'
>>> format_duration(2/52)
>>> format_duration(2.5/12)
'2.5 months'