def test_SpatialReceptiveField_reverse_locations(self): alts = [-2., -1., 0., 1., 2.] azis = [-2., -1., 0., 1., 2.] map = np.array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 1., 1., 0.], [0., 0., 1., 1., 0.], [0., 0., 0., 0., 0.]]) srf = sca.SpatialReceptiveField(mask=map, altPos=alts, aziPos=azis, sign='ON') # print(srf.get_weighted_rf_center()) assert (srf.get_weighted_rf_center() == [0.5, 0.5]) srf2 = sca.SpatialReceptiveField(mask=map, altPos=alts[::-1], aziPos=azis, sign='ON') assert (srf2.get_weighted_rf_center() == [-0.5, 0.5]) srf_f = srf.gaussian_filter(sigma=1) # print(srf_f.get_weighted_rf_center()) srf2_f = srf2.gaussian_filter(sigma=1) # print(srf2_f.get_weighted_rf_center()) assert (abs(srf_f.get_weighted_rf_center()[0] + srf2_f.get_weighted_rf_center()[0]) < 1e-10) srf_fi = srf_f.interpolate(ratio=2, method='linear') # print(srf_fi.get_weighted_mask()) # print(srf_fi.get_weighted_rf_center()) # import matplotlib.pyplot as plt # f=plt.figure() # ax=f.add_subplot(111) # srf_fi.plot_rf(plot_axis=ax, tick_spacing=1) # plt.show() srf_fit = srf_fi.threshold(thr=0.4) # print(srf_fit.get_weighted_rf_center()) assert (srf_fit.get_weighted_rf_center()[0] - 0.5 < 0.05) srf2_fi = srf2_f.interpolate(ratio=2, method='linear') # print(srf2_fi.get_weighted_mask()) # print(srf2_fi.get_weighted_rf_center()) assert (np.array_equal(srf_fi.get_weighted_mask(), srf2_fi.get_weighted_mask())) assert (abs(srf_fi.get_weighted_rf_center()[0] + srf2_fi.get_weighted_rf_center()[0]) < 1e-10)
def test_SpatialReceptiveField_interpolate(self): SRF = sca.SpatialReceptiveField(np.random.rand(5, 5), np.arange(5)[::-1], np.arange(5)) SRF_i = SRF.interpolate(5) assert (SRF_i.get_weighted_mask().shape == (20, 20))
def test_SpatialReceptiveField(self): SRF = sca.SpatialReceptiveField( np.arange(9).reshape((3, 3)), np.arange(3), np.arange(3)) assert (np.array_equal(SRF.weights, np.arange(1, 9)))
def test_SpatialReceptiveField_thresholdReceptiveField(self): SRF = sca.SpatialReceptiveField( np.arange(9).reshape((3, 3)), np.arange(3), np.arange(3)) thresholdedSRF = SRF.threshold(thr=4) assert (np.array_equal(thresholdedSRF.weights, np.arange(4, 9)))
_, rf_off_new = dt.get_rf_properties( srf=srf_off, polarity='negative', sigma=analysis_params['gaussian_filter_sigma_rf'], interpolate_rate=analysis_params[ 'interpolate_rate_rf'], z_thr_abs=analysis_params['rf_z_thr_abs'], z_thr_rel=analysis_params['rf_z_thr_rel']) else: raise ValueError rf_on_mask = rf_on_new.get_weighted_mask() rf_off_mask = rf_off_new.get_weighted_mask() rf_onoff_new = sca.SpatialReceptiveField( mask=np.max([rf_on_mask, rf_off_mask], axis=0), altPos=rf_on_new.altPos, aziPos=rf_on_new.aziPos, sign='ON_OFF', thr=analysis_params['rf_z_thr_abs']) curr_s2_grp = s2_grp.create_group(roi_row['roi_n']) rf_onoff_new.to_h5_group(curr_s2_grp) curr_s1_on_grp = s1_on_grp.create_group(roi_row['roi_n']) rf_on_new.to_h5_group(curr_s1_on_grp) curr_s1_off_grp = s1_off_grp.create_group(roi_row['roi_n']) rf_off_new.to_h5_group(curr_s1_off_grp) # positive S1 ON s1_on_df = subdf[(subdf['rf_{}_on_peak_z'.format(response_dir)] >= analysis_params['rf_z_thr_abs'])