quantem-data / README.md
bobleesj's picture
docs: make data PR prompt self-contained
421d286 verified
|
Raw
History Blame
11.1 kB
metadata
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 (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

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.

Replace every placeholder in this example:

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

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.

Copy this prompt into your coding agent. Replace every placeholder before submitting it. Do not paste a Hugging Face token into the prompt.

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.

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.