Ejemplo n.º 1
0
    def _build_details_channel(self, chl):

        sumcls = SummariserLibrary.get_summarisier(chl)
        if not sumcls:
            return mrd.Section(
                'Summary of channel: %s' % chl.name,
                mrd.Paragraph('<Summariser Missing for type: %s>' % type(chl)))

        return mrd.Section('Summary of channel: %s' % chl.name,
                           sumcls.build(chl))
Ejemplo n.º 2
0
def check_scenarios(**kwargs):
    import waf_util
    scen_filenames = waf_util.get_all_scenarios()

    # Run the individual comparisons, and produce a section for
    # each:
    all_summary_results = []
    results_sections = []
    for tgt_scen in waf_util.get_target_scenarios():
        tgt_scen_fname = scen_filenames[tgt_scen]
        results_section, summary_results = check_scenario( tgt_scen_fname, **kwargs )
        results_sections.append(results_section)
        all_summary_results.extend(summary_results)
    sim_details =  mrd.Section('Simulation Details', *results_sections)


    # Produce an overall results table
    print 'Summary Results'
    for sum_res in all_summary_results:
        print sum_res


    sims = sorted( set( [ res.sim_name for res in all_summary_results] ) )
    scens = sorted( set( [ res.scen_name for res in all_summary_results]) )
    sim_scen_lut = dict([ ((res.sim_name, res.scen_name),res) for res in all_summary_results])

    def table_entry(scen,sim):
        key = (sim, scen)
        res = sim_scen_lut.get(key , None)
        #assert res is not None
        if res is None:
            return ":warning:[None Found]"
        prefix = ':success:' if not res.nmissing and not res.nfails else ''
        if res.nmissing:
            prefix = ':warning:'
        if res.nfails:
            prefix = ':err:'
        return prefix + res.summary_str()
        return str(res)

    header = [''] + sims
    res = [ ]
    for scen in scens:
        res.append( [scen] + [ table_entry(scen,sim) for sim in sims ] )

    overview_table = mrd.VerticalColTable( header, res)
    sim_overview = mrd.Section('Results Overview', overview_table )
    return (sim_details,sim_overview)
Ejemplo n.º 3
0
 def summary_table(cls, ):
     summary_data = []
     for ((modelsrc, celltype), functor) in sorted(cls._cells.iteritems()):
         summary_data.append((modelsrc, celltype))  # , functor.__file__)
     summary_table = mredoc.VerticalColTable(('Model', 'CellType'),
                                             summary_data)
     return mredoc.Section('Cell Library Summary', summary_table)
Ejemplo n.º 4
0
    def summarise_operators(cls):

        all_types = cls._get_all_operator_types()
        trace_types = cls._trace_types
        summary_matrix = empty_str_matrix(N=len(all_types) + 1,
                                          M=len(all_types) + 1)

        for (i, tp1) in enumerate(all_types):
            summary_matrix[0][i + 1] = tp1.__name__
            summary_matrix[i + 1][0] = tp1.__name__
            for (j, tp2) in enumerate(all_types):

                # Neither of the operand is a trace_type:
                if tp1 not in trace_types and tp2 not in trace_types:
                    summary_matrix[i + 1][j + 1] = '==='
                    continue

                for (op, sym) in operators:
                    if (op, tp1, tp2) in TraceOperatorCtrl.trace_operators_all:
                        summary_matrix[i + 1][j + 1] += sym

        return mrd.Section(
            'TraceOperators',
            mrd.VerticalColTable(summary_matrix[0],
                                 summary_matrix[1:],
                                 caption='Operators'))
Ejemplo n.º 5
0
 def build_comp_section(param):
     fig = figures[param]
     trcs = sorted( trace_comp_res[param] )
     comp_tbl_header, comp_tbl_data= zip( *[ ('%s.max_ptp' %c, trace_comp_res[param][c].max_ptp) for c in trcs])
     return mrd.Section('Parameters: %s' % str(param),
         mrd.VerticalColTable(comp_tbl_header, [comp_tbl_data] ),
         mrd.Figure( mrd.Image(fig, auto_adjust=False), caption='Comparison'),
         )
