Miscellaneous

Splitter Dataset

class opensoundscape.datasets.SplitterDataset(wavs, annotations=False, label_corrections=None, overlap=1, duration=5, output_directory='segments', include_last_segment=False, column_separator='t', species_separator='|')

A PyTorch Dataset for splitting a WAV files

Segments will be written to the output_directory

Parameters:
  • wavs – A list of WAV files to split
  • annotations – Should we search for corresponding annotations files? (default: False)
  • label_corrections – Specify a correction labels CSV file w/ column headers “raw” and “corrected” (default: None)
  • overlap – How much overlap should there be between samples (units: seconds, default: 1)
  • duration – How long should each segment be? (units: seconds, default: 5)
  • Where should segments be written? (default (output_directory) – segments/)
  • include_last_segment – Do you want to include the last segment? (default: False)
  • column_separator – What character should we use to separate columns (default: ” “)
  • species_separator – What character should we use to separate species (default: “|”)
Returns:

A list of CSV rows (separated by column_separator) containing

the source audio, segment begin time (seconds), segment end time (seconds), segment audio, and present classes separated by species_separator if annotations were requested

Return type:

output

opensoundscape.datasets.annotations_with_overlaps_with_clip(df, begin, end)

Determine if any rows overlap with current segment

Parameters:
  • df – A dataframe containing a Raven annotation file
  • begin – The begin time of the current segment (unit: seconds)
  • end – The end time of the current segment (unit: seconds)
Returns:

A dataframe of annotations which overlap with the begin/end times

Return type:

sub_df

opensoundscape.datasets.get_md5_digest(input_string)

Generate MD5 sum for a string

Parameters:input_string – An input string
Returns:A string containing the md5 hash of input string
Return type:output

Commands

opensoundscape.commands.run_command(cmd)

Run a command returning output, error

Parameters:cmd – A string containing some command
Returns:A tuple of standard out and standard error
Return type:(stdout, stderr)
opensoundscape.commands.run_command_return_code(cmd)

Run a command returning the return code

Parameters:cmd – A string containing some command
Returns:The return code of the function
Return type:return_code

Helpers

opensoundscape.helpers.binarize(x, threshold)

return a list of 0, 1 by thresholding vector x

opensoundscape.helpers.bound(x, bounds)

restrict x to a range of bounds = [min, max]

opensoundscape.helpers.file_name(path)

get file name without extension from a path

opensoundscape.helpers.hex_to_time(s)

convert a hexidecimal, Unix time string to a datetime timestamp in utc

Example usage: ``` # Get the UTC timestamp t = hex_to_time(‘5F16A04E’)

# Convert it to a desired timezone my_timezone = pytz.timezone(“US/Mountain”) t = t.astimezone(my_timezone) ```

Parameters:s (string) – hexadecimal Unix epoch time string, e.g. ‘5F16A04E’
Returns:datetime.datetime object representing the date and time in UTC
opensoundscape.helpers.isNan(x)

check for nan by equating x to itself

opensoundscape.helpers.jitter(x, width, distribution='gaussian')

Jitter (add random noise to) each value of x

Parameters:
  • x – scalar, array, or nd-array of numeric type
  • width – multiplier for random variable (stdev for ‘gaussian’ or r for ‘uniform’)
  • distribution – ‘gaussian’ (default) or ‘uniform’ if ‘gaussian’: draw jitter from gaussian with mu = 0, std = width if ‘uniform’: draw jitter from uniform on [-width, width]
Returns:

x + random jitter

Return type:

jittered_x

opensoundscape.helpers.linear_scale(array, in_range=(0, 1), out_range=(0, 255))

Translate from range in_range to out_range

Inputs:
in_range: The starting range [default: (0, 1)] out_range: The output range [default: (0, 255)]
Outputs:
new_array: A translated array
opensoundscape.helpers.min_max_scale(array, feature_range=(0, 1))

rescale vaues in an a array linearly to feature_range

opensoundscape.helpers.rescale_features(X, rescaling_vector=None)

rescale all features by dividing by the max value for each feature

optionally provide the rescaling vector (1xlen(X) np.array), so that you can rescale a new dataset consistently with an old one

returns rescaled feature set and rescaling vector

opensoundscape.helpers.run_command(cmd)

run a bash command with Popen, return response

opensoundscape.helpers.sigmoid(x)

sigmoid function