simularium_metrics_calculator package

Subpackages

Submodules

simularium_metrics_calculator.constants module

class simularium_metrics_calculator.constants.METRIC_TYPE(value)[source]

Bases: Enum

The type of a metric, for determining which metrics can be plotted against one another.

OTHER = 'OTHER'
PER_AGENT = 'PER_AGENT'
PER_TIME = 'PER_TIME'
class simularium_metrics_calculator.constants.PLOT_AXIS(value)[source]

Bases: Enum

Axes for a 2D plot.

X = 'x'
Y = 'y'
class simularium_metrics_calculator.constants.PLOT_TYPE(value)[source]

Bases: Enum

The type of a plot.

HISTOGRAM = 'histogram'
SCATTER = 'scatter'
class simularium_metrics_calculator.constants.SCATTER_PLOT_MODE(value)[source]

Bases: Enum

Mode for how to draw points on a scatter plot.

LINES = 'lines'
MARKERS = 'markers'

simularium_metrics_calculator.exceptions module

exception simularium_metrics_calculator.exceptions.IncompatibleMetricsError(x_metric_name: str, y_metric_name: str, **kwargs: int)[source]

Bases: Exception

This exception is intended to communicate that the requested metrics have incompatible metric types and can’t be plotted against each other.

exception simularium_metrics_calculator.exceptions.InconsistentPlotTypeError(plot_type: PLOT_TYPE, **kwargs: int)[source]

Bases: Exception

This exception is intended to communicate that the type of a plot is not consistent with the number of metrics provided.

exception simularium_metrics_calculator.exceptions.MetricNotFoundError(metric_id: int, **kwargs: int)[source]

Bases: Exception

This exception is intended to communicate that the requested metric ID does not exist in the metrics registry.

simularium_metrics_calculator.metric_info module

class simularium_metrics_calculator.metric_info.MetricInfo(display_name: str, metric_type: METRIC_TYPE, calculator: Type[Calculator], exclude_axes: List[PLOT_AXIS] | None = None)[source]

Bases: object

Data about a metric that can be calculated.

Parameters:
display_name: str

The name for this metric to display on a plot axis.

metric_type: METRIC_TYPE

The type of metric, for determining which metrics can be plotted against one another.

calculator: Type[Calculator]

The calculator class for this metric.

exclude_axes: List[PLOT_AXIS] (optional)

A list of plot axes where this metric doesn’t make sense, if any. Default: [] (don’t exclude any axes)

calculator: Type[Calculator]
display_name: str
exclude_axes: List[str]
metric_type: METRIC_TYPE
to_dict() Dict[str, Any][source]

Get a dict with info about the metric that a client needs to know.

Returns:
Dict[str, Any]

A dict of the metric info, including display name, metric type, and excluded axes.

simularium_metrics_calculator.metrics_registry module

simularium_metrics_calculator.metrics_service module

class simularium_metrics_calculator.metrics_service.MetricsService[source]

Bases: object

This object lists and calculates metrics that can be plotted in the Simularium Viewer.

available_metrics() List[Dict[str, Any]][source]

Get the IDs and display names for the metrics that are compatible with the given type of data.

Returns:
List[Dict[str, Any]]

A list of info about each available metric, including session ID, display name, metric type, and excluded axes.

metric_info_for_id(metric_id: int) MetricInfo[source]

Get a MetricInfo for a given metric’s session id. Raise an error if the metric_id is not found in the registry.

Parameters:
metric_id: int

The session ID for the requested metric.

Returns:
MetricInfo

Info about the requested metric.

plot_data(traj_data: TrajectoryData, plots: List[PlotInfo]) str[source]

Add plots with the given configuration.

Parameters:
traj_dataTrajectoryData,

A Simularium trajectory.

plots: List[PlotInfo]

A list of PlotInfo configuration for each plot.

Returns:
str

A JSON string of the plot(s) in simularium format.

simularium_metrics_calculator.plot_info module

class simularium_metrics_calculator.plot_info.PlotInfo(plot_type: PLOT_TYPE, metric_id_x: int, metric_id_y: int = -1, scatter_plot_mode: SCATTER_PLOT_MODE = SCATTER_PLOT_MODE.MARKERS, title: str = '')[source]

Bases: object

This object takes Simularium trajectory data and calculates metrics that can be plotted in the Simularium Viewer.

Parameters:
plot_type: PLOT_TYPE

What type of plot to make.

metric_id_xint

ID for the metric to plot on the x-axis.

metric_id_yint (Optional)

ID for the metric to plot on the y-axis. If not provided, the plot will be a histogram.

scatter_plot_modeSCATTER_PLOT_MODE (Optional)

If the plot is a scatterplot, how to draw the points. Default: SCATTER_PLOT_MODE.MARKERS (draw as dots)

title: str

Title to display above plot.

metric_id_x: int
metric_id_y: int
plot_type: PLOT_TYPE
scatter_plot_mode: SCATTER_PLOT_MODE
set_display_title(metric_info_x: MetricInfo, metric_info_y: MetricInfo | None) None[source]

Return the title to display above the plot. If no title is provided, default to “Y metric name vs. X metric name”.

Parameters:
metric_info_x: MetricInfo

Info about the metric to plot on the x-axis.

metric_info_y: MetricInfo (optional)

Info about the metric to plot on the y-axis. Default: None (only for histograms)

title: str
validate_plot_configuration(metric_info_x: MetricInfo, metric_info_y: MetricInfo | None) None[source]

Check that the plot type and number of metrics are consistent, and that the X and Y metrics are of the same type if this is not a histogram.

Parameters:
metric_info_x: MetricInfo

Info about the metric to plot on the x-axis.

metric_info_y: MetricInfo (optional)

Info about the metric to plot on the y-axis. Default: None (only for histograms)

Module contents

Top-level package for simularium_metrics_calculator.