Ejemplo n.º 6
0
def build_mredoc_ouput(trace_comp_res,unexpected_params, config, figures, validators, table_results, missing_parameter_sets, expected_variables, impl_param_filename_dict):
    print ' -- Producing mredoc output'
    import mredoc as mrd


    def build_comp_section(param):
        fig = figures[param]
        trcs = sorted( trace_comp_res[param] )
        comp_tbl_header, comp_tbl_data= zip( *[ ('%s.max_ptp' %c, trace_comp_res[param][c].max_ptp) for c in trcs])
        return mrd.Section('Parameters: %s' % str(param),
            mrd.VerticalColTable(comp_tbl_header, [comp_tbl_data] ),
            mrd.Figure( mrd.Image(fig, auto_adjust=False), caption='Comparison'),
            )

    comparison_graphs = mrd.Section('Trace Comparisons', [build_comp_section(p) for p in figures.keys() ] )

    tbl_comp_sections = []
    for impl in  impl_param_filename_dict:
        s = build_mredoc_results_table(impl=impl, validators=validators, table_results=table_results, missing_parameter_sets=missing_parameter_sets, expected_variables=expected_variables)
        tbl_comp_sections.append(s)

    results_section = mrd.SectionNewPage('%s - %s' % ( config['scenario_short'].capitalize(), config['title'],),
        mrd.Section('Overview',
            mrd.Section('Description', mrd.VerbatimBlock(config['description'], caption='Description' ) ),
            mrd.Section('Implementations', mrd.Paragraph('Tesing against: %s' % ', '.join(impl_param_filename_dict) ) ),
            mrd.Section('Failures', mrd.Paragraph('TODO!')),
            mrd.Section('Unexpected Files', mrd.Paragraph('Files:' + ','.join([str(u[1]) for u in unexpected_params]) )),
            ),
        mrd.Section('Table Comparisons',*tbl_comp_sections ),
        comparison_graphs,
    )

    return results_section
Ejemplo n.º 7
0
    def build_simulation(self):

        from morphforge.management import PluginMgr
        return mrd.Section(
            'Simulation Summary: %s' % self.sim._sim_desc_str(),
            mrd.TableOfContents(),
            self.build_simulation_overview(),
            self.build_simulation_details(),
            #PluginMgr.summarise_all(),
        )
Ejemplo n.º 8
0
    def build(cls, obj, result=None):
        sim_redoc = SimulationMRedoc(obj).mredoc

        if result is None:
            return sim_redoc

        else:
            return mrd.Section(
                'Simulation Results:',
                mrd.Image(result.fig.fig, auto_adjust=False),
                sim_redoc,
            )
Ejemplo n.º 9
0
 def summarise_channels(cls):
     mech_types = cls.get_all_chls()
     col1 = ['Channel Name'] + [mech.__name__ for mech in mech_types]
     cols = [[env._env_name] +
             [to_symbol(mech, env.channels) for mech in mech_types]
             for env in cls._environments]
     col_ = ['Summary'] + [
         to_symbol(mech, SummariserLibrary.summarisers)
         for mech in mech_types
     ]
     cols = [col1] + cols + [col_]
     rows = zip(*cols)
     return mrd.Section('Channels', mrd.VerticalColTable(rows[0], rows[1:]))
Ejemplo n.º 10
0
 def summarise_postsynapticmechs(cls):
     mech_types = cls.get_all_postsynmechs()
     col1 = ['PostSynMech'] + [mech.__name__ for mech in mech_types]
     cols = [[env._env_name] + [
         to_symbol(mech, env.postsynapticmechanisms) for mech in mech_types
     ] for env in cls._environments]
     col_ = ['Summary'] + [
         to_symbol(mech, SummariserLibrary.summarisers)
         for mech in mech_types
     ]
     cols = [col1] + cols + [col_]
     rows = zip(*cols)
     return mrd.Section('Postsynaptic Mechanisms',
                        mrd.VerticalColTable(rows[0], rows[1:]))
