placecell.io#

I/O functions for loading behavior and neural data.

Functions

compute_overlap_time_range(neural_timestamp, ...)

Compute the overlapping time range between neural and behavior recordings.

load_behavior_data(behavior_position, ...[, ...])

Load behavior data and compute speed-filtered trajectory.

load_visualization_data(neural_path, trace_name)

Load visualization data: traces, max projection, and footprints.

placecell.io.compute_overlap_time_range(neural_timestamp: Path, behavior_timestamp: Path, use_neural_last_timestamp: bool = True) tuple[float, float]#

Compute the overlapping time range between neural and behavior recordings.

Parameters:
  • neural_timestamp (Path) – Path to neural timestamp CSV (columns: frame, timestamp_first, timestamp_last).

  • behavior_timestamp (Path) – Path to behavior timestamp CSV (columns: frame_index, unix_time).

  • use_neural_last_timestamp (bool) – Whether to use timestamp_last for neural frames.

Returns:

(start_time, end_time) of the overlapping window in unix time.

Return type:

tuple[float, float]

placecell.io.load_behavior_data(behavior_position: Path, behavior_timestamp: Path, bodypart: str, speed_window_frames: int, speed_threshold: float, time_range: tuple[float, float] | None = None, x_col: str = 'x', y_col: str = 'y') tuple[DataFrame, DataFrame]#

Load behavior data and compute speed-filtered trajectory.

Parameters:
  • behavior_position (Path) – Path to behavior position CSV file.

  • behavior_timestamp (Path) – Path to behavior timestamp CSV file.

  • bodypart (str) – Body part name to use for trajectory.

  • speed_window_frames (int) – Window size for speed computation.

  • speed_threshold (float) – Minimum speed threshold.

  • time_range (tuple[float, float] | None) – Optional (start_time, end_time) to restrict behavior data. Use compute_overlap_time_range() to get this from neural/behavior timestamps.

  • x_col (str) – Coordinate column name for the x-axis in the behavior CSV.

  • y_col (str) – Coordinate column name for the y-axis in the behavior CSV.

Returns:

(trajectory_with_speed, trajectory_filtered) - full trajectory with speed and speed-filtered trajectory.

Return type:

tuple[pd.DataFrame, pd.DataFrame]

placecell.io.load_visualization_data(neural_path: Path | None, trace_name: str) tuple[Any, ndarray | None, Any]#

Load visualization data: traces, max projection, and footprints.

Parameters:
  • neural_path (Path | None) – Path to neural data directory.

  • trace_name (str) – Name of trace zarr to load.

Returns:

(traces, max_proj, footprints) - xarray DataArray or None for each.

Return type:

tuple