lauraduncanson / icesat2_boreal

Biomass modeling and mapping of forest biomass in the boreal using NASA's ICESat-2
14 stars 7 forks source link

replace JSON https links with S3 paths (3.1.2_dps.py) #46

Closed nmt28 closed 3 years ago

wildintellect commented 3 years ago

I think you're looking for this code

for band in bands:
                try:
                    key = feature['assets'][f'SR_{band}.TIF']['href'].replace(
                        'https://landsatlook.usgs.gov/data/',
                        '')
                    output_file = os.path.join(
                        f's3://maap-ops-dataset/alexdevseed/landsat8/sample2/{feature["id"]}/'
                        , os.path.basename(key))
                    #print(key)
                    ## Uncomment next line to actually download the data as a local sample
                    #s3.Bucket('usgs-landsat').download_file(key, output_file, ExtraArgs={'RequestPayer':'requester'})
                    feature['assets'][f'SR_{band}.TIF']['href'] = output_file
                except botocore.exceptions.ClientError as e:
                    if e.response['Error']['Code'] == "404":
                        print("The object does not exist.")
                    else:
                        raise

The s3 path will obviously change once we can use the usgs bucket directly.