Example #1
0
def plot_spectrogram(audio_file, loc, t1_sec, t2_sec, geometry=(1, 1, 1)):

    fmin = 0
    fmax = 1000
    frame = 0.0625
    window_type = 'hann'
    nfft = 0.0853
    step = 0.01
    channel = 0
    chunk = [t1_sec, t2_sec]

    graph_spectros = GrapherFactory('SoundPlotter',
                                    title='Spectrograms',
                                    frequency_max=fmax)
    sound = Sound(audio_file)
    sound.read(channel=channel, chunk=chunk, unit='sec', detrend=True)
    # Calculates  spectrogram
    spectro = Spectrogram(frame,
                          window_type,
                          nfft,
                          step,
                          sound.waveform_sampling_frequency,
                          unit='sec')
    spectro.compute(sound, dB=True, use_dask=False)
    # Crop unused frequencies
    spectro.crop(frequency_min=fmin, frequency_max=fmax, inplace=True)
    # Plot
    graph_spectros.add_data(spectro)

    #graph_spectros.add_annotation(loc, panel=0, color='burlywood',label='Detections')
    graph_spectros.add_annotation(loc, panel=0, color='peachpuff')

    graph_spectros.colormap = 'binary'  #'jet'
    fig, ax = graph_spectros.show()

    if ax.get_geometry() != geometry:
        ax.change_geometry(*geometry)
    return fig, ax
# for index, row in classes_encoder.iterrows():
#     pred_class = [row['label'] if i==row['ID'] else i for i in pred_class]
# # update measuremnets
# data['label_class'] = pred_class
# data['confidence'] = pred_prob
# data_fish = data[data['label_class']=='FS']
# data_noise = data[data['label_class']=='NN']
# classif_fish = copy.deepcopy(measurements)
# classif_fish.data = data_fish
# classif_noise = copy.deepcopy(measurements)
# classif_noise.data = data_noise



# # Plot
graph = GrapherFactory('SoundPlotter', title='Recording', frequency_max=5000)
# graph.add_data(sound)
# #graph.add_annotation(classif_fish, panel=0,color='red', label='Fish', tag=True)
# graph.add_data(spectro1)
# graph.add_data(spectro2)
graph.add_data(spectro2)
# graph.add_data(spectro2)
graph.add_annotation(detections, panel=0,color='red', label='Detections')
# graph.add_annotation(classif_fish, panel=4,color='red', label='Fish', tag=True)
# graph.add_annotation(classif_noise, panel=4,color='blue', label='Noise',tag=True)
# graph.colormap = 'binary'
graph.colormap = 'jet'
graph.show()


Example #3
0
# Detector
detector = DetectorFactory('BlobDetector',
                           use_dask=True,
                           dask_chunks=(2048, 2000),
                           kernel_duration=0.1,
                           kernel_bandwidth=300,
                           threshold=10,
                           duration_min=0.05,
                           bandwidth_min=40)
detections = detector.run(spectro, debug=False)

toc = time.perf_counter()
print(f"Executed in {toc - tic:0.4f} seconds")

# Plot
graph = GrapherFactory('SoundPlotter', title='Recording', frequency_max=1000)
graph.add_data(sound)
graph.add_annotation(detections, panel=0, color='grey', label='Detections')
graph.add_data(spectro)
graph.add_annotation(detections, panel=1, color='black', label='Detections')
graph.colormap = 'binary'
#graph.colormap = 'jet'
graph.show()

## To test the .crop method
#detecSpectro = spectro.crop(time_min=2,time_max=10, inplace=False)
#detecSpectro = spectro.crop(time_max=10, inplace=False)
#detecSpectro = spectro.crop(frequency_min=50, inplace=False)
#detecSpectro = spectro.crop(frequency_max=800,inplace=False)
# detecSpectro = spectro.crop(frequency_min=0,frequency_max=600,time_min=10,time_max=10.3, inplace=False)
# graph = GrapherFactory('SoundPlotter', title='Detection', frequency_max=1000)
def plot_data(audio_files,frame, window_type, nfft, step, fmin, fmax, chunk = None, detections=None, detections_channel=0):
    graph_spectros = GrapherFactory('SoundPlotter', title='Spectrograms', frequency_max=fmax)
    graph_waveforms = GrapherFactory('SoundPlotter', title='Waveforms')
    for audio_file, channel in zip(audio_files['path'], audio_files['channel'] ): # for each channel
        # load waveform
        sound = Sound(audio_file)
        sound.read(channel=channel, chunk=chunk, unit='sec', detrend=True)
        # Calculates  spectrogram
        spectro = Spectrogram(frame, window_type, nfft, step, sound.waveform_sampling_frequency, unit='sec')
        spectro.compute(sound, dB=True, use_dask=False)
        # Crop unused frequencies
        spectro.crop(frequency_min=fmin, frequency_max=fmax, inplace=True)
        # Plot
        graph_spectros.add_data(spectro, time_offset_sec=chunk[0])
        graph_waveforms.add_data(sound, time_offset_sec=chunk[0])

    graph_spectros.colormap = 'binary'
    if detections:
        graph_spectros.add_annotation(detections, panel=detections_channel, color='green',label='Detections')
        graph_waveforms.add_annotation(detections, panel=detections_channel, color='green',label='Detections')

    if chunk:
        graph_spectros.time_min = chunk[0]
        graph_spectros.time_max = chunk[1]
        graph_waveforms.time_min = chunk[0]
        graph_waveforms.time_max = chunk[1]

    graph_spectros.show()
    graph_waveforms.show()
Example #5
0
# detec.data = ovlp
# print(len(detec))

detec.filter_overlap_with(annot, 
                          freq_ovp=freq_ovp,
                          dur_factor_max=dur_factor_max,
                          dur_factor_min=dur_factor_min,
                          ovlp_ratio_min=ovlp_ratio_min,
                          remove_duplicates=remove_duplicates,
                          inherit_metadata=inherit_metadata,
                          filter_deploymentID=filter_deploymentID,
                          inplace=True
                          )
print(len(detec))    

# # detec.overlap_with(annot)
# toc = time.perf_counter()
# print(f"Executed in {toc - tic:0.4f} seconds")

# Plot
graph = GrapherFactory('SoundPlotter', title='Recording', frequency_max=1000, time_min=20, time_max=200)
graph.add_data(sound)
graph.add_annotation(detec, panel=0, color='green', label='Detections')
graph.add_data(spectro)
graph.add_annotation(annot, panel=1, color='red', label='Annotations')
graph.add_annotation(detec, panel=1, color='green', label='Detections')
graph.colormap = 'binary'
#graph.colormap = 'jet'
graph.show()