bobleesj commited on
Commit
46a7877
·
verified ·
1 Parent(s): ea467e0

docs: draft widget-tutorials meta.json process and dummy 8x8 test

Browse files
README.md CHANGED
@@ -10,59 +10,147 @@ pretty_name: quantem-data
10
 
11
  # quantem-data
12
 
13
- Reference electron-microscopy datasets (gold 4D-STEM and HAADF) for browsing
14
- and learning with [quantem.widget](https://github.com/bobleesj/quantem.widget).
15
- This repo just hosts the data all instructions live in one place:
 
16
 
17
- **How to download and use this data:** follow the
18
- [Download data tutorial](https://bobleesj.github.io/quantem.widget/tutorials/download_data.html)
19
- in the quantem.widget docs. One call per dataset:
 
 
 
 
 
 
20
 
21
  ```python
22
- from quantem.widget import Show4DSTEM
23
  from quantem.widget.datasets import show4dstem_gold
24
 
25
- Show4DSTEM(show4dstem_gold())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ```
27
 
28
- Layout two trees:
 
 
 
 
 
29
 
30
- - **`widget-tutorials/<widget>/<dataset>/<size>/`** baseline tutorial
31
- bundles for the core widgets (`show1d/`, `show4dstem/`, `showfolder/`;
32
- data shared by Show2D and Show3D lives under `shared/`). These back the
33
- one-call loaders in `quantem.widget.datasets` and the Colab workshops.
34
- Baseline tutorials only — real work uses your own data.
35
- - **`4dstem/`, `haadf/`** — full-size originals (Arina h5, Velox EMD) for
36
- power users.
37
 
38
- Every NumPy bundle ships a `meta.json` (shape, dtype, sampling, units,
39
- optics) next to `data.npy`.
 
40
 
41
- Workshop notebooks (Google Colab, no local install):
42
- [Show4DSTEM demo](https://colab.research.google.com/gist/bobleesj/54864ce5b2a6f0a4fd5ae1e5d5719b45/show4dstem_colab.ipynb)
43
- ·
44
- [Workshop v1](https://colab.research.google.com/gist/bobleesj/a05a90185c6cddbb331342cae6d7e9c1/berk_workshop_v1.ipynb)
45
 
46
  ## Acquisition parameters
47
 
48
- The 20260423 drift session's optics are **confirmed via the session's own
49
- HAADF EMD** (`AccelerationVoltage`, `BeamConvergence`, `CameraLength`).
50
- 4D-STEM `scan_sampling` is an **operator pattern from a sibling SSB session**
51
- — the drift acquisition itself was never per-file calibrated.
 
 
 
 
 
 
 
 
52
 
53
- | dataset | voltage | probe | CL | scan | scan sampling | det pitch | mag |
54
- |---|---|---|---|---|---|---|---|
55
- | `haadf/gold_haadf_npy` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
56
- | `4dstem/gold_512_npy_bin8` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 3.68 mrad/px | unknown |
57
- | `4dstem/gold_512_npy_bin4` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 1.84 mrad/px | unknown |
58
- | `4dstem/gold_512` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 0.46 mrad/px | unknown |
59
- | `4dstem/gold_30mrad1.3mx04`…`09` | 300 kV | 30 mrad | 91 mm | smaller | (session yaml) | 0.46 mrad/px | 1.3 Mx |
60
- | `haadf/gold_haadf.emd` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
61
 
62
  ✓ = confirmed via EMD/yaml. `(op)` = operator pattern, not file-certified.
63
 
64
  ## License
65
 
66
- MIT free to use for anything. Citing
67
- [quantem.widget](https://github.com/bobleesj/quantem.widget) in publications
68
- is appreciated.
 
 
 
 
 
 
 
 
10
 
11
  # quantem-data
12
 
13
+ **This page is in draft mode. We are still exploring the upload process
14
+ and the `meta.json` template.** Keys, the checker, and these instructions
15
+ will change as we try real pull requests. Use the current required keys
16
+ for new PRs, and expect the template to grow.
17
 
18
+ **This repo is currently used primarily by
19
+ [quantem.widget**](https://github.com/electronmicroscopy/quantem.widget)
20
+ (tutorial notebooks and `quantem.widget.datasets`). Other QuantEM packages
21
+ may use it later.
22
+
23
+ Public electron-microscopy data. MIT license. Downloads need no token.
24
+ This page is the upload and download protocol.
25
+
26
+ ## Download
27
 
28
  ```python
 
29
  from quantem.widget.datasets import show4dstem_gold
30
 
31
+ ds = show4dstem_gold(size="small")
32
+ ```
33
+
34
+ Notebook: [Example Data](https://github.com/electronmicroscopy/quantem.widget/blob/main/docs/tutorials/download_data.ipynb).
35
+
36
+ ## Add data (Hugging Face pull request)
37
+
38
+ Anyone with a Hugging Face account can add data. We follow a pull request
39
+ process. Do not use `quantem.widget.io.upload`.
40
+
41
+ A PR is the data file(s) plus one `meta.json`. Example already on the hub
42
+ (2 files):
43
+
44
+ ```text
45
+ widget-tutorials/show4dstem/gold-512-bin4/full/data.npy
46
+ widget-tutorials/show4dstem/gold-512-bin4/full/meta.json
47
+ ```
48
+
49
+ One EMD: `gold_haadf.emd` + `meta.json` (2 files). A session folder: the
50
+ `.emd` files + `meta.json`.
51
+
52
+ Copy this `meta.json`. Required: `name`, `source`, `date`, `sample`,
53
+ `shape`, `dtype`, `permission`. Optional: `sampling`, `units`, optics.
54
+ Omit a key if unknown. Do not invent a number.
55
+
56
+ `shape` is `[row, col]` for an image, `[frame, row, col]` for a stack, or
57
+ `[scan_row, scan_col, det_row, det_col]` for 4D-STEM. `dtype` is the NumPy
58
+ name of the stored array (or of the EMD image). Examples already on this
59
+ repo:
60
+
61
+
62
+ | Data | `shape` | `dtype` |
63
+ | ------------------------- | -------------------- | -------- |
64
+ | 2D HAADF (`gold-haadf`) | `[4096, 4096]` | `uint16` |
65
+ | 4D-STEM (`gold-512-bin4`) | `[512, 512, 48, 48]` | `uint16` |
66
+ | One EMD HAADF | `[4096, 4096]` | `uint16` |
67
+
68
+
69
+ Processed float data uses `"float32"`. Read both values from the file
70
+ (`arr.shape`, `arr.dtype`, or the EMD image) and copy them into
71
+ `meta.json`.
72
+
73
+ ```json
74
+ {
75
+ "name": "gold_512_npy_bin4",
76
+ "source": "Arina 4D-STEM, Nano Titan, session 20260423, gold_004_master.h5",
77
+ "date": "2026-04-23",
78
+ "sample": "gold nanoparticles",
79
+ "shape": [512, 512, 48, 48],
80
+ "dtype": "uint16",
81
+ "permission": {
82
+ "received": true,
83
+ "from": ["Sangjoon Lee"],
84
+ "collectors": ["Sangjoon Lee"],
85
+ "date": "2026-04-23"
86
+ },
87
+ "sampling": [0.5, 0.5, 1.84, 1.84],
88
+ "units": ["A", "A", "mrad", "mrad"],
89
+ "voltage_kV": 300,
90
+ "semiangle_mrad": 30,
91
+ "camera_length_mm": 91
92
+ }
93
+ ```
94
+
95
+ `source` is microscope, facility, and original file. `date` is acquisition
96
+ day (`YYYY-MM-DD`). `permission.received` must be `true`. `from` is who granted the MIcan yT share (one name or several). `collectors` is who used the
97
+ instrument (one name or several). `permission.date` is when that share was
98
+ granted.
99
+
100
+ ```bash
101
+ python templates/check_meta.py ./gold-512-bin4
102
+ hf auth login
103
+ hf upload bobleesj/quantem-data ./gold-512-bin4 \
104
+ widget-tutorials/show4dstem/gold-512-bin4/full \
105
+ --repo-type dataset --create-pr
106
  ```
107
 
108
+ The last path is the folder on this repo. `./gold-512-bin4` is your local
109
+ folder (`data.npy` + `meta.json`). The hub path is
110
+ `widget-tutorials/<widget>/<name>/<size>/`. For a new ShowBragg set that
111
+ would be `widget-tutorials/showbragg/<name>/full`. Size is `small`,
112
+ `medium`, `large`, or `full`. Use `widget-tutorials/shared/` only when
113
+ more than one widget will read the same files.
114
 
115
+ `check_meta.py` must print `ok` or do not open the PR. Resume a stopped
116
+ upload with `--revision refs/pr/N` (do not pass `--create-pr` again).
117
+ Merge is on the
118
+ [Community tab](https://huggingface.co/datasets/bobleesj/quantem-data/discussions).
 
 
 
119
 
120
+ If a notebook should call `quantem.widget.datasets`, open a GitHub PR after
121
+ this one merges:
122
+ [Contribute tutorial data](https://github.com/electronmicroscopy/quantem.widget/blob/main/docs/tutorials/contribute_data.md).
123
 
124
+ Colab: [Show4DSTEM](https://colab.research.google.com/gist/bobleesj/54864ce5b2a6f0a4fd5ae1e5d5719b45/show4dstem_colab.ipynb)
125
+ · [Workshop v1](https://colab.research.google.com/gist/bobleesj/a05a90185c6cddbb331342cae6d7e9c1/berk_workshop_v1.ipynb)
 
 
126
 
127
  ## Acquisition parameters
128
 
129
+ The 20260423 drift session optics are confirmed via the session HAADF EMD.
130
+ 4D-STEM `scan_sampling` is an operator pattern from a sibling SSB session.
131
+
132
+
133
+ | dataset | voltage | probe | CL | scan | scan sampling | det pitch | mag |
134
+ | -------------------------------- | -------- | --------- | ------- | ----------- | -------------- | ------------ | ----------- |
135
+ | `haadf/gold_haadf_npy` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
136
+ | `4dstem/gold_512_npy_bin8` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 3.68 mrad/px | unknown |
137
+ | `4dstem/gold_512_npy_bin4` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 1.84 mrad/px | unknown |
138
+ | `4dstem/gold_512` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 0.46 mrad/px | unknown |
139
+ | `4dstem/gold_30mrad1.3mx04`…`09` | 300 kV | 30 mrad | 91 mm | smaller | (session yaml) | 0.46 mrad/px | 1.3 Mx |
140
+ | `haadf/gold_haadf.emd` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
141
 
 
 
 
 
 
 
 
 
142
 
143
  ✓ = confirmed via EMD/yaml. `(op)` = operator pattern, not file-certified.
144
 
145
  ## License
146
 
147
+ Files on this repo are published under **MIT**.
148
+
149
+ **You must have explicit written permission from the person who collected
150
+ the data before you open a pull request**, unless you collected the data
151
+ yourself. Put that receipt in `meta.json` (`permission.received`,
152
+ `permission.from`, `permission.collectors`, `permission.date`). If you
153
+ collected it yourself, set `from` and `collectors` to your name.
154
+
155
+ Do not open a pull request without that permission. `check_meta.py` must
156
+ print `ok`.
templates/check_meta.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Refuse a folder whose meta.json is missing required keys.
3
+
4
+ Required: name, source, date, sample, shape, dtype, permission
5
+ (permission.received, permission.from, permission.collectors,
6
+ permission.date). from and collectors are one or more names.
7
+ Optional: sampling, units, and optics keys.
8
+
9
+ Usage:
10
+ python check_meta.py /path/to/folder
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import json
16
+ import re
17
+ import sys
18
+ from pathlib import Path
19
+
20
+ REQUIRED = ("name", "source", "date", "sample", "shape", "dtype", "permission")
21
+ PERMISSION_REQUIRED = ("received", "from", "collectors", "date")
22
+ DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
23
+
24
+
25
+ def _name_list(value) -> list[str] | None:
26
+ """Accept one name or a list of names. Empty is missing."""
27
+
28
+ if isinstance(value, str) and value.strip():
29
+ return [value.strip()]
30
+ if isinstance(value, list) and value and all(isinstance(item, str) and item.strip() for item in value):
31
+ return [item.strip() for item in value]
32
+ return None
33
+
34
+
35
+ def check_meta(folder: Path) -> list[str]:
36
+ """Return a list of problems. Empty means the sidecar is complete."""
37
+
38
+ problems: list[str] = []
39
+ path = folder / "meta.json"
40
+ if not path.is_file():
41
+ return [f"missing {path}"]
42
+ try:
43
+ meta = json.loads(path.read_text())
44
+ except json.JSONDecodeError as exc:
45
+ return [f"{path} is not JSON: {exc}"]
46
+ if not isinstance(meta, dict):
47
+ return [f"{path} must be a JSON object"]
48
+ for key in REQUIRED:
49
+ value = meta.get(key)
50
+ if value in (None, "", []):
51
+ problems.append(f"missing {key}")
52
+ if "name" in meta and not isinstance(meta.get("name"), str):
53
+ problems.append("name must be a string")
54
+ if "source" in meta and not isinstance(meta.get("source"), str):
55
+ problems.append("source must be a string")
56
+ if "sample" in meta and not isinstance(meta.get("sample"), str):
57
+ problems.append("sample must be a string")
58
+ permission = meta.get("permission")
59
+ if permission not in (None, "", []):
60
+ if not isinstance(permission, dict):
61
+ problems.append("permission must be an object")
62
+ else:
63
+ for key in PERMISSION_REQUIRED:
64
+ value = permission.get(key)
65
+ if value in (None, "", []):
66
+ problems.append(f"missing permission.{key}")
67
+ if permission.get("received") is not True:
68
+ problems.append("permission.received must be true")
69
+ if permission.get("from") not in (None, "", []) and _name_list(permission.get("from")) is None:
70
+ problems.append("permission.from must be one name or a list of names")
71
+ if permission.get("collectors") not in (None, "", []) and _name_list(permission.get("collectors")) is None:
72
+ problems.append("permission.collectors must be one name or a list of names")
73
+ perm_date = permission.get("date")
74
+ if perm_date not in (None, "") and not (isinstance(perm_date, str) and DATE_RE.match(perm_date)):
75
+ problems.append("permission.date must be YYYY-MM-DD")
76
+ date = meta.get("date")
77
+ if date not in (None, "", []) and not (isinstance(date, str) and DATE_RE.match(date)):
78
+ problems.append("date must be YYYY-MM-DD")
79
+ shape = meta.get("shape")
80
+ if shape not in (None, "", []):
81
+ if not (
82
+ isinstance(shape, list)
83
+ and len(shape) >= 2
84
+ and all(isinstance(n, int) and not isinstance(n, bool) for n in shape)
85
+ ):
86
+ problems.append("shape must be a list of ints, length >= 2")
87
+ dtype = meta.get("dtype")
88
+ if dtype not in (None, "", []) and not isinstance(dtype, str):
89
+ problems.append("dtype must be a string")
90
+ sampling = meta.get("sampling")
91
+ if sampling not in (None, "", []):
92
+ if not (isinstance(sampling, list) and all(isinstance(n, (int, float)) and not isinstance(n, bool) for n in sampling)):
93
+ problems.append("sampling must be a list of numbers")
94
+ if isinstance(shape, list) and isinstance(sampling, list) and len(sampling) != len(shape):
95
+ problems.append("sampling length must match shape length")
96
+ units = meta.get("units")
97
+ if units not in (None, "", []):
98
+ if not (isinstance(units, list) and all(isinstance(u, str) for u in units)):
99
+ problems.append("units must be a list of strings")
100
+ if isinstance(shape, list) and isinstance(units, list) and len(units) != len(shape):
101
+ problems.append("units length must match shape length")
102
+ return problems
103
+
104
+
105
+ def main(argv: list[str]) -> int:
106
+ if len(argv) != 2:
107
+ print("usage: python check_meta.py /path/to/folder", file=sys.stderr)
108
+ return 2
109
+ folder = Path(argv[1])
110
+ if not folder.is_dir():
111
+ print(f"not a folder: {folder}", file=sys.stderr)
112
+ return 2
113
+ problems = check_meta(folder)
114
+ if problems:
115
+ print(f"{folder / 'meta.json'}:")
116
+ for item in problems:
117
+ print(f" {item}")
118
+ return 1
119
+ print(f"{folder / 'meta.json'}: ok ({', '.join(REQUIRED)})")
120
+ return 0
121
+
122
+
123
+ if __name__ == "__main__":
124
+ raise SystemExit(main(sys.argv))
templates/meta.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "gold_512_npy_bin4",
3
+ "source": "Arina 4D-STEM, Nano Titan, session 20260423, gold_004_master.h5",
4
+ "date": "2026-04-23",
5
+ "sample": "gold nanoparticles",
6
+ "shape": [512, 512, 48, 48],
7
+ "dtype": "uint16",
8
+ "permission": {
9
+ "received": true,
10
+ "from": ["Sangjoon Lee"],
11
+ "collectors": ["Sangjoon Lee"],
12
+ "date": "2026-04-23"
13
+ },
14
+ "sampling": [0.5, 0.5, 1.84, 1.84],
15
+ "units": ["A", "A", "mrad", "mrad"],
16
+ "voltage_kV": 300,
17
+ "semiangle_mrad": 30,
18
+ "camera_length_mm": 91
19
+ }
widget-tutorials/_test/dummy-8x8/small/data.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68fd641ce06cf36fdc5037567d8b360b806fcf08f8f3e6c36d521f036ba94c87
3
+ size 256
widget-tutorials/_test/dummy-8x8/small/meta.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "dummy-8x8",
3
+ "source": "synthetic test array, not instrument data",
4
+ "date": "2026-08-19",
5
+ "sample": "dummy uint16 ramp for PR-process test only",
6
+ "shape": [
7
+ 8,
8
+ 8
9
+ ],
10
+ "dtype": "uint16",
11
+ "permission": {
12
+ "received": true,
13
+ "from": [
14
+ "Sangjoon Lee"
15
+ ],
16
+ "collectors": [
17
+ "Sangjoon Lee"
18
+ ],
19
+ "date": "2026-08-19"
20
+ },
21
+ "sampling": [
22
+ 1.0,
23
+ 1.0
24
+ ],
25
+ "units": [
26
+ "px",
27
+ "px"
28
+ ]
29
+ }