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
コード例 #2
0
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()
コード例 #3
0
# 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()



# classifier = Classifier()
# classifier.load_model(model_filename)
# classif2 = classifier.classify(measurements)

# # Plot
コード例 #4
0
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)
# graph.add_data(detecSpectro)