srim.notebook

Run folders for notebooks: read a run or scan folder back, finished or not (Qt-free).

A notebook opens a folder with load_run(). A finished folder (result/scan.csv is there) is read as it was written. An unfinished one (a run that stopped or crashed) gives the points whose folders have outputs. LoadedRun.point() reads a point’s results, a plain Results or the merged results of a batched point.

LoadedRun.mark_loaded() records in the folder (.pysrim2-notebook/loaded.json) how many points the notebook read, so a later reader can tell whether the folder has changed since.

srim.notebook.LOADED_FILE = 'loaded.json'

the file in NOTEBOOK_DIR that LoadedRun.mark_loaded() writes

class srim.notebook.LoadedRun(folder: Path, result: ScanResult, finished: bool, count: int, outputs: dict[int, str]=<factory>)

A run or scan folder read for a notebook.

folder is the folder, result its ScanResult, finished whether the run finished, and count the number of the scan’s points with outputs. outputs maps the index of each of those points to its path relative to folder.

mark_loaded() → None

Write .pysrim2-notebook/loaded.json (the count and whether the run finished).

The file is written to a temporary file in the same folder and then moved into place, so a reader never sees a part-written file. It is readable by others (mode 0644).

point(index: int) → Results

The results of point index. Raises KeyError for a point without outputs.

points() → list[int]

The indexes of the points that have outputs, in order.

srim.notebook.NOTEBOOK_DIR = '.pysrim2-notebook'

the folder inside a run folder where notebooks keep their own files

srim.notebook.RELOAD_FILE = 'reload'

the name of the file that asks for a reload (only the name is defined here)

srim.notebook.has_outputs(point_dir: Path) → bool

A point’s folder holds its run.yaml (or units.csv, when it was batched).

srim.notebook.load_run(folder) → LoadedRun

Read a run or scan folder for a notebook, finished or not.

count is the number of the scan’s own points (from scan.yaml) whose folder points/<id[:16]> has outputs; results_count() gives the same number for an unchanged folder. Raises FileNotFoundError naming the folder when it has no scan.yaml.

srim.notebook.loaded_count(folder) → int | None

The points of .pysrim2-notebook/loaded.json, or None when the file is absent or cannot be read as a count.

srim.notebook.open_point(folder: Path, rel_path: str)

The results of a point of a scan folder: merged when the point was batched (it has a units.csv), else the plain Results of its folder.

srim.notebook.read_run_folder(folder) → tuple[ScanResult, bool]

The scan result of a run folder, and whether the run finished.

A finished run (result/scan.csv is there) is read as it was written. Otherwise the table is built from the scan’s points: done for a point whose folder has outputs, else missing. Raises FileNotFoundError for a folder without scan.yaml.

srim.notebook.results_count(folder) → int

The number of the scan’s points whose folder has outputs (see load_run()).

Reads scan.yaml. 0 for a folder that is missing, or whose scan.yaml cannot be read; never raises OSError.