def test_landsat_id_pre_invalid(): """ Should raise an error with invalid sceneid """ scene = 'L0300342017083LGN00' with pytest.raises(InvalidLandsatSceneId): utils.landsat_parse_scene_id(scene)
def test_landsat_id_c1_invalid(): """ Should raise an error with invalid sceneid """ scene = 'LC08_005004_20170410_20170414_01_T1' with pytest.raises(InvalidLandsatSceneId): utils.landsat_parse_scene_id(scene)
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
def test_landsat_id_c1_valid(): """ Should work as expected (parse landsat c1 sceneid) """ scene = 'LC08_L1TP_005004_20170410_20170414_01_T1' expected_content = { 'category': 'T1', 'collection': '01', 'acquisition_date': '20170410', 'key': 'c1/L8/005/004/LC08_L1TP_005004_20170410_\ 20170414_01_T1/LC08_L1TP_005004_20170410_20170414_01_T1', 'path': '005', 'correction_level': 'L1TP', 'ingestion_date': '20170414', 'row': '004', 'satellite': 'L8', 'scene_id': 'LC08_L1TP_005004_20170410_20170414_01_T1', 'sensor': 'C' } assert utils.landsat_parse_scene_id(scene) == expected_content
def test_landsat_id_pre_valid(): """ Should work as expected (parse landsat pre sceneid) """ scene = 'LC80300342017083LGN00' expected_content = { 'acquisitionJulianDay': '083', 'acquisitionYear': '2017', 'archiveVersion': '00', 'category': 'pre', 'acquisition_date': '20170324', 'groundStationIdentifier': 'LGN', 'key': 'L8/030/034/LC80300342017083LGN00/LC80300342017083LGN00', 'path': '030', 'row': '034', 'satellite': 'L8', 'scene_id': 'LC80300342017083LGN00', 'sensor': 'C' } assert utils.landsat_parse_scene_id(scene) == expected_content