Skip to main content

Ask DeepWiki Documentation Status Latest Version PyPI - Python Version Test Status Codecov License

ancpBIDS is a modular Python library for reading, querying, validating, and writing BIDS datasets. Its architecture is designed for extensibility and maintainability.

Key Features

  • BIDS Dataset Loading
    Load BIDS datasets of any size or complexity, with support for multiple BIDS schema versions.

  • Flexible Query Engine
    Query files, folders, and metadata using a powerful, Pythonic API. Supports entity-based, scope-based, and custom queries.

  • Validation
    Validate datasets against the BIDS specification and custom rules using a plugin-based validation system.

  • Writing and Derivatives
    Write and update BIDS datasets, including support for creating and saving BIDS derivatives.

  • Lazy Loading
    Efficiently handle large datasets with optional lazy loading, reducing memory usage and speeding up initial access.

  • Plugin Architecture
    Extend or customize core functionality (validation, file handling, schema, etc.) via a robust plugin system.

  • PyBIDS Compatibility Layer
    Drop-in compatibility for many pybids API calls, easing migration from or integration with existing codebases.

  • Synthetic and Real Data Support
    Works with both synthetic test datasets and real-world BIDS datasets.

  • CI/CD Ready
    Includes a comprehensive suite of automated and manual tests, with synthetic datasets for reproducibility.

  • Extensible and Versioned Schema
    Supports multiple BIDS schema versions and allows for easy extension as the BIDS standard evolves.

Architecture

  • Core Models:
    The core BIDS data model is implemented in ancpbids/model_base.py and versioned model files (e.g., model_v1_8_0.py). These define the schema and object graph for BIDS datasets.

  • Plugin System:
    The plugin mechanism (see ancpbids/plugin.py) allows for dynamic extension of core functionality. Plugins can hook into schema modification, dataset processing, file handling, writing, and validation.

  • Query Engine:
    The query logic is implemented in ancpbids/query.py, providing flexible access to dataset contents and metadata.

  • Compatibility Layer:
    ancpbids/pybids_compat.py provides compatibility with the pybids API for easier migration and integration.

  • Utilities:
    Helper functions and utilities are in ancpbids/utils.py.

  • Testing:
    The tests/ directory is organized into auto (CI-safe) and manual (non-deterministic or performance) tests, with synthetic datasets under tests/data/.

Plugin System

The plugin system is a core feature for extensibility:

  • Plugin Types:

    • SchemaPlugin: Modify or extend the BIDS schema.
    • DatasetPlugin: Operate on in-memory dataset graphs.
    • FileHandlerPlugin: Register custom file readers/writers.
    • WritingPlugin: Add files/folders during dataset writing.
    • ValidationPlugin: Add custom validation rules.
  • Registration and Discovery:
    Plugins are registered via register_plugin or discovered with load_plugins_by_package. They are prioritized by a ranking value.

  • Execution:
    At key points (e.g., dataset load, write, validate), the system retrieves and executes all relevant plugins using get_plugins.

  • How to Add a Plugin:

    1. Subclass the appropriate plugin base class from plugin.py.
    2. Implement the required execute method.
    3. Register your plugin using register_plugin or by placing it in a discoverable package.

Versioning and Schema Evolution

  • The codebase supports multiple BIDS schema versions, with separate model files for each version.
  • The schema is loaded dynamically based on the dataset version, allowing for forward compatibility.

Testing and CI

  • Unit Tests:
    Located in tests/auto/, these are run automatically in CI.
  • Manual/Performance Tests:
    Located in tests/manual/, these are for benchmarking or non-deterministic checks.
  • Synthetic Data:
    All tests use synthetic datasets in tests/data/ to ensure reproducibility.

Developer Guidelines

  • Extending the Model:
    Add new schema versions as new files in ancpbids/, following the pattern of existing model files.
  • Adding Plugins:
    Follow the plugin system described above.
  • Testing:
    Add new tests to tests/auto/ for CI-safe code, and to tests/manual/ for performance or integration tests.
  • Documentation:
    Update README.md and docstrings for any new features or changes.

Code Quality

  • The codebase uses type hints and docstrings for clarity.
  • Contributions should follow PEP8 and include tests and documentation.

Model Generation Utility

The script tools/generatemodel.py is provided to automate the generation of Python model classes from BIDS schema files. This utility ensures that the codebase can easily stay up-to-date with the latest BIDS schema versions.

Features:

  • Fetches the latest or a specified BIDS schema version directly from the official BIDS GitHub repository.
  • Downloads the schema and generates Python model files in the ancpbids/ directory (e.g., model_base.py, model_v<version>.py).
  • Supports custom ordering and enum generation for BIDS datatypes, modalities, suffixes, and entities.

Usage:

cd tools
python generatemodel.py [--schema-version <version>]
  • If --schema-version is omitted, the latest available schema version will be used.
  • The generated files will be saved in the ancpbids/ directory and the corresponding schema in the schema/ directory.

When to use:

  • When a new BIDS schema version is released and you want to update the models.
  • When making changes to the schema or model structure for development or testing.

Further Reading

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ancpbids-0.3.2.tar.gz (100.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ancpbids-0.3.2-py3-none-any.whl (93.8 kB view details)

Uploaded Python 3

File details

Details for the file ancpbids-0.3.2.tar.gz.

File metadata

  • Download URL: ancpbids-0.3.2.tar.gz
  • Upload date:
  • Size: 100.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ancpbids-0.3.2.tar.gz
Algorithm Hash digest
SHA256 ab83d8e797e38e4a47e4766056b529ee19d6c7201aaefbb75d8b904956f61e1a
MD5 3360632c2c85a39890486151c3625431
BLAKE2b-256 c6452e1aa90c521e5f0f1ea23747a5477b516db3c95996c5f7dd5c92575745fb

See more details on using hashes here.

File details

Details for the file ancpbids-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: ancpbids-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 93.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ancpbids-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d47e0fa007fd4aeddb749eb57dd9461674bc5f07f8a1631bae4a2a59a93d162
MD5 c5ddb4e0fc2b96f85776f430364e2d0c
BLAKE2b-256 13712b2cc44bbd9d3dc4b0fe4e303895a778fa126874083a1c21e0c7f416c6c2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

This release

0.3.2 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.22

2 files

0.0.21

2 files

0.0.20

2 files

0.0.19

2 files

0.0.18

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page