Skip to main content
deleted 5 characters in body
Source Link
nyquist
  • 148
  • 8

Sounds like you might want something like numpy.repeat. Open read 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]])

See numpy / scipy docs for more info

Note that this is different from resampling, which one could accomplish by using gdal_translate or similar.

Sounds like you might want something like numpy.repeat. Open read 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]])

See numpy / scipy docs for more info

Note that this is different from resampling, which one could accomplish by using gdal_translate or similar.

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]])

See numpy / scipy docs for more info

Note that this is different from resampling, which one could accomplish by using gdal_translate or similar.

Source Link
nyquist
  • 148
  • 8

Sounds like you might want something like numpy.repeat. Open read 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]])

See numpy / scipy docs for more info

Note that this is different from resampling, which one could accomplish by using gdal_translate or similar.