Efficient way to find spatial extrema in 2-D space time netcdf field

I have a 2-D latitude-time zonal wind netCDF dataset (such as this small sample from ERA-Interim) from which I want to find all local maxima of the zonal wind as a function of latitude, for each time step. The output should be a list of latitudes (possibly empty) for each time step.

I would prefer to use mostly python, cdo and/or nco, if possible. I can use the derivative function in python xarray and specify the latitude dimension, for example, and then find roots of this new function subject to a condition on the second derivate, but I've not come across a function for finding zeroes/roots of a 2-D array along a specific dimension. Is there a more efficient, preferable way of going about this task?

Please let me know if this is not appropriate for the Earth Science Stack Exchange and where I should rather post the question if so.

• If you're using xarray, you have direct access to the values of the array and you can apply pre-existing local extrema-finding functions, such as docs.scipy.org/doc/scipy/reference/generated/… or docs.scipy.org/doc/scipy/reference/generated/… (which allows you to set a minimum distance between consecutive minima/maxima). Would that help?
– Erik
Jan 6 at 4:44
• @Erik, thank you, yes, scipy.signal.find_peaks seems to be particularly flexible and useful. I was hoping for something that could possibly estimate the location of a maximum/minimum between grid locations, but that's not strictly necessary. Could you suggest an efficient way of applying scipy.signal.find_peaks over order 10^5 timesteps? Or is that a separate question? Jan 6 at 8:57
• Hmm, no I suspect (but leave this open to other commenters) that these types of statistics about local extrema are computationally expensive; algorithms must check each sample, possibly multiple times. Any speedup can probably only be achieved using your computing resources maximally, e.g.: a multiprocessing approach following docs.python.org/3/library/multiprocessing.html can at least make sure you process 8 (or more) NetCDF files in parallel.
– Erik
Jan 6 at 14:13