osekit 1.0.1__tar.gz → 1.0.2__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 (172) hide show
  1. {osekit-1.0.1 → osekit-1.0.2}/PKG-INFO +1 -1
  2. osekit-1.0.2/docs/logo/osmose_texte_sombre.png +0 -0
  3. osekit-1.0.2/docs/logo/osmose_texte_sombre_small.png +0 -0
  4. {osekit-1.0.1 → osekit-1.0.2}/pyproject.toml +4 -1
  5. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/audio_backend/audio_file_manager.py +0 -3
  6. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/audio_data.py +45 -3
  7. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/audio_dataset.py +22 -3
  8. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/audio_file.py +1 -1
  9. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/base_dataset.py +13 -5
  10. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/base_file.py +1 -1
  11. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/spectro_dataset.py +2 -2
  12. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/spectro_file.py +1 -1
  13. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/public/project.py +48 -16
  14. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/public/transform.py +5 -1
  15. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/audio.py +101 -0
  16. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/path.py +2 -1
  17. {osekit-1.0.1 → osekit-1.0.2}/tests/conftest.py +1 -53
  18. osekit-1.0.2/tests/helpers/audio.py +39 -0
  19. {osekit-1.0.1 → osekit-1.0.2}/tests/test_audio.py +99 -15
  20. {osekit-1.0.1 → osekit-1.0.2}/tests/test_core_api_base.py +24 -2
  21. {osekit-1.0.1 → osekit-1.0.2}/tests/test_files.py +9 -2
  22. {osekit-1.0.1 → osekit-1.0.2}/tests/test_public_api.py +27 -0
  23. {osekit-1.0.1 → osekit-1.0.2}/tests/test_spectro.py +24 -30
  24. {osekit-1.0.1 → osekit-1.0.2}/tests/test_utils.py +13 -80
  25. osekit-1.0.2/uv.lock +3196 -0
  26. osekit-1.0.1/docs/logo/osmose_texte_sombre.png +0 -0
  27. osekit-1.0.1/docs/logo/osmose_texte_sombre_small.png +0 -0
  28. osekit-1.0.1/src/osekit/utils/formatting.py +0 -179
  29. osekit-1.0.1/uv.lock +0 -3032
  30. {osekit-1.0.1 → osekit-1.0.2}/.github/workflows/documentation.yml +0 -0
  31. {osekit-1.0.1 → osekit-1.0.2}/.github/workflows/github_ci.yml +0 -0
  32. {osekit-1.0.1 → osekit-1.0.2}/.github/workflows/publish.yml +0 -0
  33. {osekit-1.0.1 → osekit-1.0.2}/.gitignore +0 -0
  34. {osekit-1.0.1 → osekit-1.0.2}/.pre-commit-config.yaml +0 -0
  35. {osekit-1.0.1 → osekit-1.0.2}/CHANGELOG.md +0 -0
  36. {osekit-1.0.1 → osekit-1.0.2}/CITATION.cff +0 -0
  37. {osekit-1.0.1 → osekit-1.0.2}/CONTRIBUTING.md +0 -0
  38. {osekit-1.0.1 → osekit-1.0.2}/LICENSE +0 -0
  39. {osekit-1.0.1 → osekit-1.0.2}/README.md +0 -0
  40. {osekit-1.0.1 → osekit-1.0.2}/docs/Makefile +0 -0
  41. {osekit-1.0.1 → osekit-1.0.2}/docs/logo/osekit.png +0 -0
  42. {osekit-1.0.1 → osekit-1.0.2}/docs/logo/osekit_mid.png +0 -0
  43. {osekit-1.0.1 → osekit-1.0.2}/docs/logo/osekit_small.png +0 -0
  44. {osekit-1.0.1 → osekit-1.0.2}/docs/logo/osmose.png +0 -0
  45. {osekit-1.0.1 → osekit-1.0.2}/docs/make.bat +0 -0
  46. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/audio_data/ex1.svg +0 -0
  47. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/audio_data/ex2.svg +0 -0
  48. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/data_structure/file_item_data_0.svg +0 -0
  49. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/data_structure/file_item_data_1.svg +0 -0
  50. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/data_structure/file_item_data_2.svg +0 -0
  51. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/favicon.ico +0 -0
  52. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/ltas/ltas.gif +0 -0
  53. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1829.wav +0 -0
  54. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1830.wav +0 -0
  55. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1832.wav +0 -0
  56. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1833.wav +0 -0
  57. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1834.wav +0 -0
  58. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1835.wav +0 -0
  59. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1836.wav +0 -0
  60. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1837.wav +0 -0
  61. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/id/1838.wav +0 -0
  62. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223450.wav +0 -0
  63. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223500.wav +0 -0
  64. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223510.wav +0 -0
  65. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223520.wav +0 -0
  66. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223530.wav +0 -0
  67. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223600.wav +0 -0
  68. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223610.wav +0 -0
  69. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223620.wav +0 -0
  70. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223630.wav +0 -0
  71. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/sample_audio/timestamped/sample_220925_223640.wav +0 -0
  72. {osekit-1.0.1 → osekit-1.0.2}/docs/source/_static/spectrograms/frequency_scale.png +0 -0
  73. {osekit-1.0.1 → osekit-1.0.2}/docs/source/api.rst +0 -0
  74. {osekit-1.0.1 → osekit-1.0.2}/docs/source/audiodata.rst +0 -0
  75. {osekit-1.0.1 → osekit-1.0.2}/docs/source/audiodataset.rst +0 -0
  76. {osekit-1.0.1 → osekit-1.0.2}/docs/source/audiofile.rst +0 -0
  77. {osekit-1.0.1 → osekit-1.0.2}/docs/source/audiofilemanager.rst +0 -0
  78. {osekit-1.0.1 → osekit-1.0.2}/docs/source/audioitem.rst +0 -0
  79. {osekit-1.0.1 → osekit-1.0.2}/docs/source/basedata.rst +0 -0
  80. {osekit-1.0.1 → osekit-1.0.2}/docs/source/basedataset.rst +0 -0
  81. {osekit-1.0.1 → osekit-1.0.2}/docs/source/basefile.rst +0 -0
  82. {osekit-1.0.1 → osekit-1.0.2}/docs/source/baseitem.rst +0 -0
  83. {osekit-1.0.1 → osekit-1.0.2}/docs/source/conf.py +0 -0
  84. {osekit-1.0.1 → osekit-1.0.2}/docs/source/contributing.rst +0 -0
  85. {osekit-1.0.1 → osekit-1.0.2}/docs/source/coreapi.rst +0 -0
  86. {osekit-1.0.1 → osekit-1.0.2}/docs/source/coreapi_home.rst +0 -0
  87. {osekit-1.0.1 → osekit-1.0.2}/docs/source/coreapi_introduction.rst +0 -0
  88. {osekit-1.0.1 → osekit-1.0.2}/docs/source/coreapi_usage.rst +0 -0
  89. {osekit-1.0.1 → osekit-1.0.2}/docs/source/event.rst +0 -0
  90. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_ltas.rst +0 -0
  91. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_ltas_core.ipynb +0 -0
  92. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_ltas_public.ipynb +0 -0
  93. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms.rst +0 -0
  94. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms_core.ipynb +0 -0
  95. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms_id.rst +0 -0
  96. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms_id_core.ipynb +0 -0
  97. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms_id_public.ipynb +0 -0
  98. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_multiple_spectrograms_public.ipynb +0 -0
  99. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_reshaping_multiple_files.rst +0 -0
  100. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_reshaping_multiple_files_core.ipynb +0 -0
  101. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_reshaping_multiple_files_public.ipynb +0 -0
  102. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_reshaping_one_file.ipynb +0 -0
  103. {osekit-1.0.1 → osekit-1.0.2}/docs/source/example_spectrogram.ipynb +0 -0
  104. {osekit-1.0.1 → osekit-1.0.2}/docs/source/examples.rst +0 -0
  105. {osekit-1.0.1 → osekit-1.0.2}/docs/source/export_transform.rst +0 -0
  106. {osekit-1.0.1 → osekit-1.0.2}/docs/source/frequencyscale.rst +0 -0
  107. {osekit-1.0.1 → osekit-1.0.2}/docs/source/index.rst +0 -0
  108. {osekit-1.0.1 → osekit-1.0.2}/docs/source/installation.rst +0 -0
  109. {osekit-1.0.1 → osekit-1.0.2}/docs/source/instrument.rst +0 -0
  110. {osekit-1.0.1 → osekit-1.0.2}/docs/source/job.rst +0 -0
  111. {osekit-1.0.1 → osekit-1.0.2}/docs/source/jobs.rst +0 -0
  112. {osekit-1.0.1 → osekit-1.0.2}/docs/source/ltasdata.rst +0 -0
  113. {osekit-1.0.1 → osekit-1.0.2}/docs/source/multiprocessing.rst +0 -0
  114. {osekit-1.0.1 → osekit-1.0.2}/docs/source/normalization.rst +0 -0
  115. {osekit-1.0.1 → osekit-1.0.2}/docs/source/project.rst +0 -0
  116. {osekit-1.0.1 → osekit-1.0.2}/docs/source/publicapi.rst +0 -0
  117. {osekit-1.0.1 → osekit-1.0.2}/docs/source/publicapi_usage.rst +0 -0
  118. {osekit-1.0.1 → osekit-1.0.2}/docs/source/spectrodata.rst +0 -0
  119. {osekit-1.0.1 → osekit-1.0.2}/docs/source/spectrodataset.rst +0 -0
  120. {osekit-1.0.1 → osekit-1.0.2}/docs/source/spectrofile.rst +0 -0
  121. {osekit-1.0.1 → osekit-1.0.2}/docs/source/spectroitem.rst +0 -0
  122. {osekit-1.0.1 → osekit-1.0.2}/docs/source/transform.rst +0 -0
  123. {osekit-1.0.1 → osekit-1.0.2}/docs/source/usage.rst +0 -0
  124. {osekit-1.0.1 → osekit-1.0.2}/docs/source/utils.rst +0 -0
  125. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/__init__.py +0 -0
  126. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/audio_backend/audio_backend.py +0 -0
  127. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/audio_backend/mseed_backend.py +0 -0
  128. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/audio_backend/soundfile_backend.py +0 -0
  129. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/config.py +0 -0
  130. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/__init__.py +0 -0
  131. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/audio_item.py +0 -0
  132. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/base_data.py +0 -0
  133. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/base_item.py +0 -0
  134. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/event.py +0 -0
  135. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/frequency_scale.py +0 -0
  136. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/instrument.py +0 -0
  137. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/json_serializer.py +0 -0
  138. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/ltas_data.py +0 -0
  139. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/ltas_dataset.py +0 -0
  140. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/spectro_data.py +0 -0
  141. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core/spectro_item.py +0 -0
  142. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/core_api/__init__.py +0 -0
  143. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/logging_config.yaml +0 -0
  144. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/logging_context.py +0 -0
  145. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/public/__init__.py +0 -0
  146. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/public/export_transform.py +0 -0
  147. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/public_api/__init__.py +0 -0
  148. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/__init__.py +0 -0
  149. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/core.py +0 -0
  150. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/deserialization.py +0 -0
  151. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/job.py +0 -0
  152. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/multiprocess.py +0 -0
  153. {osekit-1.0.1 → osekit-1.0.2}/src/osekit/utils/timestamp.py +0 -0
  154. {osekit-1.0.1 → osekit-1.0.2}/tests/__init__.py +0 -0
  155. {osekit-1.0.1 → osekit-1.0.2}/tests/helpers/__init__.py +0 -0
  156. {osekit-1.0.1 → osekit-1.0.2}/tests/helpers/dummy.py +0 -0
  157. {osekit-1.0.1 → osekit-1.0.2}/tests/sample_dataset/sample1_180701_204453.wav +0 -0
  158. {osekit-1.0.1 → osekit-1.0.2}/tests/sample_dataset/sample1_190222_010000.wav +0 -0
  159. {osekit-1.0.1 → osekit-1.0.2}/tests/sample_dataset/sample1_220998_185532.wav +0 -0
  160. {osekit-1.0.1 → osekit-1.0.2}/tests/test_audio_file_manager.py +0 -0
  161. {osekit-1.0.1 → osekit-1.0.2}/tests/test_event.py +0 -0
  162. {osekit-1.0.1 → osekit-1.0.2}/tests/test_export_transform.py +0 -0
  163. {osekit-1.0.1 → osekit-1.0.2}/tests/test_frequency_scales.py +0 -0
  164. {osekit-1.0.1 → osekit-1.0.2}/tests/test_instrument.py +0 -0
  165. {osekit-1.0.1 → osekit-1.0.2}/tests/test_job.py +0 -0
  166. {osekit-1.0.1 → osekit-1.0.2}/tests/test_logging.py +0 -0
  167. {osekit-1.0.1 → osekit-1.0.2}/tests/test_mseed.py +0 -0
  168. {osekit-1.0.1 → osekit-1.0.2}/tests/test_multiprocessing.py +0 -0
  169. {osekit-1.0.1 → osekit-1.0.2}/tests/test_permissions.py +0 -0
  170. {osekit-1.0.1 → osekit-1.0.2}/tests/test_serialization.py +0 -0
  171. {osekit-1.0.1 → osekit-1.0.2}/tests/test_timestamp_utils.py +0 -0
  172. {osekit-1.0.1 → osekit-1.0.2}/tests/test_welch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osekit
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: OSEkit
5
5
  Author-email: OSmOSE team <osmose@ensta-bretagne.fr>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "osekit"
