Sen2Cor tries to change original SRTM input data and would delete it on error

Since there still seems to be no way to report a bug to the Sen2Cor development team I’ll try here.

Sen2Cor tries to open the SRTM input data in it’s original location and tries to change it.

The behavior is different depending on if the mosaicking of multiple SRTM tiles is necessary:

1. No merging necessary

If 1 SRTM tile is used then Sen2Cor seems to want to open the data and change the no data values from -32768 to 0

srtmf_src points to the original file location in this case.

I think Sen2Cor should really make a local copy of the data if it tries to change things.

File from line 1780

        src_ds = gdal.Open(srtmf_src, GA_Update)
        if src_ds is None:
            return False
        src_band = src_ds.GetRasterBand(1)
        rows = src_ds.RasterYSize
        cols = src_ds.RasterXSize
        src_arr = src_band.ReadAsArray(0,0,cols,rows)
        NODATA_DEM = -32768

        # Fix for SIIMPC-944 VD-JL - International Date Line handling for DEM mosaicking
        if (lonMinId > lonMaxId) and (cols == 12000):
            column_west = src_arr[:, 5999].astype(float32)
            column_east = src_arr[:, 6001].astype(float32)
            column_interp = src_arr[:, 6000]
            interp_valid = (column_west != NODATA_DEM) & (column_east != NODATA_DEM)
            column_interp[interp_valid] = ((column_west[interp_valid] + column_east[interp_valid])/2.).astype(int16)
            src_arr[:, 6000] = column_interp
        # end of fix for SIIMPC-944 VD-JL - International Date Line handling for DEM mosaicking

        src_arr[(src_arr == NODATA_DEM)] = 0
        src_band.WriteArray(src_arr, 0, 0)
        src_ds = None
        # end fix for SIIMPC-550

There are also a few of these sections in the file which would delete the original data if something would go wrong:

e.g. from line 1816 in

        srtmf_dst = os.path.join(tmpDir, 'srtm_' + self.config.L2A_TILE_ID + '_dem.tif')
        callstr = command + arguments + t_srs + t_warp + srtmf_src + ' ' + srtmf_dst + self._DEV0
            p = subprocess.Popen(callstr, shell=self._SHELL)
            self.logger.fatal('Error reading DEM, flat surface will be used')
            return False

2. Mosaicking

In that case a copy is made of the original files. The original file would however be deleted again if something goes wrong in gdalwarp