osekit 1.1.1__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. {osekit-1.1.1 → osekit-1.2.0}/PKG-INFO +1 -1
  2. osekit-1.2.0/docs/source/_static/sample_audio/multichannel/multichannel_220925_223450.wav +0 -0
  3. osekit-1.2.0/docs/source/example_multichannel.ipynb +276 -0
  4. {osekit-1.1.1 → osekit-1.2.0}/docs/source/examples.rst +8 -0
  5. osekit-1.2.0/docs/source/multichannel.rst +46 -0
  6. {osekit-1.1.1 → osekit-1.2.0}/docs/source/usage.rst +1 -0
  7. {osekit-1.1.1 → osekit-1.2.0}/pyproject.toml +1 -1
  8. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/audio_data.py +40 -26
  9. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/audio_file.py +35 -4
  10. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/base_data.py +2 -11
  11. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/base_dataset.py +2 -8
  12. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/base_file.py +8 -5
  13. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/json_serializer.py +2 -1
  14. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/spectro_data.py +36 -10
  15. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/spectro_file.py +1 -0
  16. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/public/project.py +55 -23
  17. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/public/transform.py +3 -6
  18. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/audio.py +23 -13
  19. osekit-1.2.0/src/osekit/utils/plot.py +47 -0
  20. osekit-1.2.0/tests/helpers/audio.py +86 -0
  21. {osekit-1.1.1 → osekit-1.2.0}/tests/helpers/dummy.py +9 -2
  22. {osekit-1.1.1 → osekit-1.2.0}/tests/test_audio.py +134 -34
  23. {osekit-1.1.1 → osekit-1.2.0}/tests/test_core_api_base.py +66 -1
  24. {osekit-1.1.1 → osekit-1.2.0}/tests/test_public_api.py +162 -41
  25. {osekit-1.1.1 → osekit-1.2.0}/tests/test_serialization.py +99 -3
  26. {osekit-1.1.1 → osekit-1.2.0}/tests/test_spectro.py +59 -6
  27. {osekit-1.1.1 → osekit-1.2.0}/uv.lock +2 -20
  28. osekit-1.1.1/src/osekit/utils/plot.py +0 -40
  29. osekit-1.1.1/tests/helpers/audio.py +0 -39
  30. {osekit-1.1.1 → osekit-1.2.0}/.github/dependabot.yml +0 -0
  31. {osekit-1.1.1 → osekit-1.2.0}/.github/workflows/documentation.yml +0 -0
  32. {osekit-1.1.1 → osekit-1.2.0}/.github/workflows/github_ci.yml +0 -0
  33. {osekit-1.1.1 → osekit-1.2.0}/.github/workflows/publish.yml +0 -0
  34. {osekit-1.1.1 → osekit-1.2.0}/.gitignore +0 -0
  35. {osekit-1.1.1 → osekit-1.2.0}/.pre-commit-config.yaml +0 -0
  36. {osekit-1.1.1 → osekit-1.2.0}/CHANGELOG.md +0 -0
  37. {osekit-1.1.1 → osekit-1.2.0}/CITATION.cff +0 -0
  38. {osekit-1.1.1 → osekit-1.2.0}/CONTRIBUTING.md +0 -0
  39. {osekit-1.1.1 → osekit-1.2.0}/LICENSE +0 -0
  40. {osekit-1.1.1 → osekit-1.2.0}/README.md +0 -0
  41. {osekit-1.1.1 → osekit-1.2.0}/docs/Makefile +0 -0
  42. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osekit.png +0 -0
  43. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osekit_mid.png +0 -0
  44. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osekit_small.png +0 -0
  45. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osmose.png +0 -0
  46. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osmose_texte_sombre.png +0 -0
  47. {osekit-1.1.1 → osekit-1.2.0}/docs/logo/osmose_texte_sombre_small.png +0 -0
  48. {osekit-1.1.1 → osekit-1.2.0}/docs/make.bat +0 -0
  49. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/audio_data/ex1.svg +0 -0
  50. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/audio_data/ex2.svg +0 -0
  51. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/data_structure/file_item_data_0.svg +0 -0
  52. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/data_structure/file_item_data_1.svg +0 -0
  53. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/data_structure/file_item_data_2.svg +0 -0
  54. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/detections/aplose_results.csv +0 -0
  55. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/favicon.ico +0 -0
  56. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/ltas/ltas.gif +0 -0
  57. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1829.wav +0 -0
  58. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1830.wav +0 -0
  59. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1832.wav +0 -0
  60. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1833.wav +0 -0
  61. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1834.wav +0 -0
  62. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1835.wav +0 -0
  63. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1836.wav +0 -0
  64. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1837.wav +0 -0
  65. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/id/1838.wav +0 -0
  66. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223450.wav +0 -0
  67. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223500.wav +0 -0
  68. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223510.wav +0 -0
  69. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223520.wav +0 -0
  70. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223530.wav +0 -0
  71. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223600.wav +0 -0
  72. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223610.wav +0 -0
  73. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223620.wav +0 -0
  74. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223630.wav +0 -0
  75. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/sample_audio/timestamped/sample_220925_223640.wav +0 -0
  76. {osekit-1.1.1 → osekit-1.2.0}/docs/source/_static/spectrograms/frequency_scale.png +0 -0
  77. {osekit-1.1.1 → osekit-1.2.0}/docs/source/api.rst +0 -0
  78. {osekit-1.1.1 → osekit-1.2.0}/docs/source/aplose.rst +0 -0
  79. {osekit-1.1.1 → osekit-1.2.0}/docs/source/audiodata.rst +0 -0
  80. {osekit-1.1.1 → osekit-1.2.0}/docs/source/audiodataset.rst +0 -0
  81. {osekit-1.1.1 → osekit-1.2.0}/docs/source/audiofile.rst +0 -0
  82. {osekit-1.1.1 → osekit-1.2.0}/docs/source/audiofilemanager.rst +0 -0
  83. {osekit-1.1.1 → osekit-1.2.0}/docs/source/audioitem.rst +0 -0
  84. {osekit-1.1.1 → osekit-1.2.0}/docs/source/basedata.rst +0 -0
  85. {osekit-1.1.1 → osekit-1.2.0}/docs/source/basedataset.rst +0 -0
  86. {osekit-1.1.1 → osekit-1.2.0}/docs/source/basefile.rst +0 -0
  87. {osekit-1.1.1 → osekit-1.2.0}/docs/source/baseitem.rst +0 -0
  88. {osekit-1.1.1 → osekit-1.2.0}/docs/source/conf.py +0 -0
  89. {osekit-1.1.1 → osekit-1.2.0}/docs/source/contributing.rst +0 -0
  90. {osekit-1.1.1 → osekit-1.2.0}/docs/source/coreapi.rst +0 -0
  91. {osekit-1.1.1 → osekit-1.2.0}/docs/source/coreapi_home.rst +0 -0
  92. {osekit-1.1.1 → osekit-1.2.0}/docs/source/coreapi_introduction.rst +0 -0
  93. {osekit-1.1.1 → osekit-1.2.0}/docs/source/coreapi_usage.rst +0 -0
  94. {osekit-1.1.1 → osekit-1.2.0}/docs/source/detection.rst +0 -0
  95. {osekit-1.1.1 → osekit-1.2.0}/docs/source/event.rst +0 -0
  96. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_aplose_result.ipynb +0 -0
  97. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_ltas.rst +0 -0
  98. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_ltas_core.ipynb +0 -0
  99. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_ltas_public.ipynb +0 -0
  100. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms.rst +0 -0
  101. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms_core.ipynb +0 -0
  102. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms_id.rst +0 -0
  103. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms_id_core.ipynb +0 -0
  104. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms_id_public.ipynb +0 -0
  105. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_multiple_spectrograms_public.ipynb +0 -0
  106. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_reshaping_multiple_files.rst +0 -0
  107. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_reshaping_multiple_files_core.ipynb +0 -0
  108. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_reshaping_multiple_files_public.ipynb +0 -0
  109. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_reshaping_one_file.ipynb +0 -0
  110. {osekit-1.1.1 → osekit-1.2.0}/docs/source/example_spectrogram.ipynb +0 -0
  111. {osekit-1.1.1 → osekit-1.2.0}/docs/source/export_transform.rst +0 -0
  112. {osekit-1.1.1 → osekit-1.2.0}/docs/source/frequencyscale.rst +0 -0
  113. {osekit-1.1.1 → osekit-1.2.0}/docs/source/index.rst +0 -0
  114. {osekit-1.1.1 → osekit-1.2.0}/docs/source/installation.rst +0 -0
  115. {osekit-1.1.1 → osekit-1.2.0}/docs/source/instrument.rst +0 -0
  116. {osekit-1.1.1 → osekit-1.2.0}/docs/source/job.rst +0 -0
  117. {osekit-1.1.1 → osekit-1.2.0}/docs/source/jobs.rst +0 -0
  118. {osekit-1.1.1 → osekit-1.2.0}/docs/source/ltasdata.rst +0 -0
  119. {osekit-1.1.1 → osekit-1.2.0}/docs/source/multiprocessing.rst +0 -0
  120. {osekit-1.1.1 → osekit-1.2.0}/docs/source/normalization.rst +0 -0
  121. {osekit-1.1.1 → osekit-1.2.0}/docs/source/project.rst +0 -0
  122. {osekit-1.1.1 → osekit-1.2.0}/docs/source/publicapi.rst +0 -0
  123. {osekit-1.1.1 → osekit-1.2.0}/docs/source/publicapi_usage.rst +0 -0
  124. {osekit-1.1.1 → osekit-1.2.0}/docs/source/spectrodata.rst +0 -0
  125. {osekit-1.1.1 → osekit-1.2.0}/docs/source/spectrodataset.rst +0 -0
  126. {osekit-1.1.1 → osekit-1.2.0}/docs/source/spectrofile.rst +0 -0
  127. {osekit-1.1.1 → osekit-1.2.0}/docs/source/spectroitem.rst +0 -0
  128. {osekit-1.1.1 → osekit-1.2.0}/docs/source/transform.rst +0 -0
  129. {osekit-1.1.1 → osekit-1.2.0}/docs/source/utils.rst +0 -0
  130. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/__init__.py +0 -0
  131. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/audio_backend/audio_backend.py +0 -0
  132. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/audio_backend/audio_file_manager.py +0 -0
  133. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/audio_backend/mseed_backend.py +0 -0
  134. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/audio_backend/soundfile_backend.py +0 -0
  135. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/config.py +0 -0
  136. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/__init__.py +0 -0
  137. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/audio_dataset.py +0 -0
  138. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/audio_item.py +0 -0
  139. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/base_item.py +0 -0
  140. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/detection.py +0 -0
  141. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/event.py +0 -0
  142. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/frequency_scale.py +0 -0
  143. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/instrument.py +0 -0
  144. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/ltas_data.py +0 -0
  145. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/ltas_dataset.py +0 -0
  146. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/spectro_dataset.py +0 -0
  147. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core/spectro_item.py +0 -0
  148. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/core_api/__init__.py +0 -0
  149. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/logging_config.yaml +0 -0
  150. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/logging_context.py +0 -0
  151. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/public/__init__.py +0 -0
  152. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/public/export_transform.py +0 -0
  153. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/public_api/__init__.py +0 -0
  154. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/__init__.py +0 -0
  155. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/aplose.py +0 -0
  156. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/core.py +0 -0
  157. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/deserialization.py +0 -0
  158. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/job.py +0 -0
  159. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/multiprocess.py +0 -0
  160. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/path.py +0 -0
  161. {osekit-1.1.1 → osekit-1.2.0}/src/osekit/utils/timestamp.py +0 -0
  162. {osekit-1.1.1 → osekit-1.2.0}/tests/__init__.py +0 -0
  163. {osekit-1.1.1 → osekit-1.2.0}/tests/_static/aplose_result.csv +0 -0
  164. {osekit-1.1.1 → osekit-1.2.0}/tests/_static/minimal_detector_result.csv +0 -0
  165. {osekit-1.1.1 → osekit-1.2.0}/tests/conftest.py +0 -0
  166. {osekit-1.1.1 → osekit-1.2.0}/tests/helpers/__init__.py +0 -0
  167. {osekit-1.1.1 → osekit-1.2.0}/tests/sample_dataset/sample1_180701_204453.wav +0 -0
  168. {osekit-1.1.1 → osekit-1.2.0}/tests/sample_dataset/sample1_190222_010000.wav +0 -0
  169. {osekit-1.1.1 → osekit-1.2.0}/tests/sample_dataset/sample1_220998_185532.wav +0 -0
  170. {osekit-1.1.1 → osekit-1.2.0}/tests/test_audio_file_manager.py +0 -0
  171. {osekit-1.1.1 → osekit-1.2.0}/tests/test_detection.py +0 -0
  172. {osekit-1.1.1 → osekit-1.2.0}/tests/test_event.py +0 -0
  173. {osekit-1.1.1 → osekit-1.2.0}/tests/test_export_transform.py +0 -0
  174. {osekit-1.1.1 → osekit-1.2.0}/tests/test_files.py +0 -0
  175. {osekit-1.1.1 → osekit-1.2.0}/tests/test_frequency_scales.py +0 -0
  176. {osekit-1.1.1 → osekit-1.2.0}/tests/test_instrument.py +0 -0
  177. {osekit-1.1.1 → osekit-1.2.0}/tests/test_job.py +0 -0
  178. {osekit-1.1.1 → osekit-1.2.0}/tests/test_logging.py +0 -0
  179. {osekit-1.1.1 → osekit-1.2.0}/tests/test_mseed.py +0 -0
  180. {osekit-1.1.1 → osekit-1.2.0}/tests/test_multiprocessing.py +0 -0
  181. {osekit-1.1.1 → osekit-1.2.0}/tests/test_permissions.py +0 -0
  182. {osekit-1.1.1 → osekit-1.2.0}/tests/test_timestamp_utils.py +0 -0
  183. {osekit-1.1.1 → osekit-1.2.0}/tests/test_utils.py +0 -0
  184. {osekit-1.1.1 → osekit-1.2.0}/tests/test_welch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osekit
