I decided that I am putting some of my code that I used last semester in the jupyter books, because I think that this makes it more readable. So I decided to refractor the code that I used and put it here.
I only tested on the small samples, so I might have missed something. But I think it should work.
You can find the code here.