import pandas as pd
import numpy as np

import bird_data as data

import wav_utils

from IPython.core.display import HTML

# Plot in the notebook
%pylab inline

"""
Explanation: Explore the Forest
Welcome to a forest in Provence, France. In these IPython notebooks you'll explore classifying the birds around you from audio clips of their songs and calls. The code is available on Github
The data used in this activity were provided during the NIPS4B
workshop in Nevada 2013, in the Bird challenge, organized by Bas,
Dufour and Glotin. They shall not be used for another purpose.
Publication or report using them shall cite:
Bas Y., Dufour O., Glotin H., (2013) 'NIP4B Bird Challenge Overview',
in Proc. of 'Neural Information Processing Scaled for Bioacoustics:
from Neurons to Big Data- NIP4B', Ed. Glotin et al., joint to NIPS
Conf., ISSN 979-10-90821-04-0, http://sabiod.org
End of explanation
"""


data.call_df.head(10)

"""
Explanation: Explore the data
Which calls will we try to identify?
This information is in the call dataframe. Each call has a number, which we'll often use in place of its name
End of explanation
"""


HTML(data.label_df.head(10).to_html())

"""
Explanation: How do we know the calls in a particular training audio clip?
This is in the label dataframe. Each row is a particular training audio clip, and each column is a particular label. A 1 means the call is present, 0 means it is not
End of explanation
"""


data.call_df.type.unique()

"""
Explanation: Exercises

Which calls are not made by birds?
What is a filename for an audio clip containing an insect?
End of explanation
"""


wavs = data.get_wav_dict()

"""
Explanation: What about the sound clips?
End of explanation
"""


three_call_clipnames = data.label_df.index[data.label_df.sum(axis=1)==3]

"""
Explanation: Find all the clips with three calls
End of explanation
"""


plot(wavs[three_call_clipnames[1]])

"""
Explanation: #### Plot the audio for one of these three-bird clips
End of explanation
"""


wav_utils.view_clip(three_call_clipnames[4])

"""
Explanation: That wasn't too helpful, maybe a spectrogram will be more illuminating
End of explanation
"""


wav_utils.view_clip(three_call_clipnames[1])

"""
Explanation: Much better, how about some more clips
Sounds (and looks) like there may be a stream in the background on this one
End of explanation
"""


wav_utils.view_clip(data.label_df.index[32])

"""
Explanation: Is that a car in the background?
End of explanation
"""


wav_utils.view_clip(data.label_df.index[8])

wav_utils.view_clip(data.label_df.index[31])

"""
Explanation: Uhhhhh, anyone there?
End of explanation
"""


wav_utils.view_clip(data.label_df.index[34])

"""
Explanation: That's an uncommonly interesting call, Firecrest
End of explanation
"""


