API Reference¶
Complete API documentation for neurospatial, automatically generated from source code docstrings.
Core Modules¶
neurospatial.environment¶
The main Environment class and related functionality (modular package).
Key Classes:
Environment: Main class for discretized spatial environments
Modules:
environment.core: Core dataclass with state and propertiesenvironment.factories: Factory classmethods for creating environmentsenvironment.queries: Spatial query methodsenvironment.trajectory: Trajectory analysis methodsenvironment.fields: Spatial field operationsenvironment.metrics: Environment metrics and properties
neurospatial.composite¶
Merge multiple environments into composite structures.
Key Classes:
CompositeEnvironment: Combine multiple environments with automatic bridge inference
neurospatial.regions¶
Define and manage named regions of interest (ROIs).
Key Classes:
Region: Immutable point or polygon regionRegions: Container for managing multiple regions
neurospatial.layout¶
Layout engines for discretizing continuous space.
Key Modules:
layout.base:LayoutEngineprotocol definitionlayout.engines.*: Concrete layout implementationslayout.factories: Factory functions for creating layouts
neurospatial.ops.alignment¶
Transform and align spatial representations.
Key Functions:
map_probabilities(): Align probability distributions between environmentsget_2d_rotation_matrix(): Create 2D rotation matrices
neurospatial.ops.transforms¶
2D affine transformations.
Key Classes:
Affine2D: Composable 2D affine transformations
neurospatial.encoding¶
Neural encoding analyses: how neurons represent space, direction, egocentric targets, and gaze.
Key Modules:
encoding.spatial: Place fields and spatial firing-rate mapsencoding.grid: Grid cells (autocorrelation, gridness score)encoding.directional: Head-direction cells and tuning curvesencoding.border: Border / boundary cell metricsencoding.egocentric: Object-vector cells and egocentric tuningencoding.view: Spatial-view cells and gaze-based fieldsencoding.phase_precession: Theta-phase precessionencoding.population: Population-level metrics
Key Functions:
compute_spatial_rate()/compute_spatial_rates(): Build firing-rate mapscompute_directional_rate(): Head-direction tuning curvecompute_egocentric_rate(): Object-vector tuningcompute_view_rate(): Spatial-view tuningdetect_place_fields(): Threshold-and-cluster on a rate mapspatial_information(),sparsity(),selectivity(),border_score(),grid_score(): Classic place / boundary / grid metrics
neurospatial.decoding¶
Bayesian decoding of position from spike counts.
Key Functions:
decode_position(): Single-step or sequential Bayesian decoderdecoding_error(),median_decoding_error(): Accuracy metricsfit_isotonic_trajectory(),fit_linear_trajectory(): Detect trajectory structure in posteriors
Key Classes:
DecodingResult: Posterior + helpers (MAP, mean, entropy)
neurospatial.behavior¶
Behavioral analysis built on trajectory + environment.
Key Modules:
behavior.trajectory: Step lengths, MSD, curvature, home rangebehavior.navigation: Path efficiency, goal-directed metrics, graph turn sequencesbehavior.segmentation: Laps, trials, region crossings, velocity-based segmentationbehavior.decisions/behavior.vte: Decision-point analysis, vicarious trial-and-errorbehavior.reward: Reward-field construction
neurospatial.events¶
Peri-event spike alignment and GLM regressors.
Key Functions:
peri_event_histogram(): PSTH around discrete eventsalign_spikes_to_events(): Per-trial spike rasterstime_to_nearest_event(),distance_to_reward(): GLM regressors
neurospatial.ops.egocentric¶
Allocentric ↔ egocentric coordinate transforms.
Key Functions:
heading_from_velocity(),heading_from_body_orientation(): Derive head direction from tracking dataallocentric_to_egocentric(),egocentric_to_allocentric(): Frame conversionscompute_egocentric_bearing(),compute_egocentric_distance(): Relate animal to external targets
neurospatial.ops.visibility¶
Visibility / gaze / viewshed computations.
Key Classes:
FieldOfView: Symmetric / rat / primate FOV presetsViewshedResult: Visible bins + visibility fraction
Key Functions:
compute_viewshed(),compute_view_field(),compute_viewshed_trajectory(): Viewshed from positions / headingscompute_viewed_location(): Gaze-direction projectionvisibility_occupancy(),visible_cues(): View-time aggregates
neurospatial.ops.basis¶
Spatial basis functions for regression / kernel methods.
Key Functions:
select_basis_centers(): K-means / random / farthest-point placementgeodesic_rbf_basis(),heat_kernel_wavelet_basis(),chebyshev_filter_basis(): Graph-aware kernelsspatial_basis(),plot_basis_functions(): Unified spatial-basis API
neurospatial.stats¶
Circular statistics, surrogates, and shuffle controls.
Key Modules:
stats.circular: Rayleigh test, circular mean / variance / R, circular-circular and circular-linear correlations, circular basisstats.shuffle: Position / cell / posterior shuffles with reproducibility helpersstats.surrogates: Poisson and inhomogeneous-Poisson surrogates, jittered-spike controls
neurospatial.animation¶
Field animation backends (napari / video / HTML / widget).
Key Function:
animate_fields(): Single entry point; dispatches across backends
Key Classes:
PositionOverlay,EventOverlay,SpikeOverlay,HeadDirectionOverlay,BodypartOverlay,VideoOverlay: Composable overlays for animations
neurospatial.io.nwb¶
NWB (Neurodata Without Borders) read / write integration.
Key Functions:
read_environment(),read_position(),read_pose(),read_events(),read_intervals(),read_trials(): Read NWB components into neurospatial typeswrite_environment(),write_place_field(),write_occupancy(),write_events(),write_laps(),write_region_crossings(),write_trials(): Persist neurospatial results back into an NWBFileenvironment_from_position(): Build an environment directly from the position channel of an NWB file
neurospatial.simulation v0.2.0+¶
Generate synthetic spatial data, neural activity, and spike trains for testing and validation.
Key Modules:
simulation.trajectory: Trajectory generation (OU process, structured laps)simulation.models: Neural models (place cells, boundary cells, grid cells)simulation.spikes: Spike generation (Poisson process, refractory periods)simulation.session: High-level session simulation APIsimulation.validation: Automated validation against ground truthsimulation.examples: Pre-configured example sessions
Key Classes:
PlaceCellModel: Gaussian place field model with ground truthBoundaryCellModel: Distance-tuned boundary/border cell modelGridCellModel: Hexagonal grid cell model (2D only)SimulationSession: Complete simulation session dataclass
Key Functions:
simulate_trajectory_ou(): Ornstein-Uhlenbeck process for realistic explorationsimulate_trajectory_sinusoidal(): Sinusoidal movement for 1D trackssimulate_trajectory_laps(): Structured lap-based trajectoriesgenerate_poisson_spikes(): Generate spikes from firing ratesgenerate_population_spikes(): Generate spikes for neuron populationssimulate_session(): One-call workflow for complete sessionsvalidate_simulation(): Compare detected fields to ground truthopen_field_session(),linear_track_session(), etc.: Pre-configured examples
See Also:
- Simulation Workflows Tutorial: Comprehensive examples and quick start guide
Layout Engines¶
Detailed documentation for each layout engine:
- RegularGridLayout
- HexagonalLayout
- GraphLayout
- MaskedGridLayout
- ShapelyPolygonLayout
- TriangularMeshLayout
- ImageMaskLayout
Navigation¶
Use the sidebar to browse the complete API reference, or search for specific functions, classes, or methods.
Docstring Format¶
All docstrings follow NumPy docstring conventions for consistency with the scientific Python ecosystem.