All, Subtracting two unaligned xarrays yield a new array with a different shape as below. The shape of the subtracted arrays is (2918,25,53) and the shape of the difference is (2916,25,53)
ds = xr.tutorial.load_dataset("air_temperature")
# subtracting un-aligned dimensions!
tem_data=ds.air
print('the shape of the array is '+str(tem_data.shape))
subdata=tem_data[2:,:,:]-tem_data[0:-2,:,:]
print('the shape of the tem_data[2:,:,:] is '+str(tem_data[2:,:,:].shape))
print('the shape of the subdata '+str(subdata.shape))
>>>
the shape of the array is (2920, 25, 53)
the shape of the tem_data[2:,:,:] is (2918, 25, 53)
the shape of the subdata (2916, 25, 53)
Any idea what is happening exactly and why xarray did not raise an error or warning? Thanks
In your code this subdata = tem_data[2:,:,:] - tem_data[0:-2,:,:]
removes two dates from the start of the time dimension for the first subdataset and the second one removes two dates from the end of the time dimension for the second subdataset.
This leaves you with 2916 overlapping times, which are then used when you do the subtraction.
So for example this: subdata = tem_data - tem_data[0:-2,:,:]
gives you a shape of (2918, 25, 53)
since only two dates are missing from the second subdataset.