I created a Jupyter notebook that shows how I figured out the refraction formula used by the JPL Horizons online tool.