EM Data
This is a simple project for aggregating different Electron Microscopy files which are hosted over different sources. It uses pooch to download datasets and should be used as a way to host simple example datasets for method validation.
Data is stored in a file "User/em_database" but this can be also set to a custom location.
List of datasets https://cssfrancis.github.io/em_data/datasets.html
Installation
pip install em-database
Usage
Every dataset is a class under em_database.data. Calling download() fetches the
file to the data directory, verifies its checksum, and returns a path handle. Files
that are already present are not downloaded again.
import em_database.data as data
import hyperspy.api as hs
path = data.LayeredCuNb4DSTEM().download()
s = hs.load(path, lazy=True)
By default the download runs on a background thread so a notebook cell returns
immediately. The handle it returns is the file path, so you can hand it straight
to a loader as above — it only blocks at the moment the file is actually opened.
Call path.done() to check progress without blocking, or path.result() to wait
explicitly. Pass download(background=False) to block and get the path as a plain
string instead.
Settings
Configuration lives in a live, matplotlib-rcParams-style object,
em_database.settings, seeded at import from ~/.em_database/settings.yaml.
Change it in memory for an immediate effect, and persist it to remember the
choice across sessions:
import em_database
em_database.settings["data_dir"] = "/big/disk/em_data" # takes effect now
em_database.settings.save() # remember it next time
In Jupyter you can also edit them interactively — display(em_database.settings)
renders a panel to set (and save) the data directory directly.
The data directory defaults to ~/em_database. Convenience helpers wrap the
common case — set_data_dir persists by default:
em_database.get_data_dir() # current location
em_database.set_data_dir("/big/disk/em_data") # set + persist
em_database.set_data_dir("/scratch", persist=False) # one-off, in-memory only
em_database.reset_data_dir() # back to the default, forget the choice
No environment variable is needed. Only values you explicitly set are written to
the file, so the default is never frozen in — it keeps being obeyed even if it
changes. For a one-off override (e.g. CI) the legacy EM_DATABASE_DATA_DIR is
still honored, and EM_DATABASE_CONFIG relocates the settings file.
Shared, system-wide data
Datasets can be installed once for every user. download() and filepath()
look in the shared/system locations first, then your own data directory, and
only download (into your directory) if the file is nowhere to be found — so a
shared copy is reused instead of refetched. Shared locations come from the
EM_DATABASE_SHARED_DIR environment variable (an os.pathsep-separated list), a
shared_data_dirs list in your settings, or a system config file
(/etc/em_database/settings.yaml, or %PROGRAMDATA%\em_database\settings.yaml
on Windows).
Adding a dataset
Datasets are described by a YAML file in em_database/datasets/, one entry per file,
validated against em_database/datasets/json-schema.json. The class name is generated
from the top-level key:
MyDataset:
description: What the data is, how it was acquired and how it is calibrated.
source: https://zenodo.org/records/<record>/files
checksum: md5:<hash>
file: MyDataset.zspy
data_size: 1.2 GB
technique: 4D-STEM
license: CC-BY-4.0
Open an issue with the new dataset template, or add the YAML file directly.
Metadata
Release files for em-database 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| em_database-0.4.0.tar.gz | 56.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| em_database-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 128.9 kB
Release files / em_database-0.4.0.tar.gz
| Download URL | em_database-0.4.0.tar.gz |
|---|---|
| Size | 56.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2e9bbcc4616d410c830ef7eeee98e74bed9b7a52bb7938b75a9260d5b75de05
|
|
BLAKE2b-256 checksum How to use checksums |
5ff03fd841af0bd372de1dea9a5857d9bf0e332d80de9eade333520b735df326
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / em_database-0.4.0-py3-none-any.whl
| Download URL | em_database-0.4.0-py3-none-any.whl |
|---|---|
| Size | 72.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67d87e366a5bc73b6c20ac88e3abf75cf4121c3c1e1e28a89b21b41ace0e5f42
|
|
BLAKE2b-256 checksum How to use checksums |
8ddf95c9caa650f1fce3de8a8a916440c06fa00db1682bd6e5146335268da300
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|