finish a first pitch of docstrings
Some checks failed
Mypy / mypy (push) Failing after 2s
Pytest / pytest (3.12) (push) Failing after 2s
Pytest / pytest (3.13) (push) Failing after 2s
Pytest / pytest (3.14) (push) Failing after 2s
Ruff / ruff (push) Failing after 2s
Mypy / mypy (pull_request) Failing after 2s
Pytest / pytest (3.12) (pull_request) Failing after 2s
Pytest / pytest (3.13) (pull_request) Failing after 1s
Pytest / pytest (3.14) (pull_request) Failing after 2s
Ruff / ruff (pull_request) Failing after 2s

This commit is contained in:
Justus Kuhlmann 2026-02-12 18:39:04 +01:00
commit 4631769e81
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
7 changed files with 502 additions and 88 deletions

View file

@ -27,6 +27,10 @@ def write_measurement(path: str, ensemble: str, measurement: dict[str, dict[str,
Measurements to be captured in the backlogging system.
uuid: str
The uuid of the project.
code: str
Name of the code that was used for the project.
parameter_file: str
The parameter file used for the measurement.
"""
db_file = get_db_file(path)
db = os.path.join(path, db_file)
@ -97,6 +101,7 @@ def write_measurement(path: str, ensemble: str, measurement: dict[str, dict[str,
files.append(os.path.join(path, db_file))
conn.close()
save(path, message="Add measurements to database", files=files)
return
def load_record(path: str, meas_path: str) -> Union[Corr, Obs]:
@ -128,10 +133,13 @@ def load_records(path: str, meas_paths: list[str], preloaded: dict[str, Any] = {
Path of the correlator library.
meas_paths: list[str]
A list of the paths to the correlator in the backlog system.
perloaded: dict[str, Any]
The data that is already prelaoded. Of interest if data has alread been loaded in the same script.
Returns
-------
List
retruned_data: list
The loaded records.
"""
needed_data: dict[str, list[str]] = {}
for mpath in meas_paths:
@ -157,6 +165,20 @@ def load_records(path: str, meas_paths: list[str], preloaded: dict[str, Any] = {
def cache_dir(path: str, file: str) -> str:
"""
Returns the directory corresponding to the cache for the given file.
Parameters
----------
path: str
The path of the library.
file: str
The file in the library that we want to access the cached data of.
Returns
-------
cache_path: str
The path holding the cached data for the given file.
"""
cache_path_list = [path]
cache_path_list.append(".cache")
cache_path_list.extend(file.split("/")[1:])
@ -165,11 +187,41 @@ def cache_dir(path: str, file: str) -> str:
def cache_path(path: str, file: str, key: str) -> str:
"""
Parameters
----------
path: str
The path of the library.
file: str
The file in the library that we want to access the cached data of.
key: str
The key within the archive file.
Returns
-------
cache_path: str
The path at which the measurement of the given file and key is cached.
"""
cache_path = os.path.join(cache_dir(path, file), key)
return cache_path
def preload(path: str, file: str) -> dict[str, Any]:
"""
Read the contents of a file into a json dictionary with the pyerrors.json.load_json_dict method.
Parameters
----------
path: str
The path of the library.
file: str
The file within the library to be laoded.
Returns
-------
filedict: dict[str, Any]
The data read from the file.
"""
get(path, file)
filedict: dict[str, Any] = pj.load_json_dict(os.path.join(path, file))
print("> read file")
@ -177,6 +229,16 @@ def preload(path: str, file: str) -> dict[str, Any]:
def drop_record(path: str, meas_path: str) -> None:
"""
Drop a record by it's path.
Parameters
----------
path: str
The path of the library.
meas_path: str
The measurement path as noted in the database.
"""
file_in_archive = meas_path.split("::")[0]
file = os.path.join(path, file_in_archive)
db_file = get_db_file(path)
@ -204,6 +266,14 @@ def drop_record(path: str, meas_path: str) -> None:
def drop_cache(path: str) -> None:
"""
Drop the cache directory of the library.
Parameters
----------
path: str
The path of the library.
"""
cache_dir = os.path.join(path, ".cache")
for f in os.listdir(cache_dir):
shutil.rmtree(os.path.join(cache_dir, f))