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] 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

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.0b1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stactask-0.1.0b1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stactask-0.1.0b1.tar.gz
  • Upload date:
  • Size: 15.2 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.0b1.tar.gz
Algorithm Hash digest
SHA256 607c67a718174176100317a00cca91c0a16412fade016eb36a5a410e7ea8c26f
MD5 fe5f4d5f8e8553284621b763db634169
BLAKE2b-256 6974a2cc51983674a12f6dc5a7c482e0a1aaa9bb42d6cfb56ac91100d69f8db7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stactask-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 14.6 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.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 02969ea8d6965c92e4675f6b8bfea20eab2336b9137994d1a684dd97cb00f79f
MD5 0077dec62222f7fdfd117b9891b13130
BLAKE2b-256 45c8b7cb912478d484f87e684f98329538d3fc3352cd3af6e1a1888c71044ef0

See more details on using hashes here.

Supported by

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