4.7.2 pde.trackers.interactive module
Special module for defining an interactive tracker that uses napari to display fields.
- class InteractivePlotTracker(interrupts='0:01', *, close=True, show_time=False, interval=None)[source]
Bases:
TrackerBase
Tracker showing the state interactively in napari.
Note
The interactive tracker uses the python
multiprocessing
module 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 patterndef 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.
- Parameters:
interrupts (InterruptData) – Determines when the tracker interrupts the simulation. A single numbers determines an interval (measured in the simulation time unit) of regular interruption. A string is interpreted as a duration in real time assuming the format ‘hh:mm:ss’. A list of numbers is taken as explicit simulation time points. More fine- grained control is possible by passing an instance of classes defined in
interrupts
.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=None)[source]
Finalize the tracker, supplying additional information.
- Parameters:
info (dict) – Extra information from the simulation
- Return type:
None
- handle(state, t)[source]
Handle data supplied to this tracker.
- Parameters:
state (
FieldBase
) – The current state of the simulationt (float) – The associated time
- Return type:
None
- name = 'interactive'
- class NapariViewer(state, t_initial=None)[source]
Bases:
object
Allows viewing and updating data in a separate napari process.
- Parameters:
state (
pde.fields.base.FieldBase
) – The initial state to be shownt_initial (float) – The initial time. If None, no time will be shown.
- close(force=True)[source]
Closes the napari process.
- Parameters:
force (bool) – Whether to force closing of the napari program. If this is False, this method blocks until the user closes napari manually.
- update(state, t)[source]
Update the state in the napari viewer.
- Parameters:
state (
pde.fields.base.FieldBase
) – The new statet (float) – Current time
- napari_process(data_channel, initial_data, t_initial=None, viewer_args=None)[source]
multiprocessing.Process
running napari120- Parameters:
data_channel (
multiprocessing.Queue
) – queue instance to receive data to viewinitial_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