The general strategy is to define a Python function that operates
on a given trace, and enter a list of traces as argument to that
function. You can find an example in
http://www.stimfit.org/doc/sphinx/howto/amplitudes.html that
calculates amplitudes on selected traces in Stimfit.
I will give you a very basic example
import stf
import numpy as np
def get_mean(start, end, trace):
"""
computes the average of the trace between
start and end
Arguments:
start -- starting points (in xunits)
end -- end point (in xunits)
trace -- zero-based index of the trace to calculate the mean
Returns:
mean value of the trace between start and end
Example:
>>> get_mean(0, 100, 0) # returns means between 0 and
100 in sweep 0
>>> [get_mean(0, 100, sweep) for sweep in range(0, 100,
6)] # returns a list
of averages of 100 sweeps every 6 trace
"""
# type checking
if type(trace) !=int:
print("Trace arguments only admits integers")
return False
# check that sweep is not out of range
if trace>stf.get_size_channel():
print("Trace out of range")
return False
# transform time into sampling points
dt = stf.get_sampling_interval()
pstart = int(round(start/dt))
pend = int(round(end/dt))
# obtain average
sweep = stf.get_trace(trace, channel=-1)[pstart:pend]
avg = np.mean(sweep)
return(avg)
As you can see in the example, you can enter a list of traces as
argument with a list comprehension, or
alternatively with a for loop:
>>> mylist = range(0,100,6)
>>> for sweep in mylist:
>>> get_mean(0, 100, sweep)
Hope it helps!
Jose