Datasets:
GeoCarto v2.0: minimum mapping unit (no invisible slivers in labels)
Browse files- README.md +10 -2
- build_config.json +3 -1
- code/geocarto.py +86 -26
- data/test-00000.parquet +2 -2
- data/test-00001.parquet +2 -2
- data/train-00000.parquet +2 -2
- data/train-00001.parquet +2 -2
- data/train-00002.parquet +2 -2
- data/train-00003.parquet +2 -2
- data/train-00004.parquet +2 -2
- data/train-00005.parquet +2 -2
- data/train-00006.parquet +2 -2
- data/train-00007.parquet +2 -2
- data/train-00008.parquet +2 -2
- data/train-00009.parquet +2 -2
- data/train-00010.parquet +2 -2
- data/validation-00000.parquet +2 -2
- data/validation-00001.parquet +2 -2
- index.csv +0 -0
- preview.png +2 -2
README.md
CHANGED
|
@@ -57,7 +57,7 @@ only if it lies entirely inside blocks of its split. Real and synthetic GMNA til
|
|
| 57 |
| column | content |
|
| 58 |
|---|---|
|
| 59 |
| `image` | RGB map tile (PNG, 512×512) |
|
| 60 |
-
| `instances` | uint16 PNG: 0 = no mapped unit (sea, lake, outside the map), 1..N = connected components of one geological unit. Two touching polygons of the **same** unit form **one** instance (no boundary is visible between them on a map). |
|
| 61 |
| `faults` | PNG {0,255}: fault traces rasterised 1 px wide (concealed/inferred faults included) |
|
| 62 |
| `units` | JSON: for each instance id → unit code, age and lithology from the source map |
|
| 63 |
| `source`, `continent`, `kind` (`real`/`synthetic`), `split` | provenance |
|
|
@@ -82,4 +82,12 @@ rgb = np.array(x["image"]); inst = np.array(x["instances"]).astype(np.int32); fa
|
|
| 82 |
| Oceania | Geoscience Australia, *Surface geology of Australia 1:1M* (dataset 149179) | CC BY 4.0 |
|
| 83 |
|
| 84 |
Because the Ethiopian map is CC BY-SA, the whole dataset is released under **CC BY-SA 4.0**.
|
| 85 |
-
The generator code (`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
| column | content |
|
| 58 |
|---|---|
|
| 59 |
| `image` | RGB map tile (PNG, 512×512) |
|
| 60 |
+
| `instances` | uint16 PNG: 0 = no mapped unit (sea, lake, outside the map), 1..N = connected components of one geological unit. Two touching polygons of the **same** unit form **one** instance (no boundary is visible between them on a map). A **minimum mapping unit** is applied before rendering: polygons smaller than 40 px or thinner than ~4 px (invisible under contact lines) are merged into their neighbours, so image and labels always agree. |
|
| 61 |
| `faults` | PNG {0,255}: fault traces rasterised 1 px wide (concealed/inferred faults included) |
|
| 62 |
| `units` | JSON: for each instance id → unit code, age and lithology from the source map |
|
| 63 |
| `source`, `continent`, `kind` (`real`/`synthetic`), `split` | provenance |
|
|
|
|
| 82 |
| Oceania | Geoscience Australia, *Surface geology of Australia 1:1M* (dataset 149179) | CC BY 4.0 |
|
| 83 |
|
| 84 |
Because the Ethiopian map is CC BY-SA, the whole dataset is released under **CC BY-SA 4.0**.
|
| 85 |
+
The generator code (`geocarto.py`) and its configuration (`build_config.json`) are included.
|
| 86 |
+
|
| 87 |
+
## Versions
|
| 88 |
+
| version | date | change |
|
| 89 |
+
|---|---|---|
|
| 90 |
+
| **v2.0** (current) | 2026-11-12 | **Minimum mapping unit** applied to the labels (and to the rendering of synthetic tiles): polygons < 40 px or with half-width < 1.5 px are merged into their neighbours, at render and at final resolution. In v1 ~58 % of the "small" instances were rasterisation slivers or fragments hidden under contact lines, i.e. not visible in the image; they made small-polygon metrics meaningless. Same sources, same spatial splits, same seed. |
|
| 91 |
+
| v1.0 | 2026-11-07 | first release (6,600 tiles). Still available: `load_dataset("PerfectWin/geocarto", revision="v1.0")` |
|
| 92 |
+
|
| 93 |
+
Trained model and vectorisation pipeline (polygons + faults → GeoPackage for QGIS/ArcGIS): [PerfectWin/geocarto-model](https://huggingface.co/PerfectWin/geocarto-model).
|
build_config.json
CHANGED
|
@@ -16,5 +16,7 @@
|
|
| 16 |
"USGS-Nevada": 150000.0,
|
| 17 |
"GMNA": 600000.0
|
| 18 |
},
|
| 19 |
-
"tile": 512
|
|
|
|
|
|
|
| 20 |
}
|
|
|
|
| 16 |
"USGS-Nevada": 150000.0,
|
| 17 |
"GMNA": 600000.0
|
| 18 |
},
|
| 19 |
+
"tile": 512,
|
| 20 |
+
"mmu_area_px": 40,
|
| 21 |
+
"mmu_half_width_px": 1.5
|
| 22 |
}
|
code/geocarto.py
CHANGED
|
@@ -294,6 +294,35 @@ def fault_lines_px(src, win, x0, y1, px, rng=None):
|
|
| 294 |
return out
|
| 295 |
|
| 296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
def instances(U):
|
| 298 |
"""Composantes connexes d'une même unité -> instances (0 = vide)."""
|
| 299 |
inst = cc_label(U, background=0, connectivity=1).astype(np.int32)
|
|
@@ -353,6 +382,9 @@ def edition(rng):
|
|
| 353 |
|
| 354 |
def _palette(src, uids, e, rng, ed_seed):
|
| 355 |
lut = {}
|
|
|
|
|
|
|
|
|
|
| 356 |
if e["palette"] == "random": # couleurs bien séparées, attribuées au hasard (le réseau n'apprend pas "couleur = unité")
|
| 357 |
n = max(len(uids), 1)
|
| 358 |
style = rng.choice(["pastel", "vif", "moyen"])
|
|
@@ -490,9 +522,11 @@ def _spaced(t):
|
|
| 490 |
return " ".join(t) if len(t) < 12 else t
|
| 491 |
|
| 492 |
|
| 493 |
-
def render_map(src, U, lines, rng, px_m):
|
| 494 |
-
"""U : uid (R x R) ; lines : failles en px internes. Retourne l'image RGB uint8 (TILE x TILE).
|
|
|
|
| 495 |
e = edition(rng)
|
|
|
|
| 496 |
ed_seed = int(rng.integers(1 << 30))
|
| 497 |
uids = [int(u) for u in np.unique(U) if u > 0]
|
| 498 |
lut = _palette(src, uids, e, rng, ed_seed)
|
|
@@ -509,7 +543,7 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 509 |
pref = src.pref.get(u)
|
| 510 |
r = np.random.default_rng(_seed(ed_seed, "pat", u))
|
| 511 |
p = e["pattern_p"] * (2.2 if pref else 1)
|
| 512 |
-
if r.random() > p:
|
| 513 |
continue
|
| 514 |
kind = pref if (pref and r.random() < 0.7) else r.choice(["dots", "lines", "lines", "v", "tri", "dash", "grid", "cross"])
|
| 515 |
if kind not in masks:
|
|
@@ -549,6 +583,14 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 549 |
sea_frac = 1 - land.mean()
|
| 550 |
im = Image.fromarray(np.clip(img, 0, 255).astype(np.uint8))
|
| 551 |
d = ImageDraw.Draw(im)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
# --- mer : isobathes + grands noms bleus
|
| 554 |
if sea_frac > 0.1 and rng.random() < 0.6:
|
|
@@ -570,8 +612,9 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 570 |
t = rng.choice(SEA_WORDS)
|
| 571 |
t = _spaced(t) if rng.random() < .7 else t
|
| 572 |
f = font(rng.choice(["bital", "serifi", "ital"]), rng.uniform(30, 70))
|
| 573 |
-
|
| 574 |
-
|
|
|
|
| 575 |
|
| 576 |
# --- graticule (méridiens / parallèles) + degrés
|
| 577 |
for _ in range(rng.integers(0, 3)):
|
|
@@ -584,7 +627,9 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 584 |
d.line([(0, a), (R, b2)], fill=col, width=int(rng.integers(1, 3)))
|
| 585 |
lab_xy = (rng.uniform(20, R - 80), a + 6)
|
| 586 |
if rng.random() < 0.5:
|
| 587 |
-
|
|
|
|
|
|
|
| 588 |
|
| 589 |
# --- rivières
|
| 590 |
if rng.random() < 0.55:
|
|
@@ -628,13 +673,19 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 628 |
if e["label_font"] == "bold" and rng.random() < .3:
|
| 629 |
t = t.upper()
|
| 630 |
tw = d.textlength(t, font=f)
|
| 631 |
-
|
|
|
|
| 632 |
x, y = px - tw / 2, py - fs / 2
|
| 633 |
-
elif v >
|
| 634 |
ang = rng.uniform(0, 2 * np.pi)
|
| 635 |
-
L = rng.uniform(
|
| 636 |
-
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
else:
|
| 639 |
continue
|
| 640 |
bb = (x - 2, y - 2, x + tw + 2, y + fs + 2)
|
|
@@ -645,16 +696,20 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 645 |
d.text((x, y), t, font=f, fill=e["label_col"], stroke_width=3, stroke_fill=(255, 255, 255))
|
| 646 |
else:
|
| 647 |
d.text((x, y), t, font=f, fill=e["label_col"])
|
|
|
|
| 648 |
|
| 649 |
# --- villes et grands noms de régions (distracteurs)
|
| 650 |
for _ in range(rng.integers(0, 4)):
|
| 651 |
x, y = rng.uniform(20, R - 200), rng.uniform(20, R - 40)
|
| 652 |
d.ellipse([x - 5, y - 5, x + 5, y + 5], fill=(0, 0, 0), outline=(255, 255, 255))
|
| 653 |
-
|
|
|
|
|
|
|
| 654 |
if rng.random() < 0.15:
|
| 655 |
-
t = _spaced(rng.choice(LAND_WORDS))
|
| 656 |
-
|
| 657 |
-
|
|
|
|
| 658 |
|
| 659 |
# --- réduction x2 (anti-crénelage d'impression)
|
| 660 |
im = im.resize((TILE, TILE), Image.LANCZOS if rng.random() < .5 else Image.BOX)
|
|
@@ -680,7 +735,9 @@ def render_map(src, U, lines, rng, px_m):
|
|
| 680 |
buf = io.BytesIO()
|
| 681 |
im.save(buf, "JPEG", quality=q)
|
| 682 |
im = Image.open(buf).convert("RGB")
|
| 683 |
-
|
|
|
|
|
|
|
| 684 |
|
| 685 |
|
| 686 |
# =====================================================================================
|
|
@@ -714,7 +771,7 @@ class BlockSplit:
|
|
| 714 |
return s.pop() if len(s) == 1 else None
|
| 715 |
|
| 716 |
|
| 717 |
-
def synth_tile(src, bs, split, rng, max_tries=60):
|
| 718 |
"""Tire une fenêtre entièrement contenue dans des blocs du split demandé, et la rend."""
|
| 719 |
lo, hi = src.px_range
|
| 720 |
for _ in range(max_tries):
|
|
@@ -732,6 +789,7 @@ def synth_tile(src, bs, split, rng, max_tries=60):
|
|
| 732 |
if bs.window_split(x0, y1 - ext, x0 + ext, y1) != split:
|
| 733 |
continue
|
| 734 |
U, win = raster_units(src, x0, y1, px / SS, R)
|
|
|
|
| 735 |
land = (U > 0).mean()
|
| 736 |
if land < src.min_land:
|
| 737 |
continue
|
|
@@ -739,11 +797,12 @@ def synth_tile(src, bs, split, rng, max_tries=60):
|
|
| 739 |
if nu < 2 or (nu < 4 and rng.random() < 0.6):
|
| 740 |
continue
|
| 741 |
lines = fault_lines_px(src, win, x0, y1, px / SS)
|
| 742 |
-
rgb, ed = render_map(src, U, lines, rng, px)
|
| 743 |
-
Uf = U[SS // 2::SS, SS // 2::SS]
|
| 744 |
inst = instances(Uf)
|
| 745 |
flt = faults_gt(lines, 1 / SS)
|
| 746 |
-
|
|
|
|
| 747 |
return rgb, inst, Uf, flt, meta
|
| 748 |
return None
|
| 749 |
|
|
@@ -785,6 +844,7 @@ def make_record(tid, source, continent, kind, split, crs, rgb, inst, flt, meta,
|
|
| 785 |
"bounds": [float(v) for v in meta["bounds"]],
|
| 786 |
"units": json.dumps(units, ensure_ascii=False),
|
| 787 |
"render": json.dumps(meta.get("edition", {}), ensure_ascii=False),
|
|
|
|
| 788 |
}
|
| 789 |
|
| 790 |
|
|
@@ -803,7 +863,7 @@ _FIELDS = [("id", pa.string()), ("source", pa.string()), ("continent", pa.string
|
|
| 803 |
("split", pa.string()), ("image", _IMG), ("instances", _IMG), ("faults", _IMG),
|
| 804 |
("n_instances", pa.int32()), ("land_fraction", pa.float32()), ("fault_pixels", pa.int32()),
|
| 805 |
("px_size_m", pa.float32()), ("crs", pa.string()), ("bounds", pa.list_(pa.float64())),
|
| 806 |
-
("units", pa.string()), ("render", pa.string())]
|
| 807 |
|
| 808 |
|
| 809 |
def arrow_schema():
|
|
@@ -815,7 +875,7 @@ def arrow_schema():
|
|
| 815 |
"instances": HFImage(), "faults": HFImage(), "n_instances": Value("int32"),
|
| 816 |
"land_fraction": Value("float32"), "fault_pixels": Value("int32"),
|
| 817 |
"px_size_m": Value("float32"), "crs": Value("string"), "bounds": Sequence(Value("float64")),
|
| 818 |
-
"units": Value("string"), "render": Value("string")})
|
| 819 |
return f.arrow_schema
|
| 820 |
except Exception as ex:
|
| 821 |
print("datasets indisponible, schéma sans métadonnées HF :", ex)
|
|
@@ -827,9 +887,8 @@ class ShardWriter:
|
|
| 827 |
self.dir = Path(out_dir) / "data"
|
| 828 |
self.dir.mkdir(parents=True, exist_ok=True)
|
| 829 |
self.schema, self.n = arrow_schema(), shard_rows
|
| 830 |
-
|
| 831 |
-
self.k =
|
| 832 |
-
self.count = {s: 0 for s in SPLITS}
|
| 833 |
self.index = []
|
| 834 |
|
| 835 |
def add(self, rec):
|
|
@@ -851,7 +910,7 @@ class ShardWriter:
|
|
| 851 |
self.buf[s] = []
|
| 852 |
|
| 853 |
def close(self):
|
| 854 |
-
for s in
|
| 855 |
self.flush(s)
|
| 856 |
df = pd.DataFrame(self.index)
|
| 857 |
df.to_csv(self.dir.parent / "index.csv", index=False)
|
|
@@ -892,6 +951,7 @@ def real_tiles(raster_path, src, bs, name, writer, easy_frac=0.2, min_cover=0.5,
|
|
| 892 |
tr = rasterio.windows.transform(win, s.transform)
|
| 893 |
rgb = np.ascontiguousarray(np.transpose(s.read([1, 2, 3], window=win), (1, 2, 0)))
|
| 894 |
U, w = raster_units(src, tr.c, tr.f, tr.a, TILE)
|
|
|
|
| 895 |
lines = fault_lines_px(src, w, tr.c, tr.f, tr.a)
|
| 896 |
inst, flt = instances(U), faults_gt(lines, 1.0)
|
| 897 |
meta = {"bounds": list(rasterio.windows.bounds(win, s.transform)), "px_size_m": abs(tr.a),
|
|
|
|
| 294 |
return out
|
| 295 |
|
| 296 |
|
| 297 |
+
MMU_AREA, MMU_RAD = 40, 1.5 # unité minimale de cartographie (px de la tuile finale) : aire et demi-épaisseur
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def generalize(U, s=1, min_area=MMU_AREA, min_rad=MMU_RAD, passes=3):
|
| 301 |
+
"""Généralisation cartographique : tout polygone (composante connexe d'une même valeur) trop petit
|
| 302 |
+
ou trop fin pour être visible sous les traits de contour est absorbé par ses voisins (pixel le plus proche).
|
| 303 |
+
s = pixels internes par pixel final (rendu sur-échantillonné)."""
|
| 304 |
+
U = np.asarray(U)
|
| 305 |
+
for _ in range(passes):
|
| 306 |
+
lab = cc_label(U, background=-1, connectivity=1)
|
| 307 |
+
n = int(lab.max())
|
| 308 |
+
if n <= 1:
|
| 309 |
+
break
|
| 310 |
+
area = np.bincount(lab.ravel(), minlength=n + 1)
|
| 311 |
+
b = np.zeros(lab.shape, bool)
|
| 312 |
+
b[:, 1:] |= lab[:, 1:] != lab[:, :-1]; b[:, :-1] |= lab[:, 1:] != lab[:, :-1]
|
| 313 |
+
b[1:, :] |= lab[1:, :] != lab[:-1, :]; b[:-1, :] |= lab[1:, :] != lab[:-1, :]
|
| 314 |
+
dist = ndi.distance_transform_edt(~b)
|
| 315 |
+
rad = np.zeros(n + 1); rad[1:] = ndi.maximum(dist, lab, np.arange(1, n + 1))
|
| 316 |
+
small = (area < min_area * s * s) | (rad < min_rad * s)
|
| 317 |
+
small[0] = False
|
| 318 |
+
rm = small[lab]
|
| 319 |
+
if not rm.any() or rm.all():
|
| 320 |
+
break
|
| 321 |
+
_, (iy, ix) = ndi.distance_transform_edt(rm, return_indices=True)
|
| 322 |
+
U = U[iy, ix]
|
| 323 |
+
return U
|
| 324 |
+
|
| 325 |
+
|
| 326 |
def instances(U):
|
| 327 |
"""Composantes connexes d'une même unité -> instances (0 = vide)."""
|
| 328 |
inst = cc_label(U, background=0, connectivity=1).astype(np.int32)
|
|
|
|
| 382 |
|
| 383 |
def _palette(src, uids, e, rng, ed_seed):
|
| 384 |
lut = {}
|
| 385 |
+
if e["palette"] == "mono": # piège : TOUTES les unités de la même couleur, seuls les contacts les séparent
|
| 386 |
+
c = np.array(colorsys.hsv_to_rgb(rng.random(), rng.uniform(0.15, 0.5), rng.uniform(0.75, 0.95)), np.float32) * 255
|
| 387 |
+
return {u: c.copy() for u in uids}
|
| 388 |
if e["palette"] == "random": # couleurs bien séparées, attribuées au hasard (le réseau n'apprend pas "couleur = unité")
|
| 389 |
n = max(len(uids), 1)
|
| 390 |
style = rng.choice(["pastel", "vif", "moyen"])
|
|
|
|
| 522 |
return " ".join(t) if len(t) < 12 else t
|
| 523 |
|
| 524 |
|
| 525 |
+
def render_map(src, U, lines, rng, px_m, overrides=None):
|
| 526 |
+
"""U : uid (R x R) ; lines : failles en px internes. Retourne l'image RGB uint8 (TILE x TILE).
|
| 527 |
+
overrides : force des paramètres d'édition (ex. palette='mono', pattern_p=1.0 pour les jeux 'pièges')."""
|
| 528 |
e = edition(rng)
|
| 529 |
+
e.update(overrides or {})
|
| 530 |
ed_seed = int(rng.integers(1 << 30))
|
| 531 |
uids = [int(u) for u in np.unique(U) if u > 0]
|
| 532 |
lut = _palette(src, uids, e, rng, ed_seed)
|
|
|
|
| 543 |
pref = src.pref.get(u)
|
| 544 |
r = np.random.default_rng(_seed(ed_seed, "pat", u))
|
| 545 |
p = e["pattern_p"] * (2.2 if pref else 1)
|
| 546 |
+
if p < 1 and r.random() > p:
|
| 547 |
continue
|
| 548 |
kind = pref if (pref and r.random() < 0.7) else r.choice(["dots", "lines", "lines", "v", "tri", "dash", "grid", "cross"])
|
| 549 |
if kind not in masks:
|
|
|
|
| 583 |
sea_frac = 1 - land.mean()
|
| 584 |
im = Image.fromarray(np.clip(img, 0, 255).astype(np.uint8))
|
| 585 |
d = ImageDraw.Draw(im)
|
| 586 |
+
texts = [] # tous les textes imprimés : {"k": "u" (code d'unité) / "o" (autre), "b": boîte, "t": point désigné}
|
| 587 |
+
|
| 588 |
+
def note(kind, xy, t, f, target=None, **kw):
|
| 589 |
+
b = d.textbbox(xy, t, font=f, **kw)
|
| 590 |
+
rec = {"k": kind, "b": [round(v / SS, 1) for v in b], "s": t}
|
| 591 |
+
if target is not None:
|
| 592 |
+
rec["t"] = [round(target[0] / SS, 1), round(target[1] / SS, 1)]
|
| 593 |
+
texts.append(rec)
|
| 594 |
|
| 595 |
# --- mer : isobathes + grands noms bleus
|
| 596 |
if sea_frac > 0.1 and rng.random() < 0.6:
|
|
|
|
| 612 |
t = rng.choice(SEA_WORDS)
|
| 613 |
t = _spaced(t) if rng.random() < .7 else t
|
| 614 |
f = font(rng.choice(["bital", "serifi", "ital"]), rng.uniform(30, 70))
|
| 615 |
+
xy = (xs[k] * 16 - rng.uniform(0, 300), ys[k] * 16)
|
| 616 |
+
d.text(xy, t, font=f, fill=(int(rng.integers(20, 80)), int(rng.integers(80, 140)), int(rng.integers(170, 220))))
|
| 617 |
+
note("o", xy, t, f)
|
| 618 |
|
| 619 |
# --- graticule (méridiens / parallèles) + degrés
|
| 620 |
for _ in range(rng.integers(0, 3)):
|
|
|
|
| 627 |
d.line([(0, a), (R, b2)], fill=col, width=int(rng.integers(1, 3)))
|
| 628 |
lab_xy = (rng.uniform(20, R - 80), a + 6)
|
| 629 |
if rng.random() < 0.5:
|
| 630 |
+
t, f = f"{rng.integers(0, 180)}°", font("bold", rng.uniform(22, 40))
|
| 631 |
+
d.text(lab_xy, t, font=f, fill=col)
|
| 632 |
+
note("o", lab_xy, t, f)
|
| 633 |
|
| 634 |
# --- rivières
|
| 635 |
if rng.random() < 0.55:
|
|
|
|
| 673 |
if e["label_font"] == "bold" and rng.random() < .3:
|
| 674 |
t = t.upper()
|
| 675 |
tw = d.textlength(t, font=f)
|
| 676 |
+
r_ = rng.random()
|
| 677 |
+
if v > fs * 0.8: # l'étiquette tient dans le polygone
|
| 678 |
x, y = px - tw / 2, py - fs / 2
|
| 679 |
+
elif v > 2 and r_ < 0.45: # trop petit : étiquette à côté + trait de rappel
|
| 680 |
ang = rng.uniform(0, 2 * np.pi)
|
| 681 |
+
L = rng.uniform(30, 110)
|
| 682 |
+
cx_, cy_ = px + L * np.cos(ang), py + L * np.sin(ang)
|
| 683 |
+
x, y = cx_ - tw / 2, cy_ - fs / 2
|
| 684 |
+
ax_ = min(max(px, x), x + tw) # point d'attache : bord de la boîte le plus proche
|
| 685 |
+
ay_ = min(max(py, y), y + fs)
|
| 686 |
+
d.line([(px, py), (ax_, ay_)], fill=e["label_col"], width=2)
|
| 687 |
+
elif v > 2 and r_ < 0.75: # trop petit : étiquette qui déborde du polygone
|
| 688 |
+
x, y = px - tw / 2 + rng.uniform(-tw / 3, tw / 3), py - fs / 2 + rng.uniform(-fs / 3, fs / 3)
|
| 689 |
else:
|
| 690 |
continue
|
| 691 |
bb = (x - 2, y - 2, x + tw + 2, y + fs + 2)
|
|
|
|
| 696 |
d.text((x, y), t, font=f, fill=e["label_col"], stroke_width=3, stroke_fill=(255, 255, 255))
|
| 697 |
else:
|
| 698 |
d.text((x, y), t, font=f, fill=e["label_col"])
|
| 699 |
+
note("u", (x, y), t, f, target=(px, py))
|
| 700 |
|
| 701 |
# --- villes et grands noms de régions (distracteurs)
|
| 702 |
for _ in range(rng.integers(0, 4)):
|
| 703 |
x, y = rng.uniform(20, R - 200), rng.uniform(20, R - 40)
|
| 704 |
d.ellipse([x - 5, y - 5, x + 5, y + 5], fill=(0, 0, 0), outline=(255, 255, 255))
|
| 705 |
+
t, f = _rname(rng), font(rng.choice(["sans", "ital"]), rng.uniform(18, 26))
|
| 706 |
+
d.text((x + 10, y - 14), t, font=f, fill=(20, 20, 20))
|
| 707 |
+
note("o", (x + 10, y - 14), t, f)
|
| 708 |
if rng.random() < 0.15:
|
| 709 |
+
t, f = _spaced(rng.choice(LAND_WORDS)), font("bold", rng.uniform(28, 50))
|
| 710 |
+
xy = (rng.uniform(0, R / 2), rng.uniform(0, R - 60))
|
| 711 |
+
d.text(xy, t, font=f, fill=(int(rng.integers(80, 140)), int(rng.integers(50, 90)), int(rng.integers(20, 60))))
|
| 712 |
+
note("o", xy, t, f)
|
| 713 |
|
| 714 |
# --- réduction x2 (anti-crénelage d'impression)
|
| 715 |
im = im.resize((TILE, TILE), Image.LANCZOS if rng.random() < .5 else Image.BOX)
|
|
|
|
| 735 |
buf = io.BytesIO()
|
| 736 |
im.save(buf, "JPEG", quality=q)
|
| 737 |
im = Image.open(buf).convert("RGB")
|
| 738 |
+
ed = {k: (v if isinstance(v, (int, float, str, bool)) else str(v)) for k, v in e.items()}
|
| 739 |
+
ed["_texts"] = texts
|
| 740 |
+
return np.asarray(im, np.uint8), ed
|
| 741 |
|
| 742 |
|
| 743 |
# =====================================================================================
|
|
|
|
| 771 |
return s.pop() if len(s) == 1 else None
|
| 772 |
|
| 773 |
|
| 774 |
+
def synth_tile(src, bs, split, rng, max_tries=60, overrides=None):
|
| 775 |
"""Tire une fenêtre entièrement contenue dans des blocs du split demandé, et la rend."""
|
| 776 |
lo, hi = src.px_range
|
| 777 |
for _ in range(max_tries):
|
|
|
|
| 789 |
if bs.window_split(x0, y1 - ext, x0 + ext, y1) != split:
|
| 790 |
continue
|
| 791 |
U, win = raster_units(src, x0, y1, px / SS, R)
|
| 792 |
+
U = generalize(U, SS)
|
| 793 |
land = (U > 0).mean()
|
| 794 |
if land < src.min_land:
|
| 795 |
continue
|
|
|
|
| 797 |
if nu < 2 or (nu < 4 and rng.random() < 0.6):
|
| 798 |
continue
|
| 799 |
lines = fault_lines_px(src, win, x0, y1, px / SS)
|
| 800 |
+
rgb, ed = render_map(src, U, lines, rng, px, overrides)
|
| 801 |
+
Uf = generalize(U[SS // 2::SS, SS // 2::SS], 1) # le sous-échantillonnage peut couper des isthmes fins
|
| 802 |
inst = instances(Uf)
|
| 803 |
flt = faults_gt(lines, 1 / SS)
|
| 804 |
+
texts = ed.pop("_texts", [])
|
| 805 |
+
meta = {"bounds": [x0, y1 - ext, x0 + ext, y1], "px_size_m": px, "edition": ed, "texts": texts}
|
| 806 |
return rgb, inst, Uf, flt, meta
|
| 807 |
return None
|
| 808 |
|
|
|
|
| 844 |
"bounds": [float(v) for v in meta["bounds"]],
|
| 845 |
"units": json.dumps(units, ensure_ascii=False),
|
| 846 |
"render": json.dumps(meta.get("edition", {}), ensure_ascii=False),
|
| 847 |
+
"texts": json.dumps(meta.get("texts", []), ensure_ascii=False),
|
| 848 |
}
|
| 849 |
|
| 850 |
|
|
|
|
| 863 |
("split", pa.string()), ("image", _IMG), ("instances", _IMG), ("faults", _IMG),
|
| 864 |
("n_instances", pa.int32()), ("land_fraction", pa.float32()), ("fault_pixels", pa.int32()),
|
| 865 |
("px_size_m", pa.float32()), ("crs", pa.string()), ("bounds", pa.list_(pa.float64())),
|
| 866 |
+
("units", pa.string()), ("render", pa.string()), ("texts", pa.string())]
|
| 867 |
|
| 868 |
|
| 869 |
def arrow_schema():
|
|
|
|
| 875 |
"instances": HFImage(), "faults": HFImage(), "n_instances": Value("int32"),
|
| 876 |
"land_fraction": Value("float32"), "fault_pixels": Value("int32"),
|
| 877 |
"px_size_m": Value("float32"), "crs": Value("string"), "bounds": Sequence(Value("float64")),
|
| 878 |
+
"units": Value("string"), "render": Value("string"), "texts": Value("string")})
|
| 879 |
return f.arrow_schema
|
| 880 |
except Exception as ex:
|
| 881 |
print("datasets indisponible, schéma sans métadonnées HF :", ex)
|
|
|
|
| 887 |
self.dir = Path(out_dir) / "data"
|
| 888 |
self.dir.mkdir(parents=True, exist_ok=True)
|
| 889 |
self.schema, self.n = arrow_schema(), shard_rows
|
| 890 |
+
from collections import defaultdict
|
| 891 |
+
self.buf, self.k, self.count = defaultdict(list), defaultdict(int), defaultdict(int)
|
|
|
|
| 892 |
self.index = []
|
| 893 |
|
| 894 |
def add(self, rec):
|
|
|
|
| 910 |
self.buf[s] = []
|
| 911 |
|
| 912 |
def close(self):
|
| 913 |
+
for s in list(self.buf):
|
| 914 |
self.flush(s)
|
| 915 |
df = pd.DataFrame(self.index)
|
| 916 |
df.to_csv(self.dir.parent / "index.csv", index=False)
|
|
|
|
| 951 |
tr = rasterio.windows.transform(win, s.transform)
|
| 952 |
rgb = np.ascontiguousarray(np.transpose(s.read([1, 2, 3], window=win), (1, 2, 0)))
|
| 953 |
U, w = raster_units(src, tr.c, tr.f, tr.a, TILE)
|
| 954 |
+
U = generalize(U, 1)
|
| 955 |
lines = fault_lines_px(src, w, tr.c, tr.f, tr.a)
|
| 956 |
inst, flt = instances(U), faults_gt(lines, 1.0)
|
| 957 |
meta = {"bounds": list(rasterio.windows.bounds(win, s.transform)), "px_size_m": abs(tr.a),
|
data/test-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a327a7e8f0b760503ce9de17104ea1ae29082a5e9a888dcf64a3338aa9890b8
|
| 3 |
+
size 183509651
|
data/test-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4230195a06b88716fdf9e18dd2c384b0eee05cab18c452de325f85088d349f48
|
| 3 |
+
size 40123162
|
data/train-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dd08407ea52944e546ab3236e2035e6ccd4aa79bc02c1151de9b6064eb625af
|
| 3 |
+
size 178831342
|
data/train-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c4dfbc3041f69f9f0bb7c20f4c7a4b70a7cf870856b7fb00a353f8d35f8c094
|
| 3 |
+
size 173709941
|
data/train-00002.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b05c6bf23117002f73b55b4e223fada1a19378c7c3c8aeac341f08683eca728
|
| 3 |
+
size 172431783
|
data/train-00003.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2a2bbad7ac03217f4f31441e553db1aa85390a2d1b1949fb765437a22edd8a85
|
| 3 |
+
size 180725548
|
data/train-00004.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:090729cef737f422386c4fc0517094a4199959e31bb9dc670dd311e14345f070
|
| 3 |
+
size 175909649
|
data/train-00005.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b050be69d182f44a31c655903094735c10845aa60e5780ef29294b223f58c6bb
|
| 3 |
+
size 185806365
|
data/train-00006.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:889589ab3f5685fd995b7b10d33d38f331f1862aa73fb95bfd97f5cf1481991b
|
| 3 |
+
size 182550837
|
data/train-00007.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75935d3bbbd87f7a632aa2a80b7bd7c9fc2f292fb80175c90e73e1eb813fe8f3
|
| 3 |
+
size 180969974
|
data/train-00008.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dee3a610b57c317406cf623c5882a0dc77479561df8158d951672c8a38ea27f0
|
| 3 |
+
size 186224003
|
data/train-00009.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:905d0e08a4cd96a5ead908ab9d07c0c7ed3938f455fbdcfb62f26b31572db3ba
|
| 3 |
+
size 188115764
|
data/train-00010.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:05411f6acdbbf916b9f8944173270782e0336cb4ef89b136c1d463dd2d6189c7
|
| 3 |
+
size 139884717
|
data/validation-00000.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b4481f41e1bcf545b66e0d27b3afd66afbc8a380baa149640968035229090b0c
|
| 3 |
+
size 163342823
|
data/validation-00001.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:108619053a7c37b2522c783aa381aab65e67a9d01c06637493e5fe7409dded2f
|
| 3 |
+
size 37159092
|
index.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
preview.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|