File size: 11,057 Bytes
1727504 79d40fa 1727504 a3b9716 1727504 a3b9716 1727504 dae4fc4 8eb365e dae4fc4 8eb365e 30d14c8 79d40fa 30d14c8 8eb365e 30d14c8 8eb365e b617ca2 8eb365e b617ca2 8eb365e 7c1c6ea 8eb365e ab12b62 8eb365e ab12b62 8eb365e ab12b62 8eb365e ab12b62 8eb365e ab12b62 421d286 ab12b62 8eb365e 7c1c6ea 8eb365e 8baf809 7c1c6ea 8baf809 7c1c6ea 79d40fa 1727504 8eb365e ab12b62 | 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | ---
license: mit
tags:
- electron-microscopy
- 4D-STEM
- materials-science
- quantem
pretty_name: quantem-data
---
# quantem-data
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. Keys, the checker, and these instructions can grow as
we take more Community pull requests. Use the current required keys for
new PRs.
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`.
Replace every placeholder in this example:
```json
{
"name": "<public dataset name>",
"source": "<public-facing microscope, facility, and acquisition description>",
"date": "<YYYY-MM-DD>",
"sample": "<sample description>",
"shape": [512, 512, 48, 48],
"dtype": "uint16",
"permission": {
"received": true,
"from": ["<person who granted permission>"],
"collectors": ["<data collector>"],
"date": "<YYYY-MM-DD>"
},
"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 a public-facing microscope, facility, and acquisition description;
omit local paths and non-public filenames. `date` is the 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.
Copy this prompt into your coding agent. Replace every placeholder before
submitting it. Do not paste a Hugging Face token into the prompt.
```text
Add these files to the public Hugging Face dataset bobleesj/quantem-data
as a Community pull request.
Local folder:
<path to a folder that already contains the data files and will get meta.json>
Target hub path:
widget-tutorials/<widget-or-shared>/<name>/<size>/
Permission (required; do not invent):
- I collected this data myself: <yes/no>
- permission.from: <name or list>
- permission.collectors: <name or list>
- permission.date: <YYYY-MM-DD>
- I have written permission from the collector: <yes, or "I collected it">
Follow the current Add data and Coding agents instructions on this dataset
card. Do not use quantem.widget.io.upload. Do not commit .npy or .emd into
electronmicroscopy/quantem.widget.
1. Confirm `hf auth whoami` prints a username. If it fails, stop and ask me
to create a Write token and run `hf auth login`, or export `HF_TOKEN`.
Do not run an interactive login yourself or write the token into a repo.
2. Download the checker and template, then copy the template into the folder:
hf download bobleesj/quantem-data --repo-type dataset \
--include "check_meta/**" --include "templates/meta.json" \
--local-dir ./quantem-data-tools
cp ./quantem-data-tools/templates/meta.json <folder>/meta.json
3. Fill every required field in `<folder>/meta.json` from the files and the
permission lines above. Read shape and dtype from the array or EMD. Omit
optional values when unknown; do not invent them. Do not put a local path
or credential in `meta.json`. Validate it:
export PYTHONPATH="$PWD/quantem-data-tools${PYTHONPATH:+:$PYTHONPATH}"
python -m check_meta <folder>
Stop unless validation prints `ok`.
4. Open the Community pull request:
hf upload bobleesj/quantem-data <folder> \
widget-tutorials/<widget-or-shared>/<name>/<size>/ \
--repo-type dataset --create-pr \
--commit-message "add <widget> <name> <size> tutorial data"
5. Give me the Community URL. Do not merge. Open a GitHub PR only if a named
loader is also needed in `quantem.widget.datasets`; that PR waits until
this Hugging Face PR merges. A new widget is discuss-first.
```
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`.
|