3
- Version: 1.1.1
3
+ Version: 1.2.0
4
4
  Summary: OSEkit
5
5
  Author-email: OSmOSE team <osmose@ensta-bretagne.fr>
6
6
  License-Expression: MIT
@@ -0,0 +1,276 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "id": "initial_id",
6
+ "metadata": {
7
+ "collapsed": true,
8
+ "tags": [
9
+ "remove-cell"
10
+ ]
11
+ },
12
+ "source": [
13
+ "# Executing this cell will:\n",
14
+ "\n",
15
+ "# Disable all TQDM outputs in stdout.\n",
16
+ "import os\n",
17
+ "\n",
18
+ "os.environ[\"DISABLE_TQDM\"] = \"True\"\n",
19
+ "\n",
20
+ "# Setup the python logger for the Public API\n",
21
+ "from osekit import setup_logging\n",
22
+ "\n",
23
+ "setup_logging() # Overwrites the default logger to"
24
+ ],
25
+ "outputs": [],
26
+ "execution_count": null
27
+ },
28
+ {
29
+ "cell_type": "markdown",
30
+ "id": "8c395a2079d86493",
31
+ "metadata": {},
32
+ "source": [
33
+ "# Working with multichannel audio files [^download]\n",
34
+ "\n",
35
+ "[^download]: This notebook can be downloaded as **{nb-download}`example_multichannel.ipynb`**."
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "id": "90049102bdc38599",
41
+ "metadata": {},
42
+ "source": [
43
+ "# Basics: Core API\n",
44
+ "\n",
45
+ "## Parsing a multichannel file\n",
46
+ "\n",
47
+ "The `AudioFile.channels` property indicates the number of channels that a given `AudioFile` has.\n",
48
+ "\n",
49
+ "The `AudioData.channels` property is a **list of ints** that represents the targeted channels of the file:"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "id": "c1f1dcd7e3e90141",
55
+ "metadata": {},
56
+ "source": [
57
+ "from pathlib import Path\n",
58
+ "from osekit.core.audio_file import AudioFile\n",
59
+ "from osekit.core.audio_data import AudioData\n",
60
+ "\n",
61
+ "af = AudioFile(\n",
62
+ " path=Path(\"_static/sample_audio/multichannel/multichannel_220925_223450.wav\"),\n",
63
+ " strptime_format=r\"%y%m%d_%H%M%S\",\n",
64
+ ")\n",
65
+ "\n",
66
+ "print(f\"The audio file has {af.channels} channels.\")\n",
67
+ "\n",
68
+ "ad: AudioData = AudioData.from_files([af])\n",
69
+ "\n",
70
+ "print(f\"By default, all channels are targeted: {ad.channels}.\")"
71
+ ],
72
+ "outputs": [],
73
+ "execution_count": null
74
+ },
75
+ {
76
+ "cell_type": "markdown",
77
+ "id": "fd8e3d095a534d5",
78
+ "metadata": {},
79
+ "source": [
80
+ "## Targeting specific channel(s)\n",
81
+ "\n",
82
+ "`AudioData.channels` can be set to target specific channel(s):"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "id": "ea1c469c76a14fe3",
88
+ "metadata": {},
89
+ "source": [
90
+ "import matplotlib.pyplot as plt\n",
91
+ "\n",
92
+ "ad.channels = [0, 2] # Removing channel 1 from targeted channels\n",
93
+ "ad.plot()\n",
94
+ "plt.show()"
95
+ ],
96
+ "outputs": [],
97
+ "execution_count": null
98
+ },
99
+ {
100
+ "cell_type": "markdown",
101
+ "id": "1b00f1600c66e3c6",
102
+ "metadata": {},
103
+ "source": [
104
+ "## Computing the spectrum of a specific channel\n",
105
+ "\n",
106
+ "`SpectroData` target **a specific** channel of a file:"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "id": "87f3839389f684c3",
112
+ "metadata": {},
113
+ "source": [
114
+ "from osekit.core.spectro_data import SpectroData\n",
115
+ "from scipy.signal import ShortTimeFFT, windows\n",
116
+ "\n",
117
+ "sd = SpectroData.from_audio_data(\n",
118
+ " data=ad,\n",
119
+ " fft=ShortTimeFFT(win=windows.hamming(1024), hop=128, fs=ad.sample_rate),\n",
120
+ ")\n",
121
+ "\n",
122
+ "sd.audio_channel = 2 # Targets the third channel of the file (which is the second channel of the AudioData)\n",
123
+ "sd.plot()\n",
124
+ "plt.show()"
125
+ ],
126
+ "outputs": [],
127
+ "execution_count": null
128
+ },
129
+ {
130
+ "cell_type": "markdown",
131
+ "id": "8bfbe3f450ad73cd",
132
+ "metadata": {},
133
+ "source": "# Public API"
134
+ },
135
+ {
136
+ "cell_type": "markdown",
137
+ "id": "e2d5321198880205",
138
+ "metadata": {},
139
+ "source": [
140
+ "## Build the Project\n",
141
+ "\n",
142
+ "First, we have to build the project from the raw audio files:"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "id": "3ab3cb447c59a857",
148
+ "metadata": {},
149
+ "source": [
150
+ "from pathlib import Path\n",
151
+ "from osekit.public.project import Project\n",
152
+ "\n",
153
+ "folder = Path(r\"_static/sample_audio/multichannel\")\n",
154
+ "strptime_format = r\"%y%m%d_%H%M%S\"\n",
155
+ "\n",
156
+ "project = Project(\n",
157
+ " folder=folder,\n",
158
+ " strptime_format=strptime_format,\n",
159
+ ")\n",
160
+ "\n",
161
+ "project.build()"
162
+ ],
163
+ "outputs": [],
164
+ "execution_count": null
165
+ },
166
+ {
167
+ "cell_type": "markdown",
168
+ "id": "2f5510c9c396ee2f",
169
+ "metadata": {},
170
+ "source": [
171
+ "## Declare the Transform\n",
172
+ "\n",
173
+ "Then we **declare** a `Transform` which would work on the audio (e.g. export spectrograms):"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "id": "d993991e8c23a2c0",
179
+ "metadata": {},
180
+ "source": [
181
+ "from osekit.public.transform import Transform, OutputType\n",
182
+ "from scipy.signal import ShortTimeFFT\n",
183
+ "from scipy.signal.windows import hamming\n",
184
+ "\n",
185
+ "transform = Transform(\n",
186
+ " output_type=OutputType.SPECTROGRAM,\n",
187
+ " fft=ShortTimeFFT(win=hamming(1024), hop=128, fs=project.origin_dataset.sample_rate),\n",
188
+ " name=\"one_spectrogram_per_channel\",\n",
189
+ ")"
190
+ ],
191
+ "outputs": [],
192
+ "execution_count": null
193
+ },
194
+ {
195
+ "cell_type": "markdown",
196
+ "id": "7f58320386d3dc14",
197
+ "metadata": {},
198
+ "source": "Now, we will use some **Core API** on top of the **Public API** to get one spectrogram per channel:"
199
+ },
200
+ {
201
+ "cell_type": "code",
202
+ "id": "c6b54cf5f1ecb44b",
203
+ "metadata": {},
204
+ "source": [
205
+ "import copy\n",
206
+ "\n",
207
+ "# We get the transform SpectroData(s) -- here there is only one\n",
208
+ "sds = project.prepare_spectro(transform=transform)\n",
209
+ "\n",
210
+ "# We'll create one spectro data per channel:\n",
211
+ "sds_channels = []\n",
212
+ "for sd in sds.data:\n",
213
+ " for channel in (0, 2): # Targeting the specific channels here\n",
214
+ " sd_copy = copy.copy(sd)\n",
215
+ " sd_copy.audio_channel = channel\n",
216
+ " sd_copy.name += \"_channel_\" + str(channel)\n",
217
+ " sds_channels.append(sd_copy)\n",
218
+ "\n",
219
+ "# We'll then set the sds data as sd_channels:\n",
220
+ "sds.data = sds_channels\n",
221
+ "\n",
222
+ "# Let's check everything's ok:\n",
223
+ "for sd in sds.data:\n",
224
+ " print(f\"Spectrogram for channel {sd.audio_channel}\")"
225
+ ],
226
+ "outputs": [],
227
+ "execution_count": null
228
+ },
229
+ {
230
+ "cell_type": "markdown",
231
+ "id": "a119e3339b02e775",
232
+ "metadata": {},
233
+ "source": "We should now be able to run the transform on the edited `SpectroDataset`:"
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "id": "1948b260fcaf03ab",
238
+ "metadata": {},
239
+ "source": "project.run(transform=transform, spectro_dataset=sds)",
240
+ "outputs": [],
241
+ "execution_count": null
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "id": "449dc442b4a5df75",
246
+ "metadata": {},
247
+ "source": [
248
+ "# Reset the project to get all files back to place.\n",
249
+ "project.reset()"
250
+ ],
251
+ "outputs": [],
252
+ "execution_count": null
253
+ }
254
+ ],
255
+ "metadata": {
256
+ "kernelspec": {
257
+ "display_name": "Python 3",
258
+ "language": "python",
259
+ "name": "python3"
260
+ },
261
+ "language_info": {
262
+ "codemirror_mode": {
263
+ "name": "ipython",
264
+ "version": 2
265
+ },
266
+ "file_extension": ".py",
267
+ "mimetype": "text/x-python",
268
+ "name": "python",
269
+ "nbconvert_exporter": "python",
270
+ "pygments_lexer": "ipython2",
271
+ "version": "2.7.6"
272
+ }
273
+ },
274
+ "nbformat": 4,
275
+ "nbformat_minor": 5
276
+ }
@@ -57,10 +57,17 @@ In the ``docs/source/_static/sample_audio/timestamped`` folder, files are just n
57
57
 
58
58
  ===========
59
59
 
60
+ .. topic:: :doc:`Work with multichannel audio files <example_multichannel>`
61
+
62
+ Work on multichannel audio, compute spectrums from specific channels...
63
+
64
+ ===========
65
+
60
66
  .. topic:: :doc:`Use APLOSE results <example_aplose_result>`
61
67
 
62
68
  Parse `APLOSE <https://osmose.ifremer.fr/doc/>`_ results csv files in OSEkit, and use the detections to filter the audio or spectrograms from the project.
63
69
 
70
+
64
71
  .. toctree ::
65
72
  :hidden:
66
73
 
@@ -70,4 +77,5 @@ In the ``docs/source/_static/sample_audio/timestamped`` folder, files are just n
70
77
  example_multiple_spectrograms
71
78
  example_multiple_spectrograms_id
72
79
  example_ltas
80
+ example_multichannel
73
81
  example_aplose_result
@@ -0,0 +1,46 @@
1
+ .. _multichannel:
2
+
3
+ Working with multichannel audio files
4
+ -------------------------------------
5
+
6
+ The audio classes in **OSEkit** allow multichannel audio handling, e.g. the :meth:`osekit.core.audio_data.AudioData.get_value` method returns a ``samples x channels`` matrix.
7
+
8
+ The :attr:`osekit.core.audio_file.AudioFile.channels` property depicts the number of channels of a given ``AudioFile``:
9
+
10
+ .. code-block:: python
11
+
12
+ from pathlib import Path
13
+ from osekit.core.audio_file import AudioFile
14
+
15
+ af = AudioFile(...)
16
+ print(af.channels)
17
+
18
+ >>> 3
19
+
20
+ The :attr:`osekit.core.audio_data.AudioData.channels` property relates to the list of channels concerned by this audio data:
21
+
22
+ .. code-block:: python
23
+
24
+ from osekit.core.audio_data import AudioData
25
+
26
+ ad = AudioData.from_files(files=[af])
27
+ ad.channels = [0,2] # We want to keep only channels 0 and 2
28
+ print(ad.get_value().shape[1])
29
+
30
+ >>> 2 # One value array per channel
31
+
32
+ Finally, a ``SpectroData`` that has a linked ``AudioData`` targets a **specific channel** of this ``AudioData``:
33
+
34
+ .. code-block:: python
35
+
36
+ from osekit.core.spectro_data import SpectroData
37
+ from scipy.signal import ShortTimeFFT
38
+
39
+ sd = SpectroData.from_audio_data(data=ad, ...)
40
+ sd.audio_channel = 2 # The spectrum will be computed on the channel 2 of the file
41
+
42
+ .. important::
43
+
44
+ The :attr:`osekit.core.spectro_data.SpectroData.audio_channel` value refers to the index of the channel of the **file**.
45
+
46
+ If, as in the example above, the ``AudioFile`` has 3 channels ``[0,1,2]``, the ``AudioData`` targets channels ``[0,2]`` and the ``SpectroData`` targets the channel ``2``, the spectrum will be computed on the **third channel** of the file (with index ``2``).
@@ -28,3 +28,4 @@ The package combines two APIs:
28
28
  multiprocessing
29
29
  jobs
30
30
  aplose
31
+ multichannel
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "osekit"
3
- version = "1.1.1"
3
+ version = "1.2.0"
4
4
  description = "OSEkit"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -49,6 +49,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
49
49
  normalization: Normalization = Normalization.RAW,
50
50
  normalization_values: dict | None = None,
51
51
  butter: Butterworth | None = None,
52
+ channels: list[int] | None = None,
52
53
  ) -> None:
53
54
  """Initialize an ``AudioData`` from a list of ``AudioItems``.
54
55
 
@@ -73,6 +74,8 @@ class AudioData(BaseData[AudioItem, AudioFile]):
73
74
  The type of normalization to apply to the audio data.
74
75
  butter: Butterworth | None
75
76
  Butterworth filter to apply to the audio data.
77
+ channels: list[int]
78
+ Considered channels of the linked audio file(s).
76
79
 
77
80
  """
78
81
  super().__init__(items=items, begin=begin, end=end, name=name)
@@ -81,13 +84,12 @@ class AudioData(BaseData[AudioItem, AudioFile]):
81
84
  self.normalization = normalization
82
85
  self.normalization_values = normalization_values
83
86
  self.butter = butter
87
+ self.channels = channels
84
88
 
85
89
  @property
86
90
  def nb_channels(self) -> int:
87
91
  """Number of channels of the audio data."""
88
- return max(
89
- [1] + [item.nb_channels for item in self.items if type(item) is AudioItem],
90
- )
92
+ return len(self.channels)
91
93
 
92
94
  @property
93
95
  def shape(self) -> tuple[int, int]:
@@ -120,15 +122,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
120
122
 
121
123
  @normalization_values.setter
122
124
  def normalization_values(self, value: dict | None) -> None:
123
- self._normalization_values = (
124
- value
125
- if value
126
- else {
127
- "mean": None,
128
- "peak": None,
129
- "std": None,
130
- }
131
- )
125
+ self._normalization_values = value or {"mean": None, "peak": None, "std": None}
132
126
 
133
127
  @property
134
128
  def butter(self) -> Butterworth:
@@ -139,6 +133,21 @@ class AudioData(BaseData[AudioItem, AudioFile]):
139
133
  def butter(self, value: Butterworth) -> None:
140
134
  self._butter = value
141
135
 
136
+ @property
137
+ def channels(self) -> list[int]:
138
+ """The Butterworth filter to apply to the audio data."""
139
+ return self._channels
140
+
141
+ @channels.setter
142
+ def channels(self, value: list[int] | None) -> None:
143
+ if value is None:
144
+ nb_channels_max = max(
145
+ [1]
146
+ + [item.nb_channels for item in self.items if type(item) is AudioItem],
147
+ )
148
+ value = list(range(nb_channels_max))
149
+ self._channels = value
150
+
142
151
  @classmethod
143
152
  def _make_item(
144
153
  cls,
@@ -165,15 +174,13 @@ class AudioData(BaseData[AudioItem, AudioFile]):
165
174
  return AudioItem(file=file, begin=begin, end=end)
166
175
 
167
176
  @classmethod
168
- def _make_file(cls, path: Path, begin: Timestamp) -> AudioFile:
177
+ def _make_file(cls, file_dict: dict) -> AudioFile:
169
178
  """Make an ``AudioFile`` from a path and a begin timestamp.
170
179
 
171
180
  Parameters
172
181
  ----------
173
- path: Path
174
- Path to the file.
175
- begin: Timestamp
176
- Begin of the file.
182
+ file_dict: dict
183
+ Serialized AudioFile.
177
184
 
178
185
  Returns
179
186
  -------
@@ -181,7 +188,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
181
188
  The ``AudioFile`` instance.
182
189
 
183
190
  """
184
- return AudioFile(path=path, begin=begin)
191
+ return AudioFile.from_dict(serialized=file_dict)
185
192
 
186
193
  def get_normalization_values(self) -> dict:
187
194
  """Return the values used for normalizing the audio data.
@@ -196,9 +203,9 @@ class AudioData(BaseData[AudioItem, AudioFile]):
196
203
  """
197
204
  values = np.array(self.get_filtered_value())
198
205
  self.normalization_values = {
199
- "mean": values.mean(),
200
- "peak": values.max(),
201
- "std": values.std(),
206
+ "mean": values.mean(axis=0),
207
+ "peak": values.max(axis=0),
208
+ "std": values.std(axis=0),
202
209
  }
203
210
  return self.normalization_values
204
211
 
@@ -319,7 +326,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
319
326
  )
320
327
 
321
328
  for chunk in item.stream(chunk_size=chunk_size):
322
- y = chunk
329
+ y = chunk[:, self.channels]
323
330
  if item.sample_rate != self.sample_rate:
324
331
  y = resampler.resample_chunk(x=chunk)
325
332
 
@@ -395,13 +402,18 @@ class AudioData(BaseData[AudioItem, AudioFile]):
395
402
  to the ``matplotlib.axes._axes.Axes.plot()`` method.
396
403
 
397
404
  """
398
- ax = ax if ax is not None else get_default_axes()
405
+ ax = ax if ax is not None else get_default_axes(nb_rows=self.nb_channels)
399
406
  values = self.get_value() if values is None else values
400
407
 
401
408
  time = pd.date_range(start=self.begin, end=self.end, periods=values.shape[0])
402
409
 
403
- ax.xaxis_date()
404
- ax.plot(time, values, **kwargs)
410
+ if type(ax) is plt.Axes:
411
+ ax.xaxis_date()
412
+ ax.plot(time, values, **kwargs)
413
+ if type(ax) is np.ndarray: # Multichannel audio
414
+ for idx, axes in enumerate(ax):
415
+ axes.xaxis_date()
416
+ axes.plot(time, values[:, idx], **kwargs)
405
417
 
406
418
  def write(
407
419
  self,
@@ -618,6 +630,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
618
630
  "sample_rate": self.sample_rate,
619
631
  "normalization": self.normalization.value,
620
632
  "normalization_values": self.normalization_values,
633
+ "channels": self.channels,
621
634
  }
622
635
  )
623
636
 
@@ -671,8 +684,9 @@ class AudioData(BaseData[AudioItem, AudioFile]):
671
684
  instrument=instrument,
672
685
  sample_rate=dictionary["sample_rate"],
673
686
  normalization=Normalization(dictionary["normalization"]),
674
- normalization_values=dictionary["normalization_values"],
687
+ normalization_values=dictionary.get("normalization_values", None),
675
688
  butter=butter,
689
+ channels=dictionary.get("channels", None),
676
690
  )
677
691
 
678
692
  @classmethod
@@ -5,6 +5,9 @@ from __future__ import annotations
5
5
  import typing
6
6
  from typing import TYPE_CHECKING
7
7
 
8
+ from osekit.config import TIMESTAMP_FORMATS_EXPORTED_FILES
9
+ from osekit.utils.timestamp import strptime_from_text
10
+
8
11
  if TYPE_CHECKING:
9
12
  from os import PathLike
10
13
  from pathlib import Path
@@ -30,6 +33,7 @@ class AudioFile(BaseFile):
30
33
  begin: Timestamp | None = None,
31
34
  strptime_format: str | list[str] | None = None,
32
35
  timezone: str | pytz.timezone | None = None,
36
+ **kwargs: dict,
33
37
  ) -> None:
34
38
  """Initialize an ``AudioFile`` object with a path and a begin timestamp.
35
39
 
@@ -55,7 +59,8 @@ class AudioFile(BaseFile):
55
59
  If different from a timezone parsed from the filename, the timestamps'
56
60
  timezone will be converted from the parsed timezone
57
61
  to the specified timezone.
58
-
62
+ kwargs: dict
63
+ Audio file info that might bypass the afm.info() call on deserialization.
59
64
  """
60
65
  super().__init__(
61
66
  path=path,
@@ -63,13 +68,25 @@ class AudioFile(BaseFile):
63
68
  strptime_format=strptime_format,
64
69
  timezone=timezone,
65
70
  )
66
- sample_rate, frames, channels = afm.info(path)
67
- duration = frames / sample_rate
71
+ sample_rate, channels, end = self._get_info(path=path, kwargs=kwargs)
68
72
  self.sample_rate = sample_rate
69
73
  self.channels = channels
70
- self.end = self.begin + Timedelta(seconds=duration)
74
+ self.end = end
71
75
  self._check_validity()
72
76
 
77
+ def _get_info(self, path: Path, kwargs: dict) -> tuple[int, int, Timestamp]:
78
+ keys = ["sample_rate", "channels", "end"]
79
+ if all(key in kwargs for key in keys):
80
+ end = strptime_from_text(
81
+ text=kwargs["end"],
82
+ datetime_template=TIMESTAMP_FORMATS_EXPORTED_FILES,
83
+ )
84
+ return kwargs["sample_rate"], kwargs["channels"], end
85
+ sample_rate, frames, channels = afm.info(path=path)
86
+ duration = frames / sample_rate
87
+ end = self.begin + Timedelta(seconds=duration)
88
+ return sample_rate, channels, end
89
+
73
90
  def _check_validity(self) -> None:
74
91
  """Raise an error if the audio file is not valid."""
75
92
  if not self.duration:
@@ -169,3 +186,17 @@ class AudioFile(BaseFile):
169
186
  if data.ndim == 1:
170
187
  return data[:, None] # 2D array to match the format of multichannel audio
171
188
  return data
189
+
190
+ def to_dict(self) -> dict:
191
+ """Serialize an ``AudioFile`` to a dictionary.
192
+
193
+ Returns
194
+ -------
195
+ dict:
196
+ The serialized dictionary representing the ``AudioFile``.
197
+
198
+ """
199
+ return super().to_dict() | {
200
+ "channels": self.channels,
201
+ "sample_rate": self.sample_rate,
202
+ }
@@ -18,12 +18,10 @@ from osekit.config import (
18
18
  DPDEFAULT,
19
19
  TIMESTAMP_FORMAT_AUDIO_FILE,
20
20
  TIMESTAMP_FORMAT_EXPORTED_FILES_LOCALIZED,
21
- TIMESTAMP_FORMATS_EXPORTED_FILES,
22
21
  )
23
22
  from osekit.core.base_file import BaseFile
24
23
  from osekit.core.base_item import BaseItem
25
24
  from osekit.core.event import Event
26
- from osekit.utils.timestamp import strptime_from_text
27
25
 
28
26
  TItem = TypeVar("TItem", bound=BaseItem)
29
27
  TFile = TypeVar("TFile", bound=BaseFile)
@@ -212,14 +210,7 @@ class BaseData[TItem: BaseItem, TFile: BaseFile](Event, ABC):
212
210
 
213
211
  """
214
212
  files = [
215
- cls._make_file(
216
- path=Path(file["path"]),
217
- begin=strptime_from_text(
218
- file["begin"],
219
- datetime_template=TIMESTAMP_FORMATS_EXPORTED_FILES,
220
- ),
221
- )
222
- for file in dictionary["files"].values()
213
+ cls._make_file(file_dict=file) for file in dictionary["files"].values()
223
214
  ]
224
215
  begin = Timestamp(dictionary["begin"])
225
216
  end = Timestamp(dictionary["end"])
@@ -233,7 +224,7 @@ class BaseData[TItem: BaseItem, TFile: BaseFile](Event, ABC):
233
224
 
234
225
  @classmethod
235
226
  @abstractmethod
236
- def _make_file(cls, path: Path, begin: Timestamp) -> type[TFile]:
227
+ def _make_file(cls, file_dict: dict) -> type[TFile]:
237
228
  """Make a File from a path and a begin timestamp."""
238
229
  ...
239
230
 
@@ -50,7 +50,6 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
50
50
  """Instantiate a Dataset object from the Data objects."""
51
51
  self.data = data
52
52
  self._name = name
53
- self._has_default_name = name is None
54
53
  self._suffix = suffix
55
54
  self._folder = folder
56
55
 
@@ -101,11 +100,6 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
101
100
  def suffix(self, suffix: str | None) -> None:
102
101
  self._suffix = suffix
103
102
 
104
- @property
105
- def has_default_name(self) -> bool:
106
- """Return ``True`` if the dataset has a default name, ``False`` if it has a given name."""
107
- return self._has_default_name
108
-
109
103
  @property
110
104
  def begin(self) -> Timestamp:
111
105
  """Begin of the first data object."""
@@ -133,11 +127,11 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
133
127
  @property
134
128
  def data(self) -> list[TData]:
135
129
  """List of Data contained in this Dataset."""
136
- return sorted(self._data, key=lambda d: d.begin)
130
+ return self._data
137
131
 
138
132
  @data.setter
139
133
  def data(self, data: list[TData]) -> None:
140
- self._data = data
134
+ self._data = sorted(data, key=lambda d: d.begin)
141
135
 
142
136
  @folder.setter
143
137
  def folder(self, folder: Path) -> None: