4.7.2. pde.trackers.interactive module¶
Special module for defining an interactive tracker that uses napari to display fields
- class InteractivePlotTracker(interval: Union[ConstantIntervals, float, int, str] = '0:01', close: bool = True, show_time: bool = False)¶
Tracker showing the state interactively in napari
The interactive tracker uses the python
multiprocessingmodule to run napari externally. The multiprocessing module has limitations on some platforms, which requires some care when writing your own programs. In particular, the main method needs to be safe-guarded so that the main module can be imported again after spawning a new process. An established pattern that works is to introduce a function main in your code, which you call using the following pattern
def main(): # here goes your main code if __name__ == "__main__": main()
The last two lines ensure that the main function is only called when the module is run initially and not again when it is re-imported.
interval – Determines how often the tracker interrupts the simulation. Simple numbers are interpreted as durations measured in the simulation time variable. Alternatively, a string using the format ‘hh:mm:ss’ can be used to give durations in real time. Finally, instances of the classes defined in
intervalscan be given for more control.
close (bool) – Flag indicating whether the napari window is closed automatically at the end of the simulation. If False, the tracker blocks when finalize is called until the user closes napari manually.
show_time (bool) – Whether to indicate the time
- finalize(info: Optional[Dict[str, Any]] = None) None ¶
finalize the tracker, supplying additional information
info (dict) – Extra information from the simulation
- handle(state: FieldBase, t: float) None ¶
handle data supplied to this tracker
FieldBase) – The current state of the simulation
t (float) – The associated time
- initialize(state: FieldBase, info: Optional[Dict[str, Any]] = None) float ¶
initialize the tracker with information about the simulation
- name = 'interactive'¶
- class NapariViewer(state: FieldBase, t_initial: float = None)¶
allows viewing and updating data in a separate napari process
- close(force: bool = True)¶
closes the napari process
force (bool) – Whether to force closing of the napari program. If this is False, this method blocks until the user closes napari manually.
- napari_process(data_channel: Queue, initial_data: Dict[str, Dict[str, Any]], t_initial: float = None, viewer_args: Optional[Dict[str, Any]] = None)¶
multiprocessing.Queue) – queue instance to receive data to view
initial_data (dict) – Initial data to be shown by napari. The layers are named according to the keys in the dictionary. The associated value needs to be a tuple, where the first item is a string indicating the type of the layer and the second carries the associated data
t_initial (float) – Initial time
viewer_args (dict) – Additional arguments passed to the napari viewer