deepdrrzmq package¶
Subpackages¶
- deepdrrzmq.devices package
- deepdrrzmq.utils package
Submodules¶
deepdrrzmq.basedir module¶
deepdrrzmq.deepdrrd module¶
- class deepdrrzmq.deepdrrd.DeepDRRServer(context, rep_port, pub_port, sub_port)¶
Bases:
object
DeepDRR server that handles requests from the client and sends responses.
The server is implemented as a single asyncio task that runs forever.
The server is responsible for: - handling requests from the client - sending responses to the client - managing the projector - managing the volumes
- __init__(context, rep_port, pub_port, sub_port)¶
Create a new DeepDRR server.
- Parameters:
context – The zmq context.
rep_port – The port to use for the request-reply socket.
pub_port – The port to use for the publish socket.
sub_port – The port to use for the subscribe socket.
- async handle_project_request(pub_socket, data)¶
Handle a project request from the client.
- Parameters:
pub_socket – The socket to send the response on.
data – The data of the request.
- async handle_projector_params_response(data)¶
Handle a projector params response from the client.
- Parameters:
data – The data of the response.
- async project_server()¶
Project server that handles requests from the client and sends responses.
- async start()¶
Start the server.
- deepdrrzmq.deepdrrd.capnp_optional(optional)¶
Convert a capnp optional to a python optional.
- Parameters:
optional – The capnp optional.
- Returns:
The python optional.
- deepdrrzmq.deepdrrd.capnp_square_matrix(optional)¶
Convert a capnp optional square matrix to a numpy array.
- Parameters:
optional – The capnp optional square matrix.
- Returns:
The numpy array.
- deepdrrzmq.deepdrrd.main(rep_port=40100, pub_port=40101, sub_port=40102)¶
- deepdrrzmq.deepdrrd.mesh_msg_to_volume(meshParams)¶
Convert a mesh message to a volume.
- Parameters:
meshParams – The mesh to convert.
- Returns:
The volume.
- deepdrrzmq.deepdrrd.nifti_msg_to_volume(niftiParams, patient_data_dir)¶
Convert a nifti message to a volume.
- Parameters:
niftiParams – The nifti message to convert.
patient_data_dir – The directory containing the patient data.
- Returns:
The volume.
deepdrrzmq.loggerd module¶
- class deepdrrzmq.loggerd.LogRecorder(log_root_path, **kw)¶
Bases:
object
Context manager for logging data from the surgical simulation.
- __init__(log_root_path, **kw)¶
- Parameters:
log_root_path – The path to the root folder where the logs should be stored.
kw – Additional keyword arguments for the LogShardWriter.
- close()¶
Close the log session.
- finish()¶
Close the current log session.
- new_session()¶
Start a new logging session.
- stop_session()¶
Stop the current logging session.
- write(data)¶
Write data to the current log session if there is one.
- class deepdrrzmq.loggerd.LogShardWriter(pattern, maxcount, maxsize, start_shard=0, verbose=False, **kw)¶
Bases:
object
Stream wrapper for writing to a log file. Automatically switches to a new file when the current one reaches a certain size.
- __init__(pattern, maxcount, maxsize, start_shard=0, verbose=False, **kw)¶
- Parameters:
pattern – The pattern for the log file names. Must contain a single %d placeholder.
maxcount – The maximum number of messages per file.
maxsize – The maximum size of a file in bytes.
start_shard – The shard number to start with.
verbose – Whether to print information about the log files.
kw – Additional keyword arguments for the LogWriter.
- close()¶
Close the current log file stream.
- finish()¶
Close the current log file.
- next_stream()¶
Switch to the next log file.
- write(data)¶
Write data to the current log file. If the file is full, switch to a new one. :param data: The data to write.
- class deepdrrzmq.loggerd.LogWriter(fileobj)¶
Bases:
object
Stream wrapper for writing to a log file.
- __init__(fileobj)¶
- close()¶
- write(data)¶
- class deepdrrzmq.loggerd.LoggerServer(context, rep_port, pub_port, sub_port, log_root_path)¶
Bases:
object
Server for logging data from the surgical simulation.
- __init__(context, rep_port, pub_port, sub_port, log_root_path)¶
- Parameters:
context – The zmq context to use.
rep_port – The port to use for the request-reply socket.
pub_port – The port to use for the publish socket.
sub_port – The port to use for the subscribe socket.
log_root_path – The path to the root folder where the logs should be stored.
- async logger_server()¶
Server for logging data from the surgical simulation.
- async start()¶
- async status_server()¶
Server for sending the status of the logger.
- deepdrrzmq.loggerd.main(rep_port=40100, pub_port=40101, sub_port=40102, log_root_path='pvrlogs')¶
deepdrrzmq.logreplay module¶
- class deepdrrzmq.logreplay.LoggerServer(context, rep_port, pub_port, sub_port)¶
Bases:
object
A process that replays all messages from a log file.
- __init__(context, rep_port, pub_port, sub_port)¶
- Parameters:
context – The ZMQ context to use for creating sockets.
rep_port – The port to use for the request/reply socket.
pub_port – The port to use for the publisher socket.
sub_port – The port to use for the subscriber socket.
- async logger_server()¶
- async start()¶
- deepdrrzmq.logreplay.main(rep_port=40100, pub_port=40101, sub_port=40102)¶
deepdrrzmq.manager module¶
Manager for deepdrrzmq processes. Prints a status line for each process every second.
- Usage:
python -m deepdrrzmq.manager
- deepdrrzmq.manager.main() None ¶
- deepdrrzmq.manager.manager_cleanup() None ¶
- deepdrrzmq.manager.manager_prepare() None ¶
- deepdrrzmq.manager.manager_thread() None ¶
deepdrrzmq.patientloaderd module¶
- class deepdrrzmq.patientloaderd.PatientLoaderServer(context, rep_port, pub_port, sub_port)¶
Bases:
object
This class implements a server that can be used to load patient data. The server is used to load data from the patient loader service. It uses the ZeroMQ REQ/REP pattern to handle requests from the client.
- __init__(context, rep_port, pub_port, sub_port)¶
- Parameters:
context – The ZMQ context to use for creating sockets.
rep_port – The port to use for the request/reply socket.
pub_port – The port to use for the publisher socket.
sub_port – The port to use for the subscriber socket.
- async handle_patient_annotation_request(pub_socket, data)¶
Handle a patient annotation request. This method is called when a message is received on the patient_anno_request topic. The message is parsed and the annotation is loaded from the patient data directory. The annotation is then sent back to the client on the patient_anno_response topic.
- Parameters:
pub_socket – The publisher socket to use for sending the response.
data – The message data.
- async handle_patient_mesh_request(pub_socket, data)¶
Handle a patient mesh request. This method is called when a message is received on the patient_mesh_request topic. The message is parsed and the mesh is loaded from the patient data directory. The mesh is then sent back to the client on the patient_mesh_response topic.
- Parameters:
pub_socket – The publisher socket to use for sending the response.
data – The message data.
- async project_server()¶
- async start()¶
- deepdrrzmq.patientloaderd.main(rep_port=40100, pub_port=40101, sub_port=40102)¶
deepdrrzmq.printd module¶
A simple server that prints all messages it receives for debugging purposes.
- class deepdrrzmq.printd.PrintServer(context, rep_port, pub_port, sub_port)¶
Bases:
object
A process that prints all messages it receives.
- __init__(context, rep_port, pub_port, sub_port)¶
- Parameters:
context – The ZMQ context to use for creating sockets.
rep_port – The port to use for the request/reply socket.
pub_port – The port to use for the publisher socket.
sub_port – The port to use for the subscriber socket.
- async start()¶
- async time_server()¶
- deepdrrzmq.printd.main(rep_port=40100, pub_port=40101, sub_port=40102)¶
deepdrrzmq.process module¶
Process manager helper classes with auto-restart watchdogs.
- class deepdrrzmq.process.ManagerProcess¶
Bases:
ABC
- check_watchdog(last_watchdog_time: float | None) None ¶
- daemon = False¶
- enabled = True¶
- last_watchdog_time = 0¶
- name = ''¶
- abstract prepare() None ¶
- proc: Process | None = None¶
- restart() None ¶
- shutting_down = False¶
- sigkill = False¶
- signal(sig: int) None ¶
- abstract start() None ¶
- stop(retry: bool = True, block: bool = True) int | None ¶
- unkillable = False¶
- watchdog_max_dt: int | None = None¶
- watchdog_seen = False¶
- class deepdrrzmq.process.NativeProcess(name, cwd, cmdline, enabled=True, sigkill=False, watchdog_max_dt=None)¶
Bases:
ManagerProcess
- __init__(name, cwd, cmdline, enabled=True, sigkill=False, watchdog_max_dt=None)¶
- prepare() None ¶
- start() None ¶
- class deepdrrzmq.process.PythonProcess(name, module, enabled=True, sigkill=False, watchdog_max_dt=None)¶
Bases:
ManagerProcess
- __init__(name, module, enabled=True, sigkill=False, watchdog_max_dt=None)¶
- prepare() None ¶
- start() None ¶
- deepdrrzmq.process.ensure_running(procs: List[ManagerProcess], not_run: List[str] | None = None, last_watchdog_times: Dict[str, float] | None = None) None ¶
- deepdrrzmq.process.join_process(process: Process, timeout: float) None ¶
- deepdrrzmq.process.launcher(proc: str, name: str) None ¶
- deepdrrzmq.process.nativelauncher(pargs: List[str], cwd: str, name: str) None ¶
deepdrrzmq.timed module¶
- class deepdrrzmq.timed.TimeServer(context, rep_port, pub_port, sub_port)¶
Bases:
object
A class that implements a time server.
The time server is a process that publishes the current time to all subscribers. The time is published once per second. The time is used to synchronize the multiplayer messages.
- __init__(context, rep_port, pub_port, sub_port)¶
- Parameters:
context – The ZMQ context to use for creating sockets.
rep_port – The port to use for the request/reply socket.
pub_port – The port to use for the publisher socket.
sub_port – The port to use for the subscriber socket.
- async start()¶
- async time_server()¶
- deepdrrzmq.timed.main(rep_port=40100, pub_port=40101, sub_port=40102)¶
deepdrrzmq.zmqproxyd module¶
This module implements a zmq pub/sub proxy server.
The proxy server is used to forward messages from the client to the server and vice versa. It uses the ZeroMQ XPUB/XSUB pattern to handle requests from the client.
- deepdrrzmq.zmqproxyd.main()¶