This function is copy-and-paste from `source_estimate.py`, moved it to avoid a circular import. It seems more fitting to have it here or, probably even better, in `surface.py`.