Skip to content

Commit e489c1b

Browse files
committed
refactor: improve code formatting and readability across multiple files
1 parent e4ba6be commit e489c1b

4 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/vresto/services/sentinel_stream.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def stream_tci(
9696

9797
# Compute output transform
9898
from rasterio.transform import from_bounds
99+
99100
transform = from_bounds(*src.bounds, out_width, out_height)
100101

101102
profile = {
@@ -159,7 +160,7 @@ def _build_tci_vsis3_path(self, s3_path: str, tile_code: str) -> Optional[str]:
159160
else:
160161
path = path.lstrip("/")
161162
if path.startswith(f"{CDSE_S3_BUCKET}/"):
162-
path = path[len(CDSE_S3_BUCKET) + 1:]
163+
path = path[len(CDSE_S3_BUCKET) + 1 :]
163164

164165
# Ensure trailing slash
165166
if not path.endswith("/"):
@@ -216,7 +217,7 @@ def find_tci_path_in_product(self, s3_path: str, tile_code: str) -> Optional[str
216217
prefix = prefix.lstrip("/")
217218
# Strip bucket name (eodata/) from prefix to get the S3 key
218219
if prefix.startswith(f"{CDSE_S3_BUCKET}/"):
219-
prefix = prefix[len(CDSE_S3_BUCKET) + 1:]
220+
prefix = prefix[len(CDSE_S3_BUCKET) + 1 :]
220221
if not prefix.endswith("/"):
221222
prefix += "/"
222223

@@ -243,13 +244,8 @@ def find_tci_path_in_product(self, s3_path: str, tile_code: str) -> Optional[str
243244
# Sentinel-2 TCI filenames always carry the ``T`` prefix on
244245
# the tile id (``T34TFL_...``); MGRS callers may pass the
245246
# bare code (``34TFL``). Normalise here.
246-
tile_with_t = (
247-
tile_code if tile_code.startswith("T") else f"T{tile_code}"
248-
)
249-
tci_key = (
250-
f"{granule_prefix}IMG_DATA/R10m/"
251-
f"{tile_with_t}_{product_datetime}_TCI_10m.jp2"
252-
)
247+
tile_with_t = tile_code if tile_code.startswith("T") else f"T{tile_code}"
248+
tci_key = f"{granule_prefix}IMG_DATA/R10m/{tile_with_t}_{product_datetime}_TCI_10m.jp2"
253249
# Cheap HEAD verify (~50-150 ms) before returning so any
254250
# unexpected layout falls back to the full LIST below
255251
# rather than blowing up later in ``stream_tci`` with
@@ -258,10 +254,7 @@ def find_tci_path_in_product(self, s3_path: str, tile_code: str) -> Optional[str
258254
s3_client.head_object(Bucket=CDSE_S3_BUCKET, Key=tci_key)
259255
return f"/vsis3/{CDSE_S3_BUCKET}/{tci_key}"
260256
except Exception:
261-
logger.debug(
262-
f"Constructed TCI path missing, falling back to "
263-
f"LIST: {tci_key}"
264-
)
257+
logger.debug(f"Constructed TCI path missing, falling back to LIST: {tci_key}")
265258
# If delimiter LIST returned nothing, fall through to full LIST.
266259

267260
# Fallback: full prefix LIST (covers L1C and any unexpected layout)

src/vresto/services/tiles.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def _shutdown_client_obj(self, name: str, client) -> None:
241241
client.shutdown()
242242
try:
243243
from server_thread.server import ServerManager
244+
244245
if hasattr(client, "_key"):
245246
ServerManager.shutdown_server(client._key, force=True)
246247
except Exception:
@@ -345,9 +346,14 @@ def get_tile_url(
345346
self.shutdown()
346347
self._active_path = path
347348
return tile_pool.get_or_create(
348-
self._pool_name, path,
349-
port=port, palette=palette, min_val=min_val,
350-
max_val=max_val, nodata=nodata, external_host=external_host,
349+
self._pool_name,
350+
path,
351+
port=port,
352+
palette=palette,
353+
min_val=min_val,
354+
max_val=max_val,
355+
nodata=nodata,
356+
external_host=external_host,
351357
)
352358

353359
def shutdown(self):

src/vresto/ui/widgets/map_search_tab.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ async def _stream_tile(self, tile_code: str):
264264
# Find TCI file path within the product
265265
tci_path = await asyncio.to_thread(
266266
sentinel_stream_service.find_tci_path_in_product,
267-
product.s3_path, tile_code,
267+
product.s3_path,
268+
tile_code,
268269
)
269270

270271
if not tci_path:
@@ -274,7 +275,10 @@ async def _stream_tile(self, tile_code: str):
274275
# Stream and cache — pass the exact TCI path to avoid wildcard issues
275276
result = await asyncio.to_thread(
276277
sentinel_stream_service.stream_tci,
277-
product.s3_path, tile_code, date, tci_path,
278+
product.s3_path,
279+
tile_code,
280+
date,
281+
tci_path,
278282
)
279283

280284
if result:
@@ -359,6 +363,7 @@ def _query():
359363
return None
360364

361365
from datetime import datetime as _dt
366+
362367
for item in resp.json().get("value", []):
363368
s3_path = item.get("S3Path", "")
364369
if not s3_path:
@@ -439,7 +444,9 @@ async def _load_worldcover_overlay(self):
439444

440445
colorized = await asyncio.to_thread(
441446
worldcover_service.get_colorized_worldcover_path,
442-
ref_path, 20, "2021",
447+
ref_path,
448+
20,
449+
"2021",
443450
)
444451

445452
if colorized:
@@ -470,7 +477,9 @@ async def _load_lcm_overlay(self):
470477

471478
colorized = await asyncio.to_thread(
472479
lcm_service.get_colorized_lcm_path,
473-
ref_path, 20, "2020",
480+
ref_path,
481+
20,
482+
"2020",
474483
)
475484

476485
if colorized:

src/vresto/ui/widgets/map_widget.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def set_grid_layer(self, geojson: dict) -> None:
242242
self.clear_grid_layer()
243243

244244
import json
245+
245246
map_id = self._map.id
246247
geojson_str = json.dumps(geojson)
247248

@@ -322,6 +323,7 @@ def highlight_tile(self, code: str) -> None:
322323
map_id = self._map.id
323324
# JSON-encode the code to be safe against injection
324325
import json
326+
325327
code_js = json.dumps(code)
326328
js = f"""
327329
(function() {{

0 commit comments

Comments
 (0)