Get location of 2D window with maximum sum using xarray in python

Lets say I load some 2-dimensional precipitation data into an xarray dataarray like this:

import xarray as xr

url = 'http://convection.meas.ncsu.edu:8080/thredds/dodsC/prism/daily/combo/2010/PRISM_combo_20100101.nc'
preicp_da = xr.open_dataset(url)['ppt']

What I want to do is, given a window of some pre-determined size, find the window on the grid that has the maximum summed value within it.

I know I can get a rolling window sum at each grid point like this:

lon_window = 5
lat_window = 5
preicp_da_rolling = preicp_da.rolling({'longitude':3, 'latitude':3, 't':2}).sum()

But this still leaves me with a grid of summed window values, the same size as the original grid.

How can I extract the window from the original grid where the summed value over that window is maximized?

🔴 No definitive solution yet