Ejemplo n.º 11
0
    def summarise_methods(cls):
        trace_types = cls._trace_types
        method_names = cls._get_all_trace_method_names()

        def get_argments(method, trace_type):
            if not TraceMethodCtrl.has_method(trace_type, method):
                return None
            functor = TraceMethodCtrl.get_method(trace_type, method)
            (args, varargs, varkw, defaults) = inspect.getargspec(functor)
            return inspect.formatargspec(args=args[1:],
                                         varargs=varargs,
                                         varkw=varkw,
                                         defaults=defaults)

        def get_argments_TraceFixedDT(method):
            return str(get_argments(method, TraceFixedDT))

        def get_docstring(method):
            trace_type = TraceFixedDT
            if not TraceMethodCtrl.has_method(trace_type, method):
                return '<None>'
            func = TraceMethodCtrl.get_method(trace_type, method)
            return inspect.getdoc(func)

        def _support_for_method(trace_type, method_name):
            if (trace_type, method_name) in TraceMethodCtrl.registered_methods:
                return 'X'
            if method_name in TraceMethodCtrl.fallback_to_fixedtrace_methods:
                return '<via fixed>'

        arguments = [
            get_argments_TraceFixedDT(method_name)
            for method_name in method_names
        ]
        docstrings = [
            get_docstring(method_name) for method_name in method_names
        ]

        col1 = [''] + method_names
        col2 = [[trace_type.__name__] + [
            _support_for_method(trace_type, method_name)
            for method_name in method_names
        ] for trace_type in trace_types]
        col_args = ['args'] + arguments
        col_docstrings = ['docstring'] + docstrings
        cols = [col1] + col2 + [col_args] + [col_docstrings]
        rows = zip(*cols)
        tbl = mrd.VerticalColTable(rows[0], rows[1:], caption='Operators')
        return mrd.Section('TraceMethods', tbl)
    def build_redoc(self,
                    time_data,
                    traces=None,
                    phase_plots=None,
                    params={},
                    state0In={},
                    default_state0=None):
        res = self.__call__(time_data=time_data,
                            params=params,
                            default_state0=default_state0)

        # What traces do we plot:

        if traces is False:
            traces = []
        if traces is None:
            traces = res.keys()

        # What phase plots shall we draw:

        if phase_plots is False:
            phase_plots = []
        if phase_plots is None:
            phase_plots = []
            for r in res.keys():
                for s in res.keys():
                    if r != s:
                        phase_plots.append((r, s))

        def build_trace_plot(sym):
            import pylab
            f = pylab.figure()
            pylab.plot(res['t'], res[sym])
            pylab.xlabel('Time (s)')
            pylab.ylabel('Symbol: %s')
            return mredoc.Figure(f)

        def build_phase_plot(sym1, sym2):
            import pylab
            f = pylab.figure()
            pylab.plot(res[sym1], res[sym2])
            pylab.xlabel('Symbol: %s' % sym1)
            pylab.ylabel('Symbol: %s' % sym2)
            return mredoc.Figure(f)

        return mredoc.Section("Simulation Results for: %s" % self.ast.name,
                              [build_trace_plot(tr) for tr in traces] +
                              [build_phase_plot(*tr) for tr in phase_plots])
Ejemplo n.º 13
0
    def build_population_overview(self):

        if not self.sim.neuron_populations:
            return None

        table = mrd.VerticalColTable(
            "Population | Size | Type "
            "", [(pop.pop_name, len(pop), ",".join(pop.cell_types))
                 for pop in self.sim.neuron_populations])
        table2 = mrd.VerticalColTable(
            "Population | Size | Type "
            "", [(pop.synapse_pop_name, len(pop), ",".join(pop.synapse_types))
                 for pop in self.sim.synapse_populations])

        return mrd.Section(
            "Population Overview",
            table,
            table2,
            #self.build_population_overview_dot(),
            self.build_population_complete_dot())
