R dissagregate method in python

It seems an easy question, but I can't find the Python equivalent of R's Dissaggregate:

Disaggregate a RasterLayer to create a new RasterLayer with a higher resolution (smaller cells)

I expected it in GDAL but no luck so far.

• Is this what you want to do? gis.stackexchange.com/questions/271226/…
– BERA
Sep 18 '18 at 9:32
• Actually, yes. So I assume in gdal there is no direct method to do so. Thanks for the hint, it will be easy to implement. Sep 18 '18 at 13:27

Sounds like you might want something like numpy.repeat. Open the raster as a numpy array by doing array = gdal.Open(file).ReadAsArray(), then use np.repeat for both the x and y axes. Here is an example:

import numpy as np

>>> array = np.random.randint(10,size =(3,3))
>>> array
array([[6, 1, 6],
[9, 7, 0],
[3, 1, 7]])
>>> downsampled_in_x = np.repeat(array,2,axis = 1)
>>> downsampled_in_x
array([[6, 6, 1, 1, 6, 6],
[9, 9, 7, 7, 0, 0],
[3, 3, 1, 1, 7, 7]])
>>> downsampled_in_both = np.repeat(downsampled_in_x,2,axis = 0)
>>> downsampled_in_both
array([[6, 6, 1, 1, 6, 6],
[6, 6, 1, 1, 6, 6],
[9, 9, 7, 7, 0, 0],
[9, 9, 7, 7, 0, 0],
[3, 3, 1, 1, 7, 7],
[3, 3, 1, 1, 7, 7]])