Hi Martin,
There are two options with PyFerret that I can think of: one within PyFerret, the other outside PyFerret.
The option for doing it within PyFerret is to write an Ferret external function written in Python. This function can then be called at the Ferret prompt. The ferret_init method of your Python script describes the result grid; the ferret_compute method will be given NumPy arrays of your input and a NumPy array for you to assign with your result. This is probably the easiest and cleanest way to do standard calculations. All the PyFerret statistical functions are done this way, making use of SciPy statistical functions.
also at a Python prompt (after importing pyferret): help(pyferret.ferret_pyfunc)
The other option is to get the input data (as NumPy arrays) from PyFerret using pyferret.getdata, do your calculations (at the Python prompt), then push the data back into PyFerret using pyferret.putdata. This is more complex but gives you more freedom. It would be nicer if PyFerret used xarray - high on the to-do list but still not there yet.
Kind regards,
Karl