Skip to content

Commit

Permalink
Added full tests coverage to array functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbsantiago committed May 9, 2024
1 parent e5b5c03 commit 3e1d1b9
Show file tree
Hide file tree
Showing 22 changed files with 2,367 additions and 120 deletions.
Binary file removed .testmondata
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/data_schemas/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ objects encountered in bioacoustic analysis. These include:

Delving into the core of acoustic analysis, we have schemas for:

- [Recordings](audio_content.md#recordins): Complete audio files.
- [Recordings](audio_content.md#recordings): Complete audio files.
- [Dataset](audio_content.md#datasets): A collection of recordings from a common
source.

Expand Down
30 changes: 30 additions & 0 deletions docs/reference/arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Arrays Module

???+ info "Additional dependencies"

To use the `soundevent.arrays` module you need to install some additional
dependencies. Make sure you have them installed by running the following
command:

```bash
pip install soundevent[audio]
```

::: soundevent.arrays
options:
members: false


::: soundevent.arrays.dimensions
options:
show_root_members_full_path: true


::: soundevent.arrays.attributes
options:
show_root_members_full_path: true


::: soundevent.arrays.operations
options:
show_root_members_full_path: true
10 changes: 5 additions & 5 deletions docs/user_guide/1_saving_and_loading.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""# Saving and Loading data
"""# Saving and Loading data.
In `soundevent`, we use the **Acoustic Objects Exchange Format** (**AOEF**) for
storing and exchanging audio objects. **AOEF** is a JSON-based format
Expand Down Expand Up @@ -88,8 +88,8 @@
# ### Loading Annotation Projects
# The [`load`][soundevent.io.load]
# function can be used to load the annotations into Python and obtain an
# [`AnnotationProject`](../../data_schemas/annotation.md#annotation_projects) object
# directly.
# [`AnnotationProject`](../../data_schemas/annotation.md#annotation_project)
# object directly.

nips4b_sample = io.load(annotation_path, type="annotation_set")
print(repr(nips4b_sample))
Expand Down Expand Up @@ -130,8 +130,8 @@
# [`save`][soundevent.io.save] and
# [`load`][soundevent.io.load] functions, respectively. The
# loading function reads the **AOEF** file and returns a
# [`ModelRun`](../../data_schemas/prediction.md#model_run) object that can be used
# for further analysis.
# [`ModelRun`](../../data_schemas/prediction.md#model_runs) object that can be
# used for further analysis.
#
# By utilizing the saving and loading functions provided by soundevent, you can
# easily manage and exchange acoustic data objects in AOEF format, promoting
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/example_dataset.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.1.0","created_on":"2023-11-27T19:53:00.688910","data":{"uuid":"b1096756-eea2-4489-9e6a-b98b559647bb","collection_type":"dataset","created_on":"2023-11-21T13:43:14.742002","recordings":[{"uuid":"89957d47-f67d-4bfe-8352-bf0fe5a8ce3e","path":"recording1.wav","duration":10.0,"channels":1,"samplerate":44100,"time_expansion":10.0,"hash":"1234567890abcdef","date":"2021-01-01","time":"21:34:56","latitude":12.345,"longitude":34.567,"tags":[0,1,2],"features":{"SNR":10.0,"ACI":0.5},"notes":[{"uuid":"2931b864-43e4-4fb1-aae1-a214dccca6e3","message":"This is a note.","created_by":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","is_issue":false,"created_on":"2023-11-21T13:43:14.742073"}],"owners":["d6eb0862-a619-4919-992c-eb3625692c13"]},{"uuid":"bd30f886-3abb-475b-aacb-c7148a4d4420","path":"recording2.wav","duration":8.0,"channels":1,"samplerate":441000,"time_expansion":10.0,"hash":"234567890abcdef1","date":"2021-01-02","time":"19:34:56","latitude":13.345,"longitude":32.567,"tags":[3,4,5],"features":{"SNR":7.0,"ACI":0.3},"notes":[{"uuid":"713b6c15-0e3d-4cc5-acc6-3f1093209a40","message":"Unsure about the species.","created_by":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","is_issue":false,"created_on":"2023-11-21T13:43:14.742147"}],"owners":["d6eb0862-a619-4919-992c-eb3625692c13"]}],"tags":[{"id":0,"key":"species","value":"Myotis myotis"},{"id":1,"key":"sex","value":"female"},{"id":2,"key":"behaviour","value":"foraging"},{"id":3,"key":"species","value":"Eptesicus serotinus"},{"id":4,"key":"sex","value":"male"},{"id":5,"key":"behaviour","value":"social calls"}],"users":[{"uuid":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","name":"John Doe"},{"uuid":"d6eb0862-a619-4919-992c-eb3625692c13","email":"[email protected]","name":"Data Collector"}],"name":"test_dataset","description":"A test dataset"}}
{"version":"1.1.0","created_on":"2024-05-05T17:07:27.856998","data":{"uuid":"b1096756-eea2-4489-9e6a-b98b559647bb","collection_type":"dataset","created_on":"2023-11-21T13:43:14.742002","recordings":[{"uuid":"89957d47-f67d-4bfe-8352-bf0fe5a8ce3e","path":"recording1.wav","duration":10.0,"channels":1,"samplerate":44100,"time_expansion":10.0,"hash":"1234567890abcdef","date":"2021-01-01","time":"21:34:56","latitude":12.345,"longitude":34.567,"tags":[0,1,2],"features":{"SNR":10.0,"ACI":0.5},"notes":[{"uuid":"2931b864-43e4-4fb1-aae1-a214dccca6e3","message":"This is a note.","created_by":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","is_issue":false,"created_on":"2023-11-21T13:43:14.742073"}],"owners":["d6eb0862-a619-4919-992c-eb3625692c13"]},{"uuid":"bd30f886-3abb-475b-aacb-c7148a4d4420","path":"recording2.wav","duration":8.0,"channels":1,"samplerate":441000,"time_expansion":10.0,"hash":"234567890abcdef1","date":"2021-01-02","time":"19:34:56","latitude":13.345,"longitude":32.567,"tags":[3,4,5],"features":{"SNR":7.0,"ACI":0.3},"notes":[{"uuid":"713b6c15-0e3d-4cc5-acc6-3f1093209a40","message":"Unsure about the species.","created_by":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","is_issue":false,"created_on":"2023-11-21T13:43:14.742147"}],"owners":["d6eb0862-a619-4919-992c-eb3625692c13"]}],"tags":[{"id":0,"key":"species","value":"Myotis myotis"},{"id":1,"key":"sex","value":"female"},{"id":2,"key":"behaviour","value":"foraging"},{"id":3,"key":"species","value":"Eptesicus serotinus"},{"id":4,"key":"sex","value":"male"},{"id":5,"key":"behaviour","value":"social calls"}],"users":[{"uuid":"04ef3927-3a3d-40df-9d6e-2cc5e21482a0","name":"John Doe"},{"uuid":"d6eb0862-a619-4919-992c-eb3625692c13","email":"[email protected]","name":"Data Collector"}],"name":"test_dataset","description":"A test dataset"}}
2 changes: 1 addition & 1 deletion docs/user_guide/nips4b_plus_sample.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.1.0","created_on":"2023-11-27T19:53:01.364978","data":{"uuid":"c18624a1-8145-4657-a3f1-b3512134ecf6","collection_type":"annotation_set","recordings":[{"uuid":"8392b0ff-293f-4d5b-bc1b-d40d2a0eb0dc","path":"train/nips4b_birds_trainfile079.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"35e120d0-1633-4864-88c9-063aca992747","path":"train/nips4b_birds_trainfile237.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"7ee23c44-1bc6-4833-8d66-14aa4a8e8634","path":"train/nips4b_birds_trainfile587.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"24eceb91-535e-42f0-80e4-8c670465bac8","path":"train/nips4b_birds_trainfile106.wav","duration":4.069297052154195,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"24dd23da-ca07-40eb-80e6-af8b6b2a75ee","path":"train/nips4b_birds_trainfile430.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"8954beed-21d0-4f20-98bd-58c14264d853","path":"train/nips4b_birds_trainfile661.wav","duration":1.3873922902494331,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"69f7bf42-087a-4d88-b312-f26688597974","path":"train/nips4b_birds_trainfile429.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"b98b5a59-3518-45e5-9306-67c522540ae1","path":"train/nips4b_birds_trainfile633.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"52e329a3-afbb-475e-938c-f70c88580723","path":"train/nips4b_birds_trainfile200.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"6eeca672-f3ec-41ca-a551-54ddec0dd1a7","path":"train/nips4b_birds_trainfile545.wav","duration":2.7921995464852607,"channels":1,"samplerate":44100,"owners":[]}],"clips":[{"uuid":"b283a71f-4aa8-4ee2-ac83-7c7d5d0af2bc","recording":"8392b0ff-293f-4d5b-bc1b-d40d2a0eb0dc","start_time":0.0,"end_time":5.00390022675737},{"uuid":"e2ec7571-bfe1-4682-8d4d-15e3e34edfc9","recording":"35e120d0-1633-4864-88c9-063aca992747","start_time":0.0,"end_time":5.00390022675737},{"uuid":"ab5bcc8f-078e-4194-97a4-763998d289fa","recording":"7ee23c44-1bc6-4833-8d66-14aa4a8e8634","start_time":0.0,"end_time":5.00390022675737},{"uuid":"dd9ad126-8b15-4121-84f5-f59dc3f85802","recording":"24eceb91-535e-42f0-80e4-8c670465bac8","start_time":0.0,"end_time":4.069297052154195},{"uuid":"0a53e14f-f51c-4ade-9567-87c2b02bd197","recording":"24dd23da-ca07-40eb-80e6-af8b6b2a75ee","start_time":0.0,"end_time":5.00390022675737},{"uuid":"ae455d97-d1fa-43a1-b179-907bee8471e6","recording":"8954beed-21d0-4f20-98bd-58c14264d853","start_time":0.0,"end_time":1.3873922902494331},{"uuid":"0b42c9e1-0289-4f03-b3cb-10859a80103e","recording":"69f7bf42-087a-4d88-b312-f26688597974","start_time":0.0,"end_time":5.00390022675737},{"uuid":"56329c3c-5beb-48ed-8a79-be4e9bd2d9ed","recording":"b98b5a59-3518-45e5-9306-67c522540ae1","start_time":0.0,"end_time":5.00390022675737},{"uuid":"57e0b23a-8663-49f3-8455-997e0f4d2b49","recording":"52e329a3-afbb-475e-938c-f70c88580723","start_time":0.0,"end_time":5.00390022675737},{"uuid":"c7b6f927-fd3b-40ac-9b25-d682eec2d3ac","recording":"6eeca672-f3ec-41ca-a551-54ddec0dd1a7","start_time":0.0,"end_time":2.7921995464852607}],"clip_annotations":[{"uuid":"0e7a786e-48e4-4424-a8da-bf080bdefd9e","clip":"b283a71f-4aa8-4ee2-ac83-7c7d5d0af2bc","created_on":"2023-11-23T20:44:32.913233"},{"uuid":"af9713a7-2bf4-45df-bdff-63d47de34d71","clip":"e2ec7571-bfe1-4682-8d4d-15e3e34edfc9","created_on":"2023-11-23T20:44:32.913255"},{"uuid":"70738dff-3c98-4838-979c-0ed073edd0ea","clip":"ab5bcc8f-078e-4194-97a4-763998d289fa","created_on":"2023-11-23T20:44:32.913264"},{"uuid":"fa0fc36e-0c1a-450f-900b-5a32df17a159","clip":"dd9ad126-8b15-4121-84f5-f59dc3f85802","created_on":"2023-11-23T20:44:32.913377"},{"uuid":"178bf156-2bab-4970-8a76-4abfdc4b31b7","clip":"0a53e14f-f51c-4ade-9567-87c2b02bd197","created_on":"2023-11-23T20:44:32.913386"},{"uuid":"dc71d06a-54d6-4fad-ac6a-205bbee7ec96","clip":"ae455d97-d1fa-43a1-b179-907bee8471e6","created_on":"2023-11-23T20:44:32.913392"},{"uuid":"b418abd6-52cc-4ef4-9725-33d3d38b7878","clip":"0b42c9e1-0289-4f03-b3cb-10859a80103e","created_on":"2023-11-23T20:44:32.913400"},{"uuid":"d18ca56f-2f13-44dd-be43-f995e4d2edb6","clip":"56329c3c-5beb-48ed-8a79-be4e9bd2d9ed","created_on":"2023-11-23T20:44:32.913415"},{"uuid":"8dfa7d26-5f8b-4f37-bf0a-c031373b22f7","clip":"57e0b23a-8663-49f3-8455-997e0f4d2b49","created_on":"2023-11-23T20:44:32.913430"},{"uuid":"ebc5e8d0-bd3e-4d01-95e0-d9a0ce337ac9","clip":"c7b6f927-fd3b-40ac-9b25-d682eec2d3ac","created_on":"2023-11-23T20:44:32.913437"}],"created_on":"2023-11-23T20:44:32.913488"}}
{"version":"1.1.0","created_on":"2024-05-05T17:07:28.277844","data":{"uuid":"c18624a1-8145-4657-a3f1-b3512134ecf6","collection_type":"annotation_set","recordings":[{"uuid":"8392b0ff-293f-4d5b-bc1b-d40d2a0eb0dc","path":"train/nips4b_birds_trainfile079.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"35e120d0-1633-4864-88c9-063aca992747","path":"train/nips4b_birds_trainfile237.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"7ee23c44-1bc6-4833-8d66-14aa4a8e8634","path":"train/nips4b_birds_trainfile587.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"24eceb91-535e-42f0-80e4-8c670465bac8","path":"train/nips4b_birds_trainfile106.wav","duration":4.069297052154195,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"24dd23da-ca07-40eb-80e6-af8b6b2a75ee","path":"train/nips4b_birds_trainfile430.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"8954beed-21d0-4f20-98bd-58c14264d853","path":"train/nips4b_birds_trainfile661.wav","duration":1.3873922902494331,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"69f7bf42-087a-4d88-b312-f26688597974","path":"train/nips4b_birds_trainfile429.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"b98b5a59-3518-45e5-9306-67c522540ae1","path":"train/nips4b_birds_trainfile633.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"52e329a3-afbb-475e-938c-f70c88580723","path":"train/nips4b_birds_trainfile200.wav","duration":5.00390022675737,"channels":1,"samplerate":44100,"owners":[]},{"uuid":"6eeca672-f3ec-41ca-a551-54ddec0dd1a7","path":"train/nips4b_birds_trainfile545.wav","duration":2.7921995464852607,"channels":1,"samplerate":44100,"owners":[]}],"clips":[{"uuid":"b283a71f-4aa8-4ee2-ac83-7c7d5d0af2bc","recording":"8392b0ff-293f-4d5b-bc1b-d40d2a0eb0dc","start_time":0.0,"end_time":5.00390022675737},{"uuid":"e2ec7571-bfe1-4682-8d4d-15e3e34edfc9","recording":"35e120d0-1633-4864-88c9-063aca992747","start_time":0.0,"end_time":5.00390022675737},{"uuid":"ab5bcc8f-078e-4194-97a4-763998d289fa","recording":"7ee23c44-1bc6-4833-8d66-14aa4a8e8634","start_time":0.0,"end_time":5.00390022675737},{"uuid":"dd9ad126-8b15-4121-84f5-f59dc3f85802","recording":"24eceb91-535e-42f0-80e4-8c670465bac8","start_time":0.0,"end_time":4.069297052154195},{"uuid":"0a53e14f-f51c-4ade-9567-87c2b02bd197","recording":"24dd23da-ca07-40eb-80e6-af8b6b2a75ee","start_time":0.0,"end_time":5.00390022675737},{"uuid":"ae455d97-d1fa-43a1-b179-907bee8471e6","recording":"8954beed-21d0-4f20-98bd-58c14264d853","start_time":0.0,"end_time":1.3873922902494331},{"uuid":"0b42c9e1-0289-4f03-b3cb-10859a80103e","recording":"69f7bf42-087a-4d88-b312-f26688597974","start_time":0.0,"end_time":5.00390022675737},{"uuid":"56329c3c-5beb-48ed-8a79-be4e9bd2d9ed","recording":"b98b5a59-3518-45e5-9306-67c522540ae1","start_time":0.0,"end_time":5.00390022675737},{"uuid":"57e0b23a-8663-49f3-8455-997e0f4d2b49","recording":"52e329a3-afbb-475e-938c-f70c88580723","start_time":0.0,"end_time":5.00390022675737},{"uuid":"c7b6f927-fd3b-40ac-9b25-d682eec2d3ac","recording":"6eeca672-f3ec-41ca-a551-54ddec0dd1a7","start_time":0.0,"end_time":2.7921995464852607}],"clip_annotations":[{"uuid":"0e7a786e-48e4-4424-a8da-bf080bdefd9e","clip":"b283a71f-4aa8-4ee2-ac83-7c7d5d0af2bc","created_on":"2023-11-23T20:44:32.913233"},{"uuid":"af9713a7-2bf4-45df-bdff-63d47de34d71","clip":"e2ec7571-bfe1-4682-8d4d-15e3e34edfc9","created_on":"2023-11-23T20:44:32.913255"},{"uuid":"70738dff-3c98-4838-979c-0ed073edd0ea","clip":"ab5bcc8f-078e-4194-97a4-763998d289fa","created_on":"2023-11-23T20:44:32.913264"},{"uuid":"fa0fc36e-0c1a-450f-900b-5a32df17a159","clip":"dd9ad126-8b15-4121-84f5-f59dc3f85802","created_on":"2023-11-23T20:44:32.913377"},{"uuid":"178bf156-2bab-4970-8a76-4abfdc4b31b7","clip":"0a53e14f-f51c-4ade-9567-87c2b02bd197","created_on":"2023-11-23T20:44:32.913386"},{"uuid":"dc71d06a-54d6-4fad-ac6a-205bbee7ec96","clip":"ae455d97-d1fa-43a1-b179-907bee8471e6","created_on":"2023-11-23T20:44:32.913392"},{"uuid":"b418abd6-52cc-4ef4-9725-33d3d38b7878","clip":"0b42c9e1-0289-4f03-b3cb-10859a80103e","created_on":"2023-11-23T20:44:32.913400"},{"uuid":"d18ca56f-2f13-44dd-be43-f995e4d2edb6","clip":"56329c3c-5beb-48ed-8a79-be4e9bd2d9ed","created_on":"2023-11-23T20:44:32.913415"},{"uuid":"8dfa7d26-5f8b-4f37-bf0a-c031373b22f7","clip":"57e0b23a-8663-49f3-8455-997e0f4d2b49","created_on":"2023-11-23T20:44:32.913430"},{"uuid":"ebc5e8d0-bd3e-4d01-95e0-d9a0ce337ac9","clip":"c7b6f927-fd3b-40ac-9b25-d682eec2d3ac","created_on":"2023-11-23T20:44:32.913437"}],"created_on":"2023-11-23T20:44:32.913488"}}
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nav:
- Reference:
- data: reference/data.md
- io: reference/io.md
- arrays: reference/arrays.md
- audio: reference/audio.md
- geometry: reference/geometry.md
- evaluation: reference/evaluation.md
Expand Down Expand Up @@ -100,6 +101,9 @@ markdown_extensions:
- pymdownx.critic
- pymdownx.keys
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.superfences:
preserve_tabs: true
custom_fences:
Expand Down
50 changes: 50 additions & 0 deletions src/soundevent/arrays/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Module for manipulation of xarray.DataArray objects.
This module provides functions for manipulating xarray.DataArray objects,
including creating range dimensions, setting dimension attributes, cropping and
extending axes, getting dimension ranges and widths, and setting values at
specific positions.
"""

from soundevent.arrays.attributes import ArrayAttrs, DimAttrs
from soundevent.arrays.dimensions import (
Dimensions,
create_frequency_dim_from_array,
create_frequency_range,
create_range_dim,
create_time_dim_from_array,
create_time_range,
estimate_dim_step,
get_dim_range,
get_dim_step,
get_dim_width,
set_dim_attrs,
)
from soundevent.arrays.operations import (
crop_dim,
extend_dim,
normalize,
set_value_at_pos,
to_db,
)

__all__ = [
"ArrayAttrs",
"DimAttrs",
"Dimensions",
"create_frequency_dim_from_array",
"create_frequency_range",
"create_range_dim",
"create_time_dim_from_array",
"create_time_range",
"crop_dim",
"estimate_dim_step",
"extend_dim",
"get_dim_range",
"get_dim_step",
"get_dim_width",
"set_dim_attrs",
"set_value_at_pos",
"normalize",
"to_db",
]
Loading

0 comments on commit 3e1d1b9

Please sign in to comment.