本文整理汇总了Python中numpy.log10方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.log10方法的具体用法?Python numpy.log10怎么用?Python numpy.log10使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.log10方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_audio_data
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def get_audio_data(self):
frames = self.rec.get_frames()
result = [0] * self.bins
if len(frames) > 0:
# keeps only the last frame
current_frame = frames[-1]
# plots the time signal
# self.line_top.set_data(self.time_vect, current_frame)
# computes and plots the fft signal
fft_frame = np.fft.rfft(current_frame)
if self.auto_gain:
fft_frame /= np.abs(fft_frame).max()
else:
fft_frame *= (1 + self.gain) / 5000000.
fft_frame = np.abs(fft_frame)
if self.log_scale:
fft_frame = np.log10(np.add(1, np.multiply(10, fft_frame)))
result = [min(int(max(i, 0.) * 1023), 1023) for i in fft_frame][0:self.bins]
return result
示例2: _interp_ebv
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def _interp_ebv(self, datum, dist):
"""
Calculate samples of E(B-V) at an arbitrary distance (in kpc) for one
test coordinate.
"""
dm = 5. * (np.log10(dist) + 2.)
idx_ceil = np.searchsorted(datum['DM_bin_edges'], dm)
if idx_ceil == 0:
dist_0 = 10.**(datum['DM_bin_edges'][0]/5. - 2.)
return dist/dist_0 * datum['samples'][:,0]
elif idx_ceil == len(datum['DM_bin_edges']):
return datum['samples'][:,-1]
else:
dm_ceil = datum['DM_bin_edges'][idx_ceil]
dm_floor = datum['DM_bin_edges'][idx_ceil-1]
a = (dm_ceil - dm) / (dm_ceil - dm_floor)
return (
(1.-a) * datum['samples'][:,idx_ceil]
+ a * datum['samples'][:,idx_ceil-1]
)
示例3: logSE
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def logSE(x1, x2=-1):
"""
10 * log10(e**2)
This function accepts two series of data or directly
one series with error.
**Args:**
* `x1` - first data series or error (1d array)
**Kwargs:**
* `x2` - second series (1d array) if first series was not error directly,\\
then this should be the second series
**Returns:**
* `e` - logSE of error (1d array) obtained directly from `x1`, \\
or as a difference of `x1` and `x2`. The values are in dB!
"""
e = get_valid_error(x1, x2)
return 10*np.log10(e**2)
示例4: speech_aug_scheduler
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def speech_aug_scheduler(step, s_r, s_i, s_f, peak_lr):
# Starting from 0, ramp-up to set LR and converge to 0.01*LR, w/ exp. decay
final_lr_ratio = 0.01
exp_decay_lambda = -np.log10(final_lr_ratio)/(s_f-s_i) # Approx. w/ 10-based
cur_step = step+1
if cur_step<s_r:
# Ramp-up
return peak_lr*float(cur_step)/s_r
elif cur_step<s_i:
# Hold
return peak_lr
elif cur_step<=s_f:
# Decay
return peak_lr*np.power(10,-exp_decay_lambda*(cur_step-s_i))
else:
# Converge
return peak_lr*final_lr_ratio
示例5: test_dist_sma
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def test_dist_sma(self):
"""
Test that smas outside of the range have zero probability
"""
for mod in self.allmods:
if 'dist_sma' in mod.__dict__:
with RedirectStreams(stdout=self.dev_null):
pp = mod(**self.spec)
a = np.logspace(np.log10(pp.arange[0].to('AU').value/10.),np.log10(pp.arange[1].to('AU').value*10.),100)
fa = pp.dist_sma(a)
self.assertTrue(np.all(fa[a < pp.arange[0].to('AU').value] == 0),'dist_sma high bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fa[a > pp.arange[1].to('AU').value] == 0),'dist_sma low bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fa[(a >= pp.arange[0].to('AU').value) & (a <= pp.arange[1].to('AU').value)] >= 0.),'dist_sma generates negative densities within range for %s'%mod.__name__)
示例6: test_dist_radius
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def test_dist_radius(self):
"""
Test that radii outside of the range have zero probability
"""
for mod in self.allmods:
if 'dist_radius' in mod.__dict__:
with RedirectStreams(stdout=self.dev_null):
pp = mod(**self.spec)
Rp = np.logspace(np.log10(pp.Rprange[0].to('earthRad').value/10.),np.log10(pp.Rprange[1].to('earthRad').value*100.),100)
fr = pp.dist_radius(Rp)
self.assertTrue(np.all(fr[Rp < pp.Rprange[0].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fr[Rp > pp.Rprange[1].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fr[(Rp >= pp.Rprange[0].to('earthRad').value) & (Rp <= pp.Rprange[1].to('earthRad').value)] > 0),'dist_radius generates zero probabilities within range for %s'%mod.__name__)
示例7: test_dist_mass
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def test_dist_mass(self):
"""
Test that masses outside of the range have zero probability
"""
for mod in self.allmods:
if 'dist_mass' in mod.__dict__:
with RedirectStreams(stdout=self.dev_null):
pp = mod(**self.spec)
Mp = np.logspace(np.log10(pp.Mprange[0].value/10.),np.log10(pp.Mprange[1].value*100.),100)
fr = pp.dist_mass(Mp)
self.assertTrue(np.all(fr[Mp < pp.Mprange[0].value] == 0),'dist_mass high bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fr[Mp > pp.Mprange[1].value] == 0),'dist_mass high bound failed for %s'%mod.__name__)
self.assertTrue(np.all(fr[(Mp >= pp.Mprange[0].value) & (Mp <= pp.Mprange[1].value)] > 0))
示例8: test_dist_sma_radius
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def test_dist_sma_radius(self):
"""
Test that sma and radius values outside of the range have zero probability
"""
for mod in self.allmods:
if 'dist_sma_radius' in mod.__dict__:
with RedirectStreams(stdout=self.dev_null):
pp = mod(**self.spec)
a = np.logspace(np.log10(pp.arange[0].value/10.),np.log10(pp.arange[1].value*100),100)
Rp = np.logspace(np.log10(pp.Rprange[0].value/10.),np.log10(pp.Rprange[1].value*100),100)
aa, RR = np.meshgrid(a,Rp)
fr = pp.dist_sma_radius(aa,RR)
self.assertTrue(np.all(fr[aa < pp.arange[0].value] == 0),'dist_sma_radius low bound failed on sma for %s'%mod.__name__)
self.assertTrue(np.all(fr[aa > pp.arange[1].value] == 0),'dist_sma_radius high bound failed on sma for %s'%mod.__name__)
self.assertTrue(np.all(fr[RR < pp.Rprange[0].value] == 0),'dist_sma_radius low bound failed on radius for %s'%mod.__name__)
self.assertTrue(np.all(fr[RR > pp.Rprange[1].value] == 0),'dist_sma_radius high bound failed on radius for %s'%mod.__name__)
self.assertTrue(np.all(fr[(aa > pp.arange[0].value) & (aa < pp.arange[1].value) & (RR > pp.Rprange[0].value) & (RR < pp.Rprange[1].value)] > 0),'dist_sma_radius is improper pdf for %s'%mod.__name__)
示例9: maxdmag
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def maxdmag(self, s):
"""Calculates the maximum value of dMag for projected separation
Args:
s (float):
Projected separation (AU)
Returns:
maxdmag (float):
Maximum planet delta magnitude
"""
if s == 0.0:
maxdmag = self.cdmax - 2.5*np.log10(self.Phi(np.pi))
elif s < self.rmax:
maxdmag = self.cdmax - 2.5*np.log10(np.abs(self.Phi(np.pi-np.arcsin(s/self.rmax))))
else:
maxdmag = self.cdmax - 2.5*np.log10(self.Phi(np.pi/2.0))
return maxdmag
示例10: calclogf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def calclogf(self):
"""
# wavelength dependence, from Table 19 in Leinert et al 1998
# interpolated w/ a quadratic in log-log space
Returns:
interpolant (object):
a 1D quadratic interpolant of intensity vs wavelength
"""
self.zodi_lam = np.array([0.2, 0.3, 0.4, 0.5, 0.7, 0.9, 1.0, 1.2, 2.2, 3.5,
4.8, 12, 25, 60, 100, 140]) # um
self.zodi_Blam = np.array([2.5e-8, 5.3e-7, 2.2e-6, 2.6e-6, 2.0e-6, 1.3e-6,
1.2e-6, 8.1e-7, 1.7e-7, 5.2e-8, 1.2e-7, 7.5e-7, 3.2e-7, 1.8e-8,
3.2e-9, 6.9e-10]) # W/m2/sr/um
x = np.log10(self.zodi_lam)
y = np.log10(self.zodi_Blam)
return interp1d(x, y, kind='quadratic')
示例11: deltaMag
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def deltaMag(p,Rp,d,Phi):
""" Calculates delta magnitudes for a set of planets, based on their albedo,
radius, and position with respect to host star.
Args:
p (ndarray):
Planet albedo
Rp (astropy Quantity array):
Planet radius in units of km
d (astropy Quantity array):
Planet-star distance in units of AU
Phi (ndarray):
Planet phase function
Returns:
dMag (ndarray):
Planet delta magnitudes
"""
dMag = -2.5*np.log10(p*(Rp/d).decompose()**2*Phi).value
return dMag
示例12: test_amplitude_to_decibel
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def test_amplitude_to_decibel():
"""test for backend_keras.amplitude_to_decibel"""
from kapre.backend_keras import amplitude_to_decibel
x = np.array([[1e-20, 1e-5, 1e-3, 5e-2], [0.3, 1.0, 20.5, 9999]]) # random positive numbers
amin = 1e-5
dynamic_range = 80.0
x_decibel = 10 * np.log10(np.maximum(x, amin))
x_decibel = x_decibel - np.max(x_decibel, axis=(1,), keepdims=True)
x_decibel_ref = np.maximum(x_decibel, -1 * dynamic_range)
x_var = K.variable(x)
x_decibel_kapre = amplitude_to_decibel(x_var, amin, dynamic_range)
assert np.allclose(K.eval(x_decibel_kapre), x_decibel_ref, atol=TOL)
示例13: plotstft
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def plotstft(audiopath, binsize=2**10, plotpath=None, colormap="gray", channel=0, name='tmp.png', alpha=1, offset=0):
samplerate, samples = wav.read(audiopath)
samples = samples[:, channel]
s = stft(samples, binsize)
sshow, freq = logscale_spec(s, factor=1, sr=samplerate, alpha=alpha)
sshow = sshow[2:, :]
ims = 20.*np.log10(np.abs(sshow)/10e-6) # amplitude to decibel
timebins, freqbins = np.shape(ims)
ims = np.transpose(ims)
# ims = ims[0:256, offset:offset+768] # 0-11khz, ~9s interval
ims = ims[0:256, :] # 0-11khz, ~10s interval
#print "ims.shape", ims.shape
image = Image.fromarray(ims)
image = image.convert('L')
image.save(name)
示例14: gain_Pratio
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def gain_Pratio(p1, p2):
"""
Antenna gain [dB] via power ratio.
From Rinehart (1997), Eqn 2.1
Parameters
----------
p1 : float or array
Power on the beam axis [W]
p2 : float or array
Power from an isotropic antenna [W]
Notes
-----
Ensure that both powers have the same units!
If arrays are used, either for one okay, or both must be the same length.
"""
return 10. * np.log10(np.asarray(p1) / np.asarray(p2))
示例15: zdr
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import log10 [as 别名]
def zdr(z_h, z_v):
"""
Differential reflectivity [dB].
From Rinehart (1997), Eqn 10.3 and Seliga and Bringi (1976)
Parameters
----------
z_h : float or array
Horizontal reflectivity [mm^6/m^3]
z_v : float or array
Vertical reflectivity [mm^6/m^3]
Notes
-----
Ensure that both powers have the same units!
Alternating horizontally and linearly polarized pulses are averaged.
Notes
-----
If arrays are used, either for one okay, or both must be the same length.
"""
return 10. * np.log10(np.asarray(z_h) / np.asarray(z_v))