Ejemplo n.º 1
0
    def __getitem__(self, time):
        from scipy.interpolate import interp1d
        from morphforge.traces.tracetypes.tracefixeddt import TraceFixedDT

        if isinstance(time, tuple):
            assert len(time) == 2
            start = unit(time[0])
            stop = unit(time[1])

            if start < self._time[0]:
                assert False, 'Time out of bounds'
            if stop > self._time[-1]:
                assert False, 'Time out of bounds'

            mask = np.logical_and(start < self.time_pts, self._time < stop)

            if len(np.nonzero(mask)[0]) < 2:
                assert False
            return TraceFixedDT(time=self._time[np.nonzero(mask)[0]],
                                data=self.data_pts[np.nonzero(mask)[0]])


        assert isinstance(time, pq.quantity.Quantity), "Times should be quantity. Found: %s %s"%(time, type(time))
        # Rebase the Time:
        time.rescale(self._time.units)
        interpolator = interp1d(self.time_pts_np,
                                self.data_pts_np)
        d_mag = interpolator(time.magnitude)
        return d_mag * self.data_unit
Ejemplo n.º 2
0
    def __getitem__(self, time):
        from scipy.interpolate import interp1d
        from morphforge.traces.tracetypes.tracefixeddt import TraceFixedDT

        if isinstance(time, tuple):
            assert len(time) == 2
            start = unit(time[0])
            stop = unit(time[1])

            if start < self._time[0]:
                assert False, 'Time out of bounds'
            if stop > self._time[-1]:
                assert False, 'Time out of bounds'

            mask = np.logical_and(start < self.time_pts, self._time < stop)

            if len(np.nonzero(mask)[0]) < 2:
                assert False
            return TraceFixedDT(time=self._time[np.nonzero(mask)[0]],
                                data=self.data_pts[np.nonzero(mask)[0]])

        assert isinstance(
            time,
            pq.quantity.Quantity), "Times should be quantity. Found: %s %s" % (
                time, type(time))
        # Rebase the Time:
        time.rescale(self._time.units)
        interpolator = interp1d(self.time_pts_np, self.data_pts_np)
        d_mag = interpolator(time.magnitude)
        return d_mag * self.data_unit
Ejemplo n.º 3
0
 def __init__(self, results, tags=(["Voltage"],  ["Current"],
 ["Conductance"],["State"], ["State (Tau)"], ["State (SteddyState)"],
 ["Tau"]), figsize=(12, 8), timeranges=(None,), filename=None,
 annotation=None, jitter=0.0, tracecolour=None, legendlabel="${result.name} - ${trace.comment}", 
 haslegend=True,sorttraces = True, colors=None):
     #from morphforge.core.pylab import mpl
     #from morphforge.core.pylab import mpl
     
     self.sorttraces = sorttraces
     self.haslegend = haslegend
     # Filter out tag sets which actually have relevant traces:
     allTraceObjs = Flatten([ result.traces for result in results ]) 
     
     self.tags = []
     for tgs in tags:
         validTraces = allTraceObjs[:] 
         for tag in tgs:
             validTraces = [ trc for trc in validTraces if tag in trc.tags ]
         if validTraces != []: self.tags.append(tgs)
     
     self.legendlabel = legendlabel
     self.results = results
     
     self.figsize = figsize
     
     self.ignoreInitial = unit("5:ms")
     self.axisPadding = 0.3
     self.axisPadding = 0.1
     
     self.jitter = float(jitter)
     self.timeranges = timeranges #if timeranges else [None] 
     
     self.tracecolour = tracecolour
     self.colors = colors
     
     self.annotation = annotation
     self.filename = filename
     
     self.fig = None
     self.subfigs = []
     self.Render()
Ejemplo n.º 4
0
    def __init__(
        self,
        srcs,
        plots=None,
        additional_plots=None,
        figtitle=None,
        fig_kwargs=None,
        show=True,
        linkage=None,
        timerange=None,
        mpl_tight_bounds=False,

        share_x_labels=True,

        nxticks=4, 
        show_xlabel='only-once',
        show_xticklabels='only-once',
        show_xticklabels_with_units=True,
        show_xaxis_position='bottom',
        xticks=None

        ):
        """Plot a set of traces.

        Keyword arguments:
        plots -- 
        srcs --
        plots --
        additional_plots -- 
        figtitle --
        fig_kwargs --
        show --
        linkage --
        timerange -- 
        mpl_tight_bounds --
        share_x_labels --

        nxticks=4, 
        show_xlabel -- which plots should the x-axis be displayed on.
        show_xticklabels --
        show_xticklabels_with_units -- 
        show_xaxis_position --
        xticks -- 
        """

        if fig_kwargs is None:
            fig_kwargs = self._default_fig_kwargs

        self.linkage = linkage


        if not is_iterable(srcs):
            srcs = [srcs]

        # For each type of input (in 'srcs'); this should return a list of traces:
        self.all_trace_objs = []
        self.all_event_set_objs = []
        trace_extractors = {
            SimulationResult:   lambda obj: self.all_trace_objs.extend(obj.traces),
            TraceFixedDT:       lambda obj: self.all_trace_objs.append(obj),
            TraceVariableDT:    lambda obj: self.all_trace_objs.append(obj),
            TracePiecewise:     lambda obj: self.all_trace_objs.append(obj),
            EventSet:           lambda obj: self.all_event_set_objs.append(obj)
                            }

        for obj in srcs:
            tr_extractor = trace_extractors[type(obj)]
            tr_extractor(obj)

        # Use the new PlotSpec architecture:
        # Filter out which plots are actually going to display something,
        # and filter out the rest:
        plots = plots if plots is not None else TagViewer._default_plot_specs

        if additional_plots:
            plots = tuple(list(plots) + list(additional_plots))

        self.plot_specs = [plotspec for plotspec in plots if
                            [tr for tr in self.all_trace_objs if plotspec.addtrace_predicate(tr)] or  \
                            [evset for evset in self.all_event_set_objs if plotspec.addeventset_predicate(evset)] \
                          ]


        self.fig_kwargs = fig_kwargs
        self.figtitle = figtitle
        self.mpl_tight_bounds = mpl_tight_bounds

        self.timerange = timerange
        self.share_x_labels = share_x_labels
        self.nxticks = nxticks


        # X-axis configuration:
        self.show_xlabel = show_xlabel
        self.show_xticklabels = show_xticklabels
        self.show_xticklabels_with_units = show_xticklabels_with_units
        self.show_xaxis_position = show_xaxis_position
        self.xticks=xticks
        assert self.show_xlabel in self._options_show_xlabel, 'Invalid'
        assert self.show_xticklabels in self._options_show_xticklabels
        assert self.show_xticklabels_with_units in self._options_show_xticklabels_with_units
        assert self.show_xaxis_position in self._options_show_xaxis_position 
        if is_iterable( self.xticks ) and all( [isinstance(xtick, (int, float)) for xtick in self.xticks]):
            self.xticks = [ xtick*pq.ms for xtick in self.xticks]
        assert self.xticks is None or isinstance(self.xticks, int) or ( is_iterable(self.xticks) and [ unit(xtick) for xtick in self.xticks] )


        self.fig = None
        self.subaxes = []
        self.create_figure()


        if TagViewer.MPL_AUTO_SHOW and show:
            import pylab
            pylab.show()