3
- version = "1.0.1"
3
+ version = "1.0.2"
4
4
  description = "OSEkit"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -70,6 +70,9 @@ lint.select = ["ALL"]
70
70
  "docs/source/*.ipynb" = [
71
71
  "E402", # Module level import not at top of cell in doc notebooks
72
72
  ]
73
+ "*" = [
74
+ "ANN401" # typing.Any type hint for *args and **kwargs
75
+ ]
73
76
 
74
77
 
75
78
  [tool.pytest.ini_options]
@@ -85,9 +85,6 @@ class AudioFileManager:
85
85
  """
86
86
  _, frames, _ = self.info(path)
87
87
 
88
- if stop is None:
89
- stop = frames
90
-
91
88
  if stop is None:
92
89
  stop = frames
93
90
 
@@ -20,7 +20,7 @@ from osekit.core.audio_file import AudioFile
20
20
  from osekit.core.audio_item import AudioItem
21
21
  from osekit.core.base_data import BaseData
22
22
  from osekit.core.instrument import Instrument
23
- from osekit.utils.audio import Normalization, normalize
23
+ from osekit.utils.audio import Butterworth, Normalization, normalize
24
24
 
25
25
  if TYPE_CHECKING:
26
26
  from pathlib import Path
@@ -45,6 +45,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
45
45
  instrument: Instrument | None = None,
46
46
  normalization: Normalization = Normalization.RAW,
47
47
  normalization_values: dict | None = None,
48
+ butter: Butterworth | None = None,
48
49
  ) -> None:
49
50
  """Initialize an ``AudioData`` from a list of ``AudioItems``.
