Data Structures

Classes

Hydrophone

The Hydrophone represents an acoustic recorder and its properties and functions to read its output data. Each object needs to have at least the same functions than the class Hydrophone. Some can add additional functions.

class pyhydrophone.hydrophone.Hydrophone(name, model, serial_number, sensitivity, preamp_gain, Vpp, string_format, calibration_file=None, **kwargs)

Base class Hydrophone initialization

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(date_string)

Read the name of the file and according to the hydrophone protocol get the date

Parameters:

date_string (string) – Datetime in string format

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

AMAR

class pyhydrophone.amar.AmarG3(name, model, serial_number, sensitivity, preamp_gain, Vpp, string_format='%Y%m%dT%H%M%S', calibration_file=None, **kwargs)

Init an instance of AMARG3

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

class pyhydrophone.amar.AmarG3MEMS(name, model, serial_number, hydroph_sensitivity, preamp_gain, mems_sensitivity, Vpp)

Add the MEMS specs

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • hydroph_sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • mems_sensitivity (float) – Sensitivity of the accelerometer

  • Vpp (float) – Voltage peak to peak in volts

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

B&K

class pyhydrophone.bruelkjaer.BruelKjaer(name, model, serial_number, preamp_gain, Vpp=2.0, string_format='%y%m%d%H%M%S', type_signal='ref', max_calibration_time=120.0, calibration_file=None, **kwargs)

Init an instance of B&K Nexus. Check well the Vpp in case you don’t have a reference signal! Specially of the recorder used.

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • preamp_gain (float) – Amplification selected in the Nexus in db 10*log10((V/uPa)^2)

  • Vpp (float) – Volts peak to peak

  • string_format (string) – Format of the datetime string present in the filename

  • type_signal (str) – Can be ‘ref’ or ‘test’

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

read_start_time_metadata(file_path)

Return the starting time of the file by getting the last modification minus the duration of the file

Parameters:

file_path (string or Path) – Path to the file to read the information from

Return type:

Datetime, starting moment of the file

update_calibration(ref_signal)

Update the calibration

Parameters:

ref_signal (str or Path) – File path to the reference file to update the Vpp according to the calibration tone

EARS

class pyhydrophone.ears.EARs(name, model, serial_number, sensitivity, preamp_gain, Vpp, string_format='%Y%m%d_%H%M%S', calibration_file=None, **kwargs)

Init an instance of EARs

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

MTE

class pyhydrophone.mte.MTE(name, model, serial_number, sensitivity, preamp_gain, Vpp, string_format='%y%m%d_%H%M%S', calibration_file=None, **kwargs)

Init an instance of Aural

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

RTSYS

class pyhydrophone.rtsys.RTSys(name, model, serial_number, sensitivity, preamp_gain, Vpp, mode, channel='A', string_format='%Y-%m-%d_%H-%M-%S', calibration_file=None)

Init an instance of RTSys

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • mode (string) – Can be ‘lowpower’ or ‘broadband’

  • channel (string) – Channel to process, ‘A’, ‘B’, ‘C’ or ‘D’

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path, zip_mode=False)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

compute_consumption(board_file_path)

Calculate the total energy consumption of the file

Parameters:

board_file_path (str or Path)

Return type:

Total consumption in the file

compute_consumption_total_mission(mission_folder_path)

Calculate the total energy consumption of the file

Parameters:

mission_folder_path (str or Path)

Return type:

Total consumption in the mission

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=';', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

meta_from_header(header)
one_rtsys_per_channel_from_header(file_path, zip_mode=False)
plot_consumption(board_file_path)

Plot the consumption evolution from the board_file_path

Parameters:

board_file_path (str or Path)

plot_consumption_total_mission(mission_folder_path, ax=None, show=True)
static read_header(file_path, zip_mode=False)

Return the parameters of the .wav file’s header as a dictionary

Parameters:

file_path (Path or string) – Path to the .wav file to read the header from

Returns:

extra_header

Return type:

dictionary with all the parameters of the configuration provided by RTSys

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

update_metadata(file_path, zip_mode=False)

Creates a new RTSys object from an already existing one but updating the metadata from the file header. The “mode” parameter stays the same.

Parameters:
  • file_path (str or Path) – path to the wav file recorded with RTSys with a correc header

  • zip_mode (bool) – True if file is zipped, otherwise false

SoundTrap

class pyhydrophone.soundtrap.SoundTrap(name, model, serial_number, sensitivity=None, Vpp=2, gain_type='High', string_format='%y%m%d%H%M%S', calibration_file=None, **kwargs)

Initialize a SoundTrap instance

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder. It has to match the one in the calibration file

  • sensitivity (float) – Sensitivity of the acoustic recorder in db. If None the one from the calibration file will be read

  • Vpp (float) – Value will be ignored and always 2 will be used. Kept for compatibility with other instruments in pipelines

  • gain_type (str) – ‘High’ or ‘Low’, depending on the settings of the recorder

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file Will convert the local in UTC. It assumes the localtime is the one from the computer

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

static get_xml_utc_datetime(file_path)

Get the UTC datetime from the xml file

Parameters:

file_path (str or Path)

static read_file_specs(xmlfile_path, last_gain, date_format='%Y-%m-%dT%H:%M:%S')

Read the specs of the recording from the XML file and save them to the object

Parameters:
  • xmlfile_path (string or path) – Path to the xml file

  • last_gain (str) – Last gain type. ‘High’ or ‘Low’, depending on the settings of the recorder

  • date_format (string) – Format of the datetime in the .log.xml file

test_calibration(signal)

Test the calibration of the soundtrap

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

