Skip to content

Commit f87d4f9

Browse files
committed
major update of docstrings
1 parent d6f39b4 commit f87d4f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2164
-1856
lines changed

libfmp/b/b_annotation.py

+21-25
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def read_csv(fn, header=True, add_label=False):
1717
"""Reads a CSV file
1818
1919
Args:
20-
fn: Filename
21-
header: Boolean
22-
add_label: Add column with constant value of `add_label`
20+
fn (str): Filename
21+
header (bool): Boolean (Default value = True)
22+
add_label (bool): Add column with constant value of `add_label` (Default value = False)
2323
2424
Returns:
25-
df: Pandas DataFrame
25+
df (pd.DataFrame): Pandas DataFrame
2626
"""
2727
df = pd.read_csv(fn, sep=';', keep_default_na=False, header=0 if header else None)
2828
if add_label:
@@ -35,29 +35,27 @@ def write_csv(df, fn, header=True):
3535
"""Writes a CSV file
3636
3737
Args:
38-
df: Pandas DataFrame
39-
fn: Filename
40-
header: Boolean
38+
df (pd.DataFrame): Pandas DataFrame
39+
fn (str): Filename
40+
header (bool): Boolean (Default value = True)
4141
"""
4242
df.to_csv(fn, sep=';', index=False, quoting=2, header=header)
4343

4444

4545
def cut_audio(fn_in, fn_out, start_sec, end_sec, normalize=True, write=True, Fs=22050):
4646
"""Cuts an audio file
4747
48-
Notebook: B/B_Annotations_cut.ipynb
49-
5048
Args:
51-
fn_in: Filename and path for input audio file
52-
fn_out: Filename and path for input audio file
53-
start_sec: Start time position (in seconds) of cut
54-
end_sec: End time position (in seconds) of cut
55-
normalize: If True, then normalize audio (with max norm)
56-
write: If True, then write audio
57-
Fs: Sampling rate of audio
49+
fn_in (str): Filename and path for input audio file
50+
fn_out (str): Filename and path for input audio file
51+
start_sec (float): Start time position (in seconds) of cut
52+
end_sec (float): End time position (in seconds) of cut
53+
normalize (bool): If True, then normalize audio (with max norm) (Default value = True)
54+
write (bool): If True, then write audio (Default value = True)
55+
Fs (scalar): Sampling rate of audio (Default value = 22050)
5856
5957
Returns:
60-
x_cut: Cut audio
58+
x_cut (np.ndarray): Cut audio
6159
"""
6260
x_cut, Fs = librosa.load(fn_in, sr=Fs, offset=start_sec, duration=end_sec-start_sec)
6361
if normalize is True:
@@ -70,17 +68,15 @@ def cut_audio(fn_in, fn_out, start_sec, end_sec, normalize=True, write=True, Fs=
7068
def cut_csv_file(fn_in, fn_out, start_sec, end_sec, write=True):
7169
"""Cuts csv annotation file
7270
73-
Notebook: B/B_Annotations_cut.ipynb
74-
7571
Args:
76-
fn_in: Filename and path for input audio file
77-
fn_out: Filename and path for input audio file
78-
start_sec: Start time position (in seconds) of cut
79-
end_sec: End time position (in seconds) of cut
80-
write: If True, then write audio
72+
fn_in (str): Filename and path for input audio file
73+
fn_out (str): Filename and path for input audio file
74+
start_sec (float): Start time position (in seconds) of cut
75+
end_sec (float): End time position (in seconds) of cut
76+
write (bool): If True, then write audio (Default value = True)
8177
8278
Returns:
83-
ann_cut: Cut annotation file
79+
ann_cut (list): Cut annotation file
8480
"""
8581
df = pd.read_csv(fn_in, sep=',', keep_default_na=False, header=None)
8682
ann_cut = []

libfmp/b/b_audio.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def read_audio(path, Fs=None, mono=False):
1616
"""Reads an audio file
1717
1818
Args:
19-
path: Path to audio file
20-
Fs: Resample audio to given sampling rate. Use native sampling rate if None.
21-
mono (bool): Convert multi-channel file to mono.
19+
path (str): Path to audio file
20+
Fs (scalar): Resample audio to given sampling rate. Use native sampling rate if None. (Default value = None)
21+
mono (bool): Convert multi-channel file to mono. (Default value = False)
2222
2323
Returns:
24-
x: Waveform signal
25-
Fs: Sampling rate
24+
x (np.ndarray): Waveform signal
25+
Fs (scalar): Sampling rate
2626
"""
2727
return librosa.load(path, sr=Fs, mono=mono)
2828

@@ -31,25 +31,25 @@ def write_audio(path, x, Fs):
3131
"""Writes an audio file
3232
3333
Args:
34-
path: Path to audio file
35-
x: Waveform signal
36-
Fs: Sampling rate
34+
path (str): Path to audio file
35+
x (np.ndarray): Waveform signal
36+
Fs (scalar): Sampling rate
3737
"""
3838
sf.write(path, x, Fs)
3939

4040

4141
def audio_player_list(signals, rates, width=270, height=40, columns=None, column_align='center'):
42-
"""Generate list of audio players
42+
"""Generates list of audio players
4343
4444
Notebook: B/B_PythonAudio.ipynb
4545
4646
Args:
47-
signals: List of audio signals
48-
rates: List of sample rates
49-
width: Width of player (either number or list)
50-
height: Height of player (either number or list)
51-
columns: Column headings
52-
column_align: Left, center, right
47+
signals (list): List of audio signals
48+
rates (list): List of sample rates
49+
width (int): Width of player (either number or list) (Default value = 270)
50+
height (int): Height of player (either number or list) (Default value = 40)
51+
columns (list): Column headings (Default value = None)
52+
column_align (str): Left, center, right (Default value = 'center')
5353
"""
5454
pd.set_option('display.max_colwidth', None)
5555

libfmp/b/b_layout.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
class FloatingBox(object):
16-
"""
17-
Inspired by https://stackoverflow.com/a/49566213/2812618
16+
"""Inspired by https://stackoverflow.com/a/49566213/2812618
17+
1818
Floating box for matplotlib plots. The added figures are part of a floating box.
1919
2020
Attributes:
@@ -57,13 +57,17 @@ def add_fig(self, fig):
5757
plt.close(fig)
5858

5959
def add_html(self, html):
60+
"""Add HTML to floating box
61+
62+
Args:
63+
html: HTML string
64+
"""
6065

6166
self.html += (
6267
f'<div class="{self.class_name}">' +
6368
f'{html}' +
6469
'</div>')
6570

6671
def show(self):
67-
"""Display the accumulated HTML
68-
"""
72+
"""Display the accumulated HTML"""
6973
display(HTML(self.html))

0 commit comments

Comments
 (0)