def test_numpy_argmax(self): # See GH#16830 data = np.arange(1, 11) s = Series(data, index=data) result = np.argmax(s) expected = np.argmax(data) assert result == expected result = s.argmax() assert result == expected msg = "the 'out' parameter is not supported" with pytest.raises(ValueError, match=msg): np.argmax(s, out=data)
def peak_frequency(self, min_frequency=0.0, max_frequency=None, column=None, run=None, label=None): """Return frequency with peak magnitude. Parameters ---------- min_frequency : float Minimum frequency to search for peak from max_frequency : float Maximum frequency to search for peak from column : str, optional Electrode to use for finding peak. If None then the mean of the magnitude across all electrodes is used. run : Index, optional Index for the run label : Index, optional Index for the label Returns ------- freq : float Peak frequency Examples -------- >>> spectrum = Spectra4D({'baseline': {'Trial 1': ... {'Cz': [1, 2, 3, 1, 2, 10, 3, 4, 1]}}}) >>> spectrum.peak_frequency() 5 """ min_frequency = max(0.0, min_frequency) if max_frequency is None: max_frequency = max(self.major_axis) indices = ((self.major_axis >= min_frequency) & (self.major_axis <= max_frequency)) if column is None and run is None and label is None: magnitudes = np.abs(self[:, :, indices, :]).values.mean( axis=(0, 1, 3)) magnitudes = Series(magnitudes, index=self.major_axis[indices]) else: magnitudes = np.abs(self[label, run, indices, column]) # TODO: Combination when some of the indices are not parameters. peak_frequency = magnitudes.argmax() return peak_frequency
def test_numpy_argmax_deprecated(self): # See GH#16830 data = np.arange(1, 11) s = Series(data, index=data) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): # The deprecation of Series.argmax also causes a deprecation # warning when calling np.argmax. This behavior is temporary # until the implementation of Series.argmax is corrected. result = np.argmax(s) assert result == 10 with tm.assert_produces_warning(FutureWarning): # argmax is aliased to idxmax result = s.argmax() assert result == 10 with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): msg = "the 'out' parameter is not supported" with pytest.raises(ValueError, match=msg): np.argmax(s, out=data)
def classify(freq,Yabs,filt,tolerance): ''' 取可疑极大值点左右两个极小值点,求出两个极小值点的均值作为这附近功率谱的基准。 ''' N=5 Yabs = np.convolve(Yabs, np.ones((N,))/N, mode='same') y = Series(Yabs ,index = freq) if filt: yFilt= y[filt[0]:filt[1]] else: yFilt = y maximum = yFilt.max() mean = yFilt.mean() threshold = 4 if compute_SNR(y, y) > threshold and maximum < 15: # Threshold maxF = y.argmax() # print("Max freq at %f" % maxF) # Inspect half frequency of max frequency with a tolerance halfMaxF = maxF/2 halfY = y[halfMaxF-tolerance:halfMaxF+tolerance] halfSNR = compute_SNR(halfY,y) doubleMaxF = maxF*2 doubleY = y[doubleMaxF-2*tolerance:doubleMaxF+2*tolerance] doubleSNR = compute_SNR(doubleY,y) if halfSNR <= threshold: if doubleSNR > threshold/2: print('Stimuli at %f' % yFilt.argmax()) else: print('SNR on double frequency too low') # print('Max freq at %f' % yFilt.argmax()) else: print('Stimuli at %f' % halfY.argmax()) else: print('SNR too low') return y
def test_numpy_argmax_deprecated(self): # See GH#16830 data = np.arange(1, 11) s = Series(data, index=data) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): # The deprecation of Series.argmax also causes a deprecation # warning when calling np.argmax. This behavior is temporary # until the implementation of Series.argmax is corrected. result = np.argmax(s) assert result == 10 with tm.assert_produces_warning(FutureWarning): # argmax is aliased to idxmax result = s.argmax() assert result == 10 with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): msg = "the 'out' parameter is not supported" with pytest.raises(ValueError, match=msg): np.argmax(s, out=data)
# longest and shortest times np.set_printoptions(threshold=175) print np.unique(in_df.PoliceDistrict) in_df.PoliceDistrict.value_counts() # Freq policeDistricts_list = np.unique(in_df.PoliceDistrict) dist_resp_times = SR(np.zeros(len(policeDistricts_list))) for i in policeDistricts_list: mask = (in_df.PoliceDistrict == i) & (response_time1 > 0) dist_resp_times[i] = response_time1[mask].mean() print 'District ', i, print_response_time('Mean', dist_resp_times[i]) print 'Longest avg. resp time ', dist_resp_times.max( ), 'for District', dist_resp_times.argmax() print 'Shortest avg. resp time ', min( dist_resp_times), 'for District', dist_resp_times.argmin() print_response_time('Difference in avg.', max(dist_resp_times) - min(dist_resp_times)) #------------------------------------------------------------------------------ # Event types that occur more often in a district print np.unique(in_df.Type_) in_df.Type_.value_counts() ## 21 has the highest freq in_df.TypeText[in_df.Type_ == '21'] ## Corresponds to 'COMPLAINT OTHER' in_df.TypeText.value_counts() tmp_df1 = in_df.groupby(['PoliceDistrict', 'Type_', 'TypeText']).size().reset_index(name='Times')