mal_commonlib.data.licenses
Dataset license registry + restriction warnings (upstream licensing audit).
Every loader module (mal_commonlib.data.loaders.*) declares license
(an identifier in KNOWN_LICENSES) and attribution (the literal
credit line to reproduce in publications/maps) in its DOWNLOADER dict.
The download runner stamps both into the manifest entry; ingest registers
derived products with a +-joined compound license id derived from its
inputs. Scr: docs/licenses.md — the human-readable audit + decision log
(e.g. MERIT DEM: ODbL branch elected 2026-09-27).
Pipeline stages that produce or consume datasets call warn_limits()
once per process; it aggregates which usage restrictions apply.
1"""Dataset license registry + restriction warnings (upstream licensing audit). 2 3Every loader module (``mal_commonlib.data.loaders.*``) declares ``license`` 4(an identifier in :data:`KNOWN_LICENSES`) and ``attribution`` (the literal 5credit line to reproduce in publications/maps) in its ``DOWNLOADER`` dict. 6The download runner stamps both into the manifest entry; ingest registers 7derived products with a ``+``-joined compound license id derived from its 8inputs. Scr: docs/licenses.md — the human-readable audit + decision log 9(e.g. MERIT DEM: ODbL branch elected 2026-09-27). 10 11Pipeline stages that produce or consume datasets call :func:`warn_limits` 12once per process; it aggregates which usage restrictions apply. 13""" 14from __future__ import annotations 15 16import warnings 17from collections.abc import Iterable 18 19__all__ = ["KNOWN_LICENSES", "collect_limits", "warn_limits", "warn_manifest_limits"] 20 21# --------------------------------------------------------------------------- 22# 8 upstream licenses cover every dataset the pipeline integrates. 23# --------------------------------------------------------------------------- 24#: license_id -> restriction spec (None = unrestricted, attribution-only) 25KNOWN_LICENSES: dict[str, dict | None] = { 26 # CC BY 4.0 — attribution required, derivatives free (incl. commercial) 27 "CC-BY-4.0": { 28 "attribution": ( 29 "This work incorporates data licensed under CC BY 4.0 " 30 "(WorldPop / FAO GLW4 / GHS-SMOD © European Union / JRC GSW / " 31 "CHIRPS—not applicable)" 32 ), 33 "limit": ( 34 "Attribution required for each CC BY 4.0 source " 35 "(WorldPop, FAO GLW4, GHS-SMOD, JRC GSW, ESA WorldCover)." 36 ), 37 }, 38 # Copernicus: CC BY 4.0 since 2025-07 but attribution had the same 39 # literal sentence under the earlier Copernicus licence 40 "Copernicus-Cite": { 41 "attribution": ( 42 "Contains modified Copernicus Climate Change Service information " 43 "[Year]. Neither the European Commission nor ECMWF is responsible " 44 "for any use that may be made of the Copernicus information or " 45 "data it contains." 46 ), 47 "limit": ( 48 "Literal 'Contains modified Copernicus Climate Change Service " 49 "information [Year]' line required in any distribution/publication." 50 ), 51 }, 52 # IdealSentinel-2-like — NASA Earthdata products: free, cite the DOI 53 "NASA-Cite": { 54 "attribution": "NASA (MODIS MOD13A3, https://doi.org/10.5067/MODIS/MOD13A3.061; SMAP RSS L3 SSS, https://doi.org/10.5067/SMP60-3SMCS)", 55 "limit": "Cite the LP DAAC / PO.DAAC dataset DOI.", 56 }, 57 # CHIRPS v2.0: free, must cite Funk et al. 2014 (USGS DS832) 58 "CHIRPS-Cite": { 59 "attribution": ( 60 "Funk, C.C., Peterson, P.J., Landsfeld, M.F., et al., 2014, " 61 "A quasi-global precipitation time series for drought " 62 "monitoring: U.S. Geological Survey Data Series 832, 4 p." 63 ), 64 "limit": "Cite Funk et al. 2014 (USGS DS832).", 65 }, 66 # GSHHG: LGPL v3 data + Wessel & Smith 1996 citation 67 "LicenseRef-GSHHG-LGPL-3.0": { 68 "attribution": ( 69 "Wessel, P., & Smith, W. H. F. (1996), A global, self-consistent, " 70 "hierarchical, high-resolution shoreline database, JGR 101, " 71 "8741-8743. GSHHG is distributed under LGPL v3+." 72 ), 73 "limit": ( 74 "LGPL v3 (data): notify Wessel/Smith if the dataset itself is " 75 "modified for commercial use; cite Wessel & Smith 1996." 76 ), 77 }, 78 # ODbL 1.0 — share-alike for derived databases 79 "ODbL-1.0": { 80 "attribution": "© OpenStreetMap contributors, Overture Maps Foundation (ODbL 1.0)", 81 "limit": ( 82 "ODbL share-alike: any DERIVED DATABASE (host_static.nc, " 83 "mobility_*.csr, wildlife_host_proxy — via Overture buildings) " 84 "redistribution requires ODbL + this attribution. MERIT DEM: " 85 "ODbL branch elected 2026-09-27 in docs/licenses.md." 86 ), 87 }, 88 # CC BY-NC 4.0 — non-commercial only (mal-data-explorer reference sets) 89 "CC-BY-NC-4.0": { 90 "attribution": "Institut Pasteur / PMI VectorLink — CC BY-NC 4.0 (GBIF-mediated)", 91 "limit": ( 92 "NON-COMMERCIAL: guf/ (Institut Pasteur) and colombia_vl/ " 93 "(PMI VectorLink) occurrence datasets — isolate to " 94 "mal-data-explorer; never import into mal-core/ABM/training; " 95 "no commercial use of derivatives." 96 ), 97 }, 98 # WorldPop responsible-use disclaimer (stacks on CC BY 4.0 for worldpop) 99 "WorldPop-harm": { 100 "attribution": "WorldPop 2019 (CC BY 4.0), www.worldpop.org", 101 "limit": ( 102 "WorldPop responsibly-use disclaimer: not for purposes that " 103 "discriminate/exploit/harm individuals or vulnerable groups; " 104 "assess risk when combined with other datasets." 105 ), 106 }, 107} 108 109 110def collect_limits(license_ids: Iterable[str]) -> list[str]: 111 """Aggregate usage-limit sentences for a set of license ids. 112 113 Compound derived ids are '+'-joined (e.g. ``CC-BY-4.0+ODbL-1.0``); in 114 that case every component id is kept only if it adds a restriction. 115 """ 116 seen: dict[str, str] = {} 117 for raw in license_ids: 118 if not raw: 119 continue 120 for lid in raw.split("+"): 121 lid = lid.strip() 122 spec = KNOWN_LICENSES.get(lid) 123 if spec is None: 124 seen.setdefault( 125 lid, f"Unknown license id {lid!r} — check docs/licenses.md" 126 ) 127 elif spec.get("limit"): 128 seen.setdefault(lid, spec["limit"]) 129 return list(seen.values()) 130 131 132def warn_limits(license_ids: Iterable[str], *, stacklevel: int = 2) -> None: 133 """Emit a single aggregated UserWarning listing all usage limits.""" 134 limits = collect_limits(license_ids) 135 if not limits: 136 return 137 body = "\n - ".join(limits) 138 warnings.warn( 139 f"Upstream dataset licenses limit some uses:\n - {body}\n" 140 f" Full audit: docs/licenses.md", 141 UserWarning, 142 stacklevel=stacklevel, 143 ) 144 145 146def warn_manifest_limits(aoi: str, data_root=None) -> None: 147 """Read an AOI manifest and warn once about its aggregate limits. 148 149 Called by download / ingest stages after registration. 150 """ 151 from mal_core.download.manifest import read_manifest 152 153 manifest = read_manifest(aoi, data_root) 154 ids = [ 155 (ds.get("license") or "") 156 for ds in manifest.get("datasets", {}).values() 157 ] 158 warn_limits([i for i in ids if i], stacklevel=3)
111def collect_limits(license_ids: Iterable[str]) -> list[str]: 112 """Aggregate usage-limit sentences for a set of license ids. 113 114 Compound derived ids are '+'-joined (e.g. ``CC-BY-4.0+ODbL-1.0``); in 115 that case every component id is kept only if it adds a restriction. 116 """ 117 seen: dict[str, str] = {} 118 for raw in license_ids: 119 if not raw: 120 continue 121 for lid in raw.split("+"): 122 lid = lid.strip() 123 spec = KNOWN_LICENSES.get(lid) 124 if spec is None: 125 seen.setdefault( 126 lid, f"Unknown license id {lid!r} — check docs/licenses.md" 127 ) 128 elif spec.get("limit"): 129 seen.setdefault(lid, spec["limit"]) 130 return list(seen.values())
Aggregate usage-limit sentences for a set of license ids.
Compound derived ids are '+'-joined (e.g. CC-BY-4.0+ODbL-1.0); in
that case every component id is kept only if it adds a restriction.
133def warn_limits(license_ids: Iterable[str], *, stacklevel: int = 2) -> None: 134 """Emit a single aggregated UserWarning listing all usage limits.""" 135 limits = collect_limits(license_ids) 136 if not limits: 137 return 138 body = "\n - ".join(limits) 139 warnings.warn( 140 f"Upstream dataset licenses limit some uses:\n - {body}\n" 141 f" Full audit: docs/licenses.md", 142 UserWarning, 143 stacklevel=stacklevel, 144 )
Emit a single aggregated UserWarning listing all usage limits.
147def warn_manifest_limits(aoi: str, data_root=None) -> None: 148 """Read an AOI manifest and warn once about its aggregate limits. 149 150 Called by download / ingest stages after registration. 151 """ 152 from mal_core.download.manifest import read_manifest 153 154 manifest = read_manifest(aoi, data_root) 155 ids = [ 156 (ds.get("license") or "") 157 for ds in manifest.get("datasets", {}).values() 158 ] 159 warn_limits([i for i in ids if i], stacklevel=3)
Read an AOI manifest and warn once about its aggregate limits.
Called by download / ingest stages after registration.