コード例 #1
0
    def plot_iv_curve(self, ax=None):
        # pylint: disable=E1103
        title = '%s: IV Curve' % (self.cell_description or None)
        if not ax:
            f = QuantitiesFigure()
            f.suptitle(title)
            ax = f.add_subplot(1, 1, 1)
            ax.set_xlabel('Injected Current')
            ax.set_ylabel('SteadyStateVoltage')

        V_in_mV = [
            self.get_iv_point_steaddy_state(c).rescale('mV').magnitude
            for c in self.currents
        ]
        v = np.array(V_in_mV) * pq.mV
        i = factorise_units_from_list(self.currents)

        low_v = V_in_mV < self.v_regressor_limit if self.v_regressor_limit else range(
            len(V_in_mV))

        print 'i[low_v]', i[low_v]
        print 'v[low_v]', v[low_v]
        ax.plot(
            i[low_v],
            v[low_v],
        )
        ax.plot(
            i[np.logical_not(low_v)],
            v[np.logical_not(low_v)],
        )
        ax.plot(
            i[np.logical_not(low_v)],
            v[np.logical_not(low_v)],
        )

        # Plot the regressor:
        i_units = unit('1:pA').units
        v_units = unit('1:mV').units
        iv = np.vstack(
            (i.rescale(i_units).magnitude, v.rescale(v_units).magnitude)).T

        if not len(iv[low_v, 0]):
            return
        (a_s, b_s, r, tt, stderr) = stats.linregress(iv[low_v, 0], iv[low_v,
                                                                      1])
        input_resistance = (a_s * (v_units / i_units)).rescale('MOhm')
        reversal_potential = b_s * v_units

        self.input_resistance = input_resistance
        self.reversal_potential = reversal_potential

        ax.plot(
            i,
            i * input_resistance + reversal_potential,
            label="Fit: [V(mV) = %2.3f * I(pA)  + %2.3f]" % (a_s, b_s) +
            " \n[Input Resistance: %2.2fMOhm  Reversal Potential: %2.2f mV" %
            (input_resistance, reversal_potential))
        ax.legend()

        PM.save_figure(figname=title)
コード例 #2
0
ファイル: mmalphabeta.py プロジェクト: bmerrison/morphforge
    def plot_state_curve_summary(cls,  alphabeta_chl, state, figsize):
        fig = QuantitiesFigure(figsize=figsize)
        fig.suptitle("AlphaBeta Channel - %s : %s"%(alphabeta_chl.name, state))
        ax1 = fig.add_subplot(221)
        ax2 = fig.add_subplot(222)
        cls.plot_alpha_beta_curves(ax1, ax2, alphabeta_chl, state)

        ax3 = fig.add_subplot(223)
        ax4 = fig.add_subplot(224)
        cls.plot_inf_tau_curves(ax3, ax4, alphabeta_chl, state)
        return fig
コード例 #3
0
    def create_figure(self):
        self.fig = QuantitiesFigure(**self.fig_kwargs)

        # Add a title to the plot:
        if self.figtitle:
            self.fig.suptitle(self.figtitle)

        # Work out what traces are on what graphs:
        plotspec_to_traces = dict([(plot_spec, [
            tr for tr in self.all_trace_objs
            if plot_spec.addtrace_predicate(tr)
        ]) for plot_spec in self.plot_specs])
        if self.linkage:
            self.linkage.process(plotspec_to_traces)

        n_plots = len(self.plot_specs)

        for (i, plot_spec) in enumerate(self.plot_specs):

            # Create the axis:
            ax = self.fig.add_subplot(n_plots, 1, i + 1)
            ax.set_xunit(pq.millisecond)
            ax.set_xmargin(0.05)
            ax.set_ymargin(0.05)

            ax.set_xaxis_maxnlocator(self.nxticks)

            # Leave the plotting to the tag-plot object
            plot_spec.plot(
                ax=ax,
                all_traces=self.all_trace_objs,
                all_eventsets=self.all_event_set_objs,
                time_range=self.timerange,
                linkage=self.linkage,
                #plot_xaxis_details=plot_xaxis_details,
                show_xlabel=self.show_xlabel,
                show_xticklabels=self.show_xticklabels,
                show_xticklabels_with_units=self.show_xticklabels_with_units,
                show_xaxis_position=self.show_xaxis_position,
                is_top_plot=(i == 0),
                is_bottom_plot=(i == n_plots - 1),
                xticks=self.xticks)

            # Save the Axis:
            self.subaxes.append(ax)

        if self.mpl_tight_bounds:
            import pylab
            try:
                pylab.tight_layout()
            except AttributeError:
                pass  # This is version specfic
            except ValueError:
                pass  # Top can't be less than bottom