50
51
 
@@ -67,6 +68,8 @@ class AudioData(BaseData[AudioItem, AudioFile]):
67
68
  the wav audio data.
68
69
  normalization: Normalization
69
70
  The type of normalization to apply to the audio data.
71
+ butter: Butterworth | None
72
+ Butterworth filter to apply to the audio data.
70
73
 
71
74
  """
72
75
  super().__init__(items=items, begin=begin, end=end, name=name)
@@ -74,6 +77,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
74
77
  self.instrument = instrument
75
78
  self.normalization = normalization
76
79
  self.normalization_values = normalization_values
80
+ self.butter = butter
77
81
 
78
82
  @property
79
83
  def nb_channels(self) -> int:
@@ -123,6 +127,15 @@ class AudioData(BaseData[AudioItem, AudioFile]):
123
127
  }
124
128
  )
125
129
 
130
+ @property
131
+ def butter(self) -> Butterworth:
132
+ """The Butterworth filter to apply to the audio data."""
133
+ return self._butter
134
+
135
+ @butter.setter
136
+ def butter(self, value: Butterworth) -> None:
137
+ self._butter = value
138
+
126
139
  @classmethod
127
140
  def _make_item(
128
141
  cls,
@@ -178,7 +191,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
178
191
  "std": standard deviation used for z-score normalization
179
192
 
180
193
  """
