Measure 4-port device with 2-port VNA
I've found the code I need on the scikit-rf site - specifically, renormalize_s (and associated functions) from http://scikit-rf.readthedocs.io/en/latest/_modules/skrf/network.html .  This is Python code that uses numpy for the calculations.

For anyone else interested, this page describes how to perform the measurement using scikit-rf.