|
13 | 13 | # the License. |
14 | 14 | """Functionality for preparing subscription requests.""" |
15 | 15 | from datetime import datetime |
16 | | -from typing import Any, Dict, Optional, List, Mapping, Sequence |
| 16 | +from dataclasses import dataclass, asdict |
| 17 | +from typing import Any, Dict, Optional, List, Mapping, Sequence, Union |
17 | 18 |
|
18 | 19 | from typing_extensions import Literal |
19 | 20 |
|
@@ -651,3 +652,63 @@ def toar_tool(scale_factor: int = 10000) -> dict: |
651 | 652 | reflectances not fitting in 16bit integers. |
652 | 653 | """ |
653 | 654 | return _tool('toar', {'scale_factor': scale_factor}) |
| 655 | + |
| 656 | + |
| 657 | +@dataclass |
| 658 | +class FilterValue: |
| 659 | + """Represents a filter value with optional greater than or equal to (gte) |
| 660 | + and less than or equal to (lte) constraints. |
| 661 | +
|
| 662 | + Attributes: |
| 663 | + gte (Optional[float]): The minimum threshold value for the filter. |
| 664 | + lte (Optional[float]): The maximum threshold value for the filter. |
| 665 | + """ |
| 666 | + |
| 667 | + gte: Optional[float] = None |
| 668 | + lte: Optional[float] = None |
| 669 | + |
| 670 | + |
| 671 | +def cloud_filter_tool( |
| 672 | + clear_percent: Optional[FilterValue] = None, |
| 673 | + cloud_percent: Optional[FilterValue] = None, |
| 674 | + shadow_percent: Optional[FilterValue] = None, |
| 675 | + heavy_haze_percent: Optional[FilterValue] = None, |
| 676 | + light_haze_percent: Optional[FilterValue] = None, |
| 677 | + snow_ice_percent: Optional[FilterValue] = None, |
| 678 | +) -> Dict[str, Dict[str, Union[float, int]]]: |
| 679 | + """Specify a subscriptions API cloud_filter tool. |
| 680 | +
|
| 681 | + The cloud_filter tool filters imagery after the clip tool has run and certain |
| 682 | + metadata values have been updated to pertain to the clip AOI. This tool offers |
| 683 | + a more detailed filtering of cloudy imagery than what can be achieved using |
| 684 | + only catalog source filters. For instance, you might want to receive only images |
| 685 | + that, after clipping, have a cloud_percent value of less than or equal to 25%. |
| 686 | +
|
| 687 | + Parameters: |
| 688 | + clear_percent: Filters for images based on the percentage of clear sky. |
| 689 | + cloud_percent: Filters for images based on the percentage of cloud cover. |
| 690 | + shadow_percent: Filters for images based on the percentage of shadow cover. |
| 691 | + heavy_haze_percent: Filters for images based on the percentage of heavy haze cover. |
| 692 | + light_haze_percent: Filters for images based on the percentage of light haze cover. |
| 693 | + snow_ice_percent: Filters for images based on the percentage of snow or ice cover. |
| 694 | + """ |
| 695 | + filters = { |
| 696 | + "clear_percent": clear_percent, |
| 697 | + "cloud_percent": cloud_percent, |
| 698 | + "shadow_percent": shadow_percent, |
| 699 | + "heavy_haze_percent": heavy_haze_percent, |
| 700 | + "light_haze_percent": light_haze_percent, |
| 701 | + "snow_ice_percent": snow_ice_percent, |
| 702 | + } |
| 703 | + |
| 704 | + result = {} |
| 705 | + |
| 706 | + for key, value in filters.items(): |
| 707 | + if value: |
| 708 | + inner_dict = asdict(value) |
| 709 | + result[key] = { |
| 710 | + k: v |
| 711 | + for k, v in inner_dict.items() if v is not None |
| 712 | + } |
| 713 | + |
| 714 | + return _tool("cloud_filter", result) |
0 commit comments