Problem: Resamping when mosaicing

When I mosaic two preprocessed satellite images, I get a line with nan values in the middle.

So I resample, but the result is the same.

How can I fix this?

python code
#%% mosaic using rasterio
import rasterio as rio
from rasterio.merge import merge
from rasterio.plot import show
import glob
import os
import numpy as np
from rasterio.enums import Resampling


dirpath = ‘/data/ym/Data/chungju/Output_s1_chungju/multiotsu_tif/’

dirpath = ‘/data/ym/data_chungju/test_pp/mosaic/’
out_fp = ‘/data/ym/data_chungju/test_pp/mosaic/’

search_criteria = “S1B_chungju_pp_20211218*.tif”

q = os.path.join(dirpath, search_criteria)


dem_fps = glob.glob(q)


src_files_to_mosaic =

for fp in dem_fps:

with, ‘r+’) as src:

data =

data[data == NaN] = np.nan

src.write(data, 1)

for fp in dem_fps:
src =
src_read =, resampling = Resampling.bilinear)
# src_read[src_read == 0 ] = np.nan

mosaic, out_trans = merge(src_files_to_mosaic, nodata = np.nan)

show(mosaic, cmap=‘terrain’)

out_meta = src.meta.copy()

out_meta.update({“driver”: “GTiff”,
“height”: mosaic.shape[1],
“width”: mosaic.shape[2],
“transform”: out_trans,
“crs”: "+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs "

with + “mosaic_test.tif”, “w”, **out_meta) as dest:


As this is a forum for SNAP and tools using SNAP, you probably won’t get an answer to a rasterio question.