python - Subdividing NumPy array into Regular Grid -
import numpy np
i have rectangle next coordinates:
ulx,uly = (110, 60) ##uppper left lon, upper left lat urx,ury = (120, 60) ##uppper right lon, upper right lat lrx, lry = (120, 50) ##lower right lon, lower right lat llx, lly = (110, 50) ##lower left lon, lower left lat
i want split single rectangle 100 regular grids within that, , want calculate (ulx, uly), (urx,ury), (lrx, lry), , (llx, lly) each grid separately:
lats = np.linspace(60, 50, 10) lons = np.linspace(110, 120, 10) lats = np.repeat(lats,10).reshape(10,10) lons = np.tile(lons,10).reshape(10,10)
i not imagine then?
is familiar such kind of problem?
for can utilize np.meshgrid
:
import numpy np lats = np.linspace(50, 60, 11) lons = np.linspace(110, 120, 11) xx, yy = np.meshgrid(lats, lons)
at point xx
, yy
2x2 matrices corner coordinates of grid tiles. if want have list of coordinates can utilize reshape:
ulx = np.reshape(xx[1:,:-1],(-1,1)) llx = np.reshape(xx[:-1,:-1],(-1,1)) urx = np.reshape(xx[1:,1:],(-1,1)) lrx = np.reshape(xx[:-1,1:],(-1,1)) uly = np.reshape(yy[1:,:-1],(-1,1)) lly = np.reshape(yy[:-1,:-1],(-1,1)) ury = np.reshape(yy[1:,1:],(-1,1)) lry = np.reshape(yy[:-1,1:],(-1,1))
but suggest utilize xx
, yy
.
python numpy
No comments:
Post a Comment