### Animate 3D Structure Field with Mayavi Source: https://wiechapeter.gitlab.io/pyGDM2-doc This script demonstrates how to create a 3D animation of the electric field around a nanostructure using pyGDM2 and Mayavi. It requires pyGDM2, mayavi, and ffmpeg. ```python from pyGDM2 import visu3d from mayavi import mlab fig = mlab.figure( size=(600, 300), bgcolor=(1.0, 1.0, 1.0), fgcolor=(0.,0.,0.) ) ## structure visu3d.structure(sim, axis_labels=False, draw_substrate=False, opacity=0.1, show=False) ## 3D field-animation ani2 = visu3d.animate_vectorfield(NF, Nframes=100, scale=8, draw_struct=False, draw_substrate=False, substrate_size=1.1, colormap='Blues', clim=[0.0, 0.5], fig=fig, view=(85, -45, 350, (0,0,-15)), ffmpeg_args="-b:v 1.5M -c:v libx264", mov_file="3D.mp4", save_anim=True, opacity=0.5) ``` -------------------------------- ### Generate and Animate Structure Field Source: https://wiechapeter.gitlab.io/pyGDM2-doc This script generates a nanostructure from an image, calculates the time-harmonic electric field, and creates an animation of the field. It requires pyGDM2, matplotlib, and ffmpeg. ```python ## --- load pyGDM from pyGDM2 import structures from pyGDM2 import materials from pyGDM2 import fields from pyGDM2 import core from pyGDM2 import propagators from pyGDM2 import tools from pyGDM2 import visu import matplotlib.pyplot as plt #=============================================================== # Setup the simulation #=============================================================== ## --- structure step = 8.0 geometry = structures.image_to_struct("pyGDM_logo_static.png", useDarkPixel=1, threshold=100, H=1, nm_per_pixel=1.*step, stepsize=step) material = materials.gold() struct = structures.struct(step, geometry, material) ## --- incident field field_generator = fields.plane_wave kwargs = dict(theta=45.0) wavelengths = [700] efield = fields.efield(field_generator, wavelengths=wavelengths, kwargs=kwargs) ## --- vacuum environment dyads = propagators.DyadsQuasistatic123(n1=1) ## --- simulation object sim = core.simulation(struct, efield, dyads) #=============================================================== # Run the simulation #=============================================================== E = core.scatter(sim) NF = tools.get_field_as_list_by_fieldindex(sim, 0) #=============================================================== # create the field-animation #=============================================================== ## setup figure / axes plt.figure(figsize=(6.0,2.5)) ax = plt.subplot(aspect='equal') plt.axis('off') plt.subplots_adjust(left=0, right=1, bottom=0,top=1) ## geometry s = visu.structure(sim, scale=0.1, color='.75', show=0) ## field-animation config_vectorfield = dict(cmin=0.5, cmap=plt.cm.Blues, borders=5, vecwidth=0.8) ani = visu.animate_vectorfield(NF, Nframes=100, scale=12, kwargs=config_vectorfield, ax=ax, show=False) ## save video to file ani.save('pyGDM_logo.mp4', writer="ffmpeg", codec='h264', bitrate=1500) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.