Copy/pasted stuff from python-subgrid