Reposting question explaining it better.

I am doing TOA corrections on Landsat8 Images in Python(3.5) by reading all image_bands and after processing them creating new GTiff of those images with GDAL, example of code:

#THIS part saves new image
def array2raster(fname,  nx, ny, matriz, geot, proj):
    drv = gdal.GetDriverByName("GTiff")
    dst_ds = drv.Create(fname, nx, ny, 1, gdal.GDT_Byte)
    # dst_ds.GetRasterBand(1).SetMetadata({"Band": "%d" % band, "Units": "W/(m2*ster*um)", "Data": "TOA Radiance"})

#Here is made the convertion
def convert_to_radiance(fname, band, gain, bias):
    global img_rad, img_original
    g = gdal.Open(fname)

    gl = g.ReadAsArray()
    print("Dimension: ", gl.shape, gl.dtype)
    radiance = gl * gain[band] + bias[band]

    img_original[:, :, band] = gl
    img_rad[:, :, band] = radiance

    output_fname = a.replace(".TIF", "_TOARAD.TIF")
    print ("Original fname  " , fname)
    print ("Creating output " , output_fname)
    # Create output dataset if `first_time` is true
    nx = g.RasterXSize
    ny = g.RasterYSize
    print("Dimension imagen: ", nx, ny)
    proj = g.GetProjectionRef()
    geoT = g.GetGeoTransform()
    array2raster(output_fname, nx, ny, radiance, geoT, proj)

#this is the main function:

def main():

    global prefix
    metadata_file = get_metadata('D:\Minam\LC80030692016324LGN00\LC80030692016324LGN00_MTL.txt')
    prefix = metadata_file.split("_")[0]
    print ("path de metadata:")
    print (metadata_file)
    (bias_rad, gain_rad, bias_ref, gain_ref,lradmax, lrefmax, nx, ny, sun, desun) = process_metadata(metadata_file) #here i Open the metadata to get values

    start_time = time.time()

    for the_band in [1, 2, 3, 4, 5, 6, 7,  9]:
        input_file = prefix + "_B%d.TIF" % the_band
        print("Procesando imagen: {}".format(the_band))

        convert_to_radiance(input_file, the_band, gain_rad, bias_rad)
        convert_to_reflectance(input_file, the_band, gain_ref, bias_ref, sun)

If is the first time processing the bands there is no problem saving the images and the metadata still exists, problem appears when trying to do it again with the images already created, here is when metedata file dissappear, debugging code, it happen on the array2rasterfunction but can't explain why because the metadata file is never called in the function again, what could be causing it?

  • The extra files that augment the input .tif go missing, or you mean there's no auxiliary files with the output GeoTIFF? GeoTIFF doesn't need any extra files, that's actually the point of the format - it's a good format. The input might be a TIFF with extra files for those metadata, or might be a GeoTIFF with redundant extra files that some software "needs" because some software doesn't support the GeoTIFF format.
    – mdsumner
    Commented Aug 19, 2017 at 5:11
  • the file D:\Minam\LC80030692016324LGN00\LC80030692016324LGN00_MTL.txt is the one who goes missing
    – Ivan
    Commented Aug 21, 2017 at 17:17

1 Answer 1


I found the solution trying a different approach, I create a folder on the same folder of Landsat for each correction and save the images there, that fixed the problem by now. The doubt still exist anyway.

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.