'Regridding coarse resolution 2D array to match fine resolution 2D geographic data

I have a gridded concentration dataset as 2d numpy array of size (96, 192). I want to project it on population grids at finer lat lon resolution of (4320, 8640). I am attempting regridding using the scipy RectBivariateSpline function, using this example, as follows:

# arranging lats of conc in increasing order:
lat_conc=lat_conc[::-1]

#interpolation:
import scipy.interpolate as sci

#creating a grid of smaller size
def latlon(res):
    return (np.arange(res)*(180/res) - 90,
            np.arange(2*res)*(360/(2*res)) - 180)

#population data
lat_fine,lon_fine = latlon(4320) 
fine_data = pop_data

lat_coarse,lon_coarse = latlon(96)
coarse_data=conc_array


f = sci.RectBivariateSpline(lat_coarse, lon_coarse, coarse_data)
scale_interp = f(lat_fine, lon_fine) # interpolated concentration data

interpolated concentration data shape= (4320, 8640)
interpolated concentration data max= 22688.237879587137
original pop data= (4320, 8640)
pop data max= 1646519.

everything looks fine till here but the graph obtained is incorrect*****

The following program runs very slowly and is not producing the desired graph. Also, I cannot see max conc on the x axis...

#Plot
fig = plt.figure(figsize=(12,8))
x_new=scale_interp
y_new=pop_data

#sorting values:
x_new=np.sort(x_new)
y_new=np.sort(y_new)

ax.plot(x_new,y_new,'m--')
plt.xlim(0,np.max(conc_array)
plt.ylim(0,np.max(pop_data)
plt.ylabel('Population', fontsize = 4) ## Had to reduce the fontsize here to avoid high pixel error
plt.xlabel('conc', fontsize = 4)

plt.show()

Need help to figure out what's wrong! Thank you in advance![enter image description here]

2



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source