meanap.network_plot

MEA network plotting: Python port of StandardisedNetworkPlot.m.

Functions

build_cell_type_matrix(cell_type_df, channels)

Convert a cell-type DataFrame to a binary membership matrix.

filter_by_cell_types(active_indices, ...)

Return subset of active_indices (and matching rows of cell_type_matrix) where nodes belong to ALL selected cell types (intersection logic from MATLAB).

load_cell_type_file(path)

Load a cell type Excel or CSV file.

plot_network(ax, adjM, coords, edge_thresh, z)

Render the MEA network onto ax.

Classes

MatData(path)

Parsed contents of a MEA-NAP output .mat file.

class meanap.network_plot.MatData(path)[source]

Bases: object

Parsed contents of a MEA-NAP output .mat file.

Parameters:

path (str)

property available_node_metrics: list[str]

Node-level metrics present in the first available lag.

get_active_indices(lag_key)[source]

Return 0-based active node indices.

Parameters:

lag_key (str)

Return type:

ndarray

get_adjM(lag_key)[source]
Parameters:

lag_key (str)

Return type:

ndarray

get_metric(lag_key, metric)[source]
Parameters:
  • lag_key (str)

  • metric (str)

Return type:

ndarray | None

get_netmet(lag_key)[source]
Parameters:

lag_key (str)

Return type:

dict

lag_ms(lag_key)[source]
Parameters:

lag_key (str)

Return type:

int

meanap.network_plot.build_cell_type_matrix(cell_type_df, channels)[source]

Convert a cell-type DataFrame to a binary membership matrix.

Mirrors MATLAB’s getCellTypeMatrix.

Returns:

  • matrix ((n_channels, n_types) int array — 1 if channel belongs to type)

  • type_names (list of column names)

Parameters:
  • cell_type_df (DataFrame)

  • channels (ndarray)

Return type:

tuple[ndarray, list[str]]

meanap.network_plot.filter_by_cell_types(active_indices, cell_type_matrix, type_names, selected_types)[source]

Return subset of active_indices (and matching rows of cell_type_matrix) where nodes belong to ALL selected cell types (intersection logic from MATLAB).

Returns (subset_active_indices, subset_cell_type_matrix)

Parameters:
  • active_indices (ndarray)

  • cell_type_matrix (ndarray)

  • type_names (list[str])

  • selected_types (list[str])

Return type:

tuple[ndarray, ndarray]

meanap.network_plot.load_cell_type_file(path)[source]

Load a cell type Excel or CSV file.

The file should have one column per cell type, with channel numbers listed in each column (the same format as the PutativeCellType xlsx files).

Parameters:

path (str)

Return type:

DataFrame

meanap.network_plot.plot_network(ax, adjM, coords, edge_thresh, z, z2=None, z2_name='None', cell_type_matrix=None, cell_type_names=None, min_node_size=0.01, title='', z_name='node degree', z_scale_override=None, z2_bounds_override=None, edge_bounds_override=None)[source]

Render the MEA network onto ax.

Closely mirrors MATLAB’s StandardisedNetworkPlot / StandardisedNetworkPlotNodeColourMap (MEA plot-type branch).

Parameters:
  • adjM ((N, N) adjacency matrix for active nodes)

  • coords ((N, 2) electrode coordinates for active nodes)

  • edge_thresh (minimum edge weight to draw)

  • z ((N,) array driving node SIZE — node degree by default, but any) – non-negative per-node metric works (e.g. node strength)

  • z2 ((N,) optional metric driving node COLOR; None / all-NaN = flat cyan)

  • z2_name (display name for the color metric)

  • cell_type_matrix ((N, K) binary membership matrix, or None)

  • cell_type_names (length-K list of type names)

  • z_name (display name for the size metric z (legend label) —) – defaults to “node degree” since that’s the Network Viewer GUI’s only use of this function; pass e.g. “node strength” when z isn’t ND

  • z_scale_override (if given, use this as the node-size scale factor) – (node_scale_f) instead of this recording’s own max(z). Set it to the batch-wide max of the size metric to render the “scaled to entire data batch” variant, where node sizes are comparable across recordings. Mirrors MATLAB’s nodeScaleF = max(Params.metricsMinMax. (zShortForm)) under useMinMaxBoundsForPlots.

  • z2_bounds_override (if given, (min, max) for the color normalization) – instead of this recording’s own z2 range — the batch-wide color scale. Mirrors MATLAB’s z2_min/z2_max from metricsMinMax.

  • edge_bounds_override (if given, (min, max) for edge-weight width/shade) – scaling instead of this recording’s own nonzero-edge range. MATLAB fixes this to EW = [0.1, 1] for the scaled variants.

  • ax (matplotlib.axes.Axes)

  • min_node_size (float)

  • title (str)

Return type:

None