i have a netcdf file containing the following:
<xarray.Dataset>
Dimensions: (latitude: 65, longitude: 49, time: 7306)
Coordinates:
* latitude (latitude) float32 21.0 20.75 20.5 20.25 ... 5.75 5.5 5.25 5.0
* longitude (longitude) float32 116.0 116.25 116.5 ... 127.5 127.75 128.0
* time (time) datetime64[ns] 1985-12-31T23:00:00 ... 2005-12-31T11:00:00
Data variables:
pr (time, latitude, longitude) float32 0.049636062 ... 0.6215298
time_bnds (time) datetime64[ns] 1985-12-31T23:00:00 ... 2005-12-31T11:00:00
my goal is to apply stats.linregress to every grid cell of this data set and i took the following approach:
from scipy import stats
import nump as np
import xarray as xr
#load data
rain = xr.load_dataset('../precipitation.1986-2005.nc')
#group by (lon,lat) pairs by:
stacked = rain.stack(paired_points=['latitude','longitude'])
grouped = stacked.groupby('paired_points').apply(stats.linregress(stacked.time.astype(float),stacked['pr']))
unstack = grouped.unstack('paired_points')
after application of stats.linregress i want to create a plot where every grid cell is colored by the value of the slope calculated from the linear regression.
when i run the code a ValueError
is raised:
ValueError: all the input array dimensions for the concatenation
axis must match exactly, but along dimension 1, the array at index 0 has size 7306 and the
array at index 1 has size 3185
it seems as if accessing the per-grid precipitation time series and successfully applying stats.linregress
for each grid cell is where the problem is.
could someone suggest a way forward?
your help would be valued.