181
- values = np.array(self.get_raw_value())
194
+ values = np.array(self.get_filtered_value())
182
195
  self.normalization_values = {
183
196
  "mean": values.mean(),
184
197
  "peak": values.max(),
@@ -222,6 +235,22 @@ class AudioData(BaseData[AudioItem, AudioFile]):
222
235
  """
223
236
  return np.vstack(list(self.stream()))
224
237
 
238
+ def get_filtered_value(self) -> np.ndarray:
239
+ """Return the value of the audio data after filtering.
240
+
241
+ Returns
242
+ -------
243
+ np.ndarray:
244
+ The value of the audio data filtered by the ``self.butter`` Butterworth filter.
245
+
246
+ """
247
+ output = self.get_raw_value()
248
+ return (
249
+ output
250
+ if self.butter is None
251
+ else self.butter.filter(sig=output, fs=self.sample_rate)
252
+ )
253
+
225
254
  @staticmethod
226
255
  def _flush(
227
256
  resampler: soxr.ResampleStream,
@@ -320,7 +349,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
320
349
 
321
350
  """
322
351
  return normalize(
323
- values=self.get_raw_value(),
352
+ values=self.get_filtered_value(),
324
353
  normalization=self.normalization,
325
354
  **self.normalization_values,
326
355
  )
@@ -547,9 +576,13 @@ class AudioData(BaseData[AudioItem, AudioFile]):
547
576
  None if self.instrument is None else self.instrument.to_dict()
548
577
  ),
549
578
  }
