Download the H5 through releases.json, not the root file

#3
by anth-volk - opened
Files changed (1) hide show
  1. README.md +26 -6
README.md CHANGED
@@ -33,16 +33,36 @@ sim = Microsimulation(dataset=load("us", 2024))
33
  sim.calculate("household_net_income", 2024).sum()
34
  ```
35
 
36
- Or grab the H5 directly:
 
 
 
 
 
37
 
38
  ```python
 
 
39
  from huggingface_hub import hf_hub_download
40
 
41
- path = hf_hub_download(
42
- repo_id="policyengine/populace-us",
43
- filename="populace_us_2024.h5",
44
- repo_type="dataset",
45
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ```
47
 
48
  ## How it is built
 
33
  sim.calculate("household_net_income", 2024).sum()
34
  ```
35
 
36
+ Or grab the H5 directly. `releases.json` at the repository root lists each
37
+ release's builds, names each release's current build and names the default
38
+ release; each build it lists is in its own folder,
39
+ `releases/<release>/<build>/`. Older builds that it doesn't list stay
40
+ readable at their tags. This example downloads the default release's current
41
+ build, so it moves to a newer build when one becomes current:
42
 
43
  ```python
44
+ import json
45
+
46
  from huggingface_hub import hf_hub_download
47
 
48
+ REPOSITORY = "policyengine/populace-us"
49
+
50
+
51
+ def download(filename):
52
+ return hf_hub_download(repo_id=REPOSITORY, filename=filename, repo_type="dataset")
53
+
54
+
55
+ with open(download("releases.json")) as file:
56
+ record = json.load(file)
57
+ release = record["default"]
58
+ if release is None or record["releases"][release]["current"] is None:
59
+ raise RuntimeError("releases.json names no current build of a default release")
60
+ build = record["releases"][release]["current"]
61
+ folder = f"releases/{release}/{build}"
62
+ with open(download(f"{folder}/release_manifest.json")) as file:
63
+ manifest = json.load(file)
64
+ dataset = manifest["artifacts"][manifest["default_datasets"]["national"]]
65
+ path = download(f"{folder}/{dataset['path']}")
66
  ```
67
 
68
  ## How it is built