示例#1
0
    def __init__(self, bucket=None, stac_list=[]):
        # session = boto3.Session(profile_name='beto')
        self.session = session = boto3.Session(
            aws_access_key_id=AWS_KEY_ID, aws_secret_access_key=AWS_SECRET_KEY)

        # ---------------------------
        # AWS infrastructure
        self.S3client = session.client('s3')
        self.SQSclient = session.client('sqs')
        self.LAMBDAclient = session.client('lambda')
        self.Kinesisclient = session.client('kinesis')
        self.dynamoDBResource = session.resource('dynamodb')

        self.bucket_name = bucket

        # ---------------------------
        # create / get DynamoDB tables
        self.tables = {}
        self.get_dynamo_tables()

        # ---------------------------
        # create / get the SQS
        self.queues = {}
        self.get_queues_url()

        # ---------------------------
        # init STAC instance
        self.stac_list = []
        for stac in stac_list:
            stac_instance = STAC(stac["url"],
                                 access_token=stac["token"]) if stac.get(
                                     "token", None) else STAC(stac["url"])
            self.stac_list.append(dict(**stac, instance=stac_instance))
示例#2
0
    def _stac(self, collection: str, url: str, **kwargs) -> STAC:
        """Check if collection is provided by given STAC url.

        The provided STAC must follow the `SpatioTemporal Asset Catalogs spec <https://stacspec.org/>`_.

        Exceptions:
            RuntimeError for any exception during STAC connection.

        Args:
            collection: Collection name
            url - STAC URL

        Returns:
            STAC client
        """
        try:
            options = dict()
            if kwargs.get('token'):
                options['access_token'] = kwargs.get('token')

            stac = self.cached_stacs.get(url) or STAC(url, **options)

            _ = stac.catalog

            _ = stac.collection(collection)

            self.cached_stacs.setdefault(url, stac)

            return stac
        except Exception as e:
            # STAC Error
            raise RuntimeError('An error occurred in STAC {}'.format(str(e)))
示例#3
0
    def __init__(self, url_stac=None, bucket=None):
        # session = boto3.Session(profile_name='default')
        session = boto3.Session(aws_access_key_id=AWS_KEY_ID,
                                aws_secret_access_key=AWS_SECRET_KEY)

        # ---------------------------
        # AWS infrastructure
        self.S3client = session.client('s3')
        self.SQSclient = session.client('sqs')
        self.LAMBDAclient = session.client('lambda')
        self.Kinesisclient = session.client('kinesis')
        self.dynamoDBResource = session.resource('dynamodb')

        self.QueueUrl = {}
        self.bucket_name = bucket

        # ---------------------------
        # create / get DynamoDB tables
        self.get_dynamo_tables()

        # ---------------------------
        # create / get the SQS
        self.get_queue_url()

        # ---------------------------
        # init STAC instance
        self.url_stac = url_stac
        if url_stac:
            self.stac = STAC(url_stac)
示例#4
0
    def _stac(cls, collection: str, url: str) -> STAC:
        """Check if collection is provided by given STAC url.

        The provided STAC must follow the `SpatioTemporal Asset Catalogs spec <https://stacspec.org/>`_.

        Exceptions:
            RuntimeError for any exception during STAC connection.

        Args:
            collection: Collection name
            url - STAC URL

        Returns:
            STAC client
        """
        try:
            stac = cls.cached_stacs.get(url) or STAC(url)

            _ = stac.catalog

            _ = stac.collection(collection)

            cls.cached_stacs.setdefault(url, stac)

            return stac
        except Exception as e:
            # STAC Error
            raise RuntimeError('An error occurred in STAC {}'.format(str(e)))
