Main Classes

Acoustic Survey

class pypam.acoustic_survey.ASA(hydrophone: object, folder_path, zipped=False, include_dirs=False, p_ref=1.0, binsize=None, nfft=1.0, overlap=0, period=None, band=None, n_join_bins=1, timezone='UTC', channel=0, calibration=None, dc_subtract=False, extra_attrs=None)

Bases: object

Init a AcousticSurveyAnalysis (ASA)

Parameters
  • hydrophone (Hydrophone class from pyhydrophone) –

  • folder_path (string or Path) – Where all the sound files are

  • zipped (boolean) – Set to True if the directory is zipped

  • include_dirs (boolean) – Set to True if the folder contains other folders with sound files

  • p_ref (float) – Reference pressure in uPa

  • binsize (float) – Time window considered, in seconds. If set to None, only one value is returned

  • nfft (int) – Samples of the fft bin used for the spectral analysis

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • period (tuple or list) – Tuple or list with two elements: start and stop. Has to be a string in the format YYYY-MM-DD HH:MM:SS

  • band (tuple or list) – Tuple or list with two elements: low-cut and high-cut of the band to analyze

  • calibration (float, -1 or None) – If float, it is the time ignored a the beginning of the file. If None, nothing is done. If negative, the function calibrate from the hydrophone is performed, and the first samples ignored (and hydrophone updated)

  • dc_subtract (bool) – Set to True to subtract the dc noise (root mean squared value

  • timezone (datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None) – Timezone where the data was recorded in

apply_to_all(method_name, **kwargs)

Apply the method to all the files

Parameters
  • method_name (string) – Method name present in AcuFile

  • **kwargs – Any accepted parameter for the method_name

cut_and_place_files_period(period, folder_name, extensions=None)

Cut the files in the specified periods and store them in the right folder

Parameters
  • period (Tuple or list) – Tuple or list with (start, stop)

  • folder_name (str or Path) – Path to the location of the files to cut

  • extensions (list of strings) – the extensions that want to be moved (csv will be splitted, log will just be moved)

detect_piling_events(min_separation, max_duration, threshold, dt=None, verbose=False, detection_band=None, analysis_band=None, **kwargs)

Return a DataFrame with all the piling events and their rms, sel and peak values

Parameters
  • min_separation (float) – Minimum separation of the event, in seconds

  • max_duration (float) – Maximum duration of the event, in seconds

  • threshold (float) – Threshold above ref value which one it is considered piling, in db

  • detection_band (list or tuple) – Band used to detect the pulses [low_freq, high_freq]

  • analysis_band (list or tuple) – Band used to analyze the pulses [low_freq, high_freq]

  • dt (float) – Window size in seconds for the analysis (time resolution). Has to be smaller than min_duration!

  • verbose (boolean) – Set to True to plot the detected events per bin

detect_ship_events(min_duration, threshold)

Return a xarray DataSet with all the piling events and their rms, sel and peak values

Parameters
  • min_duration (float) – Minimum separation of the event, in seconds

  • threshold (float) – Threshold above ref value which one it is considered piling, in db

duration()

Return the duration in seconds of all the survey

evolution(method_name, band_list=None, **kwargs)

Evolution of only one param name

Parameters
  • method_name (string) – Method to compute the evolution of

  • band_list (list of tuples, tuple or None) – Bands to filter. Can be multiple bands (all of them will be analyzed) or only one band. A band is represented with a tuple as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • **kwargs (any arguments to be passed to the method) –

evolution_freq_dom(method_name, **kwargs)

Returns the evolution of frequency domain parameters :param method_name: Name of the method of the acoustic_file class to compute :type method_name: str

Returns

Return type

A xarray DataSet with a row per bin with the method name output

evolution_multiple(method_list: list, band_list=None, **kwargs)

Compute the method in each file and output the evolution Returns a xarray DataSet with datetime as index and one row for each bin of each file

Parameters
  • method_list (string) – Method name present in AcuFile

  • tuples (list of) – Bands to filter. Can be multiple bands (all of them will be analyzed) or only one band. A band is represented with a tuple as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • None (tuple or) – Bands to filter. Can be multiple bands (all of them will be analyzed) or only one band. A band is represented with a tuple as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • **kwargs – Any accepted parameter for the method_name

mean_rms(**kwargs)

Return the mean root mean squared value of the survey Accepts any other input than the correspondent method in the acoustic file. Returns the rms value of the whole survey

Parameters

**kwargs – Any accepted arguments for the rms function of the AcuFile

plot_mean_power_spectrum(db=True, save_path=None, log=True, **kwargs)

Plot the resulting mean power spectrum

Parameters
  • db (boolean) – If set to True, output in db

  • log (boolean) – If set to True, y axis in logarithmic scale

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

  • **kwargs (Any accepted for the power_spectrum method) –

plot_mean_psd(db=True, save_path=None, log=True, **kwargs)

Plot the resulting mean psd

Parameters
  • db (boolean) – If set to True, output in db

  • log (boolean) – If set to True, y axis in logarithmic scale

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

  • **kwargs (Any accepted for the psd method) –

plot_power_ltsa(db=True, save_path=None, **kwargs)

Plot the evolution of the power frequency distribution (Long Term Spectrogram Analysis)

Parameters
  • db (boolean) – If set to True, output in db

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

  • **kwargs (Any accepted for the power spectrum method) –

plot_psd_ltsa(db=True, save_path=None, **kwargs)

Plot the evolution of the psd power spectrum density (Long Term Spectrogram Analysis)

Parameters
  • db (boolean) – If set to True, output in db

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

  • **kwargs (Any accepted for the psd method) –

plot_rms_daily_patterns(db=True, save_path=None)

Plot the daily rms patterns

Parameters
  • db (boolean) – If set to True, output in db

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

plot_rms_evolution(db=True, save_path=None)

Plot the rms evolution

Parameters
  • db (boolean) – If set to True, output in db

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

plot_spd(db=True, log=True, save_path=None, **kwargs)

Plot the the SPD graph

Parameters
  • db (boolean) – If set to True, output in db

  • log (boolean) – If set to True, y axis in logarithmic scale

  • save_path (string or Path) – Where to save the output graph. If None, it is not saved

  • **kwargs (Any accepted for the spd method) –

save(file_path)

Save the ASA with all the computed values

source_separation(window_time=1.0, n_sources=15, save_path=None, verbose=False)

Separate the signal in n_sources sources, using non negative matrix factorization :param window_time: Duration of the window in seconds :type window_time: float :param n_sources: Number of sources to separate the sound in :type n_sources: int :param save_path: Where to save the output :type save_path: str or Path :param verbose: Set to True to make plots of the process :type verbose: bool

spd(db=True, h=0.1, percentiles=None, min_val=None, max_val=None)

Return the empirical power density.

Parameters
  • db (boolean) – If set to True the result will be given in db. Otherwise in uPa^2

  • h (float) – Histogram bin (in the correspondent units, uPa or db)

  • percentiles (list) – All the percentiles that have to be returned. If set to None, no percentiles is returned

  • min_val (float) – Minimum value to compute the SPD histogram

  • max_val (float) – Maximum value to compute the SPD histogram

Returns

  • percentiles (array like) – List of the percentiles calculated

  • p (numpy matrix) – Matrix with all the probabilities

start_end_timestamp()

Return the start and the end timestamps

timestamps_array()

Return an xarray DataSet with the timestamps of each bin.

class pypam.acoustic_survey.AcousticFolder(folder_path, zipped=False, include_dirs=False, extensions=None)

Bases: object

Class to help through the iterations of the acoustic folder.

pypam.acoustic_survey.move_file(file_path, new_folder_path)

Move the file to the new folder

Parameters
  • file_path (string or Path) – Original file path

  • new_folder_path (string or Path) – New folder destination (without the file name)

Acoustic File

class pypam.acoustic_file.AcuFile(sfile, hydrophone, p_ref, timezone='UTC', channel=0, calibration=None, dc_subtract=False)

Bases: object

Data recorded in a wav file.

Parameters
  • sfile (Sound file) – Can be a path or an file object

  • hydrophone (Object for the class hydrophone) –

  • p_ref (Float) – Reference pressure in upa

  • timezone (datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None) – Timezone where the data was recorded in

  • channel (int) – Channel to perform the calculations in

  • calibration (float, -1 or None) – If float, it is the time ignored a the beginning of the file. If None, nothing is done. If negative, the function calibrate from the hydrophone is performed, and the first samples ignored (and hydrophone updated)

  • dc_subtract (bool) – Set to True to subtract the dc noise (root mean squared value

aci(binsize=None, overlap=0, nfft=1024)

Calculation of root mean squared value (rms) of the signal in upa for each bin Returns Dataframe with ‘datetime’ as index and ‘rms’ value as a column

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • nfft (int) – Window size for processing

contains_date(date)

Return True if data is included in the file

Parameters

date (datetime object) – Datetime to check

cumulative_dynamic_range(binsize=None, overlap=0, db=True)

Compute the cumulative dynamic range for each bin

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • db (bool) – If set to True the result will be given in db, otherwise in upa^2

Returns

Return type

DataFrame with an extra column with the cumulative sum of dynamic range of each bin

db2upa(db=None)

Compute the upa from the db signals. If db is None, it will read the whole file.

Parameters

db (ndarray) – Signal in db

detect_piling_events(min_separation, max_duration, threshold, dt, binsize=None, verbose=False, save_path=None, detection_band=None, analysis_band=None, method=None)

Detect piling events

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • min_separation (float) – Minimum separation of the event, in seconds

  • max_duration (float) – Maximum duration of the event, in seconds

  • threshold (float) – Threshold above ref value which one it is considered piling, in db

  • dt (float) – Window size in seconds for the analysis (time resolution). Has to be smaller than min_duration!

  • verbose (bool) – Set to True to get plots of the detections

  • save_path (Path or str) – Path where to save the images of the detections

  • detection_band (list or tuple) – Band used to detect the pulses [low_freq, high_freq]

  • analysis_band (list or tuple) – Band used to analyze the pulses [low_freq, high_freq]

  • method (str) – Method to use for the detection. Can be ‘snr’, ‘dt’ or ‘envelope’

detect_ship_events(binsize=None, threshold=160.0, min_duration=10.0, detector=None, verbose=False)

Find the loud events of the file :param binsize: Time window considered, in seconds. If set to None, only one value is returned :type binsize: float :param threshold: Threshold above which it is considered loud :type threshold: float :param min_duration: Minimum duration of the event, in seconds :type min_duration: float :param detector: The detector to be used :type detector: loud_event_detector object :param verbose: Set to True to see the spectrograms of the detections :type verbose: boolean

dynamic_range(binsize=None, overlap=0, db=True)

Compute the dynamic range of each bin Returns a dataframe with datetime as index and dr as column

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • db (bool) – If set to True the result will be given in db, otherwise in upa

freq_resolution_window(freq_resolution)

Given the frequency resolution, window length needed to obtain it Returns window length in samples

Parameters

freq_resolution (int) – Must be a power of 2, in Hz

instrument()

Instrument will be the name of the hydrophone

is_in_period(period)

Return True if the WHOLE file is included in the specified period

Parameters

period (list or a tuple with (start, end)) – Values have to be a datetime object

octaves_levels(binsize=None, overlap=0, db=True, band=None, n_join_bins=1, **kwargs)

Return the octave levels :param binsize: Length in seconds of the bin to analyze :type binsize: float :param overlap: Percentage to overlap the bin windows :type overlap: float [0 to 1] :param db: Set to True if the result should be in decibels :type db: boolean :param band: List or tuple of [low_frequency, high_frequency] :type band: list or tuple :param n_join_bins: Number of bins to join on a third dimension “bin_time” :type n_join_bins: int

Returns

Return type

DataFrame with multiindex columns with levels method and band. The method is ‘3-oct’

plot_power_spectrum(db=True, log=True, save_path=None, **kwargs)

Plot the power spectrogram of all the file (units^2) re 1 V 1 upa

Parameters
  • db (boolean) – If set to True the result will be given in db. Otherwise in upa^2/Hz

  • log (boolean) – If set to True the scale of the y axis is set to logarithmic

  • save_path (string or Path) – Where to save the images

  • **kwargs (any attribute valid on power_spectrum() function) –

plot_psd(db=True, log=True, save_path=None, **kwargs)

Plot the power spectrogram density of all the file (units^2 / Hz) re 1 V 1 upa

Parameters
  • db (boolean) – If set to True the result will be given in db. Otherwise in upa^2/Hz

  • log (boolean) – If set to True the scale of the y axis is set to logarithmic

  • save_path (string or Path) – Where to save the images

  • **kwargs (any attribute valid on psd() function) –

plot_spd(db=True, log=True, save_path=None, **kwargs)

Plot the the SPD graph of the bin

Parameters
  • db (boolean) – If set to True the result will be given in db. Otherwise in upa^2/Hz

  • log (boolean) – If set to True the scale of the y axis is set to logarithmic

  • save_path (string or Path) – Where to save the images

  • **kwargs (any attribute valid on spd() function) –

plot_spectrogram(db=True, log=True, save_path=None, **kwargs)

Return the spectrogram of the signal (entire file)

Parameters
  • db (boolean) – If set to True the result will be given in db. Otherwise in upa^2/Hz

  • log (boolean) – If set to True the scale of the y axis is set to logarithmic

  • save_path (string or Path) – Where to save the images

  • **kwargs (any attribute valid on spectrogram() function) –

power_spectrum(binsize=None, overlap=0, nfft=512, db=True, percentiles=None, band=None, n_join_bins=1)

Return the power spectrum of all the file (units^2 / Hz) re 1 V 1 upa Returns a Dataframe with ‘datetime’ as index and a column for each frequency and each percentile

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • nfft (int) – Length of the fft window in samples. Power of 2.

  • db (bool) – If set to True the result will be given in db, otherwise in upa^2

  • percentiles (list) – List of all the percentiles that have to be returned. If set to empty list, no percentiles is returned

  • band (tuple or None) – Band to filter the spectrogram in. A band is represented with a tuple - or a list - as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • n_join_bins (int) – Number of bins to join on a third dimension “bin_time”

psd(binsize=None, overlap=0, nfft=512, db=True, percentiles=None, band=None, n_join_bins=1)

Return the power spectrum density (PSD) of all the file (units^2 / Hz) re 1 V 1 upa Returns a Dataframe with ‘datetime’ as index and a column for each frequency and each percentile

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • nfft (int) – Length of the fft window in samples. Power of 2.

  • db (bool) – If set to True the result will be given in db, otherwise in upa^2

  • percentiles (list) – List of all the percentiles that have to be returned. If set to empty list, no percentiles is returned

  • band (tuple or None) – Band to filter the spectrogram in. A band is represented with a tuple - or a list - as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • n_join_bins (int) – Number of bins to join on a third dimension “bin_time”

rms(binsize=None, overlap=0, db=True)

Calculation of root mean squared value (rms) of the signal in upa for each bin Returns Dataframe with ‘datetime’ as index and ‘rms’ value as a column

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • db (bool) – If set to True the result will be given in db, otherwise in upa

samples(bintime)

Return the samples according to the fs

Parameters

bintime (Float) – Seconds of bintime desired to convert to samples

samples2time(samples)

Return the samples according to the fs

Parameters

samples (Int) – Number of samples to convert to seconds

set_calibration_time(calibration_time)

Set a calibration time in seconds. This time will be ignored in the processing

Parameters

calibration_time (float) – Seconds to ignore at the beginning of the file

signal(units='wav')

Returns the signal in the specified units

Parameters

units (string) – Units in which to return the signal. Can be ‘wav’, ‘db’, ‘upa’, ‘Pa’ or ‘acc’.

source_separation(window_time=1.0, n_sources=15, binsize=None, save_path=None, verbose=False, band=None)

Perform non-negative Matrix Factorization to separate sources

Parameters
  • window_time (float) – window time to consider in seconds

  • n_sources (int) – Number of sources

  • binsize (# TODO) –

  • save_path (str or Path) – Where to save the output

  • verbose (bool) – Set to True to make plots of the process

  • band (tuple or None) – Band to filter the spectrogram in. A band is represented with a tuple - or a list - as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

spd(binsize=None, overlap=0, h=0.1, nfft=512, db=True, percentiles=None, min_val=None, max_val=None, band=None)

Return the spectral probability density.

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • h (float) – Histogram bin width (in the correspondent units, upa or db)

  • nfft (int) – Length of the fft window in samples. Power of 2.

  • db (bool) – If set to True the result will be given in db, otherwise in upa^2

  • min_val (float) – Minimum value to compute the SPD histogram

  • max_val (float) – Maximum value to compute the SPD histogram

  • percentiles (array_like) – List of all the percentiles that have to be returned. If set to empty list, no percentiles is returned

  • band (tuple or None) – Band to filter the spectrogram in. A band is represented with a tuple - or a list - as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

Returns

  • time (ndarray) – list with the starting point of each spd df

  • fbands (ndarray) – list of all the frequencies

  • percentiles (list of float) – Percentiles to compute

  • edges_list (list of float) – list of the psd values of the distribution

  • spd_list (list of ndarray) – list of dataframes with ‘frequency’ as index and a column for each psd bin and for each percentile (one df per bin)

  • p_list (list of 2d ndarray) – list of matrices with all the probabilities

spectrogram(binsize=None, overlap=0, nfft=512, scaling='density', db=True, band=None, n_join_bins=1)

Return the spectrogram of the signal (entire file)

Parameters
  • binsize (float, in sec) – Time window considered. If set to None, only one value is returned

  • overlap (float [0 to 1]) – Percentage to overlap the bin windows

  • db (bool) – If set to True the result will be given in db, otherwise in upa^2

  • nfft (int) – Length of the fft window in samples. Power of 2.

  • scaling (string) – Can be set to ‘spectrum’ or ‘density’ depending on the desired output

  • band (tuple or None) – Band to filter the spectrogram in. A band is represented with a tuple - or a list - as (low_freq, high_freq). If set to None, the broadband up to the Nyquist frequency will be analyzed

  • n_join_bins (int) – Number of bins to join on a third dimension “bin_time”

Returns

  • time (ndarray) – Array with the starting time of each bin

  • freq (ndarray) – Array with all the frequencies

  • t (ndarray) – Time array in seconds of the windows of the spectrogram

  • sxx_list (list) – Spectrogram list, one for each bin

split(date)

Save two different files out of one splitting on the specified date

Parameters

date (datetime object) – Datetime where to split the file

third_octaves_levels(binsize=None, overlap=0, db=True, band=None, n_join_bins=1, **kwargs)

Return the octave levels :param binsize: Length in seconds of the bin to analyze :type binsize: float :param overlap: Percentage to overlap the bin windows :type overlap: float [0 to 1] :param db: Set to True if the result should be in decibels :type db: boolean :param band: List or tuple of [low_frequency, high_frequency] :type band: list or tuple :param n_join_bins: Number of bins to join on a third dimension “bin_time” :type n_join_bins: int

Returns

Return type

DataFrame with multiindex columns with levels method and band. The method is ‘3-oct’

total_time()

Return the total time in seconds of the file

upa2db(upa=None)

Compute the db from the upa signal. If upa is None, it will read the whole file.

Parameters

upa (ndarray) – Signal in upa

wav2acc(wav=None)

Convert the wav file to acceleration. If wav is None, it will read the whole file.

Parameters

wav (ndarray) – Signal in wav (-1 to 1)

wav2db(wav=None)

Compute the db from the wav signal. Consider the hydrophone sensitivity in db. If wav is None, it will read the whole file.

Parameters

wav (ndarray) – Signal in wav (-1 to 1)

wav2upa(wav=None)

Compute the pressure from the wav signal

Parameters

wav (ndarray) – Signal in wav (-1 to 1)

pypam.acoustic_file.compute_spd(psd_evolution, h=1.0, percentiles=None, max_val=None, min_val=None)

Dataset

class pypam.dataset.DataSet(summary_path, output_folder, instruments, temporal_features=None, frequency_features=None, bands_list=None, binsize=60.0, nfft=512, n_join_bins=1, overlap=0, dc_subtract=False)

Bases: object

A DataSet object is a representation of a group of acoustic deployments. It allows to calculate all the acoustic features from all the deployments and store them in a structured way in the output folder. The structure is as follows: output_folder

  • deployments : a *.nc (netcdf) file for each deployment

  • detections : files resulting of the events detections. One folder per detection type

  • img : graphs and figures - temporal_features : temporal evolution of all features per deployment - data_overview : spatial and temporal coverage, and methods used - features_analysis : ?? - spatial_features : spatial distribution of features

Parameters
  • summary_path (string or Path) – Path to the csv file where all the metadata of the deployments is

  • output_folder (string or Path) – Where to save the output files (nc) of the deployments with the processed data

  • instruments (dictionary of (name, instrument_object) entries) – A dictionary of all the instruments used in the deployments

  • temporal_features (list of strings) – A list of all the features to be calculated

  • bands_list (list of tuples) – A list of all the bands to consider (low_freq, high_freq)

  • frequency_features (list of strings) – List of all the frequency features to compute

  • binsize (float) – In seconds, duration of windows to consider

  • nfft (int) – Number of samples of window to use for frequency analysis

add_deployment_metadata(idx)
add_temporal_metadata()

Return a db with a data overview of the folder

deployments()

Iterates through all the deployments listed in the metadata file :returns: :rtype: idx, deployment_name, deployment_path per iteration

generate_deployment(idx)

Generate the deployment dataset for the index idx in the metadata file :param idx: Index of the deployment in the dataset :type idx: int

Returns

ds

Return type

xarray Dataset

join_dataset()
plot_all_features_evo()

Creates the images of the temporal evolution of all the features and saves them in the correspondent folder

plot_third_octave_bands_avg()

Plot the average third octave bands per deployment

plot_third_octave_bands_prob(h=1.0, percentiles=None)

Create a plot with the probability distribution of the levels of the third octave bands :param h: Histogram bin size (in db) :type h: float :param percentiles: Percentiles to plot (0 to 1). Default is 10, 50 and 90% ([0.1, 0.5, 0.9]) :type percentiles: list of floats

Event Detectors

Event

class pypam._event.Event(total_signal, fs, start=None, end=None)

Bases: pypam.signal.Signal

analyze()

Perform all necessary calculations for a single event

Returns

Return type

rms, sel, peak

cut(start=0, end=None)

Cut the signal :param start: :param end: :return:

sel(high_noise=False)

Compute the SEL by finding the peak of the event and then finding the first argument where the signal drops 10 or 5 db below the peak (set high_noise to True if 5 db is desired)

Parameters

high_noise (bool) – Set to True if the environment is noisy (SEL will be considered until when the signal drops 5 db below the peak)

Piling Detector

class pypam.impulse_detector.ImpulseDetector(min_separation, max_duration, detection_band, analysis_band, threshold=150, dt=None)

Bases: object

Impulse events detector

Parameters
  • min_separation (float) – Minimum separation of the event, in seconds

  • max_duration (float) – Maxium duration of the event, in seconds

  • detection_band (list) – List or tuple of (min_freq, max_freq) of the frequency band used to detect the signals

  • analysis_band (list) – List or tuple of (min_freq, max_freq) of the frequency band used to characterize the impulses

  • threshold (float) – Threshold above ref value which one it is considered piling, in db

  • dt (float) – Window size in seconds for the analysis (time resolution). Has to be smaller han min_duration!

detect_events(signal, method='dt', verbose=False, save_path=None)

Detect the events

Parameters
  • signal (np.array) – Signal to analyze

  • method (str) – Can be dt or envelope

  • verbose (bool) – Set to True to see the detection signals

  • save_path (string or Path) – Where to save the image. Set to None if it should not be saved

detect_events_dt(signal, verbose=False, save_path=None)

Detection of event times. Events are detected on the basis of the SPL time series (channel 1) The time resolution is dt

Parameters
  • signal (Signal object) – Signal to analyze

  • verbose (bool) – Set to True to see the detection signals

  • save_path (string or Path) – Where to save the image. Set to None if it should not be saved

detect_events_envelope(signal, verbose=False, save_path=None)

Detect events using the envelope approach

Parameters
  • signal (Signal object) – Signal to analyze

  • verbose (bool) – Set to True to see the detection signals

  • save_path (string or Path) – Where to save the image. Set to None if it should not be saved

detect_events_snr(signal, verbose=False, save_path=None)

Detect events using the Signal To Noise approach

Parameters
  • signal (Signal object) – Signal to analyze

  • verbose (bool) – Set to True to see the detection signals

  • save_path (string or Path) – Where to save the image. Set to None if it should not be saved

load_all_times_events(times_events, signal)

Load in a dataframe all the events and their parameters

Parameters
  • times_events (list of tuples) – Each tuple is (start, duration, end) of the event

  • signal (Signal object) – Signal where the events were detected

load_event(s, t, duration, removenoise=True)

Load the event at time t (in seconds), with supplied time before and after the event (in seconds) return an object event :param s: Signal where the event is :type s: Signal object :param t: Starting time of the event (in seconds) :type t: float :param duration: Duration of the event, in seconds :type duration: float :param removenoise: Set to True if noise calculated before and after the event can be removed from the event :type removenoise: bool

plot_all_events(signal, events_df, save_path=None)

Plot all the events in the dataframe

Parameters
  • signal (Signal object) – Signal where the events were detected

  • events_df (DataFrame) – DataFrame output of load_all_times_events

  • save_path (string or Path) – Where to save the image. Set to None if it should not be saved

class pypam.impulse_detector.PilingDetector(min_separation, max_duration, threshold, dt, detection_band=None, analysis_band=None)

Bases: pypam.impulse_detector.ImpulseDetector

pypam.impulse_detector.events_times(levels, dt, threshold, min_separation)
pypam.impulse_detector.events_times_diff(signal, fs, threshold, max_duration, min_separation)
pypam.impulse_detector.events_times_snr(signal, fs, blocksize, threshold, max_duration, min_separation)

Signal must be an envelope

Parameters
  • signal

  • fs

  • blocksize

  • threshold

  • max_duration

  • min_separation

Returns

Shipping Detector

class pypam.loud_event_detector.LoudEventDetector(min_duration, band, threshold=150)

Bases: object

detect_events(signal, verbose=False)

Detection of event times. Events are detected on the basis of the SPL time series (channel 1) The time resolution is dt

Parameters
  • signal (Signal object) – Signal to analyze

  • verbose (bool) – Set to True to plot the detection signals

static load_event(s, n_start, duration_samples)

Load the event at time t (in seconds), with supplied time before and after the event (in seconds) return an object event :param s: Signal :type s: numpy array :param n_start: Starting time of the event (in samples) :type n_start: int :param duration_samples: Duration of the event, in samples :type duration_samples: int

reset()

Reset the last detection

class pypam.loud_event_detector.ShipDetector(min_duration=100, threshold=10.0)

Bases: pypam.loud_event_detector.LoudEventDetector