Example #1
0
    def plotprot(i, varnames, limits, L):
        """Plot one protocol."""
        from pylab import figure, subplot, plot, savefig, legend, axis

        figure()
        proto0, _ = L[0]
        isclamped = len(proto0[0]) == 2
        for j, (n, lim) in enumerate(zip(varnames, limits)):
            subplot(len(varnames), 1, j + 1)
            leg = set()
            for k in n.split():
                if isclamped:  # clamp protocol
                    # For each protocol, traj is a list with a Trajectory
                    # for each pulse.
                    for _proto, traj in L:
                        t, y, _dy, a = catrec(*traj[1:])
                        plot(t, y[k] if k in y.dtype.names else a[k], label=k if (k not in leg) else None)
                        leg.add(k)
                else:  # pacing protocol
                    # For each protocol, paces is a list of Pace
                    for _proto, paces in L:
                        t, y, _dy, a, _stats = catrec(*paces)
                        plot(t, y[k] if k in y.dtype.names else a[k], label=k if (k not in leg) else None)
                        leg.add(k)
                legend()
            if lim:
                axis(lim)
        savefig("fig%s%s.png" % (i, b.name))
def pacing_output():
    # Prepacing
    for _t, _y, _stats in cell.aps(n=nprepace):
        pass
    # A few paces
    t, y, _stats = catrec(*cell.aps(n=npace), globalize_time=False)
    dy, a = cell.rates_and_algebraic(t, y)
    return t, y, dy, a
def exp_vargap(L=L):
    h = []
    for proto, traj in L:
        t, y, _dy, _a = catrec(*traj)
        h.extend(plot(t, y["V"], **lineplotopt))
    setp(h, color="gray")
    hi = h[len(h) // 2]
    setp(hi, color="black", zorder=10)
    title("Variable-gap clamping")
    ylabel("Voltage")
    tweak()
    xmin = proto[0][0] - 300
    xmax = getp(hi, "xdata")[-1]
    # from IPython.core.debugger import Tracer; Tracer()()
    xlim(xmin, xmax)
Example #4
0
def exp_p1p2(L=L):
    h = []
    for proto, traj in L:
        t, y, dy, a = catrec(*traj)
        h.extend(plot(t, y["V"], **lineplotopt))
    setp(h, color="gray")
    hi = h[len(h) // 2]
    setp(hi, color="black", zorder=10)
    # from IPython.core.debugger import Tracer; Tracer()()
    title("Double-pulse clamping")
    ylabel("Voltage")
    tweak()
    xmin = proto[0][0] - 300
    xmax = t[-1]
    xlim(xmin, xmax)
Example #5
0
 def cycle(self, index=0, tmax=None, tol=1e-4, n=None):
     """
     Find limit cycle (integrate until successive extrema are almost equal).
     
     :param str_or_int index: Index of state variable to base search on.
     :param float tmax: Time limit for aborting search for limit cycle.
     :param float tol: Tolerance for weighted root-mean-square norm of 
         change in state vector between successive extrema.
     :param int n: Keep history of up to n extrema while searching for 
         limit cycle.
     
     ..  plot::
         :include-source:
         
         >>> from matplotlib import pyplot as plt
         >>> from cgp.cvodeint.namedcvodeint import Namedcvodeint
         >>> from cgp.utils.unstruct import unstruct
         >>> from cgp.phenotyping.attractor import AttractorMixin
         >>> class Test(Namedcvodeint, AttractorMixin):
         ...     '''Inherits van der Pol equations as default example.'''
         ...     pass
         >>> test = Test(t=[0, 10000])
         >>> t, y, period = test.cycle()
         >>> period
         6.663...
         >>> h = plt.plot(t, unstruct(y), '-')
     """
     if tmax is None:
         tmax = self.t[-1]
     extrema = deque([self.next_extremum(tmax, index)], maxlen=n)
     while True:
         t, y, (te, ye) = tup = self.next_extremum(tmax, index)
         extrema.appendleft(tup)
         # pylint:disable=W0612,C0301
         for lag, (t_, y_, (te_, ye_)) in enumerate(extrema): #@UnusedVariable
             if lag == 0:
                 continue
             diff = unstruct(ye_) - unstruct(ye)
             if self.weighted_rms(diff) < tol:
                 L = reversed(list(extrema)[:lag])
                 t, y, _ = catrec(*L, globalize_time=False)
                 period = te - te_
                 return t, y.squeeze(), period
    tweak()
    xlim(pacelim)

def vis_ct(t=t, y=y):
    plot(t, y["Cai"], **lineplotopt)
    title("Calcium transient")
    ylabel("[Ca]")
    tweak()
    xlim(pacelim)


### Double-pulse protocol

L = vecvclamp(p1p2.protocol)
proto, traj = L[3]
t, y, dy, a = catrec(*traj)


def exp_p1p2(L=L):
    h = []
    for proto, traj in L:
        t, y, _dy, _a = catrec(*traj)
        h.extend(plot(t, y["V"], **lineplotopt))
    setp(h, color="gray")
    hi = h[len(h) // 2]
    setp(hi, color="black", zorder=10)
    # from IPython.core.debugger import Tracer; Tracer()()
    title("Double-pulse clamping")
    ylabel("Voltage")
    tweak()
    xmin = proto[0][0] - 300