I am trying to de-trend my dataset of size 480x2040 = close to 1,000,000 pixels. I have 17 timesteps in this series (years) however I want to move to daily timesteps at some point. This code works, however runs way way way too slow to be functional.
I feel that scipy.signal.detrend can do the whole dataset, however I have some NaNs. In some cases, NaN are continents, which means there is a NaN at every timestep, however in some rarer cases, there is some missing data.
How can I detrend every pixel of my map over time, while ignoring/skipping the NaNs? It needs to be orders of magnitude quicker than this looping.
for i in range(0,nlat):
for j in range(0,nlon):
pixel = ds[:,i,j]
b = ~np.isnan(pixel)
detrend[b,i,j]=signal.detrend(pixel[b])
Cheers!