def test_SpatialTemporalReceptiveField():
    locations = [[3.0, 4.0], [3.0, 5.0], [2.0, 4.0], [2.0, 5.0], [3.0, 4.0],
                 [3.0, 5.0], [2.0, 4.0], [2.0, 5.0]]
    signs = [1, 1, 1, 1, -1, -1, -1, -1]
    traces = [[np.arange(4)], [np.arange(1, 5)], [np.arange(2, 6)],
              [np.arange(3, 7)], [np.arange(5, 9)], [np.arange(6, 10)],
              [np.arange(7, 11)], [np.arange(8, 12)]]
    traces = [np.array(t) for t in traces]
    time = np.arange(4, 8)
    STRF = sca.SpatialTemporalReceptiveField(locations, signs, traces, time)
    assert (STRF.data['traces'][0][0][1] == 8)
    assert (STRF.data['sign'][4] == 1)
    assert (np.array_equal(STRF.get_locations()[2], np.array([3., 4., -1.])))
    newLocations = [[location[0] + 1, location[1] + 1]
                    for location in locations[0:4]]
    newSigns = [1, 1, 1, 1]
    STRF.add_traces(newLocations, newSigns, traces[0:4])
    assert (STRF.data['traces'][7][1][2] == 4)
def test_SpatialTemporalReceptiveField_IO():
    locations = [[3.0, 4.0], [3.0, 5.0], [2.0, 4.0], [2.0, 5.0], [3.0, 4.0],
                 [3.0, 5.0], [2.0, 4.0], [2.0, 5.0]]
    signs = [1, 1, 1, 1, -1, -1, -1, -1]
    traces = [[np.arange(4)], [np.arange(1, 5)], [np.arange(2, 6)],
              [np.arange(3, 7)], [np.arange(5, 9)], [np.arange(6, 10)],
              [np.arange(7, 11)], [np.arange(8, 12)]]
    time = np.arange(4, 8)

    STRF = sca.SpatialTemporalReceptiveField(locations, signs, traces, time)
    if os.path.isfile(testH5Path): os.remove(testH5Path)
    testFile = h5py.File(testH5Path)
    STRFGroup = testFile.create_group('spatial_temporal_receptive_field')
    STRF.to_h5_group(STRFGroup)
    testFile.close()

    h5File = h5py.File(testH5Path)
    STRF = sca.SpatialTemporalReceptiveField.from_h5_group(
        h5File['spatial_temporal_receptive_field'])
    h5File.close()
    assert (STRF.data['traces'][3][0][1] == 7)
Ejemplo n.º 3
0
                probe_traces.append(
                    plane_traces[:, curr_frame_start:curr_frame_end])

        plane_roi_traces.append(np.array(probe_traces))
        print('probe: {} / {}; shape: {}'.format(probe_ind + 1, len(probe_ns),
                                                 np.array(probe_traces).shape))

    # plane_roi_traces = np.array(plane_roi_traces)

    print('saving ...')
    for roi_ind in range(roi_num):

        print "roi: {} / {}".format(roi_ind + 1, roi_num)
        curr_unit_traces = [pt[:, roi_ind, :] for pt in plane_roi_traces]
        curr_unit_traces = [list(t) for t in curr_unit_traces]
        curr_strf = sca.SpatialTemporalReceptiveField(
            locations=probe_locations,
            signs=probe_signs,
            traces=curr_unit_traces,
            time=plane_t,
            # trigger_ts=trigger_ts_lst,
            trigger_ts=None,
            name='roi_{:04d}'.format(roi_ind),
            trace_data_type=trace_source)

        curr_strf_grp = plane_strf_grp.create_group(
            'strf_roi_{:04d}'.format(roi_ind))
        curr_strf.to_h5_group(curr_strf_grp)

nwb_f.close()
Ejemplo n.º 4
0
            curr_frame_end = curr_frame_start + plane_chunk_frame_dur
            if curr_frame_start >= 0 and curr_frame_end <= len(plane_trace_ts):
                probe_traces.append(
                    plane_traces[:, curr_frame_start:curr_frame_end])

        plane_roi_traces.append(np.array(probe_traces))
        print('probe: {} / {}; shape: {}'.format(probe_ind + 1, len(probe_ns),
                                                 np.array(probe_traces).shape))

    # plane_roi_traces = np.array(plane_roi_traces)

    print('saving ...')
    for roi_ind in range(roi_num):

        print "roi: {} / {}".format(roi_ind + 1, roi_num)
        curr_unit_traces = [pt[:, roi_ind, :] for pt in plane_roi_traces]
        curr_unit_traces = [list(t) for t in curr_unit_traces]
        curr_strf = sca.SpatialTemporalReceptiveField(
            probe_locations,
            probe_signs,
            curr_unit_traces,
            plane_t,
            name='roi_{:04d}'.format(roi_ind),
            trace_data_type=trace_source)

        curr_strf_grp = plane_strf_grp.create_group(
            'strf_roi_{:04d}'.format(roi_ind))
        curr_strf.to_h5_group(curr_strf_grp)

nwb_f.close()