SpectroDataset#
- class osekit.core_api.spectro_dataset.SpectroDataset(data: list[~osekit.core_api.spectro_data.SpectroData], name: str | None = None, suffix: str = '', folder: ~pathlib.Path | None = None, scale: ~osekit.core_api.frequency_scale.Scale | None = None, v_lim: tuple[float, float] | None | object = <object object>)#
SpectroDatasetis a collection ofSpectroDataobjects.SpectroDatasetis a collection ofSpectroData, with methods that simplify repeated operations on theSpectroData.Initialize a
SpectroDataset.- property colormap: str#
Return the most frequent
colormapof the spectro dataset.
- data_cls#
alias of
SpectroData
- property fft: ShortTimeFFT#
Return the fft of the spectro data.
- file_cls#
alias of
SpectroFile
- property folder: Path#
Folder in which the dataset files are located.
- classmethod from_audio_dataset(audio_dataset: AudioDataset, fft: ShortTimeFFT, name: str | None = None, colormap: str | None = None, v_lim: tuple[float, float] | None=<object object>, scale: Scale | None = None) SpectroDataset#
Return a
SpectroDatasetobject from anAudioDatasetobject.The
SpectroDatais computed from theAudioDatausingfft.
- classmethod from_dict(dictionary: dict) SpectroDataset#
Deserialize a
SpectroDatasetfrom a dictionary.Parameters#
- dictionary: dict
The serialized dictionary representing the
SpectroDataset.
Returns#
- SpectroDataset
The deserialized
SpectroDataset.
- classmethod from_files(files: list[SpectroFile], begin: Timestamp | None = None, end: Timestamp | None = None, name: str | None = None, mode: Literal['files', 'timedelta_total', 'timedelta_file'] = 'timedelta_total', overlap: float = 0.0, data_duration: Timedelta | None = None, **kwargs) AudioDataset#
Return an
SpectroDatasetobject from a list ofSpectroFiles.Parameters#
- files: list[SpectroFile]
The list of files contained in the Dataset.
- begin: Timestamp | None
Begin of the first data object. Defaulted to the begin of the first file.
- end: Timestamp | None
End of the last data object. Defaulted to the end of the last file.
- mode: Literal[“files”, “timedelta_total”, “timedelta_file”]
Mode of creation of the dataset data from the original files.
"files": one data will be created for each file."timedelta_total": data objects of duration equal todata_durationwill be created from thebegintimestamp to theendtimestamp."timedelta_file": data objects of duration equal todata_durationwill be created from the beginning of the first file that thebegintimestamp is into, until it would resume in a data beginning between two files. Then, the next data object will be created from the beginning of the next original file and so on.- overlap: float
Overlap percentage between consecutive data.
- data_duration: Timedelta | None
Duration of the spectro data objects. If mode is set to
"files", this parameter has no effect. If provided, spectro data will be evenly distributed betweenbeginandend. Else, one data object will cover the whole time period.- sample_rate: float | None
Sample rate of the audio data objects.
- name: str|None
Name of the dataset.
- instrument: Instrument | None
Instrument that might be used to obtain acoustic pressure from the
wavaudio data.- normalization: Normalization
The type of normalization to apply to the audio data.
- kwargs:
None
Returns#
SpectroDataset: The
SpectroDatasetobject.
- classmethod from_folder(folder: Path, strptime_format: str, begin: Timestamp | None = None, end: Timestamp | None = None, timezone: str | pytz.timezone | None = None, mode: Literal['files', 'timedelta_total', 'timedelta_file'] = 'timedelta_total', overlap: float = 0.0, data_duration: Timedelta | None = None, name: str | None = None, **kwargs) Self#
Return a
SpectroDatasetfrom a folder containing the spectro files.Parameters#
- folder: Path
The folder containing the spectro files.
- strptime_format: str
The strptime format of the timestamps in the spectro file names.
- begin: Timestamp | None
The begin of the spectro dataset. Defaulted to the begin of the first file.
- end: Timestamp | None
The end of the spectro dataset. Defaulted to the end of the last file.
- timezone: str | pytz.timezone | None
The timezone in which the file should be localized. If
None, the file begin/end will be tz-naive. If different from a timezone parsed from the filename, the timestamps’ timezone will be converted from the parsed timezone to the specified timezone.- mode: Literal[“files”, “timedelta_total”, “timedelta_file”]
Mode of creation of the dataset data from the original files.
"files": one data will be created for each file."timedelta_total": data objects of duration equal todata_durationwill be created from thebegintimestamp to theendtimestamp."timedelta_file": data objects of duration equal todata_durationwill be created from the beginning of the first file that thebegintimestamp is into, until it would resume in a data beginning between two files. Then, the next data object will be created from the beginning of the next original file and so on.- overlap: float
Overlap percentage between consecutive data.
- data_duration: Timedelta | None
Duration of the spectro data objects. If mode is set to
"files", this parameter has no effect. If provided, spectro data will be evenly distributed betweenbeginandend. Else, one data object will cover the whole time period.- name: str|None
Name of the dataset.
- kwargs:
None
Returns#
- Spectrodataset:
The
SpectroDatasetinstance.
- classmethod from_json(file: Path) SpectroDataset#
Deserialize a
SpectroDatasetfrom ajsonfile.Parameters#
- file: Path
Path to the serialized
jsonrepresenting theSpectroDataset.
Returns#
- SpectroDataset
The deserialized
SpectroDataset.
- get_welch(first: int = 0, last: int | None = None, nperseg: int | None = None, detrend: str | callable | False = 'constant', scaling: Literal['density', 'spectrum'] = 'density', average: Literal['mean', 'median'] = 'mean', *, return_onesided: bool = True) DataFrame#
Return the welch values of the
SpectroDataset.Each
SpectroDataof theSpectroDatasetrepresent one column of the welch values.Parameters#
- first: int
Index of the first
SpectroDataobject to include in the welch.- last: int
Index after the last
SpectroDataobject to include in the welch.- nperseg: int|None
Length of each segment. Defaults to
None, but if window isstrortuple, is set to256, and if window isarray_like, is set to the length of the window.- detrend: str | callable | False
Specifies how to detrend each segment. If detrend is a
str, it is passed as the type argument to the detrend function. If it is afunc, it takes a segment and returns a detrended segment. If detrend isFalse, no detrending is done. Defaults to'constant'.- return_onesided: bool
If
True, return a one-sided spectrum for real data. IfFalse, return a two-sided spectrum. Defaults toTrue, but for complex data, a two-sided spectrum is always returned.- scaling: Literal[“density”, “spectrum”]
Selects between computing the power spectral density (
'density') wherePxxhas units ofV**2/Hzand computing the squared magnitude spectrum ('spectrum') wherePxxhas units ofV**2, ifxis measured inVandfsis measured inHz. Defaults to'density'.- average: Literal[“mean”, “median”]
Method to use when averaging periodograms. Defaults to
'mean'.- return_onesided: bool
If True, return a one-sided spectrum for real data. If False return a two-sided spectrum. Defaults to True, but for complex data, a two-sided spectrum is always returned.
- link_audio_dataset(audio_dataset: AudioDataset, first: int = 0, last: int | None = None) None#
Link the
SpectroDatasetto theAudioDataset.The
SpectroDataof theSpectroDatasetwill be linked to theAudioDataof theAudioDataset.There should be in the
AudioDatasetanAudioDatathat have the samebeginandendthan each of theSpectroDataof theSpectroDataset.Parameters#
- audio_dataset: AudioDataset
The
AudioDatasetwhich data will be linked to theSpectroDatasetdata.- first: int
Index of the first
SpectroDataandAudioDatato link.- last: int
Index of the last
SpectroDataandAudioDatato link.
- save_all(matrix_folder: Path, spectrogram_folder: Path, first: int = 0, last: int | None = None, *, link: bool = False) None#
Export both Sx matrices as
npzfiles and spectrograms for each data.Parameters#
- matrix_folder: Path
Path to the folder in which the Sx matrices
npzfiles will be saved.- spectrogram_folder: Path
Path to the folder in which the spectrograms
pngfiles will be saved.- link: bool
If
True, theSpectroDatawill be bound to the writtennpzfile. Its items will be replaced with a single item, which will match the whole newSpectroFile.- first: int
Index of the first
SpectroDataobject to export.- last: int|None
Index after the last
SpectroDataobject to export.
- save_spectrogram(folder: Path, first: int = 0, last: int | None = None) None#
Export all spectrogram data as
pngimages in the specified folder.Parameters#
- folder: Path
Folder in which the spectrograms should be saved.
- first: int
Index of the first
SpectroDataobject to export.- last: int|None
Index after the last
SpectroDataobject to export.
- to_dict() dict#
Serialize a
SpectroDatasetto a dictionary.Returns#
- dict:
The serialized dictionary representing the
SpectroDataset.
- update_json_audio_data(first: int, last: int) None#
Update the serialized
jsonfile with the spectro data from first to last.The update is done while using the locked decorator. That way, if a
SpectroDatasetis processed through multiple jobs, each one can update thejsonfile safely.Parameters#
- first: int
Index of the first data to update.
- last: int
Index of the last data to update.
- property v_lim: tuple[float, float] | None#
Return the most frequent
v_limof the spectro dataset.
- write_welch(folder: Path, first: int = 0, last: int | None = None, nperseg: int | None = None, detrend: str | callable | False = 'constant', scaling: Literal['density', 'spectrum'] = 'density', average: Literal['mean', 'median'] = 'mean', pxs: DataFrame | None = None, *, return_onesided: bool = True) None#
Write the welch values of the SpectroDataset in a npz file.
Parameters#
- folder: Path
The folder in which the
npzfile will be written.- first: int
Index of the first
SpectroDataobject to include in the welch.- last: int
Index after the last
SpectroDataobject to include in the welch.- nperseg: int|None
Length of each segment. Defaults to
None, but if window isstrortuple, is set to256, and if window isarray_like, is set to the length of the window.- detrend: str | callable | False
Specifies how to detrend each segment. If detrend is a
str, it is passed as the type argument to the detrend function. If it is afunc, it takes a segment and returns a detrended segment. If detrend isFalse, no detrending is done. Defaults to'constant'.- return_onesided: bool
If
True, return a one-sided spectrum for real data. IfFalse, return a two-sided spectrum. Defaults toTrue, but for complex data, a two-sided spectrum is always returned.- scaling: Literal[“density”, “spectrum”]
Selects between computing the power spectral density (
'density') wherePxxhas units ofV**2/Hzand computing the squared magnitude spectrum ('spectrum') wherePxxhas units ofV**2, ifxis measured inVandfsis measured inHz. Defaults to'density'.- average: Literal[“mean”, “median”]
Method to use when averaging periodograms. Defaults to
'mean'.- pxs: DataFrame | None
Welch values as returned by
SpectroDataset.get_welch(). If provided, the computation will be skipped and the provided pxs values will be written to disk.- return_onesided: bool
If
True, return a one-sided spectrum for real data. IfFalsereturn a two-sided spectrum. Defaults toTrue, but for complex data, a two-sided spectrum is always returned.