LDF now implemented in python; a few extra helper functions