wepy.reporter.restree module

Provides a reporter for generating graphical depictions of resampling parent trees.

class wepy.reporter.restree.ResTreeReporter(resampler=None, boundary_conditions=None, row_spacing=None, step_spacing=None, default_node_radius=None, progress_key=None, max_progress_value=None, colormap_name='plasma', **kwargs)[source]

Bases: wepy.reporter.reporter.ProgressiveFileReporter

Reporter that generates resampling parent trees in the GEXF format.

Constructor for the ResTreeReporter.

Parameters
  • resampler (Resampler) – Used to generate parental relations from resampling records.

  • boundary_condition (BoundaryCondition, optional) –

    Used to determine discontinuities in the lineages.

    (Default value = None)

  • row_spacing (float, default: 5.0) – Spacing between nodes in a single row in layout.

  • step_spacing (float, default: 20.0) – Spacing between the rows of nodes in each step of the layout.

  • default_node_radius (float, default: 1.0) – Default node radius to use.

  • progress_key (str) – The key of the value in the progress records to use for coloring nodes in the tree.

  • max_progress_value (float or None) – The maximum value to consider for progress values, if None no max value will be used.

  • colormap_name (str, default: 'plasma') – The name of the colormap to use from the matplotlib colormap library (i.e. ‘matplotlib.cm.get_cmap’)

FILE_ORDER = ('gexf_restree_path',)

Specify an ordering of file paths. Should be customized.

SUGGESTED_EXTENSIONS = ('restree.gexf',)

Suggested extensions for file paths for use with the automatic reparametrization feature. Should be customized.

MAX_PROGRESS_NORM = 1.0
DISCONTINUOUS_NODE_SHAPE = 'square'

The shape of nodes that signify a discontinuity in the lineage.

DEFAULT_NODE_SHAPE = 'disc'

The shape of normal nodes that signify a continuity in the lineage.

property parent_table

The net parent table datastructure.

_make_resampling_record(record_d, cycle_idx)[source]

Make a namedtuple resampling record from a dictionary representation.

Parameters
  • record_d (dict of str : value) – The dictionary of values to make a namedtuple record from.

  • cycle_idx (int) – The cycle index the record is associated with.

Returns

record

Return type

namedtuple

_make_warping_record(record_d, cycle_idx)[source]

Make a namedtuple warping record from a dictionary representation.

Parameters
  • record_d (dict of str : value) – The dictionary of values to make a namedtuple record from.

  • cycle_idx (int) – The cycle index the record is associated with.

Returns

record

Return type

namedtuple

DEFAULT_MODE = 'x'

The default mode to set for opening files if none is specified (create if doesn’t exist, fail if it does.)

DEFAULT_SUGGESTED_EXTENSION = 'report'

The default file extension used for files during dynamic reparametrization, if none is specified

MODES = ('x', 'w', 'w-', 'r', 'r+')

Valid modes accepted for files.

SUGGESTED_FILENAME_TEMPLATE = '{config}{narration}{reporter_class}.{ext}'

Template to use for dynamic reparametrization of file path names.

The fields in the template are:

config : indicator of the runtime configuration used

narration : freeform description of the instance

reporter_classthe name of the class that produced the

output. When no specific name is given for a file report generated from a reporter this is used to disambiguate, along with the extension.

ext : The file extension, for multiple files produced from one reporter this should be sufficient to disambiguate the files.

The ‘config’ and ‘narration’ should be the same across all reporters in the same simulation manager, and the ‘narration’ is considered optional.

static _make_record(record_d, cycle_idx, record_field_names, field_names, field_shapes, rec_namedtuple)[source]

Generic record making function.

Parameters
  • record_d (dict of str : value) –

  • cycle_idx (int) –

  • record_field_names (list of str) – The record field names to use for the record.

  • field_names (list of str) – All of the field names available for the field type.

  • field_shapes (list of tuple of int) – Shapes for each field

  • rec_namedtuple (namedtuple object) – The namedtuple class to make records out of

Returns

record

Return type

namedtuple object

_validate_mode(mode)

Check if the mode spec is a valid one.

Parameters

mode (str) –

Returns

valid

Return type

bool

cleanup(**kwargs)

Teardown routines for the reporter at the end of the simulation.

Use to cleanly and safely close I/O connections or other cleanup I/O.

Use to close file descriptors, database connections etc.

Reporters can expect to have the following key word arguments passed to them during a simulation by the sim_manager.

Parameters
  • runner (Runner object) – The runner at the end of the simulation

  • work_mapper (WorkeMapper object) – The work mapper at the end of the simulation

  • resampler (Resampler object) – The resampler at the end of the simulation

  • boundary_conditions (BoundaryConditions object) – The boundary conditions at the end of the simulation

  • reporters (list of Reporter objects) – The list of reporters at the end of the simulation

property file_path

For single file path reporters the file path to that file spec.

property file_paths

The file paths for this reporter, in order.

init(**kwargs)

Construct a ProgressiveFileReporter.

This is exactly the same as the FileReporter.

Parameters
  • file_paths (list of str) – The list of file paths (in order) to use.

  • modes (list of str) – The list of mode specs (in order) to use.

  • file_path (str) – If ‘file_paths’ not specified, the single file path to use.

  • mode (str) – If ‘file_path’ option used, this is the mode for that file.

property mode

For single file path reporters the mode of that file.

property modes

The modes for the files, in order.

reparametrize(file_paths, modes)

Set the file paths and modes for all files in the reporter.

Parameters
  • file_paths (list of str) – New file paths for each file, in order.

  • modes (list of str) – New modes for each file, in order.

set_mode(file_idx, mode)

Set the mode for a single indexed file.

Parameters
  • file_idx (int) – Index in the listing of files.

  • mode (str) – The new mode spec.

set_path(file_idx, path)

Set the path for a single indexed file.

Parameters
  • file_idx (int) – Index in the listing of files.

  • path (str) – The new path to set for this file

report(cycle_idx=None, resampled_walkers=None, warp_data=None, progress_data=None, resampling_data=None, **kwargs)[source]

Generate the resampling tree GEXF file.

Parameters
  • cycle_idx (int) –

  • resampled_walkers (list of Walker) –

  • warp_data (dict of str : value) –

  • progress_data (dict of str : value) –

  • resampling_data (dict of str : value) –