I have a list of Landsat satellite images. Within the tar.gz file are the bands
ex: File " LC08018051fecha.tar.gz "
Contains:
LC08_fecha_band1.tif
LC08_fecha_band2.tif
LC08_fecha_band3.tif
LC08_fecha_band4.tif
LC08_fecha_band5.tif
LC08_fecha_band6.tif
LC08_fecha_band7.tif
LC08_fecha_azimuth_band4.tif
LC08_fecha_zenith_band4.tif
LC08_fecha_pixel_qa.tif
LC08_fecha_aerosol.tif
I need to extract from all files .tar.gz only LC08_date_band3.tif and < em> LC08_date_band4.tif to calculate an index.
The following code works for a specific file, extracting everything that says band
fileName = "LC08018051fecha.tar.gz"
tfile = tarfile.open(fileName, 'r:gz')
membersList = tfile.getmembers()
namesList = tfile.getnames()
bandsList = [x for x, y in zip(membersList, namesList) if "band" in y]
print("extracting...")
tfile.extractall("folder/",members=bandsList)
print ("Done")
I need to make it generic for all tar.gz within a folder and just extract band 3 and 4.