Linear regression in python, across time dimension for every lat lon grid

We will write a linear trend function for the 3-dimensional data set.

The function will take input variable with [time, lat, lon] dimensions and gives output as 2-dimensional trend [lat, lon] and the p-value of the trend [lat, lon]. We can also define a significance value in function input (i.e. 0.05). If we input the significance value, output linear trend will be still in 2 dimensions with nan values in insignificant grid points (i.e. lower than 95% ).

Once we defined the function we can use it to calculate and plot the trend of a 3-dimensional variable [time, lat, lon]. For example, if we use annual mean sea level pressure era-interim reanalysis data of 39 years (1979-2016) to find a trend per year, we can use the script as: