-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (55 loc) · 2.48 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# --------------
# Author : Serge Zaugg
# Description :
# --------------
import pandas as pd
import os
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
#----------------------
# Minimalistic example. Downloads 10 files and makes 111 small spectrograms
import xco
# Make an instance of the XCO class and define the start path
xc = xco.XCO(start_path = 'C:/temp_xc_projects/proj03')
# Create a template json parameter file (to be edited)
xc.make_param(filename = 'download_criteria.json', template = "mini")
# Get information of what will be downloaded
df_records = xc.get_summary(params_json = 'download_criteria.json')
# make summaries
print(df_records.shape)
# Download the files
xc.download(df_recs = df_records)
# Convert mp3s to wav with a specific sampling rate (requires ffmpeg to be installed)
xc.mp3_to_wav(target_fs = 20000)
# Extract spectrograms of fixed-length segments and store as PNG
xc.extract_spectrograms(target_fs = 20000, segm_duration = 1.0, segm_step = 0.5, win_siz = 512, win_olap = 192, equalize = True, colormap='viridis', eps = 1e-10)
# re-load and explore meta-data
df_meta = pd.read_pickle(os.path.join(xc.start_path, 'downloaded_data_meta.pkl'))
df_meta.head()
df_meta.shape
df_meta['file_name_stub'][1]
#----------------------
# A FULL example! Downloads 897 files from passerines of northern Europe and makes 48082 small spectrograms
# Possible use case : to do real work with deep neural networks for unsupervised clustering
import xco
# Make an instance of the XCO class and define the start path
xc = xco.XCO(start_path = 'C:/temp_xc_projects/proj04')
# Check where data will be retrieved
xc.XC_API_URL
# Check where data will be written
xc.start_path
# Create a template json parameter file (to be edited)
xc.make_param(filename = 'download_n_europe.json', template = "n_europe")
# Get information of what will be downloaded
df_records = xc.get_summary(params_json = 'download_n_europe.json')
# make summary tables
print(df_records.shape)
print(df_records['full_spec_name'].value_counts())
print(df_records['cnt'].value_counts())
print(df_records['lic'].value_counts())
# Download the files
xc.download(df_recs=df_records)
# Convert mp3s to wav with a specific sampling rate (requires ffmpeg to be installed)
xc.mp3_to_wav(target_fs = 24000)
# Make spectrogram with size = 128 x 128 and 1 channel
xc.extract_spectrograms(target_fs = 24000, segm_duration = 0.5, segm_step = 0.5, win_siz = 256, win_olap = 164, equalize = True, colormap='gray')