text
stringlengths 1
93.6k
|
---|
:param fraction: Bandwidth 'b'. Examples: 1/3-octave b=3, 1-octave b=1,
|
2/3-octave b = 3/2
|
:param limits: It is a list with the minimum and maximum frequency that
|
the array should have. Example: [12,20000]
|
:returns: Frequency array, lower edge array and upper edge array
|
:rtype: list, list, list
|
"""
|
if limits is None:
|
limits = [12, 20000]
|
# Octave ratio g (ANSI s1.11, 3.2, pg. 2)
|
g = 10 ** (3 / 10) # Or g = 2
|
# Reference frequency (ANSI s1.11, 3.4, pg. 2)
|
fr = 1000
|
# Get starting index 'x' and first center frequency
|
x = _initindex(limits[0], fr, g, fraction)
|
freq = _ratio(g, x, fraction) * fr
|
# Get each frequency until reach maximum frequency
|
freq_x = 0
|
while freq_x * _bandedge(g, fraction) < limits[1]:
|
# Increase index
|
x = x + 1
|
# New frequency
|
freq_x = _ratio(g, x, fraction) * fr
|
# Store new frequency
|
freq = np.append(freq, freq_x)
|
# Get band-edges
|
freq_d = freq / _bandedge(g, fraction)
|
freq_u = freq * _bandedge(g, fraction)
|
return freq.tolist(), freq_d.tolist(), freq_u.tolist()
|
def _initindex(f, fr, g, b):
|
if b % 2: # ODD ('x' solve from ANSI s1.11, eq. 3)
|
return np.round(
|
(b * np.log(f / fr) + 30 * np.log(g)) / np.log(g)
|
)
|
else: # EVEN ('x' solve from ANSI s1.11, eq. 4)
|
return np.round(
|
(2 * b * np.log(f / fr) + 59 * np.log(g)) / (2 * np.log(g))
|
)
|
def _ratio(g, x, b):
|
if b % 2: # ODD (ANSI s1.11, eq. 3)
|
return g ** ((x - 30) / b)
|
else: # EVEN (ANSI s1.11, eq. 4)
|
return g ** ((2 * x - 59) / (2 * b))
|
def _bandedge(g, b):
|
# Band-edge ratio (ANSI s1.11, 3.7, pg. 3)
|
return g ** (1 / (2 * b))
|
def _printwarn(msg):
|
print('*********\n' + msg + '\n*********')
|
def _downsamplingfactor(freq, fs):
|
guard = 0.10
|
factor = (np.floor((fs / (2+guard)) / np.array(freq))).astype('int')
|
for idx in range(len(factor)):
|
# Factor between 1<factor<50
|
factor[idx] = max(min(factor[idx], 50), 1)
|
return factor
|
# <FILESEP>
|
# pylint: disable=C0103, C0111, R0914
|
'''
|
Make the request to the inshorts url according to category with requests module.
|
Parse using beautiful soup and lxml to form the newsDictionary.
|
'''
|
import requests
|
from bs4 import BeautifulSoup
|
def getNews(category):
|
newsDictionary = {
|
'success': True,
|
'category': category,
|
'data': []
|
}
|
try:
|
htmlBody = requests.get('https://www.inshorts.com/en/read/' + category)
|
except requests.exceptions.RequestException as e:
|
newsDictionary['success'] = False
|
newsDictionary['errorMessage'] = str(e.message)
|
return newsDictionary
|
soup = BeautifulSoup(htmlBody.text, 'lxml')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.