Ejemplo n.º 1
0
def get_l8_info(scene_id, full=False, s3=None):
    """Return Landsat-8 metadata."""
    info = utils.landsat_parse_scene_id(scene_id)
    aws_url = f'https://{landsat_bucket}.s3.amazonaws.com'
    scene_key = info["key"]
    info['browseURL'] = f'{aws_url}/{scene_key}_thumb_large.jpg'
    info['thumbURL'] = f'{aws_url}/{scene_key}_thumb_small.jpg'

    if full:
        try:
            data = json.loads(aws.get_object(landsat_bucket, f'{scene_key}_MTL.json', s3=s3))
            image_attr = data['L1_METADATA_FILE']['IMAGE_ATTRIBUTES']
            prod_meta = data['L1_METADATA_FILE']['PRODUCT_METADATA']

            info['sun_azimuth'] = image_attr.get('SUN_AZIMUTH')
            info['sun_elevation'] = image_attr.get('SUN_ELEVATION')
            info['cloud_coverage'] = image_attr.get('CLOUD_COVER')
            info['cloud_coverage_land'] = image_attr.get('CLOUD_COVER_LAND')
            info['geometry'] = {
                'type': 'Polygon',
                'coordinates': [[
                    [prod_meta['CORNER_UR_LON_PRODUCT'], prod_meta['CORNER_UR_LAT_PRODUCT']],
                    [prod_meta['CORNER_UL_LON_PRODUCT'], prod_meta['CORNER_UL_LAT_PRODUCT']],
                    [prod_meta['CORNER_LL_LON_PRODUCT'], prod_meta['CORNER_LL_LAT_PRODUCT']],
                    [prod_meta['CORNER_LR_LON_PRODUCT'], prod_meta['CORNER_LR_LAT_PRODUCT']],
                    [prod_meta['CORNER_UR_LON_PRODUCT'], prod_meta['CORNER_UR_LAT_PRODUCT']]
                ]]}
        except:
            print(f'Could not get info from {scene_key}_MTL.json')

    return info
Ejemplo n.º 2
0
def test_aws_get_object_awserror(session):
    """
    Should raise an 'ClientError' error
    """

    session.return_value.client.return_value.get_object.side_effect = ClientError(
        {'Error': {
            'Code': 500,
            'Message': 'Error'
        }}, 'get_object')

    bucket = "landsat-pds"
    key = "L8/178/246/LC81782462014232LGN00/LC81782462014232LGN00_MTL.json"

    with pytest.raises(ClientError):
        aws.get_object(bucket, key)
Ejemplo n.º 3
0
def get_s2_info(bucket, scene_path, full=False, s3=None, request_pays=False):
    """return Sentinel metadata
    """

    scene_info = scene_path.split('/')

    year = scene_info[4]
    month = utils.zeroPad(scene_info[5], 2)
    day = utils.zeroPad(scene_info[6], 2)
    acquisition_date = f'{year}{month}{day}'

    latitude_band = scene_info[2]
    grid_square = scene_info[3]
    num = scene_info[7]

    info = {
        'sat':
        'S2A',
        'path':
        scene_path,
        'utm_zone':
        scene_info[1],
        'latitude_band':
        latitude_band,
        'grid_square':
        grid_square,
        'num':
        num,
        'acquisition_date':
        acquisition_date,
        'browseURL':
        f'https://sentinel-s2-l1c.s3.amazonaws.com/{scene_path}preview.jpg'
    }

    utm = utils.zeroPad(info['utm_zone'], 2)
    info[
        'scene_id'] = f'S2A_tile_{acquisition_date}_{utm}{latitude_band}{grid_square}_{num}'

    if full:
        try:
            data = json.loads(
                aws.get_object(bucket,
                               f'{scene_path}tileInfo.json',
                               s3=s3,
                               request_pays=request_pays))
            sat_name = data['productName'][0:3]
            info['sat'] = sat_name
            info['geometry'] = data.get('tileGeometry')
            info['coverage'] = data.get('dataCoveragePercentage')
            info['cloud_coverage'] = data.get('cloudyPixelPercentage')
            info[
                'scene_id'] = f'{sat_name}_tile_{acquisition_date}_{utm}{latitude_band}{grid_square}_{num}'
        except:
            print(f'Could not get info from {scene_path}tileInfo.json')

    return info
Ejemplo n.º 4
0
def test_aws_get_object_validClient(client):
    """Should work as expected
    """

    client.return_value.get_object.return_value = {'Body': BytesIO(b'0101010')}

    bucket = "landsat-pds"
    key = "L8/178/246/LC81782462014232LGN00/LC81782462014232LGN00_MTL.json"

    assert aws.get_object(bucket, key, s3=client())
Ejemplo n.º 5
0
def test_aws_get_object_validPays(session):
    """Should work as expected
    """

    session.return_value.client.return_value.get_object.return_value = {
        'Body': BytesIO(b'0101010')
    }

    bucket = "landsat-pds"
    key = "L8/178/246/LC81782462014232LGN00/LC81782462014232LGN00_MTL.json"

    assert aws.get_object(bucket, key, request_pays=True)
    assert session.return_value.client.return_value.get_object.call_args[
        1].get('RequestPayer') == 'requester'