Skip to content

Commit 893b799

Browse files
committed
Improved docstrings in Trace class
1 parent a35da7a commit 893b799

File tree

1 file changed

+67
-24
lines changed

1 file changed

+67
-24
lines changed

syncropatch_export/trace.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010

1111
class Trace:
1212
"""
13-
Defines a Trace object from the output of a Nanion experiment.
13+
Reads a Nanion experiment and provides access to the data and meta data it
14+
contains.
15+
16+
To create a :class:`Trace`, a directory name should be passed in, along
17+
with the name of a JSON file within that directory containing the meta
18+
data. Data can then be accessed using :meth:`get_all_traces` (to obtain a
19+
``dict`` mapping well names onto a 2-d numpy array containing the sampled
20+
currents (in pA) for all sweeps.
21+
22+
Well are
23+
24+
1425
1526
Args:
1627
filepath (str): A path pointing to folder containing both ``.json`` and
@@ -44,6 +55,13 @@ def __init__(self, filepath, json_file: str):
4455
self.MeasurementLayout = TraceHeader['MeasurementLayout']
4556
self.FileInformation = TraceHeader['FileInformation']
4657

58+
# Create (hardcoded) list-of-list of well names:
59+
# [['A01', 'B01', ..., 'P01'],
60+
# ['A02', 'B02', ..., 'P02'],
61+
# ...
62+
# ['A24', 'B24', ..., 'P24']]
63+
# So a list of 24 lists with 16 entries each
64+
#
4765
self.WELL_ID = np.array([
4866
[lab + str(i).zfill(2) for lab in string.ascii_uppercase[:16]]
4967
for i in range(1, 25)])
@@ -67,7 +85,7 @@ def get_voltage_protocol(self):
6785
Extract information about the voltage protocol from the JSON file.
6886
6987
Returns:
70-
VoltageProtocol: A voltage protocol object.
88+
The :class:`VoltageProtocol` used in this experiment.
7189
"""
7290
return VoltageProtocol.from_json(
7391
self.meta['ExperimentConditions']['VoltageProtocol'],
@@ -76,7 +94,8 @@ def get_voltage_protocol(self):
7694

7795
def get_voltage_protocol_json(self):
7896
"""
79-
Returns unparsed JSON object representing the voltage protocol.
97+
Returns an unparsed JSON object representing the first segment of the
98+
voltage protocol.
8099
"""
81100
# TODO Why only the first row?
82101
return self.meta['ExperimentConditions']['VoltageProtocol'][0]
@@ -86,33 +105,43 @@ def get_protocol_description(self):
86105
Returns the protocol as an ``np.numpy`` with an entry for each segment.
87106
88107
Returns:
89-
np.array: An array where each row contains the start time,
90-
end time, initial voltage, and final voltage of a ramp or step
91-
segment.
108+
A numpy ``array`` where each row contains the start time, end time,
109+
initial voltage, and final voltage of a ramp or step segment.
92110
93111
"""
94112
return self.get_voltage_protocol().get_all_sections()
95113

96114
def get_voltage(self):
97115
"""
98-
Returns the voltage stimulus from Nanion .json file
116+
Returns an array containing voltages (in mV) for each sampled point in
117+
the traces.
99118
"""
100119
return np.array(self.TimeScaling['Stimulus']).astype(np.float64) * 1e3
101120

102121
def get_times(self):
103122
"""
104-
Returns the time steps from Nanion .json file
123+
Returns the sampled times (in ms).
105124
"""
106125
return np.array(self.TimeScaling['TR_Time']) * 1e3
107126

108127
def get_all_traces(self, leakcorrect=False):
109128
"""
129+
Returns data for all wells and all sweeps (equivalent to calling
130+
:meth:`get_trace_sweeps()` without any arguments).
131+
132+
Current is returned in pA.
133+
134+
By default, the data is returned without leak correction, but the leak
135+
corrected data can be obtained by setting ``leakcorrect=True``.
110136
111137
Args:
112-
leakcorrect (bool): Set to true if using onboard leak correction
138+
sweeps (int): The number of sweeps to return.
139+
leakcorrect (bool): Used to choose corrected or uncorrected data.
113140
114141
Returns:
115-
All raw current traces from .dat files
142+
A dictionary mapping well names (e.g. "A01") onto 2-d numpy arrays
143+
of shape ``n_sweeps, n_times`` where ``n_sweeps`` is the number of
144+
sweeps and ``n_times`` is the number of sampled points.
116145
117146
"""
118147
return self.get_trace_sweeps(leakcorrect=leakcorrect)
@@ -139,7 +168,22 @@ def get_trace_file(self, sweeps):
139168

140169
def get_trace_sweeps(self, sweeps=None, leakcorrect=False):
141170
"""
142-
Returns a subset of sweeps defined by the input ``sweeps``.
171+
Returns the first ``sweeps`` sweeps, for all wells.
172+
173+
Current is returned in pA.
174+
175+
By default, the data is returned without leak correction, but the leak
176+
corrected data can be obtained by setting ``leakcorrect=True``.
177+
178+
Args:
179+
sweeps (int): The number of sweeps to return.
180+
leakcorrect (bool): Used to choose corrected or uncorrected data.
181+
182+
Returns:
183+
A dictionary mapping well names (e.g. "A01") onto 2-d numpy arrays
184+
of shape ``n_sweeps, n_times`` where ``n_sweeps`` is the number of
185+
sweeps and ``n_times`` is the number of sampled points.
186+
143187
"""
144188

145189
# initialise output
@@ -149,11 +193,11 @@ def get_trace_sweeps(self, sweeps=None, leakcorrect=False):
149193
out_dict[ijWell] = []
150194

151195
if sweeps is None:
152-
#  Sometimes NofSweeps seems to be incorrect
196+
# Sometimes NofSweeps seems to be incorrect
153197
sweeps = list(range(self.NofSweeps))
154198

155-
# check `getsweep` input is something sensible
156-
if len(sweeps) > self.NofSweeps:
199+
# Check `sweeps` is something sensible
200+
elif len(sweeps) > self.NofSweeps:
157201
raise ValueError('Required #sweeps > total #sweeps.')
158202

159203
# convert negative values to positive
@@ -193,9 +237,7 @@ def get_trace_sweeps(self, sweeps=None, leakcorrect=False):
193237

194238
# convert to double in pA
195239
iColTraces = trace[idx_i:idx_f] * self.I2DScale[i] * 1e12
196-
iColWells = self.WELL_ID[i]
197-
198-
for j, ijWell in enumerate(iColWells):
240+
for j, ijWell in enumerate(self.WELL_ID[i]):
199241
if leakcorrect:
200242
leakoffset = 1
201243
else:
@@ -229,9 +271,11 @@ def get_onboard_QC_values(self, sweeps=None):
229271
"""
230272
Return the quality control values Rseal, Cslow (Cm), and Rseries.
231273
232-
returns: A dictionary where the keys are the well e.g. 'A01' and the
233-
values are the values used for onboard QC i.e., the seal resistance,
234-
cell capacitance and the series resistance.
274+
Returns:
275+
A dict mapping well names ('A01' up to 'P24') to tuples
276+
``(R_seal, Cm, R_series)`` containing the seal resistance, membrane
277+
capacitance, and series resistance.
278+
235279
"""
236280

237281
# load QC values
@@ -268,12 +312,11 @@ def get_onboard_QC_values(self, sweeps=None):
268312

269313
def get_onboard_QC_df(self, sweeps=None):
270314
"""
271-
Create a Pandas DataFrame which lists the Rseries, memebrane
272-
capacitance and Rseries for each well and sweep.
315+
Create a Pandas DataFrame containing the seal resistance, membrane
316+
capacitance, and series resistance for each well and sweep.
273317
274318
Returns:
275-
pandas.DataFrame: A data frame describing the onboard QC estimates
276-
for each well, sweep
319+
A ``pandas.DataFrame`` with the onboard QC estimates.
277320
278321
"""
279322

0 commit comments

Comments
 (0)