4

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)

1 Answer 1

2

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))
1
  • Dear @sgillies, many thanks for your reply. I tried your code but unfortunatelly it didn't work for me: no output rescaled... I used gdal.Translate() to do so.
    – Glori P.
    Commented Jan 14, 2019 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.