microbenthos.exporters package

Submodules

microbenthos.exporters.exporter module

Base class definition for exporters

class microbenthos.exporters.exporter.BaseExporter(name='exp', logger=None, **kwargs)[source]

Bases: object

An abstract base class to define the interface for model state exporters to be used by the classes defined in runners.

is_eager = False
started

flag indicating if export has started

runner

the runner instance operating this exporter

setup(runner, state)[source]

Set up the exporter

Parameters
  • runner (object) – instance of the runner class operating it

  • state (dict) – a model state snapshot

Returns:

property sim

The simulation object of the runner, if any

Returns

None or Simulation

abstract prepare(state)[source]

Prepare the exporter based on the model state

Parameters

state (dict) – a model snapshot dict

close()[source]

Close the exporter by calling finish() to clean up resources. Sets started to False.

finish()[source]

Clean up resources. To be overridden by subclasses.

abstract process(num, state)[source]

Process the model state to create export

Parameters
  • num (int) – an index for the state

  • state (dict) – a model snapshot

get_info()[source]
Returns

dict – basic metadata about self (exports, version and cls)

microbenthos.exporters.graphic module

class microbenthos.exporters.graphic.GraphicExporter(show=False, write_video=False, video_dpi=100, video_filename='simulation.mp4', track_budget=False, write_frames=False, frames_dpi=100, frames_folder='frames', **kwargs)[source]

Bases: microbenthos.exporters._output_dir_mixin.OutputDirMixin, microbenthos.exporters.exporter.BaseExporter

An exporter for model snapshot data into a graphical representation.

This can write out videos (with write_video = True) and image frames (with write_frames = True). This uses matplotlib to render the plots.

property video_outpath
property frames_outdir
prepare(state)[source]

Prepare the ModelPlotter that will generate the plots for graphical export

process(num, state)[source]

Update the model plotter and grab or write frames

write_frame(state)[source]

Save a frame into the output directory for the current state

finish()[source]

Close the video writer and the model plotter.

microbenthos.exporters.model_data module

class microbenthos.exporters.model_data.ModelDataExporter(overwrite=False, filename='simulation_data.h5', compression=6, **kwargs)[source]

Bases: microbenthos.exporters._output_dir_mixin.OutputDirMixin, microbenthos.exporters.exporter.BaseExporter

A ‘stateless’ exporter for model snapshot data into HDF file. The exporter only keeps the output path, and reopens the file for each snapshot. This ensures that each snapshot is committed to disk, reducing risk of data corruption. It uses save_snapshot() internally.

property outpath
prepare(state)[source]

Check that the output path can be created. Create the HDF file and add some metadata from the exporter.

If newly created, then the state is stored into the disk.

Warning

If the output file already exists on disk, then it is just appended to. So, care must be taken by the caller that old files are removed, if so desired.

process(num, state)[source]

Append the state to the HDF store.

microbenthos.exporters.progress module

class microbenthos.exporters.progress.ProgressExporter(desc='evolution', position=None, **kwargs)[source]

Bases: microbenthos.exporters.exporter.BaseExporter

An exporter that displays a progress bar of a running simulation.

is_eager = True
prepare(state)[source]

Set up the progress bar

srepr(v, prec=2)[source]
process(num, state)[source]

Write the progress information to the progress bar

This includes info about residual, duration (dt), and number of sweeps in the timestep and the global progress through the model clock.

finish()[source]

Clean up resources. To be overridden by subclasses.

Module contents