Ejemplo n.º 14
0
def test_trace_method_scalarout(src_trace, method_name, method_functor):

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

        if not mf.TraceMethodCtrl.has_method(conv_type, method_name):
            res.append([conv_type.__name__, '--'])
            continue

        else:
            res_new = method_functor(tr_new)
            res.append([conv_type.__name__, str(res_new)])
        #ax2.plotTrace(method_functor(tr_new), label='%s:%s' % (conv_type.__name__, method_name) )

    print res
    (header, data) = zip(*res)
    print 'header', header
    print 'data', data
    return mrd.Section('Tesing Method: %s' % method_name,
                       mrd.VerticalColTable(header, [data]))
Ejemplo n.º 15
0
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))
Ejemplo n.º 16
0
    
    src_files = get_src_9ml_files(args)

    # Read all the input files:
    library_manager = NeuroUnitParser.Parse9MLFiles(filenames=src_files)


    print args.what
    if not args.what:
        objs = list(library_manager.objects)
    else:
        objs = [ library_manager.get(name) for name in args.what ]

    summaries = []
    for o in objs:
        print 'Summarising:', repr(o)
        summaries.append( o.to_redoc() )


    summary_obj = mredoc.Section(
            'Summary output',
            *summaries

            )

    fname = os.path.expanduser( '~/Desktop/testout1.pdf')
    summary_obj.to_pdf(fname)
    os.system('xdg-open %s' % fname)


Ejemplo n.º 17
0
 def build_population_details(self):
     return mrd.Section(
         'Population Details:', *[
             self._build_population_details(pop)
             for pop in self.sim.neuron_populations
         ])
Ejemplo n.º 18
0
 def summarise_all(cls):
     return mrd.Section('Traces', cls.summarise_methods(),
                        cls.summarise_operators(), mrd.Paragraph('asda'))
Ejemplo n.º 19
0
        #ax2.plotTrace(method_functor(tr_new), label='%s:%s' % (conv_type.__name__, method_name) )

    print res
    (header, data) = zip(*res)
    print 'header', header
    print 'data', data
    return mrd.Section('Tesing Method: %s' % method_name,
                       mrd.VerticalColTable(header, [data]))


for t in tests:

    tr = TraceStringParser.Parse(t)

    sects = []
    for (method_name, method_functor) in returning_trace_methods:
        s = test_trace_method_traceout(tr, method_name, method_functor)
        sects.append(s)

    #returning_quantities = [
    #('mean', lambda tr: tr.mean()),

    for (method_name, method_functor) in returning_quantities:
        s = test_trace_method_scalarout(tr, method_name, method_functor)
        sects.append(s)

    mrd.Section('Testing: %s' % t, sects).to_pdf('~/Desktop/trace_testing.pdf')

#import pylab
#pylab.show()
Ejemplo n.º 20
0
 def _build_population_details(self, pop):
     return mrd.Section('Population: %s' % pop.pop_name,
                        self._build_population_cell_table(pop),
                        *[self.build_neuron_details(nrn) for nrn in pop])
Ejemplo n.º 21
0
 def build_singlecell_details(self):
     sub_sections = [
         self.build_neuron_details(nrn) for nrn in self.sim.cells
     ]
     return mrd.Section('Single Cell Details', *sub_sections)
Ejemplo n.º 22
0
 def _build_singlecell_overview_vclamps(self):
     return mrd.Section(
         'Voltage Clamps',
         self._build_singlecell_overview_stimtable(
             stims=self.sim.voltage_clamps))
Ejemplo n.º 23
0
 def _build_singlecell_overview_iclamps(self):
     return mrd.Section(
         'Current Clamps',
         self._build_singlecell_overview_stimtable(
             stims=self.sim.current_clamps))
Ejemplo n.º 24
0
 def _build_singlecell_overview_cells(self):
     return mrd.Section('Individual Cells',
                        self._build_cell_table(cell_list=self.sim.cells))
