def test_SpatialReceptiveField_interpolate():
    SRF = sca.SpatialReceptiveField(np.random.rand(5, 5),
                                    np.arange(5)[::-1], np.arange(5))
    SRF.interpolate(5)
    assert (SRF.get_weighted_mask().shape == (20, 20))
def test_SpatialReceptiveField():
    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():
    SRF = sca.SpatialReceptiveField(
        np.arange(9).reshape((3, 3)), np.arange(3), np.arange(3))
    thresholdedSRF = SRF.threshold_receptive_field(4)
    assert (np.array_equal(thresholdedSRF.weights, np.arange(4, 9)))
                                                    z_thr_rel=analysis_params['rf_z_thr_rel'])

                _, 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']) &
                     (subdf['rf_{}_off_peak_z'.format(response_dir)] < analysis_params['rf_z_thr_abs'])].reset_index()