def test_SpatialTemporalReceptiveField_plot_traces(self):
        locations = [
            [2., 0.],
            [2., 1.],
            [0., 0.],
            [0., 1.],
            [2., 0.],
            [2., 1.],
            [0., 0.],
            [0., 1.],
        ]
        signs = [1, 1, 1, 1, -1, -1, -1, -1]
        traces = [
            np.array([[0., 1., 2.]]),
            np.array([[2., 1., 0.]]),
            np.array([[1., 0., 2.]]),
            np.array([[2., 0., 1.]]),
            np.array([[0., 0., 2.]]),
            np.array([[0., 0., 1.]]),
            np.array([[2., 0., 0.]]),
            np.array([[1., 0., 0.]]),
        ]
        time = [-1., 0., 1.]

        strf = sca.SpatialTemporalReceptiveField(locations=locations,
                                                 signs=signs,
                                                 traces=traces,
                                                 time=time)

        strf.plot_traces(figSize=(5, 5), yRange=[-1, 3])
        import matplotlib.pyplot as plt
        plt.show()
Example #2
0
    def test_SpatialTemporalReceptiveField_IO(self):
        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)

        # print(STRF.data)

        if os.path.isfile(self.testH5Path):
            os.remove(self.testH5Path)

        testFile = h5py.File(self.testH5Path, 'a')
        STRFGroup = testFile.create_group('spatial_temporal_receptive_field')
        STRF.to_h5_group(STRFGroup)
        testFile.close()

        h5File = h5py.File(self.testH5Path, 'r')
        STRF2 = sca.SpatialTemporalReceptiveField.from_h5_group(
            h5File['spatial_temporal_receptive_field'])
        h5File.close()

        assert (STRF2.data.altitude.equals(STRF.data.altitude))
        assert (STRF2.data.azimuth.equals(STRF.data.azimuth))
        assert (STRF2.data.sign.equals(STRF.data.sign))

        # print(STRF.data.traces)
        # print(STRF2.data.traces)

        assert (np.array_equal(
            np.array([np.array(t) for t in STRF.data.traces]),
            np.array([np.array(t) for t in STRF2.data.traces])))
Example #3
0
    def test_SpatialTemporalReceptiveField(self):
        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)

        # print(signs)
        # print(locations)
        # print(traces)
        # print(STRF.data)

        assert (STRF.data['traces'].iloc[0][0, 1] == 8)
        assert (STRF.data['sign'].loc[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)