Project#
- class osekit.public.project.Project(folder: Path, strptime_format: str | None, gps_coordinates: str | list | tuple = (0, 0), depth: float = 0.0, timezone: str | None = None, outputs: dict | None = None, job_builder: JobBuilder | None = None, instrument: Instrument | None = None, first_file_begin: Timestamp | None = None)#
Main class of the Public API.
The
Projectis the class that stores the original audio dataset, and from which transforms are ran from this dataset to generate spectro datasets, reshaped audio datasets, etc. It has additionnal metadata that can be exported, e.g. to APLOSE.Initialize a
Project.Parameters#
- folder: Path
Path to the folder containing the original audio files.
- strptime_format: str | None
The strptime format used in the filenames. It should use valid strftime codes (https://strftime.org/). If
None, the first audio file of the folder will start atfirst_file_begin, and each following file will start at the end of the previous one.- gps_coordinates: str | list | tuple
GPS coordinates of the location were audio files were recorded.
- depth: float
Depth at which the audio files were recorded.
- timezone: str | None
Timezone in which the audio data will be located. If the audio file timestamps are parsed with a tz-aware strptime_format (
%zor%Zcode), theAudioFileswill be converted from the parsed timezone to the specified timezone.- outputs: dict | None
Core API Datasets that have been exported in this project. Mainly used for deserialization.
- job_builder: Job_builder | None
If
None, outputs from thisProjectwill be run locally. Otherwise, PBS job files will be created and submitted when transforms are run. See theosekit.jobmodule for more info.- instrument: Instrument | None
Instrument that might be used to obtain acoustic pressure from the
wavaudio data. See theosekit.core.instrumentmodule for more info.- first_file_begin: Timestamp | None
Timestamp of the first audio file being processed. Will be ignored if
striptime_formatis specified.
- build() None#
Build the
Project.Building a
Projectmoves the original audio files to a specific folder and creates serializedjsonfiles used by APLOSE.
- build_from_files(files: Iterable[PathLike | str], *, move_files: bool = False) None#
Build the
Projectfrom the specified files.The files will be copied (or moved) to the
project.folderfolder.Parameters#
- files: Iterable[PathLike|str]
Files that are included in the project.
- move_files: bool
If set to
True, the files will be moved (rather than copied) in the project folder.
- delete_output(output_name: str) None#
Delete all output datasets from a given ran transform name.
WARNING: all the output files will be deleted.
Parameters#
- output_name: str
Name of the transform whose output to delete.
- deserialize_output(output_name: str) type[DatasetChild]#
Deserialize an output dataset from its json file.
The self.outputs property will be updated so that it stores the deserialized dataset rather than the json file so that it is deserialized only once.
Parameters#
- output_name: str
Name of the output dataset.
Returns#
- type[DatasetChild]:
The deserialized output dataset.
- export(output_type: OutputType, ads: AudioDataset | None = None, sds: SpectroDataset | LTASDataset | None = None, subtype: str | None = None, spectrum_folder_name: str = 'spectrum', spectrogram_folder_name: str = 'spectrogram', welch_folder_name: str = 'welch', nb_jobs: int = 1, name: str = 'OSEkit_transform', *, link: bool = False) None#
Perform a transform and write the results on disk.
An transform is defined as a manipulation of the original audio files: reshaping the audio, exporting
pngspectrograms ornpzmatrices (or a combination of those three) are examples of transforms. The tasks will be distributed to jobs ifself.job_builderis notNone, else it will be distributed onself.job_builder.nb_jobsjobs.Parameters#
- spectrogram_folder_name:
The name of the folder in which the
pngspectrograms will be exported (relative tosds.folder)- spectrum_folder_name:
The name of the folder in which the
npzmatrices will be exported (relative tosds.folder)- welch_folder_name:
The name of the folder in which the
npzwelch files will be exported (relative tosds.folder)- sds: SpectroDataset | LTASDataset
The
SpectroDataseton which the data should be written.- output_typeOutputType
Type of the transform to be performed.
AudioDatasetandSpectroDatasetinstances will be created depending on the flags. Seeosekit.public.transform.OutputTypedocstring for more information.- ads: AudioDataset
The
AudioDataseton which the data should be written.- subtype: str | None
The subtype of the audio files as provided by the soundfile module.
- nb_jobs: int
The number of jobs to run in parallel.
- name: str
The name of the transform being performed.
- link: bool
If
True, the ads data will be linked to the exported files.
- classmethod from_dict(dictionary: dict) Project#
Deserialize a project from a dictionary.
Parameters#
- dictionary: dict
The serialized dictionary representing the project.
Returns#
- Project
The deserialized project.
- classmethod from_json(file: Path) Project#
Deserialize a
Projectfrom ajsonfile.Parameters#
- file: Path
Path to the serialized
jsonfile representing theProject.
Returns#
- Project
The deserialized
Project.
- get_output(output_name: str) type[DatasetChild] | None#
Get an output dataset from its name.
Parameters#
- output_name: str
Name of the output dataset.
Returns#
- type[DatasetChild]:
Output dataset from the
project.outputsproperty.
- get_output_by_transform_name(transform_name: str) list[type[DatasetChild]]#
Get all output output datasets from a given transform.
Parameters#
- transform_name: str
Name of the transform of which to get the output datasets.
Returns#
list[type[DatasetChild]] List of the output datasets.
- property origin_dataset: AudioDataset#
Return the
AudioDatasetfrom which thisProjecthas been built.
- property origin_files: list[AudioFile] | None#
Return the original audio files from which this
Projecthas been built.
- prepare_audio(transform: Transform) AudioDataset#
Return an
AudioDatasetcreated from the transform parameters.Parameters#
- transform: Transform
Transformfor which to generate anAudioDatasetobject.
Returns#
- AudioDataset:
The
AudioDatasetthat match the transform parameters. ThisAudioDatasetcan be used either to have a peek at the transform output, or to edit the transform (adding/removing data) by editing it and passing it as a parameter to theProject.run()method.
- prepare_spectro(transform: Transform, audio_dataset: AudioDataset | None = None) SpectroDataset | LTASDataset#
Return a
SpectroDataset(orLTASDataset) created from transform parameters.Parameters#
- transform: Transform
Transformfor which to generate anAudioDatasetobject.- audio_dataset: AudioDataset|None
If provided, the
SpectroDatasetwill be initialized from thisAudioDataset. This can be used to edit the transform (e.g. adding/removing data) before running it.
Returns#
- SpectroDataset | LTASDataset:
The
SpectroDatasetthat match the transform parameters. ThisSpectroDatasetcan be used, for example, to have a peek at the transform output before running it. IfTransform.is_ltas is True, aLTASDatasetis returned.
- rename_output(output_name: str, new_output_name: str) None#
Rename an already ran transform.
Parameters#
- output_name: str
Name of the transform to rename.
- new_output_name: str
New name of the transform to rename.
- reset() None#
Reset the
Project.Resetting a project will move back the original audio files and the content of the
otherfolder to the root folder. WARNING: all other files and folders will be deleted.
- run(transform: Transform, audio_dataset: AudioDataset | None = None, spectro_dataset: SpectroDataset | None = None, nb_jobs: int = 1) None#
Create a new transform dataset from the original audio files.
The transform parameter sets which type(s) of
coredataset(s) will be created and added to theProject.outputsproperty, plus which output files will be written to disk (reshaped audio files,npzspectra matrices,pngspectrograms…).Parameters#
- transform: Transform
Transformto run. Contains the transform type and required info. See thepublic.transform.Transformdocstring for more info.- audio_dataset: AudioDataset
If provided, the transform will be run on this
AudioDataset. Else, anAudioDatasetwill be created from the transform parameters. This can be used to edit the transformAudioDataset(adding, removing, renamingAudioDataetc.)- spectro_dataset: SpectroDataset
If provided, the spectral transform will be run on this
SpectroDataset. Else, aSpectroDatasetwill be created from theaudio_datasetif provided, or from the transform parameters. This can be used to edit the transformSpectroDataset(adding, removing, renamingSpectroDataetc.)- nb_jobs: int
Number of jobs to run in parallel.
- to_dict() dict#
Serialize a project to a dictionary.
Returns#
- dict:
The serialized dictionary representing the project.
- property transforms: list[str]#
Return the list of the names of the transforms ran with this
Project.
- write_json(folder: Path | None = None) None#
Write a serialized Project to a JSON file.