[GIS] Cannot upscale raster with rasterio

pythonrasterrasterioresolution

I am trying to upscale a raster using rasterio but I don't know why my process gets killed.

It can print "i am arrived here" but on the reproject() I have as terminal output:

killed

This is the code I am trying to run:

with rasterio.open(mask) as src:
    df_mask = src.read(1)
    aff_mask = src.transform
    profile_mask = src.profile
    width = src.width


profile_esm.update( compress='lzw', dtype = 'float32' )

## using reproject with the same CRS but changing the cell size

new_df= np.empty( shape = ( round(df_mask.shape[0] * 10),
                round(df_mask.shape[1] * 10 )), dtype = 'float32')

newaff = Affine(aff_mask.a / 10, aff_mask.b, aff_mask.c,
                aff_mask.d, aff_mask.e / 10, aff_mask.f)


profile_mask.update( compress='lzw', dtype = 'float32')

print("i am arrived here")
reproject(
        df_mask, new_df,
        src_transform = aff_mask,
        dst_transform = newaff,
        src_crs = src.crs,
        dst_crs = src.crs,
        resampling = Resampling.nearest)

print("i am after")
with rasterio.open('resampling_mask.tif', 'w', **profile_mask) as dst:
    reproject(
        df_mask, new_df,
        src_transform = aff_mask,
        dst_transform = newaff,
        src_crs = src.crs,
        dst_crs = src.crs,
        resampling = Resampling.nearest)

    dst.write(new_df,  indexes=1)

Best Answer

I'm not sure why you're seeing the death of your program, but the reproject function is not the way to upscale data. Instead, use the dataset's read method and specify a larger output shape:

with rasterio.open(mask) as dataset:
    upscaled_mask = dataset.read(1, out_shape=(dataset.height * 10, dataset.width * 10))
Related Question