mirror of
https://github.com/macaodha/batdetect2.git
synced 2025-06-29 22:51:58 +02:00
Expose preprocessing functions
This commit is contained in:
parent
e383a33cbf
commit
bfa6049adc
@ -3,7 +3,6 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import xarray as xr
|
import xarray as xr
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from soundevent import data
|
from soundevent import data
|
||||||
|
|
||||||
from batdetect2.preprocess.audio import (
|
from batdetect2.preprocess.audio import (
|
||||||
@ -11,41 +10,39 @@ from batdetect2.preprocess.audio import (
|
|||||||
ResampleConfig,
|
ResampleConfig,
|
||||||
load_clip_audio,
|
load_clip_audio,
|
||||||
)
|
)
|
||||||
|
from batdetect2.preprocess.config import (
|
||||||
|
PreprocessingConfig,
|
||||||
|
load_preprocessing_config,
|
||||||
|
)
|
||||||
from batdetect2.preprocess.spectrogram import (
|
from batdetect2.preprocess.spectrogram import (
|
||||||
AmplitudeScaleConfig,
|
AmplitudeScaleConfig,
|
||||||
STFTConfig,
|
|
||||||
FrequencyConfig,
|
FrequencyConfig,
|
||||||
LogScaleConfig,
|
LogScaleConfig,
|
||||||
PcenScaleConfig,
|
PcenScaleConfig,
|
||||||
Scales,
|
Scales,
|
||||||
SpecSizeConfig,
|
SpecSizeConfig,
|
||||||
SpectrogramConfig,
|
SpectrogramConfig,
|
||||||
|
STFTConfig,
|
||||||
compute_spectrogram,
|
compute_spectrogram,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"AudioConfig",
|
|
||||||
"ResampleConfig",
|
|
||||||
"SpectrogramConfig",
|
|
||||||
"STFTConfig",
|
|
||||||
"FrequencyConfig",
|
|
||||||
"PcenScaleConfig",
|
|
||||||
"LogScaleConfig",
|
|
||||||
"AmplitudeScaleConfig",
|
"AmplitudeScaleConfig",
|
||||||
|
"AudioConfig",
|
||||||
|
"FrequencyConfig",
|
||||||
|
"LogScaleConfig",
|
||||||
|
"PcenScaleConfig",
|
||||||
|
"PreprocessingConfig",
|
||||||
|
"ResampleConfig",
|
||||||
|
"STFTConfig",
|
||||||
"Scales",
|
"Scales",
|
||||||
"SpecSizeConfig",
|
"SpecSizeConfig",
|
||||||
"PreprocessingConfig",
|
"SpectrogramConfig",
|
||||||
|
"load_preprocessing_config",
|
||||||
"preprocess_audio_clip",
|
"preprocess_audio_clip",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class PreprocessingConfig(BaseModel):
|
|
||||||
"""Configuration for preprocessing data."""
|
|
||||||
|
|
||||||
audio: AudioConfig = Field(default_factory=AudioConfig)
|
|
||||||
spectrogram: SpectrogramConfig = Field(default_factory=SpectrogramConfig)
|
|
||||||
|
|
||||||
|
|
||||||
def preprocess_audio_clip(
|
def preprocess_audio_clip(
|
||||||
clip: data.Clip,
|
clip: data.Clip,
|
||||||
config: Optional[PreprocessingConfig] = None,
|
config: Optional[PreprocessingConfig] = None,
|
||||||
|
31
batdetect2/preprocess/config.py
Normal file
31
batdetect2/preprocess/config.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
from soundevent.data import PathLike
|
||||||
|
|
||||||
|
from batdetect2.configs import BaseConfig, load_config
|
||||||
|
from batdetect2.preprocess.audio import (
|
||||||
|
AudioConfig,
|
||||||
|
)
|
||||||
|
from batdetect2.preprocess.spectrogram import (
|
||||||
|
SpectrogramConfig,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"PreprocessingConfig",
|
||||||
|
"load_preprocessing_config",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class PreprocessingConfig(BaseConfig):
|
||||||
|
"""Configuration for preprocessing data."""
|
||||||
|
|
||||||
|
audio: AudioConfig = Field(default_factory=AudioConfig)
|
||||||
|
spectrogram: SpectrogramConfig = Field(default_factory=SpectrogramConfig)
|
||||||
|
|
||||||
|
|
||||||
|
def load_preprocessing_config(
|
||||||
|
path: PathLike,
|
||||||
|
field: Optional[str] = None,
|
||||||
|
) -> PreprocessingConfig:
|
||||||
|
return load_config(path, schema=PreprocessingConfig, field=field)
|
Loading…
Reference in New Issue
Block a user