Skip to content

Commit

Permalink
Merge pull request #758 from kitzeslab/issue_756_aru_package
Browse files Browse the repository at this point in the history
Issue 756 move `aru` module to separate package (`aru_metadata_parser`, `pip install aru-metadata-parser`). The separate package is now on GitHub and PyPI, and is a dependency of opensoundscape
  • Loading branch information
sammlapp authored Jun 16, 2023
2 parents a2072dd + 2c011ea commit ec76476
Show file tree
Hide file tree
Showing 9 changed files with 1,869 additions and 2,473 deletions.
4 changes: 0 additions & 4 deletions docs/api/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ Annotations
.. automodule:: opensoundscape.annotations
:members:

ARU
^^^
.. automodule:: opensoundscape.aru
:members:

Machine Learning utils
^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion opensoundscape/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from . import annotations
from . import audio
from . import aru
from . import data_selection
from . import utils
from . import localization
Expand Down
181 changes: 0 additions & 181 deletions opensoundscape/aru.py

This file was deleted.

6 changes: 3 additions & 3 deletions opensoundscape/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
import librosa
import soundfile
import IPython.display
from aru_metadata_parser.parse import parse_audiomoth_metadata
from aru_metadata_parser.utils import load_metadata

import opensoundscape
from opensoundscape.utils import generate_clip_times_df, load_metadata
from opensoundscape.aru import parse_audiomoth_metadata
from opensoundscape.utils import generate_clip_times_df
from opensoundscape.signal_processing import tdoa

DEFAULT_RESAMPLE_TYPE = "soxr_hq" # changed from kaiser_fast in v0.9.0
Expand Down Expand Up @@ -785,7 +786,6 @@ def split(self, clip_duration, clip_overlap=0, final_clip=None):
for idx, (start, end) in enumerate(
zip(clip_df["start_time"], clip_df["end_time"])
):

# Trim the clip to desired range
audio_clip = self.trim(start, end)

Expand Down
53 changes: 0 additions & 53 deletions opensoundscape/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,6 @@ def rescale_features(X, rescaling_vector=None):
return rescaled_x, rescaling_vector


def 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)
```
Args:
s (string): hexadecimal Unix epoch time string, e.g. '5F16A04E'
Returns:
datetime.datetime object representing the date and time in UTC
"""
sec = int(s, 16)
timestamp = datetime.datetime.utcfromtimestamp(sec).replace(tzinfo=pytz.utc)
return timestamp


def min_max_scale(array, feature_range=(0, 1)):
"""rescale vaues in an a array linearly to feature_range"""
bottom, top = feature_range
Expand Down Expand Up @@ -145,35 +121,6 @@ def jitter(x, width, distribution="gaussian"):
)


def load_metadata(path, raise_exceptions=False):
"""use soundfile to load metadata from WAV or AIFF file
Args:
path: file path to WAV of AIFF file
raise_exceptions: if True, raises exception,
if False returns None if exception occurs
[default: False]
Returns:
dictionary containing audio file metadata
"""

try:
with soundfile.SoundFile(path, "r") as f:
metadata = f.copy_metadata()
metadata["samplerate"] = f.samplerate
metadata["format"] = f.format
metadata["frames"] = f.frames
metadata["sections"] = f.sections
metadata["subtype"] = f.subtype
return metadata
except:
if raise_exceptions:
raise
else:
return None


def generate_clip_times_df(
full_duration,
clip_duration,
Expand Down
Loading

0 comments on commit ec76476

Please sign in to comment.