Ejemplo n.º 25
0
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------



""" Summarise the cells and channels that are registered to an environment
"""

import mredoc
from morphforge.stdimports import PluginMgr, CellLibrary, ChannelLibrary, MorphologyLibrary
import morphforgecontrib.stdimports as mfc
from  modelling import *
fname = '~/Desktop/morphforge_channels.pdf'

mredoc.Section('Summary',
    CellLibrary.summary_table(),
    ChannelLibrary.summary_table(),
    MorphologyLibrary.summary_table(),
    ).to_pdf(fname)

print 'Cell & Channel summary stored at: %s'%fname


Ejemplo n.º 26
0
    def build_population_complete_dot(self):
        fig_count = 0
        fig_out = '/tmp/dotimages/'
        import pydot
        graph = pydot.Dot('graphname',
                          graph_type='digraph',
                          size='7,7',
                          ratio='compress',
                          compound='true',
                          splines='true',
                          sep='0.3')

        size = '0.55'
        fontsize = '6'
        kwargs_general = {
            'fontsize': fontsize,
            'fixedsize': 'True',
            'width': size,
            'height': size,
            'fontname': 'Helvetica'
        }

        cell_size = '0.15'
        kwargs_cell = {
            'shape': 'circle',
            'fillcolor': '#80b3ffff',
            'color': '#0066ffff',
            'style': 'filled',
            'penwidth': '1',
            'width': cell_size,
            'height': cell_size
        }
        kwargs_cc = {
            'shape': 'circle',
            'style': 'filled',
            'width': '0.05',
        }

        kwargs_pop = {
            'style': 'filled',
            'color': 'lightgrey',
            'nodesep': '100'
        }
        kwargs_synpop = {'shape': 'none', 'fixedsize': 'false'}
        kwargs_synpop_img = {
            'shape': 'square',
            'labelloc': 'b',
            'scale': 'false',
            'fixedsize': 'true',
        }
        kwargs_synpop_edge = {
            'penwidth': '3',
            'color': 'green',
            'minlen': '50'
        }

        # Map Simulation objects into dot objects:
        obj2nodedict = {}
        subgraphs = []

        # Populations become subgraphs:
        for population in self.sim.neuron_populations:
            n = pydot.Cluster(population.pop_name,
                              label=population.pop_name,
                              **dict(kwargs_general.items() +
                                     kwargs_pop.items()))
            subgraphs.append(n)
            obj2nodedict[population] = n

        # Cells into Nodes
        for cell in self.sim.cells:
            n = pydot.Node(
                cell.name,
                label=cell.name if cell.population is None else '<%d>' %
                cell.index_in_pop,
                **dict(kwargs_general.items() + kwargs_cell.items()))
            obj2nodedict[cell] = n

            if cell.population:
                obj2nodedict[cell.population].add_node(n)
            else:
                graph.add_node(n)

        for sg in subgraphs:
            graph.add_subgraph(sg)
        del subgraphs

        # Synapse Populations are turned into a node, with edges from pre and
        # to the post synaptic population:
        for synpopindex, synpop in enumerate(self.sim.synapse_populations):

            synpopcluster = pydot.Cluster('SynpopCluster' +
                                          synpop.synapse_pop_name)

            # Create the connectivity graph:
            connectivity_graph_figure = build_connectivity_graph(synpop)
            fname = fig_out + '/synpop%d.png' % synpopindex
            pylab.savefig(fname, transparent=True, dpi=400, bb_inches='tight')

            n = pydot.Node(synpop.synapse_pop_name + 'im',
                           label='',
                           image=fname,
                           **dict(kwargs_general.items() +
                                  kwargs_synpop_img.items()))
            synpopcluster.add_node(n)

            label = ''
            label += synpop.synapse_pop_name
            len_prepop = len(synpop.presynaptic_population
                             ) if synpop.presynaptic_population else 1
            pc_conn = 100. * len(synpop) / (
                len_prepop * len(synpop.postsynaptic_population))
            #print pc_conn
            #pc_conn=50.
            #label+= '\\nType: %s'% (synpop.type)
            label += '\\nSynapses: %d (%d%%)' % (len(synpop), pc_conn)
            #label= synpop.synapse_pop_name
            n = pydot.Node(synpop.synapse_pop_name + 'cap',
                           label='"%s"' % label,
                           **dict(kwargs_general.items() +
                                  kwargs_synpop.items()))
            synpopcluster.add_node(n)

            obj2nodedict[synpop] = synpopcluster
            graph.add_subgraph(synpopcluster)

            # Connect to pre- and post- synaptic pops:
            post_pop = synpop.postsynaptic_population
            e = pydot.Edge(
                synpopcluster.get_name(), obj2nodedict[post_pop].get_name(),
                **dict(kwargs_general.items() + kwargs_synpop_edge.items()))
            graph.add_edge(e)

            pre_pop = synpop.presynaptic_population
            if pre_pop is not None:
                e = pydot.Edge(
                    obj2nodedict[pre_pop].get_name(), synpopcluster.get_name(),
                    **dict(kwargs_general.items() +
                           kwargs_synpop_edge.items()))
                graph.add_edge(e)
            else:
                print 'NONE'

        for (i, synapse) in enumerate(self.sim.synapses):
            if synapse.population:
                continue
            pre_cell = synapse.get_presynaptic_cell()
            post_cell = synapse.get_postsynaptic_cell()

            if not pre_cell:
                pre_n = pydot.Node(name='SpikeTimes%d' % i,
                                   shape='point',
                                   color='lightsalmon',
                                   style='filled',
                                   **kwargs_general)
                graph.add_node(pre_n)
            else:
                pre_n = obj2nodedict[pre_cell]
            post_n = obj2nodedict[post_cell]

            syn_name = '%s' % synapse.name
            e = pydot.Edge(pre_n,
                           post_n,
                           label=syn_name,
                           color='red',
                           **kwargs_general)
            graph.add_edge(e)

        stims = {}
        # Simulations:
        for cclamp in self.sim.current_clamps:
            label = '"IClamp: %s\\n %s"' % (cclamp.name,
                                            cclamp.location_summary_dot_str)
            n = pydot.Node(cclamp.name,
                           label=label,
                           **dict(kwargs_general.items() + kwargs_cc.items()))
            stims[cclamp] = n
            graph.add_node(n)

            # Make the edge:
            cell_node = obj2nodedict[cclamp.cell]
            e = pydot.Edge(n, cell_node, label='', color='red')  # **kwargs)
            graph.add_edge(e)

        ## Records:
        #records = {}
        #for record in self.sim.recordables:
        #    name = record.name
        #    # label = '"Record: %s\\n %s"' % (name, record.location_summary_dot_str )
        #    label = '"Record: %s\\n"' % name  # , record.location_summary_dot_str )
        #    n = pydot.Node(
        #        name,
        #        shape='circle',
        #        style='filled',
        #        width='0.05',
        #        fixedsize='True',
        #        label=label,
        #        fontsize=fontsize,
        #        )
        #    records[record] = n
        #    graph.add_node(n)

        #    # Make the edge:
        #    if isinstance(record, NEURONRecordableOnLocation):
        #        post_node = obj2nodedict[record.cell_location.cell]
        #        e = pydot.Edge(n, post_node, label='', color='green')
        #        graph.add_edge(e)

        #    # cell_node = obj2nodedict[record.cell_location.cell]

        graph.write_raw('example_cluster2.dot')

        # Put the stimulations on:

        #fname = _DotSummaryUtils.save_dot(graph, prog='dot')
        fname = _DotSummaryUtils.save_dot(graph, format='pdf', prog='fdp')
        #fname = _DotSummaryUtils.save_dot(graph, prog='osage')
        #fname = _DotSummaryUtils.save_dot(graph, prog='neato')
        return mrd.Section('Diagram Overview', mrd.Figure(mrd.Image(fname)))