allensdk.brain_observatory.ecephys.behavior_ecephys_session module

class allensdk.brain_observatory.ecephys.behavior_ecephys_session.BehaviorEcephysSession(behavior_session: VBNBehaviorSession, metadata: BehaviorEcephysMetadata, probes: Probes, optotagging_table: OptotaggingTable)[source]

Bases: VBNBehaviorSession

Represents a session with behavior + ecephys

classmethod behavior_data_class()[source]

Return the class that is used to store the behavior data in this BehaviorEcephysSession

classmethod from_json(session_data: dict, stimulus_presentation_exclude_columns: List[str] | None = None, running_speed_load_from_multiple_stimulus_files: bool = True, skip_probes: List[str] | None = None) BehaviorEcephysSession[source]
Parameters:
session_data: Dict of input data necessary to construct a session
stimulus_presentation_exclude_columns: Optional list of columns to

exclude from stimulus presentations table

running_speed_load_from_multiple_stimulus_files:

Whether to load running speed from multiple stimulus files If False, will just load from a single behavior stimulus file

skip_probes: Names of probes to exclude (due to known bad data

for example)

Returns:
Instantiated BehaviorEcephysSession
classmethod from_nwb(nwbfile: NWBFile, probe_meta: Dict[str, ProbeWithLFPMeta] | None = None, **kwargs) BehaviorEcephysSession[source]
Parameters:
nwbfile
probe_meta

Maps the probe name to the ProbeWithLFPMeta

kwargs: kwargs sent to `BehaviorSession.from_nwb`
Returns:
instantiated BehaviorEcephysSession
get_channels(filter_by_validity: bool = True) DataFrame[source]
Parameters:
filter_by_validity: Whether to filter channels based on whether

the channel is marked as “valid_data”

Returns:
pd.DataFrame of channels
get_current_source_density(probe_id: int) DataArray | None[source]

Get current source density data for a single probe given by probe_id

get_lfp(probe_id: int) DataArray | None[source]

Get LFP data for a single probe given by probe_id

get_probes_obj() Probes[source]
get_units(filter_by_validity: bool = False, filter_out_of_brain_units: bool = False, amplitude_cutoff_maximum: float | None = None, presence_ratio_minimum: float | None = None, isi_violations_maximum: float | None = None) DataFrame[source]

Gets a dataframe representing all units detected by all probes

Parameters:
filter_by_validity

Whether to filter out units in channels with valid_data==False

filter_out_of_brain_units

Whether to filter out units with missing ecephys_structure_acronym

amplitude_cutoff_maximum

Filter units by this upper bound

presence_ratio_minimum

Filter units by this lower bound

isi_violations_maximum

Filter units by this upper bound

Returns
——-
Dataframe containing all units detected by probes
Columns:
  • properties of allensdk.ecephys._unit.Unit

except for ‘spike_times’, ‘spike_amplitudes’, ‘mean_waveforms’ which are returned separately

property mean_waveforms: Dict[int, ndarray]
Returns:
Dictionary mapping unit id to mean_waveforms for all probes
property metadata: dict

metadata for a given session

Returns:
Dict

A dictionary containing behavior session specific metadata dictionary keys:

age_in_days: (int)

age of mouse in days

behavior_session_uuid: (int)

unique identifier for a behavior session

behavior_session_id: (int)

unique identifier for a behavior session

cre_line: (string)

cre driver line for a transgenic mouse

date_of_acquisition: (date time object)

date and time of experiment acquisition, yyyy-mm-dd hh:mm:ss

driver_line: (list of string)

all driver lines for a transgenic mouse

equipment_name: (string)

identifier for equipment data was collected on

full_genotype: (string)

full genotype of transgenic mouse

mouse_id: (int)

unique identifier for a mouse

project_code: (string)

String of project session is associated with.

reporter_line: (string)

reporter line for a transgenic mouse

session_type: (string)

visual stimulus type displayed during behavior session

sex: (string)

sex of the mouse

stimulus_frame_rate: (float)

frame rate (Hz) at which the visual stimulus is displayed

property optotagging_table: DataFrame
Returns:
A dataframe with columns
  • start_time: onset of stimulation

  • condition: optical stimulation pattern

  • level: intensity (in volts output to the LED) of stimulation

  • stop_time: stop time of stimulation

  • stimulus_name: stimulus name

  • duration: duration of stimulation

property probes: DataFrame
Returns:
A dataframe with columns
  • id: probe id

  • name: probe name

  • location: probe location

  • lfp_sampling_rate: LFP sampling rate

  • has_lfp_data: Whether this probe has LFP data

property spike_amplitudes: Dict[int, ndarray]
Returns:
Dictionary mapping unit id to spike_amplitudes for all probes
property spike_times: Dict[int, ndarray]
Returns:
Dictionary mapping unit id to spike_times for all probes
to_nwb() Tuple[NWBFile, Dict[str, NWBFile | None]][source]

Adds behavior ecephys session to NWBFile instance.

Returns:
(session NWBFile instance,

mapping from probe name to optional probe NWBFile instance. C Contains LFP and CSD data if it exists)

class allensdk.brain_observatory.ecephys.behavior_ecephys_session.VBNBehaviorSession(behavior_session_id: BehaviorSessionId, stimulus_timestamps: StimulusTimestamps, running_acquisition: RunningAcquisition, raw_running_speed: RunningSpeed, running_speed: RunningSpeed, licks: Licks, rewards: Rewards, stimuli: Stimuli, task_parameters: TaskParameters, trials: Trials, metadata: BehaviorMetadata, date_of_acquisition: DateOfAcquisition, eye_tracking_table: EyeTrackingTable | None = None, eye_tracking_rig_geometry: RigGeometry | None = None)[source]

Bases: BehaviorSession

A class to create the behavior parts of a VBN session, performing all of the specialized timestamp calculations that implies.

from_lims(behavior_session_id: int, lims_db: Any | None = None, sync_file: Any | None = None, monitor_delay: float | None = None, date_of_acquisition: Any | None = None, eye_tracking_z_threshold: float = 3.0, eye_tracking_dilation_frames: int = 2) VBNBehaviorSession[source]
Parameters:
behavior_session_idint

Behavior session id

lims_dbPostgresQueryMixin, Optional

Database connection. If not provided will create a new one.

sync_fileSyncFile, Optional

If provided, will be used to compute the stimulus timestamps associated with this session. Otherwise, the stimulus timestamps will be computed from the stimulus file.

monitor_delayfloat, Optional

Monitor delay. If not provided, will use an estimate. To provide this value, see for example allensdk.brain_observatory.behavior.data_objects.stimuli.util. calculate_monitor_delay

date_of_acquisitionDateOfAcquisition, Optional

Date of acquisition. If not provided, will read from behavior_sessions table.

eye_tracking_z_thresholdfloat

See BehaviorSession.from_nwb, default 3.0

eye_tracking_dilation_framesint

See BehaviorSession.from_nwb, default 2

Returns:
BehaviorSession instance