Exemplo n.º 1
0
    def _order_payload(
        geometry: Union[Dict, Feature, FeatureCollection, List, GeoDataFrame,
                        Point, Polygon, ],
        scene: Series,
    ) -> Tuple[str, Dict]:
        """
        Helper that constructs necessary parameters for `Order.place` and `Order.estimate`.

        Args:
            geometry (Union[ Dict, Feature, FeatureCollection, List, GeoDataFrame, Point, Polygon, ]): The intended
                output AOI of the order.
            scene (GeoSeries): A single item/row of the result of `Catalog.search`. For instance, search_results.loc[0]
                for the first scene of a catalog search result.

        Returns:
            str, Dict: A tuple including a provider name and order parameters.
        """
        if not isinstance(scene, Series):
            raise ValueError(
                "`scene` parameter must be a GeoSeries, or a single item/row of a GeoDataFrame. "
                "For instance, search_results.loc[0] returns a GeoSeries.")
        aoi_fc = any_vector_to_fc(vector=geometry, )
        aoi_geometry = fc_to_query_geometry(
            fc=aoi_fc,
            geometry_operation="intersects",
            squash_multiple_features="union",
        )
        data_provider_name = scene.providerName
        order_params = {"id": scene.id, "aoi": aoi_geometry}
        return data_provider_name, order_params
Exemplo n.º 2
0
    def construct_parameters(
        self,
        geometry: Union[dict, Feature, FeatureCollection, geojson_Polygon,
                        list, GeoDataFrame, Polygon, Point, ] = None,
        geometry_operation: Optional[str] = None,
        handle_multiple_features: str = "union",
        start_date: Optional[str] = None,
        end_date: Optional[str] = None,
        limit: Optional[int] = None,
        scene_ids: Optional[list] = None,
        assets: Optional[List[Asset]] = None,
    ) -> dict:
        """
        Constructs workflow input parameters with a specified aoi, the default input parameters, and
        optionally limit and order-ids. Further parameter editing needs to be done manually
        via dict.update({key:value}).

        Args:
            geometry: One of Dict, FeatureCollection, Feature, List,
                GeoDataFrame, shapely.geometry.Polygon, shapely.geometry.Point. All
                assume EPSG 4326.
            geometry_operation: Desired operation, One of "bbox", "intersects", "contains".
            limit: Maximum number of expected results.
            start_date: Query period starting day, format "2020-01-01".
            end_date: Query period ending day, format "2020-01-01".
            scene_ids: List of scene_ids, if given ignores all other parameters except geometry.
            assets: Optional, can be used to incorporate existing assets in Storage (result
                of Orders for instance) into new workflows.

        Returns:
            Dictionary of constructed input parameters.
        """
        input_parameters = self._get_default_parameters()
        try:
            data_block_name = list(input_parameters.keys())[0]
        except IndexError as e:
            raise ValueError("The Workflow has no workflow tasks.") from e

        if assets is not None:
            # Needs to be handled in this function(not run_job) as it is only
            # relevant for the data block.
            asset_ids = [
                asset.asset_id for asset in assets if asset.source == "BLOCK"
            ]
            if not asset_ids:
                raise ValueError(
                    "None of the assets are usable in a workflow since the source is not `BLOCK`."
                )
            input_parameters[data_block_name] = {"asset_ids": asset_ids}
        else:
            if limit is not None:
                input_parameters[data_block_name]["limit"] = limit

            if scene_ids is not None:
                if not isinstance(scene_ids, list):
                    scene_ids = [scene_ids]
                input_parameters[data_block_name]["ids"] = scene_ids
                input_parameters[data_block_name]["limit"] = len(scene_ids)
                input_parameters[data_block_name].pop("time")
            elif start_date is not None and end_date is not None:
                time = f"{start_date}T00:00:00Z/{end_date}T23:59:59Z"
                input_parameters[data_block_name]["time"] = time

            if geometry is not None:
                aoi_fc = any_vector_to_fc(vector=geometry, )
                aoi_feature = fc_to_query_geometry(
                    fc=aoi_fc,
                    geometry_operation=geometry_operation,  # type: ignore
                    squash_multiple_features=handle_multiple_features,
                )

                input_parameters[data_block_name][
                    geometry_operation] = aoi_feature
        return input_parameters
