quantem-data / README.md
bobleesj's picture
docs: add coding-agent Community PR steps
383faf3 verified
|
Raw
History Blame
8.93 kB
metadata
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** (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

from quantem.widget.datasets import show4dstem_gold

ds = show4dstem_gold(size="small")

Notebook: Example Data.

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. 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.

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.

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):

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.

{
  "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.

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.

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.

# 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.

If a notebook should call quantem.widget.datasets, open a GitHub PR after this one merges: Contribute tutorial data.

Colab: Show4DSTEM · Workshop v1

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.3mx0409 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.