I have a matrix that contains NO2 measurements for a certain part of the globe, along with 2 matrices of the same size that contain the latitudes and longitudes.
NO2 = np.random.rand(100,100)
lat = np.random.rand(100,100)*90.
lon = np.random.rand(100,100)*180
I want to bin these NO2 values based on lat and lon into bins of 0.125 degrees, that look like this:
latBins = np.linspace(-90,90,180/.125+1)
lonBins = np.linspace(-180,180,360/.125+1)
Now, I know that numpy.digitize and numpy.histogram can return me the indices of the bins that each NO2 value belongs to, but I want the actual binned matrix. This matrix looks as follows:
binnedMatrix = np.zeros((1440,2880,15))
with each bin having a depth of 15. If I would now call binnedMatrix[0][0] (which holds all points with longitudes between -180.,-179.875 and latitudes between -90.,-89.875), I would like as a result all the NO2 values that were binned within these lats and lons. This would make it possible to just store this matrix somehwere, which is what I want.
Is there any function that returns this matrix? Or is there any way this can be done without a for loop?