List of S3 files into EOLearn Patch

Hi.
I am trying to get and load a list of .tiff files (saved from shub into aws S3) that are in different buckets and folders into the same EOPatch. These .tiff files are from the same region (polygon) containing imagery for a given period of time. Every tiff also has a date metadata associated with it. Could you point me to an example or help me fix the following, more specifically how to add the date dimension in this way?

for i, sat_img in df_imagery_polygon.iterrows():
    s3_bucket = buckets_s3[sat_img['sat']]
    # Download the .tiff file from S3
    obj = s3_client.get_object(Bucket=s3_bucket, Key=sat_img['file_s3'])
    tiff_data = obj['Body'].read()

    # Use rasterio to read the .tiff file from memory
    with MemoryFile(tiff_data) as memfile:
        with memfile.open() as dataset:
            tiff_array = dataset.read()

    metadata = {
        'date': sat_img['date'],
        'key_s3': sat_img['file_s3'],
        'year': sat_img['year'],
        'label_cat': sat_img['label_cat']
    }

    eopatch.bbox = get_BBOX_from_wkt(sat_img['wkt'])
    eopatch.meta_info['metadata'] = metadata
    eopatch[FeatureType.DATA]["BANDS"] = tiff_array

Gives me the error:

Blockquote ValueError: Numpy array of FeatureType.DATA feature has to have 4 dimensions but feature BANDS has 3.

Hi @felipe.guth ,

The FeatureType.DATA in EOPatch requires 4 dimensions, which are time * hight * width * channel (please see the documentation for more details). If there’s only 1 channel for each timestamp in your case, please try to reshape your image array to a shape of time * hight * width * 1.

Hope this would help!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.