Skip to content

Commit

Permalink
reorder call to GDAL band WriteArray() to fix issues with GDAL >= 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gshiroma committed Mar 6, 2024
1 parent 0635605 commit 72d0c89
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/rtc/mosaic_geobursts.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,13 @@ def mosaic_single_output_file(list_rtc_images, list_nlooks, mosaic_filename,

for i_band in range(num_bands):
gdal_band = raster_out.GetRasterBand(i_band+1)
gdal_band.WriteArray(arr_numerator[i_band])
gdal_band.SetDescription(description_list[i_band])
if ctable is not None:
gdal_band.SetRasterColorTable(ctable)
gdal_band.SetRasterColorInterpretation(gdal.GCI_PaletteIndex)
if no_data_value is not None:
gdal_band.SetNoDataValue(no_data_value)
gdal_band.WriteArray(arr_numerator[i_band])

band_ds = None
reference_raster = None
Expand Down Expand Up @@ -710,12 +710,12 @@ def mosaic_multiple_output_files(

# for i_band in range(num_bands):
band_out = raster_out.GetRasterBand(1)
band_out.WriteArray(arr_numerator[i_band])
if ctable is not None:
band_out.SetRasterColorTable(ctable)
band_out.SetRasterColorInterpretation(gdal.GCI_PaletteIndex)
if no_data_value is not None:
band_out.SetNoDataValue(no_data_value)
band_out.WriteArray(arr_numerator[i_band])

band_ds = None
reference_raster = None
2 changes: 1 addition & 1 deletion src/rtc/rtc_s1_single_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,13 @@ def set_mask_fill_value_and_ctable(mask_file, reference_file):
mask_gdal_band = mask_gdal_ds.GetRasterBand(1)
mask_array = mask_gdal_band.ReadAsArray()
mask_array[(np.isnan(ref_array)) & (mask_array == 0)] = 255
mask_gdal_band.WriteArray(mask_array)
mask_gdal_band.SetNoDataValue(255)

mask_ctable.SetColorEntry(255, (0, 0, 0, 0))
mask_gdal_band.SetRasterColorTable(mask_ctable)
mask_gdal_band.SetRasterColorInterpretation(
gdal.GCI_PaletteIndex)
mask_gdal_band.WriteArray(mask_array)

del mask_gdal_band
del mask_gdal_ds
Expand Down

0 comments on commit 72d0c89

Please sign in to comment.