add automatic saving of plots for t0 and t1
Some checks failed
Mypy / mypy (push) Failing after 46s
Pytest / pytest (3.12) (push) Failing after 45s
Pytest / pytest (3.13) (push) Failing after 42s
Ruff / ruff (push) Has been cancelled
Mypy / mypy (pull_request) Has been cancelled
Pytest / pytest (3.12) (pull_request) Has been cancelled
Pytest / pytest (3.13) (pull_request) Has been cancelled
Pytest / pytest (3.14) (pull_request) Has been cancelled
Ruff / ruff (pull_request) Has been cancelled
Pytest / pytest (3.14) (push) Has been cancelled

This commit is contained in:
Justus Kuhlmann 2026-05-26 11:16:18 +02:00
commit c6ad3f9003
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
6 changed files with 49 additions and 6 deletions

View file

@ -71,6 +71,7 @@ def _create_config(path: Path, tracker: str, cached: bool) -> ConfigParser:
'db': 'backlogger.db',
'projects_path': 'projects',
'archive_path': 'archive',
'plot_path': 'plots',
'toml_imports_path': 'toml_imports',
'import_scripts_path': 'import_scripts',
}
@ -113,6 +114,7 @@ def create(path: Path, tracker: str = 'datalad', cached: bool = True) -> None:
os.chmod(path / config['paths']['db'], 0o666)
os.makedirs(path / config['paths']['projects_path'])
os.makedirs(path / config['paths']['archive_path'])
os.makedirs(path / config['paths']['plot_path'])
os.makedirs(path / config['paths']['toml_imports_path'])
os.makedirs(path / config['paths']['import_scripts_path'] / 'template.py')
with open(path / ".gitignore", "w") as fp:

View file

