Package: aul
aulExportNetLogomodel runs as GIF or MP4 using Python.PurposeThe purpose of this project is to provide a simple and reliable way of capturing/exporting NetLogo model runs in moving image file formats.
Currently, MP4 and GIF are supported. These formats are suitable for sharing on social media or instant messager, or embedding in presentations or
documents.InstallationThis library was tested on Python 3.6. Requirements are:pyNetLogoimageioimageio-ffmpeg(if you want MP4 export)These packages also have their own requirements, notablypyNetLogo's jpype dependency.Install using:pip install aulUsageThe two main functions in the package areexport_gif(...)andexport_mp4(...). Both can take a variety of arguments, but also have useful default behavior.
Two parameters are required: the NetLogo model name (must be in same folder as Python file), and the ticks to be exported. The generated file will be saved to
the same folder as the model.TerminologyThe termstickandframemay be confusing. I use the termtickto refer to a single iteration step in the NetLogo model. Ticks are unique and sequentially numbered.Framesare individual images inside a GIF or MP4 (both of which are series of images). You can specify which ticks become frames with theticksargument.BasicsExport first 30 ticks of NetLogo run to GIF...importaulaul.export_gif('Fire.nlogo',30)or MP4.importaulaul.export_mp4('Fire.nlogo',30)TicksYou can specify ticks (see Terminology) in four ways - as an integer (see Basics), as a two- or three-element list of Pythonrange()parameters, or as an explicit list of ticks:importaul#ticks 0 to 24aul.export_gif('Fire.nlogo',[0,25])if you don't want every tick:importaul#every tenth tick from 0 to 190aul.export_gif('Fire.nlogo',[0,200,10])for specific ticks:importaul#specific ticks onlyaul.export_gif('Fire.nlogo',[0,1,2,3,4,5,7,8,9,12,22])General ArgumentsNetLogo runs will normally be instantiated with the input parameter values saved in the NetLogo model's sliders, switches, etc.
You can override these values directly from Python by passing a dictionary of keys (NetLogo global variable name) and values toparams:importaulfire_params={"density":90,"probability-of-spread":60}aul.export_gif('Fire Simple Extension 1.nlogo',45,params=fire_params)By default, the generated file will have the same pixel dimensions as the NetLogo world. You can adjust this withscale:importaul#GIF file will be twice as large as NetLogo worldaul.export_gif('Fire.nlogo',45,scale=2.0)You can also fade the last few frames of the run to black (to emphasize it is terminating) withfade:importaul#GIF will fade to black over last 30% of runtimeaul.export_gif('Fire.nlogo',45,fade=0.3)You can set the name of the output file withname.
This is useful if you to export multiple runs (e.g. with different random seeds) through a loop.importaul#GIF will be saved as "custom-fire.gif"aul.export_gif('Fire.nlogo',45,name="custom-fire")Per NetLogo conventions, the initialization and iteration procedures are expected to be namedsetupandgo. Override these
defaults with thesetupandgoparameters.importaul#Some custom model with unconventional procedure namesaul.export_gif('Custom.nlogo',45,setup='init',go='run')Adjust the playback speed of the output file withfps(frames per second).importaul#Save for playback at 8 frames per secondaul.export_gif('Fire.nlogo',45,fps=8)GIF-specific ArgumentsYou can reduce GIF file size by settingssubrectangles = True.importaul#compress fileaul.export_gif('Fire.nlogo',45,subrectangles=True)You can override thefpsparameter and specify frame durations instead withduration. This can be either as a global value
(time per frame), or as a specific value for each individual frame.importaul#show first 15 frames in Fibonacci timeaul.export_gif('Fibonacci.nlogo',15,duration=[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610])MP4-specific ArgumentsYou can reduce MP4 file size with thequalityargument. Range from 0 to 10, 10 being default and best quality.importaul#compress fileaul.export_mp4('Fire.nlogo',45,quality=3)ContactPlease get in touch if you have questions or suggestions, either through an issue or on:Twitter -@steipatr