MCPcopy Create free account
hub / github.com/DPhi-Space/SimSat / test_sentinel_multispectral

Function test_sentinel_multispectral

scripts/api_test.py:126–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124
125
126def test_sentinel_multispectral() -> None:
127 band_sets: List[List[str]] = [
128 ["red", "green", "blue"],
129 ["nir", "red", "green"],
130 ["swir22", "nir", "green"],
131 ["swir22", "swir16", "red"],
132 ["rededge1", "rededge2", "rededge3"],
133 ]
134
135 # Freeze location (and timestamp when available) once so every band set
136 # is requested at the exact same satellite coordinates.
137 position_response = _request_get("/data/current/position")
138 if position_response is None:
139 return
140 try:
141 position_data = position_response.json()
142 except ValueError:
143 print("Invalid JSON body for /data/current/position.")
144 return
145
146 lon_lat_alt = position_data.get("lon-lat-alt")
147 timestamp = position_data.get("timestamp")
148
149 images = []
150 for spectral_bands in band_sets:
151 params = {
152 "lon": lon_lat_alt[0],
153 "lat": lon_lat_alt[1],
154 "timestamp": timestamp,
155 "spectral_bands": spectral_bands,
156 "size_km": 5.0,
157 "return_type": "png",
158 #"window_seconds": 60.0
159 }
160 response = _request_get("/data/image/sentinel", params=params)
161 if response is None:
162 continue
163
164 try:
165 metadata = json.loads(response.headers.get("sentinel_metadata", ""))
166 except json.JSONDecodeError:
167 metadata = None
168
169 if not isinstance(metadata, dict) or not metadata.get("image_available"):
170 print(f"No image available for bands {spectral_bands}")
171 continue
172
173 try:
174 image = mpimg.imread(io.BytesIO(response.content), format="PNG")
175 except Exception as exc:
176 print(f"Could not decode image for bands {spectral_bands}: {exc}")
177 continue
178
179 images.append((image, "_".join(spectral_bands)))
180
181 if not images:
182 print("No hyperspectral images available to display.")
183 return

Callers

nothing calls this directly

Calls 1

_request_getFunction · 0.85

Tested by

no test coverage detected