File size: 8,926 Bytes
1727504 79d40fa 1727504 a3b9716 1727504 a3b9716 1727504 46a7877 1727504 46a7877 30d14c8 79d40fa 30d14c8 46a7877 7b9bb14 46a7877 7b9bb14 46a7877 183c224 46a7877 30d14c8 183c224 46a7877 b617ca2 183c224 46a7877 b617ca2 383faf3 46a7877 7c1c6ea 46a7877 7c1c6ea 46a7877 8baf809 7c1c6ea 8baf809 7c1c6ea 79d40fa 1727504 46a7877 183c224 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | ---
license: mit
tags:
- electron-microscopy
- 4D-STEM
- materials-science
- quantem
pretty_name: quantem-data
---
# quantem-data
**This page is in draft mode. We are still exploring the upload process
and the `meta.json` template.** Keys, the checker, and these instructions
will change as we try real pull requests. Use the current required keys
for new PRs, and expect the template to grow.
**This repo is currently used primarily by
[quantem.widget**](https://github.com/electronmicroscopy/quantem.widget)
(tutorial notebooks and `quantem.widget.datasets`). Other QuantEM packages
may use it later.
Public electron-microscopy data. MIT license. Downloads need no token.
This page is the upload and download protocol.
## Download
```python
from quantem.widget.datasets import show4dstem_gold
ds = show4dstem_gold(size="small")
```
Notebook: [Example Data](https://github.com/electronmicroscopy/quantem.widget/blob/main/docs/tutorials/download_data.ipynb).
## Add data (Hugging Face pull request)
Anyone with a Hugging Face account can add data. We follow a pull request
process. Do not use `quantem.widget.io.upload`.
Downloads need no token. Opening a pull request does. Create an account,
then a token at
[huggingface.co/settings/tokens](https://huggingface.co/settings/tokens).
Use a **Write** token (classic). A **Read** token can download; it cannot
open a PR. A fine-grained token also works if `--create-pr` is allowed on
a public dataset. You do not need collaborator access to this repo.
```bash
pip install huggingface_hub # skip if `hf` is already on PATH
hf auth login
```
Paste the token. The prompt hides it. When asked `Add token as git
credential? [y/N]`, answer `n`. `hf upload` reads
`~/.cache/huggingface/token`. You do not need a git credential helper.
Ignore any hint to run `git config --global credential.helper store`.
```bash
hf auth whoami
```
That should print your username. If you already logged in with a Read
token, run `hf auth login --force` and paste a Write token. If
`--create-pr` returns 403 after a valid login, the token is Read or the
fine-grained scopes omit Community PRs; make a Write token and login
again. On SSH (no browser on that machine), paste a token. Do not use the
browser login unless the browser and `hf` run on the same machine. Do not
commit the token.
A PR is the data file(s) plus one `meta.json`. Example already on the hub
(2 files):
```text
widget-tutorials/show4dstem/gold-512-bin4/full/data.npy
widget-tutorials/show4dstem/gold-512-bin4/full/meta.json
```
One EMD: `gold_haadf.emd` + `meta.json` (2 files). A session folder: the
`.emd` files + `meta.json`.
Copy this `meta.json`. Required: `name`, `source`, `date`, `sample`,
`shape`, `dtype`, `permission`. Optional: `sampling`, `units`, optics.
Omit a key if unknown. Do not invent a number.
`shape` is `[row, col]` for an image, `[frame, row, col]` for a stack, or
`[scan_row, scan_col, det_row, det_col]` for 4D-STEM. `dtype` is the NumPy
name of the stored array (or of the EMD image). Examples already on this
repo:
| Data | `shape` | `dtype` |
| ------------------------- | -------------------- | -------- |
| 2D HAADF (`gold-haadf`) | `[4096, 4096]` | `uint16` |
| 4D-STEM (`gold-512-bin4`) | `[512, 512, 48, 48]` | `uint16` |
| One EMD HAADF | `[4096, 4096]` | `uint16` |
Processed float data uses `"float32"`. Read both values from the file
(`arr.shape`, `arr.dtype`, or the EMD image) and copy them into
`meta.json`.
```json
{
"name": "gold_512_npy_bin4",
"source": "Arina 4D-STEM, Nano Titan, session 20260423, gold_004_master.h5",
"date": "2026-04-23",
"sample": "gold nanoparticles",
"shape": [512, 512, 48, 48],
"dtype": "uint16",
"permission": {
"received": true,
"from": ["Sangjoon Lee"],
"collectors": ["Sangjoon Lee"],
"date": "2026-04-23"
},
"sampling": [0.5, 0.5, 1.84, 1.84],
"units": ["A", "A", "mrad", "mrad"],
"voltage_kV": 300,
"semiangle_mrad": 30,
"camera_length_mm": 91
}
```
`source` is microscope, facility, and original file. `date` is acquisition
day (`YYYY-MM-DD`). `permission.received` must be `true`. `from` is who granted the share (one name or several). `collectors` is who
used the instrument (one name or several). `permission.date` is when that
share was granted.
```bash
python -m check_meta ./gold-512-bin4
hf upload bobleesj/quantem-data ./gold-512-bin4 \
widget-tutorials/show4dstem/gold-512-bin4/full \
--repo-type dataset --create-pr
```
Run `python -m check_meta` from a checkout of this dataset so the
`check_meta/` package is importable. `./gold-512-bin4` is your local
folder (`data.npy` + `meta.json`). The last `hf upload` path is the
folder on this repo. The hub path is
`widget-tutorials/<widget>/<name>/<size>/`. For a new ShowBragg set that
would be `widget-tutorials/showbragg/<name>/full`. Size is `small`,
`medium`, `large`, or `full`. Use `widget-tutorials/shared/` only when
more than one widget will read the same files.
`python -m check_meta` must print `ok` or do not open the PR. Resume a stopped
upload with `--revision refs/pr/N` (do not pass `--create-pr` again).
Merge is on the
[Community tab](https://huggingface.co/datasets/bobleesj/quantem-data/discussions).
### Coding agents
A coding agent can open the Community pull request. The human creates the
Write token and attests permission. The agent does not invent
`permission.*`, `sampling`, or optics. The agent does not run
`hf auth login` (that prompt is interactive). The agent does not write the
token into a repository file.
```bash
# human already ran `hf auth login` or exported HF_TOKEN (Write)
hf auth whoami
hf download bobleesj/quantem-data --repo-type dataset \
--include "check_meta/**" --include "templates/meta.json" \
--local-dir ./quantem-data-tools
export PYTHONPATH="$PWD/quantem-data-tools${PYTHONPATH:+:$PYTHONPATH}"
python -m check_meta ./gold-512-bin4
hf upload bobleesj/quantem-data ./gold-512-bin4 \
widget-tutorials/show4dstem/gold-512-bin4/full \
--repo-type dataset --create-pr \
--commit-message "add show4dstem gold-512-bin4 full tutorial data"
```
`hf auth whoami` must print a username. If it fails or `--create-pr`
returns 403, stop and ask the human for a Write token (`export HF_TOKEN=...`).
If `python -m check_meta` is not `ok`, stop. After the upload, give the
human the Community URL. Do not merge.
Copyable widget prompt:
[Add tutorial data](https://github.com/electronmicroscopy/quantem.widget/blob/main/docs/agent-prompts.md#add-tutorial-data-hugging-face-pull-request).
If a notebook should call `quantem.widget.datasets`, open a GitHub PR after
this one merges:
[Contribute tutorial data](https://github.com/electronmicroscopy/quantem.widget/blob/main/docs/tutorials/contribute_data.md).
Colab: [Show4DSTEM](https://colab.research.google.com/gist/bobleesj/54864ce5b2a6f0a4fd5ae1e5d5719b45/show4dstem_colab.ipynb)
· [Workshop v1](https://colab.research.google.com/gist/bobleesj/a05a90185c6cddbb331342cae6d7e9c1/berk_workshop_v1.ipynb)
## Acquisition parameters
The 20260423 drift session optics are confirmed via the session HAADF EMD.
4D-STEM `scan_sampling` is an operator pattern from a sibling SSB session.
| dataset | voltage | probe | CL | scan | scan sampling | det pitch | mag |
| -------------------------------- | -------- | --------- | ------- | ----------- | -------------- | ------------ | ----------- |
| `haadf/gold_haadf_npy` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
| `4dstem/gold_512_npy_bin8` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 3.68 mrad/px | unknown |
| `4dstem/gold_512_npy_bin4` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 1.84 mrad/px | unknown |
| `4dstem/gold_512` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 512² | 0.5 Å (op) | 0.46 mrad/px | unknown |
| `4dstem/gold_30mrad1.3mx04`…`09` | 300 kV | 30 mrad | 91 mm | smaller | (session yaml) | 0.46 mrad/px | 1.3 Mx |
| `haadf/gold_haadf.emd` | 300 kV ✓ | 30 mrad ✓ | 91 mm ✓ | 4096² image | 0.0186 nm/px | n/a | FOV 76.2 nm |
✓ = confirmed via EMD/yaml. `(op)` = operator pattern, not file-certified.
## License
Files on this repo are published under **MIT**.
**You must have explicit written permission from the person who collected
the data before you open a pull request**, unless you collected the data
yourself. Put that receipt in `meta.json` (`permission.received`,
`permission.from`, `permission.collectors`, `permission.date`). If you
collected it yourself, set `from` and `collectors` to your name.
Do not open a pull request without that permission. `python -m check_meta`
must print `ok`. |