579
+ butter_dict = {
580
+ "butter": (None if self.butter is None else self.butter.to_dict()),
581
+ }
550
582
  return (
551
583
  base_dict
552
584
  | instrument_dict
585
+ | butter_dict
553
586
  | {
554
587
  "sample_rate": self.sample_rate,
555
588
  "normalization": self.normalization.value,
@@ -595,6 +628,11 @@ class AudioData(BaseData[AudioItem, AudioFile]):
595
628
  if dictionary["instrument"] is None
596
629
  else Instrument.from_dict(dictionary["instrument"])
597
630
  )
631
+ butter = (
632
+ None
633
+ if "butter" not in dictionary or dictionary["butter"] is None
634
+ else Butterworth.from_dict(dictionary["butter"])
635
+ )
598
636
  return cls.from_files(
599
637
  files=files,
600
638
  begin=begin,
@@ -603,6 +641,7 @@ class AudioData(BaseData[AudioItem, AudioFile]):
603
641
  sample_rate=dictionary["sample_rate"],
604
642
  normalization=Normalization(dictionary["normalization"]),
605
643
  normalization_values=dictionary["normalization_values"],
644
+ butter=butter,
606
645
  )
607
646
 
608
647
  @classmethod
@@ -641,6 +680,9 @@ class AudioData(BaseData[AudioItem, AudioFile]):
641
680
  normalization: Normalization
642
681
  The type of normalization to apply to the audio data.
643
682
 
683
+ butter: Butterworth
684
+ Butterworth filter to apply to the audio data.
685
+
644
686
  Returns
645
687
  -------
646
688
  Self:
@@ -13,7 +13,7 @@ from osekit.core.audio_data import AudioData
13
13
  from osekit.core.audio_file import AudioFile
14
14
  from osekit.core.base_dataset import BaseDataset
15
15
  from osekit.core.json_serializer import deserialize_json
16
- from osekit.utils.audio import Normalization
16
+ from osekit.utils.audio import Butterworth, Normalization
17
17
  from osekit.utils.multiprocess import multiprocess
18
18
 
19
19
  if TYPE_CHECKING:
@@ -89,6 +89,17 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
89
89
  for data in self.data:
90
90
  data.normalization = normalization
91
91
 
92
+ @property
93
+ def butter(self) -> Butterworth:
94
+ """Return the most frequent Butterworth filter among those of this dataset data."""
95
+ butters = [data.butter for data in self.data]
96
+ return max(set(butters), key=butters.count)
97
+
98
+ @butter.setter
99
+ def butter(self, butter: Butterworth) -> None:
100
+ for data in self.data:
101
+ data.butter = butter
102
+
92
103
  @property
93
104
  def instrument(self) -> Instrument | None:
94
105
  """Instrument that can be used to get acoustic pressure from wav audio data."""
@@ -176,7 +187,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
176
187
  def from_folder( # noqa: PLR0913
177
188
  cls,
178
189
  folder: Path,
179
- strptime_format: str | None,
190
+ strptime_format: str | list[str] | None,
180
191
  begin: Timestamp | None = None,
181
192
  end: Timestamp | None = None,
182
193
  timezone: str | pytz.timezone | None = None,
@@ -187,6 +198,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
187
198
  name: str | None = None,
188
199
  instrument: Instrument | None = None,
189
200
  normalization: Normalization = Normalization.RAW,
201
+ butter: Butterworth | None = None,
190
202
  **kwargs, # noqa: ANN003
191
203
  ) -> Self:
192
204
  """Return an ``AudioDataset`` from a folder containing the audio files.
@@ -195,7 +207,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
195
207
  ----------
196
208
  folder: Path
197
209
  The folder containing the audio files.
198
- strptime_format: str | None
210
+ strptime_format: str | list[str] | None
199
211
  The strptime format used in the filenames.
200
212
  It should use valid strftime codes (https://strftime.org/).
201
213
  If ``None``, the first audio file of the folder will start
@@ -240,6 +252,8 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
240
252
  the wav audio data.
241
253
  normalization: Normalization
242
254
  The type of normalization to apply to the audio data.
255
+ butter: Butterworth | None
256
+ Butterworth filter to apply to the audio data.
243
257
  kwargs: any
244
258
  Keyword arguments passed to the ``BaseDataset.from_folder()`` classmethod.
245
259
 
@@ -262,6 +276,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
262
276
  name=name,
263
277
  instrument=instrument,
264
278
  normalization=normalization,
279
+ butter=butter,
265
280
  )
266
281
 
267
282
  @classmethod
@@ -277,6 +292,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
277
292
  sample_rate: float | None = None,
278
293
  instrument: Instrument | None = None,
279
294
  normalization: Normalization = Normalization.RAW,
295
+ butter: Butterworth | None = None,
280
296
  ) -> AudioDataset:
281
297
  """Return an AudioDataset object from a list of AudioFiles.
282
298
 
@@ -317,6 +333,8 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
317
333
  the wav audio data.
318
334
  normalization: Normalization
319
335
  The type of normalization to apply to the audio data.
336
+ butter: Butterworth | None
337
+ Butterworth filter to apply to the audio data.
320
338
 
321
339
  Returns
322
340
  -------
@@ -335,6 +353,7 @@ class AudioDataset(BaseDataset[AudioData, AudioFile]):
335
353
  mode=mode,
336
354
  overlap=overlap,
337
355
  data_duration=data_duration,
356
+ butter=butter,
338
357
  )
339
358
 
340
359
  @classmethod
@@ -45,7 +45,7 @@ class AudioFile(BaseFile):
45
45
  If it is not provided, ``strptime_format`` is mandatory.
46
46
  If both ``begin`` and ``strptime_format`` are provided,
47
47
  ``begin`` will overrule the timestamp embedded in the filename.
48
- strptime_format: str | None
48
+ strptime_format: str | list[str] | None
49
49
  The strptime format used in the text.