コード例 #4
0
ファイル: traces_100.py プロジェクト: bmerrison/morphforge
def test_trace_method_traceout(src_trace, method_name, method_functor):
    f = QuantitiesFigure(figsize=(6, 4))
    f.suptitle('Testing Method: %s' % method_name)
    ax1 = f.add_subplot(211)
    ax2 = f.add_subplot(212)

    ax1.plotTrace(src_trace, label='Original')

    for (conv_type, conv_functor) in conversions:
        tr_new = conv_functor(src_trace)

        if not mf.TraceMethodCtrl.has_method(conv_type, method_name):
            continue
        ax2.plotTrace(method_functor(tr_new),
                      label='%s:%s' % (conv_type.__name__, method_name))

    ax1.legend()
    ax2.legend()

    return mrd.Section('Test: %s' % method_name,
                       mrd.Image(f.fig, auto_adjust=False))
コード例 #5
0
    def PlotGHKMaxCurrentFlow(cls, calciumAlphaBetaBetaChannel, figsize):
        V = StdLimits.get_default_voltage_array().rescale("mV")
        # Plot the
        fig = QuantitiesFigure(figsize=figsize)
        ax1 = fig.add_subplot(221,
                              xUnit="mV",
                              yUnit="pA/cm2",
                              xlabel="Voltage",
                              ylabel="")

        #Plot the 'I_ca' as defined in Biophysics of Computations:
        chl = calciumAlphaBetaBetaChannel
        nmp = (chl.CaZ * chl.F) / (chl.R * chl.T)
        nmpV = (nmp * V).rescale("")

        iCa = chl.permeability * nmpV * chl.F * (
            chl.intracellular_concentration - chl.extracellular_concentration *
            np.exp(-1.0 * nmpV)) / (1.0 - np.exp(-1.0 * nmpV))

        iCa.rescale("pA/cm2")

        ax1.plot(V, iCa)
コード例 #6
0
    def plot_traces(self, ax=None):
        title = '%s: (Voltage Responses to Current Injections)' \
            % self.cell_description
        if not ax:
            f = QuantitiesFigure()
            f.suptitle(title)
            ax = f.add_subplot(1, 1, 1)
            ax.set_xlabel('Time')
            ax.set_ylabel('Voltage')

        # Plot the traces
        for i_inj in self.currents:
            ax.plotTrace(self.get_trace(i_inj), label='i_inj: %s' % i_inj)

        # Add the regions:
        ax.axvspan(self.tSteaddyStateStart,
                   self.tSteaddyStateStop,
                   facecolor='g',
                   alpha=0.25)
        ax.legend()

        from mreorg.scriptplots import PM
        PM.save_figure(figname=title)
