Skip to content

Commit 1d53e95

Browse files
authored
Allows you to set hkdb object to use in LoadSpec (#1089)
1 parent fa4c431 commit 1d53e95

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sotodlib/io/hkdb.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,17 @@ class LoadSpec:
356356
End time to load
357357
downsample_factor: int
358358
Downsample factor for data
359+
hkdb: Optional[HkDb]
360+
HkDb instance to use. If not specified, will create a new one from the
361+
cfg. This should be set manually if you are calling ``load_hk`` in a loop
362+
to prevent connection build-up.
359363
"""
360364
cfg: HkConfig
361365
fields: List[str]
362366
start: float
363367
end: float
364368
downsample_factor: int = 1
369+
hkdb: Optional[HkDb] = None
365370

366371
def __post_init__(self):
367372
fs = []
@@ -418,7 +423,11 @@ def load_hk(load_spec: Union[LoadSpec, dict], show_pb=False):
418423
if isinstance(load_spec, dict):
419424
load_spec = LoadSpec(**load_spec)
420425

421-
hkdb = HkDb(load_spec.cfg)
426+
if load_spec.hkdb is not None:
427+
hkdb: HkDb = load_spec.hkdb
428+
else:
429+
hkdb = HkDb(load_spec.cfg)
430+
422431
agent_set = list(set(f.agent for f in load_spec.fields))
423432

424433
file_spec = {} # {path: [offsets]}

0 commit comments

Comments
 (0)