Skip to content

Base

Subject

Abstract base class defining the interface for subject neural data access. All subject-specific implementations (MGH, BrainTreebank, etc.) should inherit from this.

The interface provides standardized methods to:

  • Access electrode metadata (labels, coordinates, etc.)
  • Load and retrieve neural data for specific electrodes/trials/sessions
  • Manage data caching
Source code in bfm/subject/base.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class Subject:
    """
    Abstract base class defining the interface for subject neural data access.
    All subject-specific implementations (MGH, BrainTreebank, etc.) should inherit from this.

    The interface provides standardized methods to:

    - Access electrode metadata (labels, coordinates, etc.)
    - Load and retrieve neural data for specific electrodes/trials/sessions
    - Manage data caching
    """

    def get_n_electrodes(self, session_id=None):
        """
        Get number of electrodes for this subject.

        Args:
            session_id: Optional session ID if electrode count varies by session

        Returns:
            int: Number of electrodes
        """
        raise NotImplementedError

    def get_electrode_labels(self, session_id=None):
        """
        Get list of electrode labels.

        Args:
            session_id: Optional session ID if labels vary by session

        Returns:
            list: List of electrode label strings
        """
        raise NotImplementedError

    def get_sampling_rate(self, session_id=None):
        """
        Get sampling rate in Hz.

        Args:
            session_id: Optional session ID if sampling rate varies by session

        Returns:
            float: Sampling rate in Hz
        """
        raise NotImplementedError

    def get_electrode_coordinates(self, session_id=None):
        """
        Get electrode coordinates in standardized space.

        Args:
            session_id: Optional session ID if coordinates vary by session

        Returns:
            torch.Tensor: (n_electrodes, 3) tensor of coordinates
        """
        raise NotImplementedError

    def load_neural_data(self, session_id):
        """
        Load neural data for a specific trial/session.
        Implementation should handle caching if enabled.

        Args:
            session_id: Trial/session identifier
        """
        raise NotImplementedError

    def get_electrode_data(self, electrode_label, session_id, window_from=None, window_to=None):
        """
        Get data for a specific electrode and time window.

        Args:
            electrode_label: Label of electrode to get data for
            session_id: Trial/session identifier
            window_from: Start sample index (optional)
            window_to: End sample index (optional)

        Returns:
            torch.Tensor: Neural data for specified electrode and window
        """
        raise NotImplementedError

    def get_all_electrode_data(self, session_id, window_from=None, window_to=None):
        """
        Get data for all electrodes in a time window.

        Args:
            session_id: Trial/session identifier
            window_from: Start sample index (optional)
            window_to: End sample index (optional)

        Returns:
            torch.Tensor: Neural data for all electrodes in window
        """
        raise NotImplementedError

    def clear_neural_data_cache(self, session_id=None):
        """
        Clear cached neural data.

        Args:
            session_id: Optional specific trial/session to clear, otherwise clears all
        """
        raise NotImplementedError

clear_neural_data_cache(session_id=None)

Clear cached neural data.

Parameters:

Name Type Description Default
session_id

Optional specific trial/session to clear, otherwise clears all

None
Source code in bfm/subject/base.py
100
101
102
103
104
105
106
107
def clear_neural_data_cache(self, session_id=None):
    """
    Clear cached neural data.

    Args:
        session_id: Optional specific trial/session to clear, otherwise clears all
    """
    raise NotImplementedError

get_all_electrode_data(session_id, window_from=None, window_to=None)

Get data for all electrodes in a time window.

Parameters:

Name Type Description Default
session_id

Trial/session identifier

required
window_from

Start sample index (optional)

None
window_to

End sample index (optional)

None

Returns:

Type Description

torch.Tensor: Neural data for all electrodes in window

