or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analysis-tools.mdcore-file-access.mddata-access.mdfile-information.mdindex.mdutilities.md

core-file-access.mddocs/

0

# Core File Access

1

2

Primary classes and functions for loading and accessing Axon Binary Format (ABF) and Axon Text Format (ATF) files. These classes provide the foundation for all data access operations in pyabf.

3

4

## Capabilities

5

6

### ABF Class

7

8

Main class for reading ABF files (both ABF1 and ABF2 formats). Provides comprehensive access to electrophysiology data with sweep-based organization.

9

10

```python { .api }

11

class ABF:

12

def __init__(

13

self,

14

abfFilePath: Union[str, pathlib.Path],

15

loadData: bool = True,

16

cacheStimulusFiles: bool = True,

17

stimulusFileFolder: Union[str, None] = None

18

):

19

"""

20

Load header and sweep data from an ABF file.

21

22

Parameters:

23

- abfFilePath: Path to the ABF file

24

- loadData: Whether to load sweep data immediately on instantiation.

25

Set to False for faster header-only access when iterating many files.

26

- cacheStimulusFiles: Whether stimulus files should be cached in memory

27

- stimulusFileFolder: Alternate search path for stimulus files

28

29

Raises:

30

- ValueError: If ABF file does not exist

31

- Exception: If path is a directory or if ATF file is passed

32

"""

33

```

34

35

### ATF Class

36

37

Class for reading Axon Text Format files with an API similar to the ABF class.

38

39

```python { .api }

40

class ATF:

41

def __init__(

42

self,

43

atfFilePath: Union[str, pathlib.Path],

44

loadData: bool = True

45

):

46

"""

47

Load header and sweep data from an ATF file.

48

49

Parameters:

50

- atfFilePath: Path to the ATF file

51

- loadData: Whether to parse sweep data values on instantiation

52

53

Raises:

54

- Exception: If file does not exist, path is directory, or ABF file is passed

55

"""

56

```

57

58

### Sweep Selection

59

60

Both ABF and ATF classes use sweep-based data access. You must set the active sweep before accessing data properties.

61

62

#### ABF.setSweep

63

64

```python { .api }

65

def setSweep(

66

self,

67

sweepNumber: int,

68

channel: int = 0,

69

absoluteTime: bool = False,

70

baseline: List[float] = [None, None]

71

) -> None:

72

"""

73

Set the active sweep and channel for data access (ABF class).

74

75

Parameters:

76

- sweepNumber: Zero-indexed sweep number to access (required)

77

- channel: Zero-indexed channel number to access

78

- absoluteTime: If True, sweepX shows absolute time from recording start

79

If False, sweepX shows time from sweep start

80

- baseline: Time range in seconds for baseline subtraction [start, end].

81

Use [None, None] to disable baseline subtraction.

82

83

Note: After calling setSweep(), use sweepY, sweepX, sweepC properties to access data

84

"""

85

```

86

87

#### ATF.setSweep

88

89

```python { .api }

90

def setSweep(self, sweepNumber: int = 0, channel: int = 0) -> None:

91

"""

92

Set the active sweep and channel for data access (ATF class).

93

94

Parameters:

95

- sweepNumber: Zero-indexed sweep number to access

96

- channel: Zero-indexed channel number to access

97

98

Note: ATF class does not support absoluteTime or baseline parameters

99

"""

100

```

101

102

### File Operations

103

104

Functions for saving and launching ABF files in different formats and programs.

105

106

```python { .api }

107

def saveABF1(self, filePath: Union[str, pathlib.Path]) -> None:

108

"""

109

Save this ABF file as an ABF1 file compatible with ClampFit and MiniAnalysis.

110

111

Parameters:

112

- filePath: Path where the ABF1 file should be saved

113

114

Note: Not all header values are saved, but the minimum necessary are included

115

for reading sweep data in older analysis programs.

116

"""

117

118

def launchInClampFit(self) -> None:

119

"""

120

Launch the ABF in the default ABF viewing program (usually ClampFit).

121

122

This opens the file as if it were double-clicked in Windows Explorer.

123

Assumes ClampFit is installed and will fail if ClampFit is already open.

124

125

Note: Windows-specific functionality

126

"""

127

```

128

129

### File Format Support

130

131

```python { .api }

132

# ABF files (binary format)

133

abf = ABF("recording.abf")

134

135

# ATF files (text format)

136

atf = ATF("recording.atf")

137

```

138

139

### Usage Examples

140

141

```python

142

import pyabf

143

144

# Basic ABF file loading

145

abf = pyabf.ABF("data.abf")

146

print(f"Loaded ABF with {abf.sweepCount} sweeps")

147

148

# Header-only loading for fast iteration

149

abf_header_only = pyabf.ABF("data.abf", loadData=False)

150

print(f"File info: {abf_header_only.abfID}")

151

152

# ATF file loading

153

atf = pyabf.ATF("data.atf")

154

print(f"ATF version: {atf.atfVersion}")

155

156

# Sweep selection and data access

157

abf.setSweep(0, channel=0)

158

voltage = abf.sweepY

159

time = abf.sweepX

160

161

# Absolute time mode

162

abf.setSweep(0, absoluteTime=True)

163

absolute_time = abf.sweepX # Time from recording start

164

165

# Multi-channel access

166

for channel in range(abf.channelCount):

167

abf.setSweep(0, channel=channel)

168

channel_data = abf.sweepY

169

print(f"Channel {channel}: {len(channel_data)} points")

170

```

171

172

## File Path Properties

173

174

```python { .api }

175

# Available after instantiation

176

@property

177

def abfFilePath(self) -> str: ... # Absolute path to ABF file

178

179

@property

180

def abfFolderPath(self) -> str: ... # Directory containing ABF file

181

182

@property

183

def abfID(self) -> str: ... # Filename without extension

184

185

# For ATF files

186

@property

187

def atfFilePath(self) -> str: ...

188

189

@property

190

def atfID(self) -> str: ...

191

```