Py ERFA:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- PyERFA v2.0.1.1 »
- erfa Package »
- leap_seconds

# leap_seconds

class erfa.leap_seconds

  Bases: `object`

  Leap second management.

  This singleton class allows access to ERFA’s leap second table, using the methods ‘get’, ‘set’, and ‘update’.

  One can also check expiration with ‘expires’ and ‘expired’.

  Note that usage of the class is similar to a `ScienceState` class, but it cannot be used as a context manager.

  Attributes Summary

  `expired` | Whether the leap second table is valid beyond the present.
  `expires` | The expiration date of the current ERFA table.

  Methods Summary

  `get`() | Get the current leap-second table used internally.
  `set`([table]) | Set the ERFA leap second table.
  `update`(table) | Add any leap seconds not already present to the ERFA table.
  `validate`(table) | Validate a leap-second table.

  Attributes Documentation

  expired

    Whether the leap second table is valid beyond the present.

  expires

    The expiration date of the current ERFA table.

    This is either a date inferred from the last table used to update or set the leap-second array, or a number of days beyond the last leap second.

  Methods Documentation

  classmethod get()

    Get the current leap-second table used internally.

  classmethod set(table=None)

    Set the ERFA leap second table.

    Note that it is generally safer to update the leap-second table than to set it directly, since most tables do not have the pre-1970 changes in TAI-UTC that are part of the built-in ERFA table.

    Parameters:
      table array_like or `None`

        Leap-second table that should at least hold columns of ‘year’, ‘month’, and ‘tai_utc’. Only simple validation is done before it is being used, so care need to be taken that entries are correct. If `None`, reset the ERFA table to its built-in values.

    Raises:
      ValueError

        If the leap seconds in the table are not on the 1st of January or July, or if the sorted TAI-UTC do not increase in increments of 1.

  classmethod update(table)

    Add any leap seconds not already present to the ERFA table.

    This method matches leap seconds with those present in the ERFA table, and extends the latter as necessary.

    If the ERFA leap seconds file was corrupted, it will be reset.

    If the table is corrupted, the ERFA file will be unchanged.

    Parameters:
      table array_like or `LeapSeconds`

        Array or table with TAI-UTC from leap seconds. Should have ‘year’, ‘month’, and ‘tai_utc’ columns.

    Returns:
      n_update int

        Number of items updated.

    Raises:
      ValueError

        If the leap seconds in the table are not on the 1st of January or July, or if the sorted TAI-UTC do not increase in increments of 1.

  classmethod validate(table)

    Validate a leap-second table.

    Parameters:
      table array_like

        Must have ‘year’, ‘month’, and ‘tai_utc’ entries. If a ‘day’ entry is present, it will be checked that it is always 1. If `table` has an ‘expires’ attribute, it will be interpreted as an expiration date.

    Returns:
      array `ndarray`

        Structures array with ‘year’, ‘month’, ‘tai_utc’.

      expires: `datetime` or None

        Possible expiration date inferred from the table. `None` if not present or if not a `datetime` or `Time` instance and not parsable as a ‘dd month yyyy’ string.

    Raises:
      ValueError

        If the leap seconds in the table are not on the 1st of January or July, or if the sorted TAI-UTC do not increase in increments of 1.