Как получить более одного файла, используя для цикла? - PullRequest
0 голосов
/ 09 мая 2019

У меня есть папка, которая содержит файлы с различным расширением (например, .TIF, .IMD, .txt), и я хочу получить два файла с одинаковым расширением (например, B2.TIF и B5.TIF)

   from rasterio import Affine as A
   from rasterio.warp import reproject, Resampling
   #from matplotlib.collections import PatchCollection
   fig, ax = plt.subplots(1, 1, figsize=(10, 10), subplot_kw= 
   {'projection': ccrs.UTM(42)})

   ax.set_extent([min(xmin), max(xmax), min(ymin), max(ymax)], ccrs.UTM(42))

   bounds.plot(ax=ax, transform=ccrs.PlateCarree())
   for image_path in glob(os.path.join(LANDSAT_PATH, '*/*B5.TIF')):

   with rasterio.open(image_path) as src:

    src_transform = src.transform

    # Zoom out by a factor of 2 from the center of the source
    # dataset. The destination transform is the product of the
    # source transform, a translation down and to the right, and
    # a scaling.
    dst_transform = src_transform*A.translation(
      -src.width/2.0, -src.height/2.0)*A.scale(2.0)

    data = src.read()

    kwargs = src.meta
    kwargs['transform'] = dst_transform

with rasterio.open('zoomed-out.tif', 'w', **kwargs) as dst:

    for i, band in enumerate(data, 1):
        dest = np.zeros_like(band)

        reproject(
            band,
            dest,
            src_transform=src_transform,
            src_crs=src.crs,
            dst_transform=dst_transform,
            dst_crs=src.crs,
            resampling=Resampling.nearest)         

Команда ниже возвращает только B5.TIF, но мне нужны оба B2.TIF и B5.TIF, а затем индивидуально применить проекцию for image_path in glob(os.path.join(LANDSAT_PATH, '*/*B5.TIF')):

...