Exemple #1
0
def load_reports(config_file):
    cfg = ConfigDict.from_json(config_file)
    reports = []
    for report_name, report in cfg.reports.items():
        if report['module'] not in ['membrane_report', 'multimeter_report']:
            continue
        report_file = report[
            'file_name'] if 'file_name' in report else '{}.h5'.format(
                report_name)
        report_file = report_file if os.path.isabs(
            report_file) else os.path.join(cfg.output_dir, report_file)
        reports.append(CompartmentReport(report_file, 'r'))

    return reports
def test_compartment_reader2():
    report = CompartmentReport(output_file, 'r', default_population='v1')
    assert (len(report.populations) == 2)
    assert ('v1' in report.populations)
    assert (np.all(np.sort(report.node_ids()) == np.arange(5)))
    assert (report.tstart() == 0.0)
    assert (report.tstop() == 100.0)
    assert (report.dt() == 0.1)
    assert (report.units() == 'mV')
    assert (report.n_elements() == 361)
    assert (report.element_pos().size == 361)
    assert (report.element_ids().size == 361)

    assert (report.data().shape == (1000, 361))
    assert (report.data(0).shape == (1000, 10))
    assert (report.data(0, time_window=(0.0, 50.0)).shape == (500, 10))
    assert (np.all(np.unique(report.data(0)) == [0.0]))

    assert (report.data(1).shape == (1000, 50))
    assert (np.all(np.unique(report.data(1)) == [1.0]))

    assert (report.data(2).shape == (1000, 100))
    assert (np.all(np.unique(report.data(2)) == [2.0]))

    assert (report.data(3).shape == (1000, 1))
    assert (np.all(np.unique(report.data(3)) == [3.0]))

    assert (report.data(4).shape == (1000, 200))
    assert (np.all(np.unique(report.data(4)) == [4.0]))

    # Check v2 population
    assert ('v2' in report.populations)
    assert (np.all(np.sort(report.node_ids(population='v2')) == np.arange(2)))
    assert (report.tstart(population='v2') == 0.0)
    assert (report.tstop(population='v2') == 100.0)
    assert (report.dt(population='v2') == 0.1)
    assert (report.units(population='v2') == 'mV')
    assert (report.n_elements(population='v2') == 150)
    assert (report.element_pos(population='v2').size == 150)
    assert (report.element_ids(population='v2').size == 150)

    assert (report.data(population='v2').shape == (1000, 150))
    assert (report.data(0, population='v2').shape == (1000, 100))
    assert (report.data(0, population='v2',
                        time_window=(0.0, 50.0)).shape == (500, 100))
    assert (np.all(np.unique(report.data(0, population='v2')) == [0.0]))

    assert (report.data(1, population='v2').shape == (1000, 50))
    assert (np.all(np.unique(report.data(1, population='v2')) == [1.0]))
def test_block_record():
    cells = [(0, 10), (1, 50), (2, 100), (3, 1), (4, 200)]
    total_elements = sum(n_elements for _, n_elements in cells)
    rank_cells = [c for c in cells[rank::nhosts]]
    output_file = os.path.join(cpath, 'output/multi_compartment_report.h5')
    population = 'cortical'

    cr = CompartmentReport(output_file,
                           mode='w',
                           default_population=population,
                           tstart=0.0,
                           tstop=100.0,
                           dt=0.1,
                           variable='mebrane_potential',
                           units='mV')
    for node_id, n_elements in rank_cells:
        cr.add_cell(node_id=node_id,
                    element_ids=np.arange(n_elements),
                    element_pos=np.zeros(n_elements))

    for node_id, n_elements in rank_cells:
        cr.record_cell_block(node_id,
                             np.full((1000, n_elements),
                                     fill_value=node_id + 1),
                             beg_step=0,
                             end_step=1000)

    cr.close()

    if rank == 0:
        report_h5 = h5py.File(output_file, 'r')
        report_grp = report_h5['/report/{}'.format(population)]
        assert ('data' in report_grp)
        data_ds = report_grp['data'][()]
        assert (report_grp['data'].shape == (1000, total_elements))
        assert (np.isreal(data_ds.dtype))

        assert ('mapping' in report_grp)
        mapping_grp = report_grp['mapping']
        assert (mapping_grp['element_ids'].size == total_elements)
        assert (mapping_grp['element_pos'].size == total_elements)
        assert (mapping_grp['index_pointer'].size == 6)
        assert (np.all(np.sort(mapping_grp['node_ids'][()]) == np.arange(5)))
        assert (np.allclose(mapping_grp['time'][()], [0.0, 100.0, 0.1]))

        os.remove(output_file)
    barrier()
