In [ ]:
from egg_preprocessor import EGGProcessor
In [ ]:
data_files = {
    "egg": "../EGG/0731_05_EGG.wav",
    "lx": "../EGG/0731_05_Lx.wav",
}
textgrid_file = "../TextGrids/0731_05_audio.TextGrid"

egg_processor = EGGProcessor(
    data_files=data_files, # add data by path at initiation
    textgrid_file=textgrid_file
)
In [ ]:
egg_processor.add_data({"audio": "../EGG/0731_05_audio.wav"}) # add data by path afterwards
In [ ]:
egg_processor.add_data({"filtered_egg": egg_processor.highpass_filter("egg")}) # highpass filter the egg data and add it to the processor
egg_processor.add_data({"smoothed_egg": egg_processor.smooth("filtered_egg")}) # smooth the highpass-filtered egg data and add it to the processor
egg_processor.add_data({"degg": egg_processor.differentiate("smoothed_egg")}) # differentiate the smoothed highpass-filtered egg data and add it to the processor
egg_processor.add_data({"dlx": egg_processor.differentiate("lx")})
In [ ]:
interval = egg_processor.get_intervals()[0] # get the first interval
In [ ]:
egg_processor.set_interval(interval) # set the current interval to the first interval

# print(interval)
# out: Interval(218.99, 219.42, "a-1")
# Alternatively, use a dictionary to set the interval
# egg_processor.set_interval(
#     {
#         "start_time": 218.99,
#         "end_time": 219.42
#     }
# )
egg_processor.interval_data # check the current interval
Out[ ]:
{'start_time': 218.99, 'end_time': 219.42}
In [ ]:
egg_processor.plot_interval_data() # plot the data in this interval; set `data_names` to specify which data to plot
In [ ]:
egg_processor.change_data_name("degg", "derivative_egg")
In [ ]:
egg_processor.get_interval_egg_cycles("smoothed_egg") # get egg_cycles by a certain egg data
98 cycles found.
In [ ]:
egg_processor.get_interval_all_cycle_data("smoothed_egg", data_names=["dlx", "lx", "smoothed_egg"]) # get data within each cycle; set `data_names` to specify which data to get
100%|██████████| 98/98 [00:48<00:00,  2.01it/s]
In [ ]:
egg_processor.plot_interval_all_cycle_data("smoothed_egg", data_names=["derivative_egg", "egg"]) # plot data within each cycle
In [ ]:
egg_processor.interval_data["cycle_data"]["smoothed_egg"]
Out[ ]:
{'derivative_egg': array([38.89821869, 39.62082185, 40.24465639, ..., 45.99243349,
        46.56271717, 46.71747069]),
 'egg': array([-231., -133.,  -47., ..., -647., -568., -478.]),
 'cycle': array([ 0.,  0.,  0., ..., 97., 97., 97.]),
 'time_point': array([  0.,   1.,   2., ..., 163., 164., 165.]),
 'dlx': array([ 1. , -0.5, -4. , ...,  1. , -1.5,  1. ]),
 'lx': array([3264., 3265., 3263., ..., -379., -381., -382.])}
In [ ]:
import seaborn as sns # for plotting
import matplotlib.pyplot as plt # for plotting
plt.rcParams.update({"lines.linewidth": .3})
sns.set_palette("pastel")
palette = sns.color_palette("pastel")

cmap = sns.color_palette("flare", as_cmap=True)
In [ ]:
norm = plt.Normalize(egg_processor.interval_data["cycle_data"]["smoothed_egg"]["cycle"].min(),
                     egg_processor.interval_data["cycle_data"]["smoothed_egg"]["cycle"].max())
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)

ax = sns.lineplot(
    data=egg_processor.interval_data["cycle_data"]["smoothed_egg"],
    x="lx",
    y="dlx",
    hue="cycle",
    sort=False,
    lw=.8,
    alpha=.3,
    palette=cmap
)
ax.get_legend().remove()
cb = ax.figure.colorbar(sm, ax=ax)
cb.outline.set_visible(False)