def test_cbers_awfi_valid(list_directory, session): """Should work as expected """ session.return_value.client.return_value = True list_directory.return_value = [ 'CBERS4/AWFI/123/093/CBERS_4_AWFI_20170411_123_093_L4/'] path = '123' row = '93' sensor = 'AWFI' expected = [{ 'acquisition_date': '20170411', 'key': 'CBERS4/AWFI/123/093/CBERS_4_AWFI_20170411_123_093_L4', 'path': '123', 'processing_level': 'L4', 'row': '093', 'satellite': 'CBERS', 'scene_id': 'CBERS_4_AWFI_20170411_123_093_L4', 'sensor': 'AWFI', 'thumbURL': 'https://s3.amazonaws.com/cbers-meta-pds/CBERS4/AWFI/123/093/CBERS_4_AWFI_20170411_123_093_L4/CBERS_4_AWFI_20170411_123_093_small.jpeg', 'browseURL': 'https://s3.amazonaws.com/cbers-meta-pds/CBERS4/AWFI/123/093/CBERS_4_AWFI_20170411_123_093_L4/CBERS_4_AWFI_20170411_123_093.jpg', 'version': '4'}] assert list(search.cbers(path, row, sensor)) == expected
def test_cbers_mux_valid(list_directory, session): """Should work as expected """ session.return_value.client.return_value = True list_directory.return_value = [ 'CBERS4/MUX/217/063/CBERS_4_MUX_20160416_217_063_L2/'] path = '217' row = '063' expected = [{ 'acquisition_date': '20160416', 'key': 'CBERS4/MUX/217/063/CBERS_4_MUX_20160416_217_063_L2', 'path': '217', 'processing_level': 'L2', 'row': '063', 'satellite': 'CBERS', 'scene_id': 'CBERS_4_MUX_20160416_217_063_L2', 'sensor': 'MUX', 'thumbURL': 'https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/217/063/CBERS_4_MUX_20160416_217_063_L2/CBERS_4_MUX_20160416_217_063_small.jpeg', 'browseURL': 'https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/217/063/CBERS_4_MUX_20160416_217_063_L2/CBERS_4_MUX_20160416_217_063.jpg', 'version': '4'}] assert list(search.cbers(path, row)) == expected
def search(**kwargs): ''' Returns available images for: sensor, level, start_date, end_date for both modes. path, row for 'aws_sat_api' mode. lat, lon for 'stac' mode. stac_endpoint is mandatory for this mode :param mode str: 'aws_sat_api' or 'stac' :param sensor str: Sensor ID, in ('MUX','AWFI','PAN5M','PAN10M') :param path int: Path number :param row int: Row number :param level str: Levels to be used, for instance, 'L2' or 'L4'. :param start_date str: Start date in YYYY-MM-DD format :param end_date str: End date in YYYY-MM-DD format :return: Scenes :rtype: list ''' mode = 'aws_sat_api' if not kwargs.get('mode') else kwargs['mode'] assert mode in ('aws_sat_api', 'stac'), \ "Invalid search mode: {}".format(mode) start_date = '1900-01-01' if not kwargs.get('start_date') \ else kwargs['start_date'] end_date = '9999-12-31' if not kwargs.get('end_date') \ else kwargs['end_date'] level = kwargs.get('level') if mode == 'aws_sat_api': matches = cbers(kwargs['path'], kwargs['row'], kwargs['sensor']) s_date = start_date.replace('-', '') e_date = end_date.replace('-', '') matches[:] = [value for value in matches if \ value['acquisition_date'] >= s_date and value['acquisition_date'] <= e_date] if level: matches[:] = [value for value in matches if \ value['processing_level'] == level] else: ss1 = StacSearch(kwargs['stac_endpoint']) bbox = [kwargs['lon'], kwargs['lat'], kwargs['lon'], kwargs['lat']] ids = ss1.search(instrument=kwargs['sensor'], start_date=start_date, end_date=end_date, level=level, bbox=bbox, limit=300) matches = list() for sid in ids: matches.append(stac_to_aws_sat_api(stac_id=sid['id'])) matches = sorted(matches, key=lambda k: k['acquisition_date']) return matches
def cbers( path, row, pathrow, sensor, ): """CBERS search CLI.""" # TODO: add tests for pathrow and path+row options if pathrow: pr_info = [ dict(path=x.split('-')[0], row=x.split('-')[1]) for x in pathrow ] else: pr_info = [dict(path=path, row=row)] for el in pr_info: for scene in search.cbers(**el, sensor=sensor): click.echo(json.dumps(scene))