Ejemplo n.º 5
0
    def __init__(self,
                 srcs,
                 plots=None,
                 additional_plots=None,
                 figtitle=None,
                 fig_kwargs=None,
                 show=True,
                 linkage=None,
                 timerange=None,
                 mpl_tight_bounds=False,
                 share_x_labels=True,
                 nxticks=4,
                 show_xlabel='only-once',
                 show_xticklabels='only-once',
                 show_xticklabels_with_units=True,
                 show_xaxis_position='bottom',
                 xticks=None):
        """Plot a set of traces.

        Keyword arguments:
        plots -- 
        srcs --
        plots --
        additional_plots -- 
        figtitle --
        fig_kwargs --
        show --
        linkage --
        timerange -- 
        mpl_tight_bounds --
        share_x_labels --

        nxticks=4, 
        show_xlabel -- which plots should the x-axis be displayed on.
        show_xticklabels --
        show_xticklabels_with_units -- 
        show_xaxis_position --
        xticks -- 
        """

        if fig_kwargs is None:
            fig_kwargs = self._default_fig_kwargs

        self.linkage = linkage

        if not is_iterable(srcs):
            srcs = [srcs]

        # For each type of input (in 'srcs'); this should return a list of traces:
        self.all_trace_objs = []
        self.all_event_set_objs = []
        trace_extractors = {
            SimulationResult:
            lambda obj: self.all_trace_objs.extend(obj.traces),
            TraceFixedDT: lambda obj: self.all_trace_objs.append(obj),
            TraceVariableDT: lambda obj: self.all_trace_objs.append(obj),
            TracePiecewise: lambda obj: self.all_trace_objs.append(obj),
            EventSet: lambda obj: self.all_event_set_objs.append(obj)
        }

        for obj in srcs:
            tr_extractor = trace_extractors[type(obj)]
            tr_extractor(obj)

        # Use the new PlotSpec architecture:
        # Filter out which plots are actually going to display something,
        # and filter out the rest:
        plots = plots if plots is not None else TagViewer._default_plot_specs

        if additional_plots:
            plots = tuple(list(plots) + list(additional_plots))

        self.plot_specs = [plotspec for plotspec in plots if
                            [tr for tr in self.all_trace_objs if plotspec.addtrace_predicate(tr)] or  \
                            [evset for evset in self.all_event_set_objs if plotspec.addeventset_predicate(evset)] \
                          ]

        self.fig_kwargs = fig_kwargs
        self.figtitle = figtitle
        self.mpl_tight_bounds = mpl_tight_bounds

        self.timerange = timerange
        self.share_x_labels = share_x_labels
        self.nxticks = nxticks

        # X-axis configuration:
        self.show_xlabel = show_xlabel
        self.show_xticklabels = show_xticklabels
        self.show_xticklabels_with_units = show_xticklabels_with_units
        self.show_xaxis_position = show_xaxis_position
        self.xticks = xticks
        assert self.show_xlabel in self._options_show_xlabel, 'Invalid'
        assert self.show_xticklabels in self._options_show_xticklabels
        assert self.show_xticklabels_with_units in self._options_show_xticklabels_with_units
        assert self.show_xaxis_position in self._options_show_xaxis_position
        if is_iterable(self.xticks) and all(
            [isinstance(xtick, (int, float)) for xtick in self.xticks]):
            self.xticks = [xtick * pq.ms for xtick in self.xticks]
        assert self.xticks is None or isinstance(
            self.xticks, int) or (is_iterable(self.xticks)
                                  and [unit(xtick) for xtick in self.xticks])

        self.fig = None
        self.subaxes = []
        self.create_figure()

        if TagViewer.MPL_AUTO_SHOW and show:
            import pylab
            pylab.show()