@ -4,8 +4,10 @@ import os
import fnmatch
from typing import Any, Optional
from pathlib import Path
import matplotlib.pyplot as plt
from ..pars.openQCD import ms1
from ..pars.openQCD import qcd2
from ..tools import get_plot_dir
@ -164,7 +166,7 @@ def read_rwms(path: Path, project: str, dir_in_project: str, param: dict[str, An
return rw_dict
def extract_t0(path: Path, project: str, dir_in_project: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str="", names: Optional[list[str]]=None, files: Optional[list[str]]=None,
def extract_t0(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str="", names: Optional[list[str]]=None, files: Optional[list[str]]=None,
r_start: list[int]=[], r_stop: list[int]=[], r_step:int=1) -> dict[str, Any]:
"""
Extract t0 measurements from the project.
@ -224,7 +226,7 @@ def extract_t0(path: Path, project: str, dir_in_project: str, param: dict[str, A
if not r_stop == []:
kwargs['r_stop'] = r_stop
kwargs['r_step'] = r_step
kwargs['plot_fit'] = True
t0 = input.extract_t0(directory,
prefix,
dtr_read,
@ -234,6 +236,10 @@ def extract_t0(path: Path, project: str, dir_in_project: str, param: dict[str, A
c=0.3,
**kwargs
)
plot_dir = path / get_plot_dir(path) / ensemble / project
if not os.path.exists(plot_dir):
os.makedirs(plot_dir)
plt.savefig(plot_dir / "t0.pdf")
par_list= []
for k in ["integrator", "eps", "ntot", "dnms"]:
par_list.append(str(param[k]))
@ -244,7 +250,7 @@ def extract_t0(path: Path, project: str, dir_in_project: str, param: dict[str, A
return t0_dict
def extract_t1(path: Path, project: str, dir_in_project: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str = "", names: Optional[list[str]]=None, files: Optional[list[str]]=None,
def extract_t1(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str = "", names: Optional[list[str]]=None, files: Optional[list[str]]=None,
r_start: list[int]=[], r_stop: list[int]=[], r_step:int=1) -> dict[str, Any]:
"""
Extract t1 measurements from the project.
@ -302,6 +308,7 @@ def extract_t1(path: Path, project: str, dir_in_project: str, param: dict[str, A
if not r_stop == []:
kwargs['r_stop'] = r_stop
kwargs['r_step'] = r_step
kwargs['plot_fit'] = True
t0 = input.extract_t0(directory,
prefix,
dtr_read,
@ -311,6 +318,10 @@ def extract_t1(path: Path, project: str, dir_in_project: str, param: dict[str, A
c=2./3,
**kwargs
)
plot_dir = path / get_plot_dir(path) / ensemble / project
if not os.path.exists(plot_dir):
os.makedirs(plot_dir)
plt.savefig(plot_dir / "t1.pdf")
par_list= []
for k in ["integrator", "eps", "ntot", "dnms"]:
par_list.append(str(param[k]))

View file

@ -6,7 +6,7 @@ import json
from typing import Union
from pyerrors import Obs, Corr, dump_object, load_object
from hashlib import sha256
from .tools import get_db_file, cache_enabled
from .tools import get_db_file, cache_enabled, get_plot_dir
from .tracker import get, save, unlock
import shutil
from typing import Any
@ -104,6 +104,8 @@ def write_measurement(path: Path, ensemble: str, measurement: dict[str, dict[str
subkeys.append(subkey)
pars[subkey] = json.dumps(parameters["rw_fcts"][i])
elif ms_type in ['t0', 't1']:
plot_file = path / get_plot_dir(path) / ensemble / uuid / (ms_type + ".pdf")
files_to_save.append(plot_file)
if parameter_file is not None:
parameters = openQCD.load_ms3_infile(path, uuid, parameter_file)
else:

View file

@ -229,14 +229,14 @@ def import_toml(path: Path, file: str, copy_file: bool=True) -> None:
for rwp in ["integrator", "eps", "ntot", "dnms"]:
param[rwp] = "Unknown"
param['type'] = 't0'
measurement = openQCD.extract_t0(path, uuid, md['path'], param, str(md["prefix"]), int(md["dtr_read"]), int(md["xmin"]), int(md["spatial_extent"]),
measurement = openQCD.extract_t0(path, uuid, md['path'], ensemble, param, str(md["prefix"]), int(md["dtr_read"]), int(md["xmin"]), int(md["spatial_extent"]),
fit_range=int(md.get('fit_range', 5)), postfix=str(md.get('postfix', '')), names=md.get('names', []), files=md.get('files', []),
r_start=md.get('r_start', []), r_stop=md.get('r_stop', []), r_step=md.get('r_step', 1))
elif md['measurement'] == 't1':
if 'param_file' in md:
param = openQCD.load_ms3_infile(path, uuid, md['param_file'])
param['type'] = 't1'
measurement = openQCD.extract_t1(path, uuid, md['path'], param, str(md["prefix"]), int(md["dtr_read"]), int(md["xmin"]), int(md["spatial_extent"]),
measurement = openQCD.extract_t1(path, uuid, md['path'], ensemble, param, str(md["prefix"]), int(md["dtr_read"]), int(md["xmin"]), int(md["spatial_extent"]),
fit_range=int(md.get('fit_range', 5)), postfix=str(md.get('postfix', '')), names=md.get('names', []), files=md.get('files', []),
r_start=md.get('r_start', []), r_stop=md.get('r_stop', []), r_step=md.get('r_step', 1))
write_measurement(path, ensemble, measurement, uuid, project['code'], (md['param_file'] if 'param_file' in md else None))

View file

@ -129,6 +129,33 @@ def get_db_file(path: Path) -> Path:
return db_file
def get_plot_dir(path: Path) -> Path:
"""
Get the plots directory associated with the library at the given path.
Parameters
----------
path: str
The path of the library.
Returns
-------
db_file: str
The file holding the database.
"""
path = Path(path)
if not os.path.exists(path):
raise FileNotFoundError(f"Corrlib path {path} does not exist.")
config_path = path / CONFIG_FILENAME
config = ConfigParser()
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError("Configuration file not found.")
plot_dir = Path(config.get('paths', 'plot_dir', fallback='plots'))
return plot_dir
def cache_enabled(path: Path) -> bool:
"""
Check, whether the library is cached.

View file

@ -11,6 +11,7 @@ dependencies = [
'pyerrors>=2.11.1',
"datalad>=1.1.0",
'typer>=0.12.5',
"matplotlib>=3.10.7",
]
description = "Python correlation library"
authors = [