Download src/cell_tracking/data/wormtrack_verify/inventory.py from pytc/trackingBench: direct link, hf CLI and curl.
- Browser
- Download file 4.09 kB
-
https://huggingface.co/datasets/pytc/trackingBench/resolve/main/src/cell_tracking/data/wormtrack_verify/inventory.py
- Command line
-
hf download hf://datasets/pytc/trackingBench/src/cell_tracking/data/wormtrack_verify/inventory.py
-
curl -L -o inventory.py https://huggingface.co/datasets/pytc/trackingBench/resolve/main/src/cell_tracking/data/wormtrack_verify/inventory.py
4.09 kB
| """Pin official source metadata without bulk acquisition.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import requests | |
| DANDI_COHORTS = { | |
| "000541": "EY", | |
| "000692": "KK", | |
| "000565": "SK1", | |
| "000472": "SK2", | |
| "000776": "SF", | |
| "000715": "NP", | |
| "000714": "HL", | |
| "001623": "Dunn", | |
| "000981": "Chemosensory", | |
| } | |
| ZENODO = {"17561700": "ASCENT", "10818810": "ZephIR", "10008744": "Targettrack"} | |
| WORMND_COMMIT = "0c74e9ddffee138cfc6330ab65c0e690e8e199dd" | |
| def inventory(workspace): | |
| """Save release metadata, immutable asset IDs/checksums, and the original split CSV. | |
| Re-running an inventory captures the current latest upstream release. Assembly | |
| uses saved snapshots, never silently updates an existing experiment. Original | |
| data licenses are taken from release metadata, separately from code licenses. | |
| """ | |
| out = Path(workspace) / "audit" | |
| out.mkdir(parents=True, exist_ok=True) | |
| asset_provenance = {} | |
| for identifier in DANDI_COHORTS: | |
| base = f"https://api.dandiarchive.org/api/dandisets/{identifier}/versions/" | |
| versions = requests.get(base, timeout=60) | |
| versions.raise_for_status() | |
| versions = versions.json() | |
| versions = versions.get("results", versions) if isinstance(versions, dict) else versions | |
| published = [v["version"] for v in versions if v["version"] != "draft"] | |
| version = max(published) if published else "draft" | |
| metadata = requests.get(base + version + "/", timeout=60) | |
| metadata.raise_for_status() | |
| (out / f"dandi-{identifier}-pinned.json").write_text(json.dumps(metadata.json(), indent=2)) | |
| assets = [] | |
| url = base + version + "/assets/?page_size=1000" | |
| while url: | |
| response = requests.get(url, timeout=60) | |
| response.raise_for_status() | |
| page = response.json() | |
| assets.extend(page["results"]) | |
| url = page.get("next") | |
| (out / f"dandi-{identifier}-assets.json").write_text( | |
| json.dumps({"version": version, "assets": assets}, indent=2) | |
| ) | |
| for asset in assets: | |
| response = requests.get( | |
| f"https://api.dandiarchive.org/api/assets/{asset['asset_id']}/", timeout=60 | |
| ) | |
| response.raise_for_status() | |
| value = response.json() | |
| asset_provenance[asset["asset_id"]] = { | |
| key: value.get(key) | |
| for key in ["digest", "wasAttributedTo", "wasGeneratedBy", "datePublished"] | |
| } | |
| (out / "dandi-asset-provenance.json").write_text(json.dumps(asset_provenance, indent=2)) | |
| for identifier in ZENODO: | |
| response = requests.get(f"https://zenodo.org/api/records/{identifier}", timeout=60) | |
| response.raise_for_status() | |
| (out / f"zenodo-{identifier}.json").write_text(json.dumps(response.json(), indent=2)) | |
| url = ( | |
| f"https://raw.githubusercontent.com/focolab/WormND/{WORMND_COMMIT}" | |
| "/neuron_tracking/3deecelltracker/dataset_split.csv" | |
| ) | |
| response = requests.get(url, timeout=60) | |
| response.raise_for_status() | |
| (out / "wormid-tracking-split.csv").write_text(response.text) | |
| def snapshot_hub(workspace, repo_id="pytc/trackingBench"): | |
| """Record the immutable Hub state before edits; does not publish or expose tokens.""" | |
| from huggingface_hub import HfApi, hf_hub_download | |
| api = HfApi() | |
| info = api.dataset_info(repo_id, files_metadata=True) | |
| readme = Path( | |
| hf_hub_download(repo_id, "README.md", repo_type="dataset", revision=info.sha) | |
| ).read_text() | |
| snapshot = { | |
| "repo_id": repo_id, | |
| "sha": info.sha, | |
| "private": info.private, | |
| "card": info.card_data.to_dict() if info.card_data else {}, | |
| "readme": readme, | |
| "files": [ | |
| {"path": f.rfilename, "size": f.size, "blob_id": f.blob_id} for f in info.siblings | |
| ], | |
| } | |
| Path(workspace).mkdir(parents=True, exist_ok=True) | |
| (Path(workspace) / "hub-before.json").write_text(json.dumps(snapshot, indent=2)) | |
| return snapshot | |