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)

print(q)

dem_fps = glob.glob(q)

print(dem_fps)

src_files_to_mosaic =

for fp in dem_fps:

with rasterio.open(fp, ‘r+’) as src:

data = src.read(1)

data[data == NaN] = np.nan

src.write(data, 1)

for fp in dem_fps:
src = rio.open(fp)
src_read = src.read(1, resampling = Resampling.bilinear)
# src_read[src_read == 0 ] = np.nan
src_files_to_mosaic.append(src)

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 rio.open(out_fp + “mosaic_test.tif”, “w”, **out_meta) as dest:
dest.write(mosaic)

Figure_1

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