|
25 | 25 | import stac_pydantic |
26 | 26 | import yaml |
27 | 27 | from fastapi import HTTPException, status |
28 | | -from rs_server_common.stac_api_common import map_stac_platform |
| 28 | +from rs_server_common.utils.utils import reverse_adgs_prip_map_mission |
29 | 29 |
|
30 | 30 | ADGS_CONFIG = Path(osp.realpath(osp.dirname(__file__))).parent / "config" |
31 | 31 | search_yaml = ADGS_CONFIG / "adgs_search_config.yaml" |
@@ -86,70 +86,10 @@ def serialize_adgs_asset(feature_collection, products): |
86 | 86 | return feature_collection |
87 | 87 |
|
88 | 88 |
|
89 | | -def auxip_map_mission(platform: str, constellation: str) -> tuple[str | None, str | None]: |
90 | | - """ |
91 | | - Custom function for ADGS, to read constellation mapper and return propper |
92 | | - values for platform and serial. |
93 | | - Eodag maps this values to platformShortName, platformSerialIdentifier |
94 | | -
|
95 | | - Input: platform = sentinel-1a Output: sentinel-1, A |
96 | | - Input: platform = sentinel-5P Output: sentinel-5p, None |
97 | | - Input: constellation = sentinel-1 Output: sentinel-1, None |
98 | | - """ |
99 | | - data = map_stac_platform() |
100 | | - platform_short_name: str | None = None |
101 | | - platform_serial_identifier: str | None = None |
102 | | - try: |
103 | | - if platform: |
104 | | - config = next(satellite[platform] for satellite in data["satellites"] if platform in satellite) |
105 | | - platform_short_name = config.get("constellation", None) |
106 | | - platform_serial_identifier = config.get("serialid", None) |
107 | | - if constellation: |
108 | | - if platform_short_name and platform_short_name != constellation: |
109 | | - # Inconsistent combination of platform / constellation case |
110 | | - raise HTTPException( |
111 | | - status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
112 | | - detail="Invalid combination of platform-constellation", |
113 | | - ) |
114 | | - if any( |
115 | | - satellite[list(satellite.keys())[0]]["constellation"] == constellation |
116 | | - for satellite in data["satellites"] |
117 | | - ): |
118 | | - platform_short_name = constellation |
119 | | - platform_serial_identifier = None |
120 | | - else: |
121 | | - raise KeyError |
122 | | - except (KeyError, IndexError, StopIteration) as exc: |
123 | | - raise HTTPException( |
124 | | - status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
125 | | - detail="Cannot map platform/constellation", |
126 | | - ) from exc |
127 | | - return platform_short_name, platform_serial_identifier |
128 | | - |
129 | | - |
130 | | -def adgs_reverse_map_mission( |
131 | | - platform: str | None, |
132 | | - constellation: str | None, |
133 | | -) -> tuple[str | None, str | None]: |
134 | | - """Function used to re-map platform and constellation based on satellite value.""" |
135 | | - if not (constellation or platform): |
136 | | - return None, None |
137 | | - |
138 | | - if constellation: |
139 | | - constellation = constellation.lower() # type: ignore |
140 | | - |
141 | | - for satellite in map_stac_platform()["satellites"]: |
142 | | - for key, info in satellite.items(): |
143 | | - # Check for matching serialid and constellation |
144 | | - if info.get("serialid") == platform and info.get("constellation").lower() == constellation: |
145 | | - return key, info.get("constellation") |
146 | | - return None, None |
147 | | - |
148 | | - |
149 | 89 | def prepare_collection(collection: stac_pydantic.ItemCollection) -> stac_pydantic.ItemCollection: |
150 | 90 | """Used to create a more complex mapping on platform/constallation from odata to stac.""" |
151 | 91 | for feature in collection.features: |
152 | | - feature.properties.platform, feature.properties.constellation = adgs_reverse_map_mission( |
| 92 | + feature.properties.platform, feature.properties.constellation = reverse_adgs_prip_map_mission( |
153 | 93 | feature.properties.platform, |
154 | 94 | feature.properties.constellation, |
155 | 95 | ) |
|
0 commit comments