A little bit of this was done in https://github.com/Griffin-Group/DarkMAGIC/commit/47fb949af169a7bd12ea7ca42e3bb17986e07e5a, but the code needs cleanup and generalization.