コード例 #7
0
def compareNeuroMLChl(xmlFile):
    model, chl_type = os.path.splitext(xmlFile)[0].split("/")[-2:]
    print model, chl_type

    op_dir = LocMgr.ensure_dir_exists(Join(html_output_dir, model, chl_type))
    op_html = Join(op_dir, "index.html")
    c = ComparisonResult(xmlfile=xmlFile, op_file = op_html, same_chl=True, exception=None)

    try:

        # Make the NeuroUnits channel:
        chl_neuro = NeuroML_Via_NeuroUnits_ChannelNEURON(xml_filename=xmlFile,  )
        c.chl_neurounits = chl_neuro


        op_pdf_file = Join(op_dir, 'Op1.pdf')
        #WriteToPDF(eqnset = chl_neuro.eqnset, filename = op_pdf_file)
        c.chl_neurounits_pdf = op_pdf_file


        # Make the NeuroML channel:
        xsl_file = "/home/michael/srcs/neuroml/CommandLineUtils/ChannelMLConverter/ChannelML_v1.8.1_NEURONmod.xsl"
        chl_xsl = NeuroML_Via_XSL_ChannelNEURON(xml_filename=xmlFile, xsl_filename=xsl_file,  )
        c.chl_xsl = chl_xsl
        c.chl_xsl_hoc = []


        chl_neuro_res = simulate_chl_all(chl_neuro)
        chl_xsl_res = simulate_chl_all(chl_xsl)
        c.chl_neurounit_hoc = []


        for i, (rN, rX) in enumerate(zip(chl_neuro_res, chl_xsl_res)):

            c.chl_neurounit_hoc.append(rN.hocfilename )
            c.chl_xsl_hoc.append(rX.hocfilename )

            tN = rN.get_trace("CurrentClamp").convert_to_fixed(dt=unit("1.01:ms"))
            tX = rX.get_trace("CurrentClamp").convert_to_fixed(dt=unit("1.01:ms"))

            # Compare current traces:
            tN._data[np.fabs(tN.time_pts_ms - 0) <0.05] *=0
            tX._data[np.fabs(tX.time_pts_ms - 0) <0.05] *=0
            tN._data[np.fabs(tN.time_pts_ms - 200) <0.05] *=0
            tX._data[np.fabs(tX.time_pts_ms - 200) <0.05] *=0
            tN._data[np.fabs(tN.time_pts_ms - 700) <0.05] *=0
            tX._data[np.fabs(tX.time_pts_ms - 700) <0.05] *=0
            print "TR1"
            f = QuantitiesFigure()
            ax1 = f.add_subplot(4, 1, 1)
            ax2 = f.add_subplot(4, 1, 2)
            ax3 = f.add_subplot(4, 1, 3)
            ax4 = f.add_subplot(4, 1, 4)
            ax1.plotTrace(tN, color='b')
            ax1.plotTrace(tX, color='g', linewidth=20, alpha=0.2)
            ax2.plotTrace(tN.window((200, 250)*pq.ms), color='b')
            ax2.plotTrace(tX.window((200, 250)*pq.ms), color='g', linewidth=20, alpha=0.2)

            num = (tN-tX)
            denom = (tN+tX)
            diff = num/denom
            ax3.plotTrace(diff, color='r')

            ax4.plotTrace(rN.get_trace('SomaVoltage'), color='m')
            ax4.plotTrace(rX.get_trace('SomaVoltage'), color='m', linewidth=20, alpha=0.2)

            if num.max()[1] > unit("0.1:pA"):
                c.same_chl = False

            out_im = Join(op_dir, "out_im%03d" % i)
            pylab.savefig(out_im+".png")
            pylab.savefig(out_im+".pdf")
            c.output_image_files.append(out_im)
            pylab.close()

        c.finished_ok=True



    except NeuroUnitsImportNeuroMLNotImplementedException, e:
        print 'Exception caught:', e

        s = StringIO.StringIO()
        traceback.print_exc(file=s)
        c.exception_long=s.getvalue()
        c.exception="%s (%s)"%(str(e), str(type(e)))
        c.same_chl = False
        c.finished_ok=False
コード例 #8
0
ファイル: traces_090.py プロジェクト: bmerrison/morphforge
import morphforge.stdimports as mf
from morphforge.traces.generation import TraceStringParser
import quantities as pq

from mhlibs.quantities_plot import QuantitiesFigure

t = """{d:pA} FLAT(1) FOR 100ms THEN RAMPTO(50) UNTIL 130ms THEN FLAT(0) THEN AT 150ms FLAT(120) FOR 20ms THEN  FLAT(0) UNTIL 180ms"""

tr = TraceStringParser.Parse(t)

trFix = tr.convert_to_fixed(dt=01. * pq.ms)

print 't1:', tr.integrate()
print 't2:', trFix.integrate()

f = QuantitiesFigure()
ax1 = f.add_subplot(211)
ax2 = f.add_subplot(212)

trFixSquared = trFix**2
print trFixSquared.integrate()

print(tr**2).integrate()

ax1.plotTrace(trFix)
ax2.plotTrace(trFixSquared)

import pylab
pylab.show()