Python coordinate conversions ported from Matlab/Octave functions