示例#5
0
    def __init__(self):
        # session = boto3.Session(profile_name='africa')
        session = boto3.Session(
            aws_access_key_id=AWS_KEY_ID, 
            aws_secret_access_key=AWS_SECRET_KEY)

        # ---------------------------
        # AWS infrastructure
        self.S3client = session.client('s3')
        self.SQSclient = session.client('sqs')
        self.LAMBDAclient = session.client('lambda')
        self.Kinesisclient = session.client('kinesis')
        self.dynamoDBResource = session.resource('dynamodb')

        self.QueueUrl = None
        self.prefix = 'https://s3.amazonaws.com/{}/'.format(BUCKET_NAME)
        #self.prefix = 's3//{}/'.format(BUCKET_NAME)

        # ---------------------------
        # create / get DynamoDB tables
        self.get_dynamo_tables()

        # ---------------------------
        # create / get the SQS 
        self.get_queue_url()

        # ---------------------------
        # init STAC instance
        self.stac = STAC(URL_STAC)
示例#6
0
    def __init__(self, **kwargs):
        """Build STAC provider for Element84."""
        access_token = kwargs.pop('access_token', None)

        self.kwargs = kwargs
        self.api = STAC('https://earth-search.aws.element84.com/v0',
                        access_token=access_token)
        self.progress = kwargs.get('progress')
示例#7
0
def test_catalog():
    service = STAC(url)

    retval = service.catalog()

    common_keys = {'stac_version', 'id', 'description', 'links'}

    assert common_keys <= set(retval.keys())
示例#8
0
    def search_STAC(self, activity, extra_catalogs=None):
        """Search for activity in remote STAC server.

        Notes:
            By default, uses entire activity to search for data catalog.
            When the parameter ``extra_catalog`` is set, this function will seek
            into given catalogs and then merge the result as a single query server.
            It may be useful if you have a collection in different server provider.

        Args:
            activity (dict): Current activity scope with default STAC server and stac collection
                **Make sure that ``bbox`` property is a GeoJSON Feature.
            extra_catalogs (List[dict]): Extra catalogs to seek for collection. Default is None.
        """
        # Get DATACUBE params
        _ = self.stac.catalog
        bands = activity['bands']
        datasets = activity['datasets']
        bbox_feature = activity['bbox']
        time = '{}/{}'.format(activity['start'], activity['end'])

        scenes = {}
        filter_opts = dict(datetime=time, intersects=bbox_feature, limit=10000)

        for dataset in datasets:
            filter_opts['collections'] = [dataset]
            items = self.stac.search(filter=filter_opts)

            scenes.update(**self._parse_stac_result(items, dataset, bands,
                                                    activity['quality_band']))

        if extra_catalogs:
            for catalog in extra_catalogs:
                stac_url = catalog['stac_url']
                stac_token = catalog.get('token')
                stac_dataset = catalog['dataset']
                filter_opts['collections'] = [stac_dataset]

                stac = STAC(stac_url, access_token=stac_token)

                items = stac.search(filter=filter_opts)

                res = self._parse_stac_result(items, stac_dataset, bands,
                                              activity['quality_band'])

                for band, datasets in res.items():
                    internal_dataset = list(datasets.keys())[0]

                    scenes[band][dataset].update(datasets[internal_dataset])

        return scenes
示例#9
0
                dbasen = datetime.datetime(year + 1, monthf, dayf)
            while dbase < dbasen:
                dstart = dbase
                dend = dbase + td_time_step - datetime.timedelta(days=1)
                basedate = dbase.strftime('%Y-%m-%d')
                start_date = dstart.strftime('%Y-%m-%d')
                end_date = dend.strftime('%Y-%m-%d')
                periodkey = basedate + '_' + start_date + '_' + end_date
                requested_period = []
                requested_periods[basedate] = requested_period
                requested_periods[basedate].append(periodkey)
                dbase += td_time_step
    return requested_periods


stac_cli = STAC(Config.STAC_URL)


class Maestro:
    datacube = None
    bands = []
    tiles = []
    mosaics = dict()

    def __init__(self, datacube: str, collections: List[str], tiles: List[str],
                 start_date: str, end_date: str, **properties):
        self.params = dict(datacube=datacube,
                           collections=collections,
                           tiles=tiles,
                           start_date=start_date,
                           end_date=end_date)
示例#10
0
def test_conformance():
    service = STAC(url)

    retval = service.conformance()

    assert 'conformsTo' in retval
示例#11
0
def test_creation():
    service = STAC(url)

    assert url.count(service.url) == 1