Merge branch 'master' of kuhl-mann.de:jkuhl/corrlib

This commit is contained in:
Justus Kuhlmann 2025-04-08 13:32:34 +00:00
commit 005840d212
2 changed files with 15 additions and 7 deletions

View file

@ -100,7 +100,7 @@ def load_record(path: str, meas_path: str):
return load_records(path, [meas_path])[0]
def load_records(path: str, meas_paths: list[str]) -> list[Union[Corr, Obs]]:
def load_records(path: str, meas_paths: list[str], preloaded = {}) -> list[Union[Corr, Obs]]:
"""
Load a list of records by their paths.
@ -122,15 +122,22 @@ def load_records(path: str, meas_paths: list[str]) -> list[Union[Corr, Obs]]:
needed_data[file] = []
key = mpath.split("::")[1]
needed_data[file].append(key)
dl.get([os.path.join(path, file) for file in needed_data.keys()], dataset=path)
for filename in needed_data.keys():
if not filename in preloaded:
preloaded[filename] = preload(path, filename)
returned_data: list = []
for filename in needed_data.keys():
filedict = pj.load_json_dict(os.path.join(path, filename))
for key in list(needed_data[filename]):
returned_data.append(filedict[key])
returned_data.append(preloaded[filename][key])
return returned_data
def preload(path: str, file: str):
dl.get(os.path.join(path, file), dataset=path)
filedict = pj.load_json_dict(os.path.join(path, file))
return filedict
def drop_record(path: str, meas_path: str):
file = meas_path.split("::")[0]
sub_key = meas_path.split("::")[1]