22 __all__ = (
'PhotodiodeData',
'getBOTphotodiodeData')
32 """Get the photodiode data associated with a BOT dataRef.
34 This is a temporary Gen2-only interface to the photodiode readings from
35 the SLAC Run3 datasets onwards.
39 dataRef : `lsst.daf.persistence.ButlerDataRef`
40 dataRef of the of the detector/visit to load the data for.
42 dataPath : `str`, optional
43 Path at which to find the corresponding photodiode data files.
45 logger : `lsst.log.Log`, optional
46 Logger for logging warnings.
51 photodiodeData : `lsst.cp.pipe.photodiode.PhotodiodeData` or `None`
52 The full time-series of the photodiode readings, with methods to
53 integrate the photocharge, or None if the expected file isn't found.
57 logger = lsstLog.Log.getDefaultLogger()
59 def getKeyFromDataId(dataRef, key):
60 if key
in dataRef.dataId:
61 return dataRef.dataId[key]
63 result = dataRef.getButler().queryMetadata(
'raw', key, dataRef.dataId)
64 assert len(result) == 1, f
"Failed to find unique value for {key} with {dataRef.dataId}"
67 dayObs = getKeyFromDataId(dataRef,
'dayObs')
68 seqNum = getKeyFromDataId(dataRef,
'seqNum')
70 filePattern =
'Photodiode_Readings_%s_%06d.txt'
72 dayObsAsNumber = dayObs.replace(
'-',
'')
73 diodeFilename = os.path.join(dataPath, filePattern % (dayObsAsNumber, seqNum))
75 if not os.path.exists(diodeFilename):
76 logger.warn(f
"Failed to find the photodiode data at {diodeFilename}")
83 logger.warn(f
"Photodiode data found at {diodeFilename} but failed to load.")
89 self.times, self.
values = np.loadtxt(filename, unpack=
True)
94 raise NotImplementedError
97 for i, (time, current)
in enumerate(zip(self.times[:-1], self.
values[:-1])):
98 timestep = self.times[i+1] - time
99 averageCurrent = (self.
values[i+1] + current) / 2.
100 charge += averageCurrent * timestep