MCPcopy Create free account
hub / github.com/NanoComp/meep / Animate2D

Class Animate2D

python/visualization.py:1433–1814  ·  view source on GitHub ↗

A class used to record the fields during timestepping (i.e., a [`run`](#run-functions) function). The object is initialized prior to timestepping by specifying the field component. The object can then be passed to any [step-function modifier](#step-function-modifiers). For example,

Source from the content-addressed store, hash-verified

1431# to pass to plot2D()
1432#
1433class Animate2D:
1434 """
1435 A class used to record the fields during timestepping (i.e., a [`run`](#run-functions)
1436 function). The object is initialized prior to timestepping by specifying the field component.
1437 The object can then be passed to any [step-function modifier](#step-function-modifiers).
1438 For example, one can record the $E_z$ fields at every one time unit using:
1439
1440 ```py
1441 animate = mp.Animate2D(fields=mp.Ez,
1442 realtime=True,
1443 field_parameters={'alpha':0.8, 'cmap':'RdBu', 'interpolation':'none'},
1444 boundary_parameters={'hatch':'o', 'linewidth':1.5, 'facecolor':'y', 'edgecolor':'b', 'alpha':0.3})
1445
1446 sim.run(mp.at_every(1,animate),until=25)
1447 ```
1448
1449 By default, the object saves each frame as a PNG image into memory (not disk). This is
1450 typically more memory efficient than storing the actual fields. If the user sets the
1451 `normalize` argument, then the object will save the actual field information as a
1452 NumPy array to be normalized for post processing. The fields of a figure can also be
1453 updated in realtime by setting the `realtime` flag. This does not work for
1454 IPython/Jupyter notebooks, however.
1455
1456 Once the simulation is run, the animation can be output as an interactive JSHTML
1457 object, an mp4, or a GIF.
1458
1459 Multiple `Animate2D` objects can be initialized and passed to the run function to
1460 track different volume locations (using `mp.in_volume`) or field components.
1461 """
1462
1463 def __init__(
1464 self,
1465 sim: Optional[Simulation] = None,
1466 fields: Optional = None,
1467 f: Optional[Figure] = None,
1468 realtime: bool = False,
1469 normalize: bool = False,
1470 plot_modifiers: Optional[list] = None,
1471 update_epsilon: bool = False,
1472 nb: bool = False,
1473 **customization_args
1474 ):
1475 """
1476 Construct an `Animate2D` object.
1477
1478 + **`sim`** — Optional `Simulation` object (this has no effect, and is included for backwards compatibility).
1479
1480 + **`fields`** — Optional field component to record at each time instant.
1481
1482 + **`f`** — Optional `matplotlib` figure object that the routine will update
1483 on each call. If not supplied, then a new one will be created upon
1484 initialization.
1485
1486 + **`realtime`** — Whether or not to update a figure window in realtime as
1487 the simulation progresses. Disabled by default.
1488
1489 + **`normalize`** — Records fields at each time step in memory in a NumPy
1490 array and then normalizes the result by dividing by the maximum field value at a

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected