No really, just forget about all that avisynth nonsense, instead of
y=True, u=True, v=True just do
planes=[0, 1, 2], that will make your function look like any vapoursynth function out there
. And pass that to dfttest too, if you are not going to use it don't spend time filtering it.
And before you create the mask you can just
core.std.ShufflePlanes(medium, planes=[0], colorfamily=vs.GRAY), so you can get ride of
first_plane=luma too.