Skip to content

Commit 068b51a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 708f1c6 commit 068b51a

1 file changed

Lines changed: 58 additions & 16 deletions

File tree

scripts/build_unr_frame_db.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# reusing an existing parquet (no rebuild / network)
2323
python build_unr_frame_db.py --from-parquet ../configs/data/opera_disp_s1_frame_unr_points_20260604.parquet \
2424
--frame-id 831 --plate IGS20 --html-map
25+
2526
"""
2627

2728
from __future__ import annotations
@@ -130,7 +131,9 @@ def make_html_map(
130131

131132
if frame_id is not None:
132133
if frame_id not in opera_gdf.index:
133-
raise SystemExit(f"frame_id {frame_id} not found among North-America frames")
134+
raise SystemExit(
135+
f"frame_id {frame_id} not found among North-America frames"
136+
)
134137
frame = opera_gdf.loc[[frame_id], ["geometry", "unr_grid_count"]]
135138
m = frame.explore(
136139
color="red",
@@ -163,7 +166,7 @@ def make_html_map(
163166
return out_path
164167

165168

166-
STANDALONE_TEMPLATE = r'''<!DOCTYPE html>
169+
STANDALONE_TEMPLATE = r"""<!DOCTYPE html>
167170
<html lang="en">
168171
<head>
169172
<meta charset="UTF-8" />
@@ -361,11 +364,12 @@ def make_html_map(
361364
<!-- generated __GENERATED__ -->
362365
</body>
363366
</html>
364-
'''
367+
"""
365368

366369

367370
def _round_geom(geom, ndigits: int = 5) -> dict:
368371
"""GeoJSON mapping of a geometry with coordinates rounded to shrink the file."""
372+
369373
def rnd(c):
370374
if isinstance(c, (list, tuple)):
371375
if c and isinstance(c[0], (int, float)):
@@ -419,7 +423,9 @@ def write_standalone_html(
419423
for i, lon, lat in sub.itertuples():
420424
points[int(i)] = [round(float(lon), 5), round(float(lat), 5)]
421425

422-
data = json.dumps({"type": "FeatureCollection", "features": feats}, separators=(",", ":"))
426+
data = json.dumps(
427+
{"type": "FeatureCollection", "features": feats}, separators=(",", ":")
428+
)
423429
data = data.replace("</", "<\\/") # keep the </script> tag safe
424430

425431
html = (
@@ -428,7 +434,9 @@ def write_standalone_html(
428434
.replace("__GRID_BASE__", grid_base)
429435
.replace("__PLATES__", json.dumps(list(PLATES)))
430436
.replace("__VERSION__", version)
431-
.replace("__GENERATED__", datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC"))
437+
.replace(
438+
"__GENERATED__", datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
439+
)
432440
)
433441
out_path.parent.mkdir(parents=True, exist_ok=True)
434442
out_path.write_text(html)
@@ -451,26 +459,40 @@ def main() -> None:
451459
default=Path.cwd(),
452460
help="Scratch dir for the downloaded UNR lookup table.",
453461
)
454-
p.add_argument("--version", default="0.3", help="UNR gridded data version (default: 0.3).")
455-
p.add_argument("--margin-deg", type=float, default=0.5, help="Frame buffer in degrees (default: 0.5).")
462+
p.add_argument(
463+
"--version", default="0.3", help="UNR gridded data version (default: 0.3)."
464+
)
465+
p.add_argument(
466+
"--margin-deg",
467+
type=float,
468+
default=0.5,
469+
help="Frame buffer in degrees (default: 0.5).",
470+
)
456471
p.add_argument(
457472
"--prod-date",
458473
default=datetime.now(timezone.utc).strftime("%Y%m%d"),
459-
help="Production date stamped into the filename (YYYYMMDD; default: today UTC).",
474+
help=(
475+
"Production date stamped into the filename (YYYYMMDD; default: today UTC)."
476+
),
460477
)
461478

462479
# Inspection / visualization (all optional)
463480
p.add_argument(
464481
"--from-parquet",
465482
type=Path,
466483
default=None,
467-
help="Load an existing parquet instead of rebuilding (fast for inspection/maps).",
484+
help=(
485+
"Load an existing parquet instead of rebuilding (fast for inspection/maps)."
486+
),
468487
)
469488
p.add_argument(
470489
"--frame-id",
471490
type=int,
472491
default=None,
473-
help="Report UNR grid ids + URLs for this frame_id (and focus the HTML map on it).",
492+
help=(
493+
"Report UNR grid ids + URLs for this frame_id (and focus the HTML map on"
494+
" it)."
495+
),
474496
)
475497
p.add_argument(
476498
"--plate",
@@ -492,7 +514,10 @@ def main() -> None:
492514
p.add_argument(
493515
"--standalone-html",
494516
action="store_true",
495-
help="Write a self-contained interactive viewer (data embedded; no server needed).",
517+
help=(
518+
"Write a self-contained interactive viewer (data embedded; no server"
519+
" needed)."
520+
),
496521
)
497522
p.add_argument(
498523
"--standalone-out",
@@ -509,10 +534,15 @@ def main() -> None:
509534
print(f"Loading existing DB: {args.from_parquet}")
510535
opera_gdf = gpd.read_parquet(args.from_parquet)
511536
else:
512-
print(f"Building UNR frame DB (version={args.version}, margin={args.margin_deg} deg) ...")
537+
print(
538+
f"Building UNR frame DB (version={args.version}, margin={args.margin_deg}"
539+
" deg) ..."
540+
)
513541
opera_gdf = build_database(args.work_dir, args.version, args.margin_deg)
514542
args.outdir.mkdir(parents=True, exist_ok=True)
515-
out_path = args.outdir / f"opera_disp_s1_frame_unr_points_{args.prod_date}.parquet"
543+
out_path = (
544+
args.outdir / f"opera_disp_s1_frame_unr_points_{args.prod_date}.parquet"
545+
)
516546
opera_gdf.to_parquet(out_path)
517547
print(f"Wrote {len(opera_gdf)} frames -> {out_path}")
518548
print(opera_gdf["unr_grid_count"].describe().to_string())
@@ -532,11 +562,19 @@ def main() -> None:
532562
else f"opera_disp_s1_frame_unr_points_{args.prod_date}"
533563
)
534564
suffix = f"_frame{args.frame_id}" if args.frame_id is not None else "_map"
535-
map_dir = args.from_parquet.parent if args.from_parquet is not None else args.outdir
565+
map_dir = (
566+
args.from_parquet.parent
567+
if args.from_parquet is not None
568+
else args.outdir
569+
)
536570
map_path = map_dir / f"{base}{suffix}.html"
537571

538572
# Grid point geometries are only needed to plot a selected frame's points.
539-
grid_gdf = load_grid_gdf(args.work_dir, args.version) if args.frame_id is not None else None
573+
grid_gdf = (
574+
load_grid_gdf(args.work_dir, args.version)
575+
if args.frame_id is not None
576+
else None
577+
)
540578
make_html_map(opera_gdf, map_path, frame_id=args.frame_id, grid_gdf=grid_gdf)
541579
print(f"Wrote HTML map -> {map_path}")
542580

@@ -550,7 +588,11 @@ def main() -> None:
550588
if args.from_parquet is not None
551589
else f"opera_disp_s1_frame_unr_points_{args.prod_date}"
552590
)
553-
sa_dir = args.from_parquet.parent if args.from_parquet is not None else args.outdir
591+
sa_dir = (
592+
args.from_parquet.parent
593+
if args.from_parquet is not None
594+
else args.outdir
595+
)
554596
sa_path = sa_dir / f"{base}_viewer.html"
555597
grid_base = GRID_BASE_URL.format(version=args.version)
556598
# Grid point lon/lat are needed to draw the selected frame's points.

0 commit comments

Comments
 (0)