def cbers(path, row, sensor='MUX'): """Get CBERS scenes. Valid values for sensor are: 'MUX', 'AWFI', 'PAN5M' and 'PAN10M'. """ path = utils.zeroPad(path, 3) row = utils.zeroPad(row, 3) prefix = f'CBERS4/{sensor}/{path}/{row}/' session = boto3_session(region_name=region) s3 = session.client('s3') results = aws.list_directory(cbers_bucket, prefix, s3=s3) scene_ids = [os.path.basename(key.strip('/')) for key in results] results = [] for scene_id in scene_ids: info = utils.cbers_parse_scene_id(scene_id) scene_key = info["key"] preview_id = '_'.join(scene_id.split('_')[0:-1]) info[ 'thumbURL'] = f'https://s3.amazonaws.com/{cbers_bucket}/{scene_key}/{preview_id}_small.jpeg' info[ 'browseURL'] = f'https://s3.amazonaws.com/{cbers_bucket}/{scene_key}/{preview_id}.jpg' results.append(info) return results
def landsat(path, row, full=False): """ """ path = utils.zeroPad(path, 3) row = utils.zeroPad(row, 3) levels = ['L8', 'c1/L8'] prefixes = [f'{l}/{path}/{row}/' for l in levels] # WARNING: This is fast but not thread safe session = boto3_session(region_name=region) s3 = session.client('s3') _ls_worker = partial(aws.list_directory, landsat_bucket, s3=s3) with futures.ThreadPoolExecutor(max_workers=2) as executor: results = executor.map(_ls_worker, prefixes) results = itertools.chain.from_iterable(results) scene_ids = [os.path.basename(key.strip('/')) for key in results] _info_worker = partial(get_l8_info, full=full, s3=s3) with futures.ThreadPoolExecutor(max_workers=50) as executor: results = executor.map(_info_worker, scene_ids) return results
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
def test_zeroPad_validString(): assert utils.zeroPad('3', 2) == '03'
def test_zeroPad_valid(): assert utils.zeroPad(3, 4) == '0003'