Coverage for python / lsst / summit / utils / auxtel / mount.py: 0%
19 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:44 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-17 09:44 +0000
1# This file is part of summit_utils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import logging
24import numpy as np
25from lsst_efd_client.efd_helper import EfdClient
27import lsst.daf.butler as dafButler
29from ..efdUtils import getEfdData
32def hasTimebaseErrors(expRecord: dafButler.DimensionRecord, client: EfdClient, maxDiff: float = 1.05) -> bool:
33 """Check if an exposure has cRIO timebase errors.
35 Data in the lsst.sal.ATMCS.mount_AzEl_Encoders topic is a packed
36 time-series, and if the amount of data that is packed in isn't packed for a
37 period of almost exactly one second then the unpacking code will
38 incorrectly assign the intra-second timestamps, causing misalignment, as
39 this breaks the fundamental assumption required to have a packed
40 timeseries.
42 Parameters
43 ----------
44 expRecord : `lsst.daf.butler.dimensions.DimensionRecord`
45 The exposure record to query.
46 client : `lsst_efd_client.efd_helper.EfdClient`
47 The EFD client to use.
48 maxDiff : `float`, optional
49 The maximum difference in cRIO timestamps to consider as a timebase
50 error, in seconds. The correct spacing is 1s, so 1.05 denotes a 50ms
51 difference when the jitter should be on the order of microseconds.
53 Returns
54 -------
55 containsErrors : `bool`
56 `True` if the exposure has timebase errors, `False` otherwise.
57 """
58 log = logging.getLogger(__name__)
59 mountPosition = getEfdData(
60 client,
61 "lsst.sal.ATMCS.mount_AzEl_Encoders",
62 expRecord=expRecord,
63 warn=False,
64 raiseIfTopicNotInSchema=False,
65 )
67 if mountPosition.empty:
68 log.warning(
69 f"No mount data was found for {expRecord.obs_id}, so there is technically no"
70 " timebase error present"
71 )
72 return False
74 cRIOtimestamps = mountPosition["cRIO_timestamp"]
75 if len(cRIOtimestamps) == 1:
76 log.warning(
77 f"cRIO_timestamp data had length 1 for {expRecord.obs_id}, so timebase errors are" " impossible"
78 )
79 return False
81 diff = np.diff(cRIOtimestamps.to_numpy())
82 if np.min(diff) < 0:
83 raise ValueError("cRIO timestamps are not monotonically increasing - time is running backwards!")
85 return np.max(diff) > maxDiff