Policy Studio¶
from medaugmentx.studio import StudioServer, StudioSession, launch
The studio is a local web application for designing, previewing, and stress-testing policies. See the user guide for the workflow; this page documents the Python entry points for notebooks, scripts, and embedding.
Launching¶
- medaugmentx.studio.launch(policy=None, volume=None, *, host='127.0.0.1', port=0, open_browser=True, block=True, token=None, allow_remote=False, verbose=False, source=None)[source]¶
Open the policy studio, optionally starting from a policy and volume.
With
block=False(handy in notebooks) the server runs in the background; callserver.current_policy()to retrieve the edited policy andserver.stop()when done. Withblock=Trueit serves until Ctrl+C.- Parameters:
policy (Transform | Mapping[str, Any] | None) – Transform or
to_dict()mapping to start editing.volume (MedVolume | None) – In-memory volume to preview; load data from the UI otherwise.
host (str) – Interface to bind (loopback by default).
port (int) – TCP port, or 0 for any free port.
open_browser (bool) – Open the studio in the default web browser.
block (bool) – Serve in the foreground until interrupted.
token (str | None) – Fixed API token instead of a random one.
allow_remote (bool) – Permit a non-loopback
host.verbose (bool) – Log requests to stderr.
source (str | None) – Label shown for
volume(for example its filename).
- Return type:
- class medaugmentx.studio.StudioServer(session=None, *, host='127.0.0.1', port=0, token=None, allow_remote=False, verbose=False)[source]¶
Bases:
objectA running policy studio. Use
launch()for the common case.- Parameters:
session (StudioSession | None) – State to serve; a fresh
StudioSessionby default.host (str) – Interface to bind. Non-loopback hosts expose your images to the network and are only accepted with
allow_remote=True.port (int) – TCP port, or 0 to choose a free one.
token (str | None) – API token; a random one is generated by default.
allow_remote (bool) – Permit binding a non-loopback interface.
verbose (bool) – Log every request to stderr.
- property url: str¶
Address to open, including the session token.
Session state¶
StudioSession holds the loaded volume and the edited policy, independently
of the HTTP layer. Policies travel in the canonical to_dict() form.
- class medaugmentx.studio.StudioSession(volume=None, policy=None, *, source=None)[source]¶
Bases:
objectState for one studio: a loaded volume, its source, and the edited policy.
- Parameters:
- load_path(image, mask=None, *, resample_mask=False, strict=True)[source]¶
Load NIfTI (
.nii/.nii.gz), NumPy (.npy) or DICOM data.- Return type:
dict[str, Any]
- add_channel(name, path)[source]¶
Attach a registered image as a named channel of the loaded volume.
- Return type:
dict[str, Any]
- state()[source]¶
Loaded-data summary, axis names, channels and the current policy.
- Return type:
dict[str, Any]
- set_policy(node)[source]¶
Store the edited policy and report whether it builds.
- Return type:
dict[str, Any]
- current_policy()[source]¶
The edited policy as a fresh transform (raises if it does not build).
- Return type:
- new_step(name)[source]¶
Canonical node for a newly added step, with volume-aware defaults.
- Return type:
dict[str, Any]
- preview(request)[source]¶
Run one seeded draw and render matching input/output slices.
- Return type:
dict[str, Any]
- gallery(request)[source]¶
Render consecutive augmentation indices for a quick variability scan.
- Return type:
dict[str, Any]
- stress(request)[source]¶
Run many draws and aggregate validation, failures, timing and branches.
- Return type:
dict[str, Any]