Exemplo n.º 3
0
    def construct_parameters(
        geometry: Union[Dict, Feature, FeatureCollection, List, GeoDataFrame,
                        Point, Polygon, ],
        start_date: str = "2020-01-01",
        end_date: str = "2020-01-30",
        sensors: List[str] = [
            "pleiades",
            "spot",
            "sentinel1",
            "sentinel2",
            "sentinel3",
            "sentinel5p",
        ],
        limit: int = 10,
        max_cloudcover: float = 100,
        sortby: str = "acquisitionDate",
        ascending: bool = True,
    ) -> Dict:
        """
        Follows STAC principles and property names.

        Args:
            geometry: The search geometry, one of Dict, Feature, FeatureCollection,
                List, GeoDataFrame, Point, Polygon.
            start_date: Query period starting day, format "2020-01-01".
            end_date: Query period ending day, format "2020-01-01".
            sensors: The satellite sensors to search for, one or multiple of
                ["pleiades", "spot", "sentinel1", "sentinel2", "sentinel3", "sentinel5p"]
            limit: The maximum number of search results to return (1-max.500).
            max_cloudcover: Maximum cloudcover % - e.g. 100 will return all scenes,
                8.4 will return all scenes with 8.4 or less cloudcover.
                Ignored for sensors that have no cloudcover (e.g. sentinel1).
            sortby: The property to sort by, "cloudCoverage", "acquisitionDate",
                "acquisitionIdentifier", "incidenceAngle", "snowCover".
            ascending: Ascending sort order by default, descending if False.

        Returns:
            The constructed parameters dictionary.
        """
        datetime = f"{start_date}T00:00:00Z/{end_date}T23:59:59Z"
        block_filters: List[str] = []
        for sensor in sensors:
            if sensor not in list(supported_sensors.keys()):
                raise ValueError(
                    f"Currently only these sensors are supported: "
                    f"{list(supported_sensors.keys())}")
            block_filters.extend(supported_sensors[sensor]["blocks"])

        aoi_fc = any_vector_to_fc(vector=geometry, )
        aoi_geometry = fc_to_query_geometry(
            fc=aoi_fc,
            geometry_operation="intersects",
            squash_multiple_features="union",
        )

        sort_order = "asc" if ascending else "desc"
        query_filters = {"dataBlock": {"in": block_filters}}
        if sensors != ["sentinel1"]:
            query_filters["cloudCoverage"] = {
                "lte": max_cloudcover
            }  # type: ignore

        search_parameters = {
            "datetime": datetime,
            "intersects": aoi_geometry,
            "limit": limit,
            "query": query_filters,
            "sortby": [{
                "field": f"properties.{sortby}",
                "direction": sort_order
            }],
        }
        return search_parameters
Exemplo n.º 4
0
    def construct_parameters(
        self,
        geometry: Union[
            Dict,
            Feature,
            FeatureCollection,
            geojson_Polygon,
            List,
            GeoDataFrame,
            Polygon,
            Point,
        ] = None,
        geometry_operation: str = None,
        handle_multiple_features: str = "union",
        start_date: str = None,
        end_date: str = None,
        limit: int = None,
        scene_ids: List = None,
        order_ids: List[str] = None,
    ) -> Dict:
        """
        Constructs workflow input parameters with a specified aoi, the default input parameters, and
        optionally limit and order-ids. Further parameter editing needs to be done manually
        via dict.update({key:value}).

        Args:
            geometry: One of Dict, FeatureCollection, Feature, List,
                GeoDataFrame, shapely.geometry.Polygon, shapely.geometry.Point. All
                assume EPSG 4326.
            geometry_operation: Desired operation, One of "bbox", "intersects", "contains".
            limit: Maximum number of expected results.
            start_date: Query period starting day, format "2020-01-01".
            end_date: Query period ending day, format "2020-01-01".
            scene_ids: List of scene_ids, if given ignores all other parameters except geometry.
            order_ids: Optional, can be used to incorporate existing bought imagery on UP42
                into new workflows.

        Returns:
            Dictionary of constructed input parameters.
        """
        input_parameters = self._get_default_parameters()
        data_block_name = list(input_parameters.keys())[0]

        if order_ids is not None:
            # Needs to be handled in this function(not run_job) as it is only
            # relevant for the data block.
            input_parameters[data_block_name] = {"order_ids": order_ids}
        else:
            if limit is not None:
                input_parameters[data_block_name]["limit"] = limit

            if scene_ids is not None:
                if not isinstance(scene_ids, list):
                    scene_ids = [scene_ids]
                input_parameters[data_block_name]["ids"] = scene_ids
                input_parameters[data_block_name]["limit"] = len(scene_ids)
                input_parameters[data_block_name].pop("time")
            elif start_date is not None and end_date is not None:
                time = f"{start_date}T00:00:00Z/{end_date}T23:59:59Z"
                input_parameters[data_block_name]["time"] = time

            if geometry is not None:
                aoi_fc = any_vector_to_fc(
                    vector=geometry,
                )
                aoi_feature = fc_to_query_geometry(
                    fc=aoi_fc,
                    geometry_operation=geometry_operation,  # type: ignore
                    squash_multiple_features=handle_multiple_features,
                )

                input_parameters[data_block_name][geometry_operation] = aoi_feature
        return input_parameters