Source code in bfm/subject/base.py
86
87
88
89
90
91
92
93
94
95
96
97
98
def get_all_electrode_data(self, session_id, window_from=None, window_to=None):
    """
    Get data for all electrodes in a time window.

    Args:
        session_id: Trial/session identifier
        window_from: Start sample index (optional)
        window_to: End sample index (optional)

    Returns:
        torch.Tensor: Neural data for all electrodes in window
    """
    raise NotImplementedError

get_electrode_coordinates(session_id=None)

Get electrode coordinates in standardized space.

Parameters:

Name Type Description Default
session_id

Optional session ID if coordinates vary by session

None

Returns:

Type Description

torch.Tensor: (n_electrodes, 3) tensor of coordinates

Source code in bfm/subject/base.py
49
50
51
52
53
54
55
56
57
58
59
def get_electrode_coordinates(self, session_id=None):
    """
    Get electrode coordinates in standardized space.

    Args:
        session_id: Optional session ID if coordinates vary by session

    Returns:
        torch.Tensor: (n_electrodes, 3) tensor of coordinates
    """
    raise NotImplementedError

get_electrode_data(electrode_label, session_id, window_from=None, window_to=None)

Get data for a specific electrode and time window.

Parameters:

Name Type Description Default
electrode_label

Label of electrode to get data for

required
session_id

Trial/session identifier

required
window_from

Start sample index (optional)

None
window_to

End sample index (optional)

None

Returns:

Type Description

torch.Tensor: Neural data for specified electrode and window

Source code in bfm/subject/base.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def get_electrode_data(self, electrode_label, session_id, window_from=None, window_to=None):
    """
    Get data for a specific electrode and time window.

    Args:
        electrode_label: Label of electrode to get data for
        session_id: Trial/session identifier
        window_from: Start sample index (optional)
        window_to: End sample index (optional)

    Returns:
        torch.Tensor: Neural data for specified electrode and window
    """
    raise NotImplementedError

get_electrode_labels(session_id=None)

Get list of electrode labels.

Parameters:

Name Type Description Default
session_id

Optional session ID if labels vary by session

None

Returns:

Name Type Description
list

List of electrode label strings

Source code in bfm/subject/base.py
25
26
27
28
29
30
31
32
33
34
35
def get_electrode_labels(self, session_id=None):
    """
    Get list of electrode labels.

    Args:
        session_id: Optional session ID if labels vary by session

    Returns:
        list: List of electrode label strings
    """
    raise NotImplementedError

get_n_electrodes(session_id=None)

Get number of electrodes for this subject.

Parameters:

Name Type Description Default
session_id

Optional session ID if electrode count varies by session

None

Returns:

Name Type Description
int

Number of electrodes

Source code in bfm/subject/base.py
13
14
15
16
17
18
19
20
21
22
23
def get_n_electrodes(self, session_id=None):
    """
    Get number of electrodes for this subject.

    Args:
        session_id: Optional session ID if electrode count varies by session

    Returns:
        int: Number of electrodes
    """
    raise NotImplementedError

get_sampling_rate(session_id=None)

Get sampling rate in Hz.

Parameters:

Name Type Description Default
session_id

Optional session ID if sampling rate varies by session

None

Returns:

Name Type Description
float

Sampling rate in Hz

Source code in bfm/subject/base.py
37
38
39
40
41
42
43
44
45
46
47
def get_sampling_rate(self, session_id=None):
    """
    Get sampling rate in Hz.

    Args:
        session_id: Optional session ID if sampling rate varies by session

    Returns:
        float: Sampling rate in Hz
    """
    raise NotImplementedError

load_neural_data(session_id)

Load neural data for a specific trial/session. Implementation should handle caching if enabled.

Parameters:

Name Type Description Default
session_id

Trial/session identifier

required
Source code in bfm/subject/base.py
61
62
63
64
65
66
67
68
69
def load_neural_data(self, session_id):
    """
    Load neural data for a specific trial/session.
    Implementation should handle caching if enabled.

    Args:
        session_id: Trial/session identifier
    """
    raise NotImplementedError