50
50
  It should use valid strftime codes (https://strftime.org/).
51
51
  Example: ``'%y%m%d_%H:%M:%S'``.
@@ -151,20 +151,28 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
151
151
  """
152
152
  self._folder = folder
153
153
 
154
- def move_files(self, folder: Path) -> None:
154
+ def move_files(self, folder: Path, *, keep_relative_structure: bool = True) -> None:
155
155
  """Move the dataset files to the destination folder.
156
156
 
157
157
  Parameters
158
158
  ----------
159
159
  folder: Path
160
160
  Destination folder in which the dataset files will be moved.
161
+ keep_relative_structure: bool
162
+ If True, the relative path from the dataset to the file will be preserved.
163
+ If False, the files will be moved to ``folder`` regardless of their original
164
+ relative path to the dataset folder.
161
165
 
162
166
  """
163
167
  for file in tqdm(
164
168
  self.files,
165
169
  disable=os.getenv("DISABLE_TQDM", "False").lower() in ("true", "1", "t"),
166
170
  ):
167
- file.move(folder)
171
+ if not keep_relative_structure:
172
+ file.move(folder)
173
+ continue
174
+ relative_folder = folder / file.path.relative_to(self.folder).parent
175
+ file.move(relative_folder)
168
176
  self._folder = folder
169
177
 
170
178
  @property
@@ -511,7 +519,7 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
511
519
  def from_folder( # noqa: PLR0913
512
520
  cls: type[Self],
513
521
  folder: Path,
514
- strptime_format: str | None,
522
+ strptime_format: str | list[str] | None,
515
523
  begin: Timestamp | None = None,
516
524
  end: Timestamp | None = None,
517
525
  timezone: str | pytz.timezone | None = None,
@@ -528,7 +536,7 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
528
536
  ----------
529
537
  folder: Path
530
538
  The folder containing the files.
531
- strptime_format: str | None
539
+ strptime_format: str | list[str] | None
532
540
  The strptime format used in the filenames.
533
541
  It should use valid strftime codes (https://strftime.org/).
534
542
  If None, the first audio file of the folder will start
@@ -619,7 +627,7 @@ class BaseDataset[TData: BaseData, TFile: BaseFile](Event, ABC):
619
627
  def _parse_file(
620
628
  cls: type[Self],
621
629
  file: Path,
622
- strptime_format: str,
630
+ strptime_format: str | list[str] | None,
623
631
  timezone: str | pytz.timezone | None,
624
632
  begin_timestamp: Timestamp,
625
633
  valid_files: list[TFile],
@@ -62,7 +62,7 @@ class BaseFile(Event, ABC):
62
62
  ``begin`` will overrule the timestamp embedded in the filename.
63
63
  end: pandas.Timestamp | None
64
64
  (Optional) timestamp after the last data point in the file.
65
- strptime_format: str | None
65
+ strptime_format: str | list[str] | None
66
66
  The strptime format used in the text.
67
67
  It should use valid strftime codes (https://strftime.org/).
68
68
  Example: ``'%y%m%d_%H:%M:%S'``.
@@ -527,7 +527,7 @@ class SpectroDataset(BaseDataset[SpectroData, SpectroFile]):
527
527
  def from_folder( # noqa: PLR0913
528
528
  cls,
529
529
  folder: Path,
530
- strptime_format: str,
530
+ strptime_format: str | list[str] | None,
531
531
  begin: Timestamp | None = None,
532
532
  end: Timestamp | None = None,
533
533
  timezone: str | pytz.timezone | None = None,
@@ -543,7 +543,7 @@ class SpectroDataset(BaseDataset[SpectroData, SpectroFile]):
543
543
  ----------
544
544
  folder: Path
545
545
  The folder containing the spectro files.
546
- strptime_format: str
546
+ strptime_format: str | list[str] | None
547
547
  The strptime format of the timestamps in the spectro file names.
548
548
  begin: Timestamp | None
549
549
  The begin of the spectro dataset.
@@ -51,7 +51,7 @@ class SpectroFile(BaseFile):
51
51
  If it is not provided, ``strptime_format`` is mandatory.
52
52
  If both ``begin`` and ``strptime_format`` are provided,
53
53
  ``begin`` will overrule the timestamp embedded in the filename.
54
- strptime_format: str | None
54
+ strptime_format: str | list[str] | None
55
55
  The strptime format used in the text.
56
56
  It should use valid strftime codes (https://strftime.org/).
57
57
  Example: ``'%y%m%d_%H:%M:%S'``.
@@ -11,6 +11,7 @@ from __future__ import annotations
11
11
 
12
12
  import logging
13
13
  import shutil
14
+ import typing
14
15
  from pathlib import Path
15
16
  from typing import TYPE_CHECKING, TypeVar
16
17
 
@@ -50,10 +51,17 @@ class Project:
50
51
 
51
52
  """
52
53
 
54
+ SUBFOLDERS: typing.ClassVar = {
55
+ "data": "data",
56
+ "processed": "processed",
57
+ "other": "other",
58
+ "log": "log",
59
+ }
60
+
53
61
  def __init__( # noqa: PLR0913
54
62
  self,
55
63
  folder: Path,
56
- strptime_format: str | None,
64
+ strptime_format: str | list[str] | None,
57
65
  gps_coordinates: str | list | tuple = (0, 0),
58
66
  depth: float = 0.0,
59
67
  timezone: str | None = None,
@@ -68,7 +76,7 @@ class Project:
68
76
  ----------
69
77
  folder: Path
70
78
  Path to the folder containing the original audio files.
71
- strptime_format: str | None
79
+ strptime_format: str | list[str] | None
72
80
  The strptime format used in the filenames.
73
81
  It should use valid strftime codes (https://strftime.org/).
74
82
  If ``None``, the first audio file of the folder will start
@@ -162,16 +170,13 @@ class Project:
162
170
 
163
171
  self.logger.info("Organizing project folder...")
164
172
  afm.close()
173
+ for folder in self.SUBFOLDERS.values():
174
+ (self.folder / folder).mkdir(exist_ok=True)
165
175
  move_tree(
166
176
  source=self.folder,
167
- destination=self.folder / "other",
177
+ destination=self.folder / self.SUBFOLDERS["other"],
168
178
  excluded_paths={file.path for file in ads.files}
169
- | set(
170
- (self.folder / "log").iterdir()
171
- if (self.folder / "log").exists()
172
- else (),
173
- )
174
- | {self.folder / "log"},
179
+ | {self.folder / folder for folder in self.SUBFOLDERS.values()},
175
180
  )
176
181
  self._sort_dataset(ads)
177
182
  ads.write_json(ads.folder)
@@ -228,7 +233,7 @@ class Project:
228
233
  self.logger = logging.getLogger()
229
234
  return
230
235
 
231
- logs_directory = self.folder / "log"
236
+ logs_directory = self.folder / self.SUBFOLDERS["log"]
232
237
  if not logs_directory.exists():
233
238
  logs_directory.mkdir(mode=DPDEFAULT, parents=True)
234
239
  self.logger = logging.getLogger("project").getChild(self.folder.name)
@@ -250,10 +255,29 @@ class Project:
250
255
  afm.close()
251
256
 
252
257
  files_to_remove = list(self.folder.iterdir())
258
+
259
+ misplaced_files = []
260
+ for file in files_to_remove:
261
+ if file.name == "project.json":
262
+ continue
263
+ if file in (
264
+ self.folder / subfolder for subfolder in self.SUBFOLDERS.values()
265
+ ):
266
+ continue
267
+ misplaced_files.append(file)
268
+ if misplaced_files:
269
+ msg = (
270
+ "Some file(s) or folder(s) would be deleted by a reset.\n"
271
+ "Either delete them manually or move them to the "
272
+ "'other' folder before resetting the project:\n"
273
+ )
274
+ msg += "\n".join(file.name for file in misplaced_files)
275
+ raise RuntimeError(msg)
276
+
253
277
  self.get_output("original").move_files(self.folder)
254
278
 
255
- if self.folder / "other" in files_to_remove:
256
- move_tree(self.folder / "other", self.folder)
279
+ if self.folder / self.SUBFOLDERS["other"] in files_to_remove:
280
+ move_tree(self.folder / self.SUBFOLDERS["other"], self.folder)
257
281
 
258
282
  self.logger.handlers.clear()
259
283
 
@@ -294,6 +318,7 @@ class Project:
294
318
  mode=transform.mode,
295
319
  overlap=transform.overlap,
296
320
  normalization=transform.normalization,
321
+ butter=transform.butter,
297
322
  name=transform.name,
298
323
  instrument=self.instrument,
299
324
  )
@@ -458,7 +483,7 @@ class Project:
458
483
  ) -> Path:
459
484
  return (
460
485
  self.folder
461
- / "data"
486
+ / self.SUBFOLDERS["data"]
462
487
  / "audio"
463
488
  / (
464
489
  f"{round(ads.data_duration.total_seconds())}_{round(ads.sample_rate)}"
@@ -585,7 +610,7 @@ class Project:
585
610
  "dataset-json-path": self.folder / "project.json",
586
611
  },
587
612
  name=name + (f"_{index}" if len(batch_indexes) > 1 else ""),
588
- output_folder=self.folder / "log",
613
+ output_folder=self.folder / self.SUBFOLDERS["log"],
589
614
  )
590
615
  self.job_builder.submit_pbs()
591
616
 
@@ -612,7 +637,7 @@ class Project:
612
637
  fft_folder = f"{sds.fft.mfft}_{sds.fft.win.shape[0]}_{sds.fft.hop}_linear"
613
638
  return (
614
639
  self.folder
615
- / "processed"
640
+ / self.SUBFOLDERS["processed"]
616
641
  / (ads_folder / fft_folder if sds.has_default_name else sds.name)
617
642
  )
618
643
 
@@ -624,7 +649,10 @@ class Project:
624
649
  self._sort_spectro_dataset(dataset)
625
650
 
626
651
  def _sort_audio_dataset(self, dataset: AudioDataset) -> None:
627
- dataset.move_files(self._get_audio_dataset_subpath(dataset))
652
+ dataset.move_files(
653
+ self._get_audio_dataset_subpath(dataset),
654
+ keep_relative_structure=False,
655
+ )
628
656
 
629
657
  def _sort_spectro_dataset(self, dataset: SpectroDataset | LTASDataset) -> None:
630
658
  raise NotImplementedError
@@ -744,6 +772,10 @@ class Project:
744
772
  Name of the transform whose output to delete.
745
773
 
746
774
  """
775
+ if transform_name not in self.transforms:
776
+ message = f"Transform '{transform_name}' not found."
777
+ raise ValueError(message)
778
+
747
779
  for dataset_to_delete in self.get_output_by_transform_name(
748
780
  transform_name,
749
781
  ):
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from enum import Flag, auto
4
4
  from typing import TYPE_CHECKING, Literal
5
5
 
6
- from osekit.utils.audio import Normalization
6
+ from osekit.utils.audio import Butterworth, Normalization
7
7
 
8
8
  if TYPE_CHECKING:
9
9
  from pandas import Timedelta, Timestamp
@@ -73,6 +73,7 @@ class Transform:
73
73
  overlap: float = 0.0,
74
74
  sample_rate: float | None = None,
75
75
  normalization: Normalization = Normalization.RAW,
76
+ butter: Butterworth | None = None,
76
77
  name: str | None = None,
77
78
  subtype: str | None = None,
78
79
  fft: ShortTimeFFT | None = None,
@@ -118,6 +119,8 @@ class Transform:
118
119
  will be set to the one of the original dataset.
119
120
  normalization: Normalization
120
121
  The type of normalization to apply to the audio data.
122
+ butter: Butterworth | None
123
+ Butterworth filter to apply to the audio data.
121
124
  name: str | None
122
125
  Name of the transform dataset.
123
126
  Defaulted as the begin timestamp of the transform dataset.
@@ -160,6 +163,7 @@ class Transform:
160
163
  self.sample_rate = sample_rate
161
164
  self.name = name
162
165
  self.normalization = normalization
166
+ self.butter = butter
163
167
  self.subtype = subtype
164
168
  self.v_lim = v_lim
165
169
  self.colormap = colormap
@@ -1,11 +1,14 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import dataclasses
3
4
  import enum
5
+ from collections.abc import Iterable
4
6
  from typing import Literal, Self
5
7
 
6
8
  import numpy as np
7
9
  import soxr
8
10
  from pandas import Timedelta
11
+ from scipy import signal
9
12
 
10
13
  from osekit.config import (
11
14
  resample_quality_settings,
@@ -203,3 +206,101 @@ def normalize(
203
206
  if Normalization.ZSCORE in normalization:
204
207
  values = normalize_zscore(values=values, mean=mean, std=std)
205
208
  return values
209
+
210
+
211
+ @dataclasses.dataclass
212
+ class Butterworth:
213
+ """Class that represent a Butterworth sos filter.
214
+
215
+ Parameters
216
+ ----------
217
+ N: int
218
+ The order of the filter.
219
+ For "bandpass" and "bandstop" filters, the resulting order of the final
220
+ second-order sections ("sos") matrix is ``2*N``,
221
+ with ``N`` the number of biquad sections of the desired system.
222
+ Wn: Iterable | int | float
223
+ The critical frequency or frequencies.
224
+ For lowpass and highpass filters, ``Wn`` is a scalar.
225
+ For bandpass and bandstop filters, ``Wn`` is a length-2 sequence.
226
+ For a Butterworth filter, this is the point at which the gain
227
+ drops to ``1/sqrt(2)`` that of the passband (the “-3 dB point”).
228
+ For digital filters, if ``fs`` is not specified,
229
+ ``Wn`` units are normalized from ``0`` to ``1``,
230
+ where ``1`` is the Nyquist frequency
231
+ (``Wn`` is thus in half cycles / sample and defined as
232
+ ``2*critical frequencies / fs``).
233
+ If ``fs`` is specified, ``Wn`` is in the same units as ``fs``.
234
+ For analog filters, ``Wn`` is an angular frequency (e.g. ``rad/s``).
235
+ btype: Literal["lowpass", "highpass", "bandpass", "bandstop"]
236
+ The type of filter. Default is "lowpass".
237
+
238
+ """
239
+
240
+ N: int
241
+ Wn: Iterable | int | float
242
+ btype: Literal["lowpass", "highpass", "bandpass", "bandstop"] = "lowpass"
243
+
244
+ def to_dict(self) -> dict:
245
+ """Serialize a Butterworth sos filter to a dictionary.
246
+
247
+ Returns
248
+ -------
249
+ dict:
250
+ Serialized Butterworth sos filter.
251
+
252
+ """
253
+ return {
254
+ "N": self.N,
255
+ "Wn": self.Wn,
256
+ "btype": self.btype,
257
+ }
258
+
259
+ @classmethod
260
+ def from_dict(cls, data: dict) -> Butterworth:
261
+ """Deserialize a Butterworth sos filter from a dictionary.
262
+
263
+ Parameters
264
+ ----------
265
+ data: dict
266
+ Serialized Butterworth sos filter.
267
+
268
+ Returns
269
+ -------
270
+ Butterworth:
271
+ The Butterworth sos filter.
272
+
273
+ """
274
+ return cls(
275
+ N=data["N"],
276
+ Wn=data["Wn"],
277
+ btype=data["btype"],
278
+ )
279
+
280
+ def filter(self, sig: np.typing.NDArray, fs: float) -> np.typing.NDArray:
281
+ """Filter an input signal with the Butterworth sos filter.
282
+
283
+ Parameters
284
+ ----------
285
+ sig: np.typing.NDArray
286
+ Input signal
287
+ fs: float
288
+ Sampling frequency of the signal
289
+
290
+ Returns
291
+ -------
292
+ np.typing.NDArray
293
+ Filtered signal
294
+
295
+ """
296
+ sos = signal.butter(
297
+ N=self.N,
298
+ Wn=self.Wn,
299
+ btype=self.btype,
300
+ fs=fs,
301
+ output="sos",
302
+ )
303
+ return signal.sosfilt(sos=sos, x=sig, axis=0)
304
+
305
+ def __hash__(self) -> int:
306
+ return hash((self.N, self.Wn, self.btype))