Skip to main content

STAC Task class provides a class interface for running custom algorithms on STAC Items

Project description

STAC Task (stactask)

This Python library consists of the Task class, which is used to create custom tasks based on a "STAC In, STAC Out" approach. The Task class acts as wrapper around custom code and provides several convenience methods for modifying STAC Items, creating derived Items, and providing a CLI.

This library is currently under development and may not be a final standalone repo and may be merged into stactools, see #345. It is based on a branch of cirrus-lib except aims to be more generic.

Quickstart for Creating New Tasks

from stactask import Task

class MyTask(Task):
    name = 'my-task'
    description = 'this task does it all'

    def validate(self):
        assert len(self.items) == 1

    def process(self):
        item = self.items[0]
        
        # download a datafile
        item = self.download_item_assets(item, assets=['data'])
        
        # operate on the local file to create a new asset


        item = self.upload_item_assets_to_s3(item)

        # this task returns a single item
        return [item]

Task Input

Field Name Type Description
type string Must be FeatureCollection
features [Item] A list of STAC Item
process ProcessDefinition A Process Definition

ProcessDefinition Object

A STAC task can be provided additional configuration via the 'process' field in the input ItemCollection.

Field Name Type Description
description string Optional description of the process configuration
collections Map<str, str> A mapping of output collection name to a JSONPath pattern (for matching Items)
upload_options UploadOptions Options used when uploading assets to a remote server
tasks List[TaskConfig] OR Map<str, Dict> Ordered List of task configurations

TaskConfig Object

A Task Configuration contains information for running a specific task.

Field Name Type Description
name str REQUIRED Name of the task
parameters Map<str, str> Dictionary of keyword parameters that will be passed to the Tasks process function

Using a Dictionary for task_configs ("task_name": ) is deprecated. Convert to List of TaskConfig objects

collections

The collections dictionary provides a collection ID and JSONPath pattern for matching against STAC Items. At the end of processing, before the final STAC Items are returned, the Task class can be used to assign all of the Items to specific collection IDs. For each Item the JSONPath pattern for all collections will be compared. The first match will cause the Item's Collection ID to be set to the provided value.

Example

    "collections": {
        "landsat-c2l2": "$[?(@.id =~ 'LC08.*')]"
    }

In this example, the task will set any STAC Items that have an ID beginning with "LC08" to the landsat-c2l2 collection.

See Jayway JsonPath Evaluator to experiment with JSONpath and regex101 to experiment with regex.

tasks

The tasks field is a dictionary with an optional key for each task. If present, it contains a dictionary that is converted to a set of keywords and passed to the Task's process function. The documentation for each task will provide the list of available parameters.

{
    "tasks": [
        {
            "name": "task-a",
            "parameters": {
                "param1": "value1"
            }
        },
        {
            "name": "task-c",
            "parameters": {
                "param2": "value2"
            }
        }
    ]
}

In the example above a task named task-a would have the param1=value1 passed as a keyword, while task-c would have param2=value2 passed. If there were a task-b to be run it would not be passed any keywords.

UploadOptions Object

Field Name Type Description
path_template string REQUIRED A string template for specifying the location of uploaded assets
public_assets [str] A list of asset keys that should be marked as public when uploaded
headers Map<str, str> A set of key, value headers to send when uploading data to s3
s3_urls bool Controls if the final published URLs should be an s3 (s3://bucket/key) or https URL

path_template

The path_template string is a way to control the output location of uploaded assets from a STAC Item using metadata from the Item itself. The template can contain fixed strings along with variables used for substitution. The following variables can be used in the template.

See [https://jsonpath.herokuapp.com/](Jayway JsonPath Evaluator) to experiment with JSONpath and https://regex101.com/ to experiment with regex

Full Payload Example

{
    "description": "My process configuration",
    "collections": {
        "landsat-c2l2": "$[?(@.id =~ 'LC08.*')]"
    },
    "upload_options": {
        "path_template": "s3://my-bucket/${collection}/${year}/${month}/${day}/${id}"
    },
    "tasks": {
        "task-name": {
            "param": "value"
        }
    }
}

Development

run tests

$ pytest -v -s tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stactask-0.1.0b5.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

stactask-0.1.0b5-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file stactask-0.1.0b5.tar.gz.

File metadata

  • Download URL: stactask-0.1.0b5.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for stactask-0.1.0b5.tar.gz
Algorithm Hash digest
SHA256 f0530582b42a64c902cc765d8bc6ebc5b567b755d54bcd00e80835a862a67645
MD5 9afd1021aee712d9a48a8f9eb84a994d
BLAKE2b-256 96f77cdae9d6ffad6fbf17f2979c3a67e103421d7384e4e0716d5b771f756e49

See more details on using hashes here.

Provenance

File details

Details for the file stactask-0.1.0b5-py3-none-any.whl.

File metadata

  • Download URL: stactask-0.1.0b5-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for stactask-0.1.0b5-py3-none-any.whl
Algorithm Hash digest
SHA256 d485a8277f4ee29599c3cad72ea999d338ad3587bee9a05b08a3950e048dae93
MD5 9c61421ab9b9f5a5a77244ad3537700a
BLAKE2b-256 2a25032a7fe9a066fd183890b156440539a97296ec9810c9133fa4c6b2ce1baa

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page