Source code for vak.prep.frame_classification.validators
"""Validators for frame classification datasets"""from__future__importannotationsimportpandasaspd
[docs]defvalidate_and_get_frame_dur(dataset_df:pd.DataFrame,input_type:str)->float:"""Validate that there is a single, unique value for the frame duration for all samples (audio signals / spectrograms) in a dataset. If so, return that value. The dataset is represented as a pandas DataFrame. Parameters ---------- dataset_df : pandas.Dataframe A pandas.DataFrame created by :func:`vak.prep.spectrogram_dataset.prep_spectrogram_dataset` or :func:`vak.prep.audio_dataset.prep_audio_dataset`. input_type : str The type of input to the neural network model. One of {'audio', 'spect'}. Returns ------- frame_dur : float The duration of a time bin in seconds for all spectrograms in the dataset. """from..importconstants# avoid circular importifinput_typenotinconstants.INPUT_TYPES:raiseValueError(f"``input_type`` must be one of: {constants.INPUT_TYPES}\n"f"Value for ``input_type`` was: {input_type}")# TODO: handle possible KeyError here?ifinput_type=="audio":frame_dur=dataset_df["sample_dur"].unique()elifinput_type=="spect":frame_dur=dataset_df["timebin_dur"].unique()iflen(frame_dur)>1:raiseValueError(f"Found more than one frame duration in dataset: {frame_dur}")frame_dur=frame_dur.item()returnframe_dur