replay_trajectory_classification.environments.Environment#

class Environment(environment_name: str = '', place_bin_size: float = 2.0, track_graph: Graph | None = None, edge_order: tuple | None = None, edge_spacing: tuple | None = None, is_track_interior: ndarray | None = None, position_range: ndarray | None = None, infer_track_interior: bool = True, fill_holes: bool = False, dilate: bool = False, bin_count_threshold: int = 0)[source]#

Bases: object

Represent the spatial environment with a discrete grid.

Parameters:
  • environment_name (str, optional)

  • place_bin_size (float, optional) – Approximate size of the position bins.

  • track_graph (networkx.Graph, optional) – Graph representing the 1D spatial topology

  • edge_order (tuple of 2-tuples, optional) – The order of the edges in 1D space

  • edge_spacing (None or int or tuples of len n_edges-1, optional) – Any gapes between the edges in 1D space

  • is_track_interior (np.ndarray or None, optional) – If given, this will be used to define the valid areas of the track. Must be of type boolean.

  • position_range (sequence, optional) – A sequence of n_position_dims, each an optional (lower, upper) tuple giving the outer bin edges for position. An entry of None in the sequence results in the minimum and maximum values being used for the corresponding dimension. The default, None, is equivalent to passing a tuple of n_position_dims None values.

  • infer_track_interior (bool, optional) – If True, then use the given positions to figure out the valid track areas.

  • fill_holes (bool, optional) – Fill holes when inferring the track

  • dilate (bool, optional) – Inflate the available track area with binary dilation

  • bin_count_threshold (int, optional) – Greater than this number of samples should be in the bin for it to be considered on the track.

Attributes:
edge_order
edge_spacing
is_track_interior
position_range
track_graph

Methods

fit_place_grid([position, infer_track_interior])

Fits a discrete grid of the spatial environment.

load_environment([filename])

Load the environment from a file.

plot_grid([ax])

Plot the fitted spatial grid of the environment.

save_environment([filename])

Saves the environment as a pickled file.

Methods

fit_place_grid

Fits a discrete grid of the spatial environment.

load_environment

Load the environment from a file.

plot_grid

Plot the fitted spatial grid of the environment.

save_environment

Saves the environment as a pickled file.

Attributes

bin_count_threshold

dilate

edge_order

edge_spacing

environment_name

fill_holes

infer_track_interior

is_track_interior

place_bin_size

position_range

track_graph

fit_place_grid(position: ndarray | None = None, infer_track_interior: bool = True)[source]#

Fits a discrete grid of the spatial environment.

Parameters:
  • position (np.ndarray, optional) – Position of the animal.

  • infer_track_interior (bool, optional) – Whether to infer the spatial geometry of track from position

Return type:

self

static load_environment(filename: str = 'environment.pkl')[source]#

Load the environment from a file.

Parameters:

filename (str, optional)

Return type:

environment instance

plot_grid(ax: Axes | None = None)[source]#

Plot the fitted spatial grid of the environment.

Parameters:

ax (plt.axes, optional) – Plot on this axis if given, by default None

save_environment(filename: str = 'environment.pkl')[source]#

Saves the environment as a pickled file.

Parameters:

filename (str, optional) – File name to pickle the environment to, by default “environment.pkl”