class pyhydrophone.soundtrap.SoundTrapHF(name, model, serial_number, sensitivity=None, gain_type='High', Vpp=2, string_format='%y%m%d%H%M%S', calibration_file=None, **kwargs)

Init a SoundTrap HF reader

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder. It has to match the one in the calibration file

  • sensitivity (float) – Sensitivity of the acoustic recorder in db. If None the one from the calibration file will be read

  • gain_type (str) – ‘High’ or ‘Low’, depending on the settings of the recorder

  • Vpp (float) – Value will be ignored and always 2 will be used. Kept for compatibility with other instruments in pipelines

  • string_format (string) – Format of the datetime string present in the filename

  • calibration_file (string or Path) – File where the frequency dependent sensitivity values for the calibration are

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file Will convert the local in UTC. It assumes the localtime is the one from the computer

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

static get_xml_utc_datetime(file_path)

Get the UTC datetime from the xml file

Parameters:

file_path (str or Path)

read_HFclicks_file(wavfile_path, zip_mode=False, click_len=None)

Read all the clicks stored in a folder with soundtrap files

Parameters:
  • wavfile_path (str) – Wav file path

  • zip_mode (boolean) – Set to True if the folders are zipped

  • click_len (int) – Length of the click. Should be the sum of the parameters PREDET and POSTDET in the XML file of ST

Return type:

A DataFrame with all the clicks and a fs metadata parameter with the sampling rate

read_HFfolder(main_folder_path, zip_mode=False, include_dirs=False)

Read all the clicks in all the folders. If zip_mode is True and include_dirs is True, only the INSIDE folders can be zipped inside a non-zipped folder. If only one zip folder is to be analyzed, then set include_dirs to False.

Parameters:
  • main_folder_path (str or Path) – Folder containing all the files and/or subfolders to be extracted

  • zip_mode (boole) – Set to True if the folders are zipped

  • include_dirs (bool) – Set to True if folder needs to be analyzed recursively

Return type:

A DataFrame with all the clicks of all the folders and a fs metadata parameter with the sampling rate

static read_HFparams(xml_path)

Return the length of the clips and the time in between

Parameters:

xml_path (string or Path) – Path to the .log.xml file

Return type:

Clip length in samples (int)

static read_file_specs(xmlfile_path, last_gain, date_format='%Y-%m-%dT%H:%M:%S')

Read the specs of the recording from the XML file and save them to the object

Parameters:
  • xmlfile_path (string or path) – Path to the xml file

  • last_gain (str) – Last gain type. ‘High’ or ‘Low’, depending on the settings of the recorder

  • date_format (string) – Format of the datetime in the .log.xml file

test_calibration(signal)

Test the calibration of the soundtrap

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain

uPAM

class pyhydrophone.upam.uPam(name, model, serial_number, sensitivity, preamp_gain, Vpp, string_format='%Y%m%d_%H%M%S_%f', calibration_file=None, **kwargs)

Init an instance of Seiche

Parameters:
  • name (str) – Name of the acoustic recorder

  • model (str or int) – Model of the acoustic recorder

  • serial_number (str or int) – Serial number of the acoustic recorder

  • sensitivity (float) – Sensitivity of the acoustic recorder in db

  • preamp_gain (float) – Gain of the preamplifier in dB

  • Vpp (float) – Voltage peak to peak in volts

  • string_format (string) – Format of the datetime string present in the filename

calibrate(file_path)

Find the beginning and ending sample of the calibration tone Returns start and end points, in seconds

Parameters:

file_path (string or Path) – File where to look for the calibration (at the beginning of the file)

Return type:

end sample of the calibration (int)

change_calibration_system(cal_freq, cal_val)

Change the parameters of the calibration system (piston phone)

Parameters:
  • cal_freq (float) – Calibration frequency in Hz

  • cal_val (float) – Expected value in db

end_to_end_calibration(p_ref=1.0)

Returns the end to end calibration of the system, so it can be directly used on a wav file to obtain uPa

Parameters:

p_ref

Return type:

End to end calibration in db

freq_cal_inc(frequencies, p_ref=1.0)

Returns a dataframe with the frequency dependent values to increment from the selected frequencies you give from the data you want to increment

Parameters:
  • frequencies (1d array) – Frequencies from the data you want to increment with frequency dependent calibration

  • p_ref (float) – Reference pressure to compute db from

Returns:

df_freq_inc – Frequency dependent values to increment in your data

Return type:

pandas Dataframe

get_freq_cal(val='sensitivity', sep=',', freq_col_id=0, val_col_id=1, start_data_id=0)

Compute a dataframe with all the frequency dependent sensitivity values from the calibration file

Parameters:
  • val (str) – Can be ‘sensitivity’ or ‘end_to_end’ depending on what are the values in the calibration file

  • sep (str) – Separator between the different columns in csv or txt files

  • freq_col_id (int) – Id of the frequency column in the file (starts with 0)

  • val_col_id (int) – Id of the values column in the file (starts with 0)

  • start_data_id (int) – Id of the first line with data (without title) in the file (starts with 0)

get_name_datetime(file_name)

Get the data and time of recording from the name of the file

Parameters:

file_name (string) – File name (not path) of the file

get_new_name(filename, new_date)

Replace the datetime with the appropriate one

Parameters:
  • filename (string) – File name (not path) of the file

  • new_date (datetime object) – New datetime to be replaced in the filename

update_calibration(calibration_signal, p_ref=1.0)

Updates ONLY the parameter preamp_gain of the hydrophone with a correction factor to match expected calibration.

Parameters:
  • calibration_signal (np.array) – signal to calibrate from (already cut to ONLY calibration)

  • p_ref (float) – Reference pressure to compute db from

Return type:

Updates the parameter preamp_gain