Skip to content

clip_to_source order error #1206

@hildermesmedeiros

Description

@hildermesmedeiros

Expected behavior
clip_to_source to work in subscription creation properly.

it gives this error:

Error in Planet subscription: {"error":{"reason":"Problem with request","details":["unsupported tool sequencing: clip must come before the following tools: [cloud_filter]"]}}

Workaround
Manually edit the build request json to rebuild it in the current order.

if 'tools' in request:
    tools_list = request['tools']
    harmonize_tools = [t for t in tools_list if t.get('type') == 'harmonize']
    clip_tools = [t for t in tools_list if t.get('type') == 'clip']
    other_tools = [t for t in tools_list if t.get('type') not in ('clip', 'harmonize')]
    request['tools'] = harmonize_tools + clip_tools + other_tools

the problem

from planet.subscription_request import (
    catalog_source,
    build_request,
    amazon_s3,
    harmonize_tool,
    reproject_tool,
    band_math_tool,
    cloud_filter_tool,
    FilterValue,
)
#[other code MyClass]
        clear_percent = int(clear_percent)
        
        if product_bundle == 'analytic_8b_sr_udm2':
            asset_types = ['ortho_analytic_8b_sr', 'ortho_analytic_8b_xml','ortho_udm2']
            tools = [
                harmonize_tool(target_sensor="Sentinel-2"),
                reproject_tool(projection="WGS84", kernel="cubic"),
                band_math_tool(b1="b1", b2="b2", b3="b3", b4="b4", b5="b5", b6="b6", b7="b7", b8="b8", pixel_type="32R"),
                cloud_filter_tool(clear_percent=FilterValue(gte=clear_percent))
            ]
        elif product_bundle == 'visual':
            asset_types = ['ortho_visual']
            tools = [
                reproject_tool(projection="WGS84", kernel="cubic"),
                cloud_filter_tool(clear_percent=FilterValue(gte=clear_percent)) 
            ]

        combined_filter = data_filter.and_filter(
        [
            data_filter.permission_filter()
        ])
        
        source = catalog_source(
            [self.item_type_psscene],
            asset_types,
            geometry=geometry,
            start_time=start_date,
            filter=combined_filter,
            end_time=end_date,
            time_range_type="acquired",
            publishing_stages=["standard", "finalized"],
            geometry_relation="contains"
        )
        
        delivery = amazon_s3(
            aws_access_key_id=self.aws_access_key_id,
            aws_secret_access_key=self.aws_secret_access_key,
            bucket=self.aws_s3_bucket,
            aws_region=self.aws_region,
            path_prefix=f"{name}/{product_bundle}"
        )
        
        request = build_request(
            name=name,
            source=source,
            delivery=delivery,
            tools=tools,
            clip_to_source=True
        )

using clip_to_source is creating the tools array in wrong sequence

{
    "name": "Brasilia_talhao_SI_14",
    "source": {
        "parameters": {
            "item_types": [
                "PSScene"
            ],
            "asset_types": [
                "ortho_visual"
            ],
            "geometry": {
                "type": "Polygon",
                "coordinates": [...]

            },
            "start_time": "2026-01-01T00:00:00Z",
            "filter": {
                "type": "AndFilter",
                "config": [
                    {
                        "type": "PermissionFilter",
                        "config": [
                            "assets:download"
                        ]
                    }
                ]
            },
            "end_time": "2026-12-31T23:59:59.999999Z",
            "publishing_stages": [
                "standard",
                "finalized"
            ],
            "time_range_type": "acquired",
            "geometry_relation": "contains"
        }
    },
    "delivery": {
        "type": "amazon_s3",
        "parameters": {
            "aws_access_key_id": "",
            "aws_secret_access_key": "",
            "bucket": "imagem-arcgis",
            "aws_region": "",
            "path_prefix": ""
        }
    },
    "tools": [
        {
            "type": "reproject",
            "parameters": {
                "projection": "WGS84",
                "kernel": "cubic"
            }
        },
        {
            "type": "cloud_filter",
            "parameters": {
                "clear_percent": {
                    "gte": 80
                }
            }
        },
        {
            "type": "clip",
            "parameters": {}
        }
    ]
}

Environment Information
Python 3.11.11 (main, Mar 3 2025, 15:29:37) [MSC v.1938 64 bit (AMD64)] :: Anaconda, Inc. on win32

planet 3.4.0 pypi_0 pypi
planet-auth 2.3.0 pypi_0 pypi

Installation Method
pip in a conda env

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions