Package: tintervals
tintervalsA python package collecting  functions and tools to work with time intervals and to convert time data.The package also provides utilities for handling optical link data developed for theEMPIR project ROCITand for theEuropean Partnership on Metrology Project TOCK..Development is available athttps://github.com/INRIM/tintervalshttps://gitlab.ininrim.it/m.pizzocaro/tintervals(INRIM only)Documentation is available athttps://tintervals.readthedocs.ioPackage is available athttps://pypi.org/project/tintervals/InstallationThe package can be installed using pip:pip install tintervalsor directly from github:pip install git+https://github.com/INRIM/tintervals.gitRequirementsnumpy,scipyciso8601(for fast ISO format reading)pandas(used only for fast file loading)pyyamlBasic usageimport tintervals as tiFunctions to convert timetag formats.
Fast functions used as converters when importing files:FunctionFromTokk2epochK+K counter formatEpochiso2epochISO format*Epochkk2isoK+K counter formatISO format (naive)iso2datetimeISO format*datetimedatetime2isodatetimeISO format ('Z' notation for UTC)datetime2epochdatetime*Epochepoch2datetimeEpochDatetimeepoch2isoEpochISO format ('Z' notation for UTC)mjd2isoMJDISO format ('Z' notation for UTC)epoch2mjdEpochMJDmjd2epochMJDEpochStarred  inputs (*), if naive are considered as system/local time.
K+K format is always naive and interpreted as sytem/local time.
ISO format can be read with microseconds but it is printed without.
Conversion from Epoch time (Unix) and MJD is done by simple affine function,
as both are aligned with UTC and basically ignore leap seconds.Vectorized functions:FunctionFromTomjd_from_epochEpochMJDepoch_from_mjdMJDEpochiso_from_epochEpochISO format ('Z' notation for UTC)iso_from_mjdMJDISO format ('Z' notation for UTC)Functions to manipulate array of timetags or array of start/stop intervals:FunctionDescriptionarray2intervalsconvert from an array of timetags to an array of start/stop intervalsintervals2weightsconvert from start/stop intervals to timetags and weightsintersecttake the intersection of two arrays of start/stop intervalssplitSubdivide an array of start/stop intervals to a fixed scale (e.g., every 10 s)regvalsretrun regular intervals between a start and stopraverageAverage data with timetags in regular intervals (reshape algorithm)maverageAverage data with timetags in given intervals (mask algorithm)csaverageAverage data  start/stop intervals in different start/stop intervals (cumsum algorithm)Functions to calculate deadtime uncertainty:FunctionDescriptiondeadtime.unc_fftcalculate deadtime uncertainty from given maser noise (FFT algorithm)Advanced usageFor handling optical links:import ti.rocitlinks as rlSee the docs for more details.LicenseMITAcknowledgmentsThis work is partially funded by the European Metrology Program for Innovation and Research (EMPIR) project 18SIB05 ROCIT.
The EMPIR initiative is cofunded by the European Union’s Horizon 2020 research and innovation programme and the EMPIR Participating States.This work has received funding from the European Partnership on Metrology, co-financed by the European Union’s Horizon Europe Research and Innovation Programme and by the Participating States, under grant number 22IEM01 TOCK.Authors(c) 2021-2024 Marco Pizzocaro - Istituto Nazionale di Ricerca Metrologica (INRIM)Speed testti.kk2iso('210922*161141.810')
166 ns ± 2.09 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
ti.kk2epoch('210922*161141.810')
658 ns ± 1.24 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
ti.iso2datetime('20210922T161141.810Z')
222 ns ± 18 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
ti.iso2epoch('20210922T161141.810Z')
473 ns ± 5.11 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
ti.datetime2iso(datetime(2021,9,22,11,12,tzinfo=timezone.utc))
2.51 µs ± 9.92 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
ti.datetime2epoch(datetime(2021,9,22,11,12,tzinfo=timezone.utc))
613 ns ± 3.99 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
ti.epoch2datetime(1632319901)
406 ns ± 2.87 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
ti.mjd_from_epoch(1632319901)
131 ns ± 0.334 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
ti.epoch_from_mjd(59479.356)
99.4 ns ± 0.228 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
ti.iso_from_epoch(1632319901)
19.8 µs ± 86.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
ti.iso_from_mjd(59479.356)
23 µs ± 266 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)