def test_custom_columns():
    cells = [(0, 10), (1, 50), (2, 100), (3, 1), (4, 200)]
    total_elements = sum(n_elements for _, n_elements in cells)
    rank_cells = [c for c in cells[rank::nhosts]]
    output_file = os.path.join(cpath, 'output/multi_compartment_report.h5')
    population = 'cortical'

    cr = CompartmentReport(output_file,
                           mode='w',
                           default_population=population,
                           tstart=0.0,
                           tstop=100.0,
                           dt=0.1,
                           variable='mebrane_potential',
                           units='mV')
    for node_id, n_elements in rank_cells:
        cr.add_cell(node_id=node_id,
                    element_ids=np.arange(n_elements),
                    element_pos=np.zeros(n_elements),
                    synapses=[node_id * 2] * n_elements)

    for i in range(1000):
        for node_id, n_elements in rank_cells:
            cr.record_cell(node_id, [node_id + i / 1000.0] * n_elements,
                           tstep=i)
    cr.close()

    if rank == 0:
        report_h5 = h5py.File(output_file, 'r')
        report_grp = report_h5['/report/{}'.format(population)]
        assert ('mapping' in report_grp)
        mapping_grp = report_grp['mapping']
        assert (mapping_grp['element_ids'].size == total_elements)
        assert (mapping_grp['element_pos'].size == total_elements)
        assert (mapping_grp['index_pointer'].size == 6)
        assert (np.all(np.sort(mapping_grp['node_ids'][()]) == np.arange(5)))
        assert (np.allclose(mapping_grp['time'][()], [0.0, 100.0, 0.1]))

        assert ('synapses' in mapping_grp.keys())
        assert (mapping_grp['synapses'][()].size == total_elements)
        os.remove(output_file)
    barrier()
Exemple #5
0
            def get_var_recorder(node_recording_df):
                if self._var_recorder is None:
                    self._var_recorder = CompartmentReport(
                        self._file_name,
                        mode='w',
                        variable=self._variable_name[0],
                        default_population=self._population,
                        tstart=node_recording_df['time'].min(),
                        tstop=node_recording_df['time'].max(),
                        dt=self._interval,
                        n_steps=len(node_recording_df),
                        mpi_size=1)
                    if self._to_h5 and MPI_RANK == 0:
                        for gid in self._gids:
                            self._var_recorder.add_cell(
                                gid,
                                element_ids=[0],
                                element_pos=[0.0],
                                population=self._population)

                    self._var_recorder.initialize()

                return self._var_recorder
def build_file():
    rank_cells = [(0, 10, 'v1'), (1, 50, 'v1'), (2, 100, 'v1'), (3, 1, 'v1'),
                  (4, 200, 'v1'), (0, 100, 'v2'), (1, 50, 'v2')]
    cr = CompartmentReport(output_file,
                           mode='w',
                           tstart=0.0,
                           tstop=100.0,
                           dt=0.1,
                           variable='Vm',
                           units='mV')
    for node_id, n_elements, pop in rank_cells:
        cr.add_cell(node_id=node_id,
                    population=pop,
                    element_ids=np.arange(n_elements),
                    element_pos=np.zeros(n_elements))

    for i in range(1000):
        for node_id, n_elements, pop in rank_cells:
            cr.record_cell(node_id,
                           population=pop,
                           vals=[node_id] * n_elements,
                           tstep=i)
    cr.close()
def test_multi_compartment_report():
    population = 'cortical'
    output_file = tempfile.mkstemp(suffix='h5')[1]
    n_elements = 50

    cr = CompartmentReport(output_file,
                           mode='w',
                           default_population=population,
                           tstart=0.0,
                           tstop=100.0,
                           dt=0.1)
    cr.add_cell(node_id=0,
                element_ids=np.arange(n_elements),
                element_pos=[0.5] * n_elements)
    cr.initialize()
    for i in range(1000):
        cr.record_cell(0, [i + j for j in range(n_elements)], tstep=i)

    cr.close()

    report_h5 = h5py.File(output_file, 'r')
    report_grp = report_h5['/report/{}'.format(population)]
    assert ('data' in report_grp)
    data_ds = report_grp['data'][()]
    assert (report_grp['data'].shape == (1000, n_elements))
    assert (np.isreal(data_ds.dtype))
    assert (data_ds[0, 0] == 0.0)
    assert (data_ds[999, n_elements - 1] == 999.0 + n_elements - 1)

    assert ('mapping' in report_grp)
    mapping_grp = report_grp['mapping']
    assert (np.allclose(mapping_grp['element_ids'][()], np.arange(n_elements)))
    assert (np.allclose(mapping_grp['element_pos'][()], [0.5] * n_elements))
    assert (mapping_grp['index_pointer'][()].size == 2)
    assert (mapping_grp['node_ids'][()] == [0])
    assert (np.allclose(mapping_grp['time'][()], [0.0, 100.0, 0.1]))
    os.remove(output_file)