Repository navigation
Format-metadata framework: vocabulary, formats and conversions (without wiring) #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
balbasty
wants to merge
18
commits into
claude/chore/233-metadata-stack-base
Choose a base branch
from
claude/feat/233-metadata-system
base: claude/chore/233-metadata-stack-base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2ee635a
Feat(datamodel): the format-agnostic Metadata and its vocabulary (#233)
claude 9a6c41e
Feat(io): file-based metadata, the BIDS sidecar and per-format metada…
claude ffbe850
Docs(metadata): the format author's guide and the API pages (#233)
claude 90c82a4
Feat(metadata): export the vocabulary groups (#233)
claude 3c4238e
Refactor(metadata): build the repr of Metadata with bagof's field pol…
claude 510a2dd
Refactor(metadata): no input or output on Metadata (#233)
claude 8e254fb
Refactor(metadata): the conversion and the record checks are module f…
claude de4421b
Feat(metadata): directions in a CoordinateSystem, mapped by a Transfo…
claude 3253d81
Fix(metadata): round the scaled values only into an integer type (#233)
claude 2f9493d
Refactor(io): the metadata parser only reads; the HDF5 one is an Hdf5…
claude 30fa2dc
Refactor(metadata): import at the top, except across a cycle (#233)
claude 170af7d
Style(metadata): public code first, then public helpers, then private…
claude 41ceecc
Feat(metadata): operation objects drive the propagation to derived im…
claude 8c3e387
Docs(metadata): the operation objects in the format guide and the mem…
claude 2b6e1cb
Style(metadata): the class of a format hides `format` from its repr (…
claude 0f25da0
Merge the stack base (origin/main with #311) into the metadata system
claude f1c1c56
Refactor(metadata): drop the `from_bytes` override of the metadata pa…
claude 2390b07
Fix(metadata): `Resampled.geometry` is optional (#233)
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Metadata for format authors | ||
|
|
||
| The public names of [`brainhops.datamodel.metadata`](metadata.md) are | ||
| those a user of the library needs, and the vocabulary groups that a | ||
| format names in `supports=`. The names below are for whoever adds | ||
| the metadata of a file format; the | ||
| [format author's guide](../../dev/metadata-formats.md) explains how they | ||
| fit together. They are imported from the private modules that define | ||
| them. | ||
|
|
||
| # ::: brainhops.datamodel.metadata._vocabulary | ||
| # ::: brainhops.datamodel.metadata._operations | ||
| # ::: brainhops.datamodel.metadata._field | ||
| # ::: brainhops.datamodel.metadata._report | ||
| # ::: brainhops.datamodel.metadata._dtype | ||
| # ::: brainhops.datamodel.metadata._sentinel | ||
| # ::: brainhops.io.base._metadata_parser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # ::: brainhops.datamodel.metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # ::: brainhops.io.metadata._base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # ::: brainhops.io.metadata.bids |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # ::: brainhops.io.metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| # ::: brainhops.io.transformations.itk.h5 | ||
|
|
||
| # ::: brainhops.io.transformations.itk._metadata |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """ | ||
| Non-spatial metadata, shared across file formats. | ||
|
|
||
| Every file format keeps descriptive metadata, such as a description, a | ||
| repetition time, a slice timing or a provenance, under its own names | ||
| and types. This package gives that metadata one representation, in a | ||
| class hierarchy that mirrors the hierarchy of the images (`Image`, | ||
| `FileBasedImage`, `NiftiImage`): | ||
|
|
||
| - [`Metadata`][brainhops.datamodel.metadata.Metadata] holds the common | ||
| vocabulary, one field per concept, named after its BIDS key in snake | ||
| case and stored in BIDS units, plus `extra`, a free-form store of | ||
| string keys. In-memory images and transformations carry it, and | ||
| formats convert through it. | ||
| - [`FileBasedMetadata`][brainhops.io.metadata.FileBasedMetadata], which | ||
| lives in `brainhops.io.metadata` as `FileBasedImage` lives in | ||
| `brainhops.io.images`, is the base of the metadata of a file format, | ||
| which reads its fields from the raw record of the format (a `nibabel` | ||
| header, the attributes of a Zarr array, ...) and writes them back. | ||
| - Each format has its own `<Fmt>Metadata` class, next to its parser | ||
| under `brainhops.io`. `FileBasedMetadata.load(path)` reads the | ||
| metadata of a file without its data, and `brainhops.io.metadata.bids` | ||
| reads and writes BIDS sidecars. The data model does no input or | ||
| output. | ||
|
|
||
| A vocabulary field holds a value, `None` when the value is unknown, or | ||
| [`UNSUPPORTED`][brainhops.datamodel.metadata.UNSUPPORTED] when the format | ||
| has no slot for the field. Converting into a format, with | ||
| `metadata.to(NiftiMetadata)`, records what the format cannot hold in a | ||
| [`ConversionReport`][brainhops.datamodel.metadata.ConversionReport], and | ||
| the loss policy (`"ignore"`, `"warn"` or `"raise"`, see | ||
| [`metadata_loss_policy`][brainhops.datamodel.metadata.metadata_loss_policy]) | ||
| decides what happens to the report. A | ||
| [`Scope`][brainhops.datamodel.metadata.Scope] says how each field | ||
| propagates to a derived image, through the | ||
| [`Operation`][brainhops.datamodel.metadata.Operation] an image operation | ||
| describes (an [`Indexed`][brainhops.datamodel.metadata.Indexed] image or | ||
| a [`Resampled`][brainhops.datamodel.metadata.Resampled] one). | ||
|
|
||
| The names exported here are those a user of the library needs, and the | ||
| vocabulary groups (`ProvenanceVocabulary`, `MRIVocabulary`, ..., and | ||
| their base `Vocabulary`), which a format names in its `supports=` | ||
| declaration. What else a format author needs (the field annotations, | ||
| the `metadata` field of images, the loss helpers) is imported from the | ||
| private modules of this package, which the format author's guide lists | ||
| (`docs/dev/metadata-formats.md`). The user guide is | ||
| `docs/start/metadata.md`. | ||
| """ | ||
|
|
||
| __all__ = [ | ||
| "Metadata", | ||
| "UNSUPPORTED", | ||
| "Scope", | ||
| "Operation", | ||
| "Indexed", | ||
| "Resampled", | ||
| "GeneratedBy", | ||
| "Channel", | ||
| "EncodingDirection", | ||
| "ConversionReport", | ||
| "MetadataLossWarning", | ||
| "MetadataLossError", | ||
| "metadata_loss_policy", | ||
| "Vocabulary", | ||
| "ProvenanceVocabulary", | ||
| "MRIVocabulary", | ||
| "DiffusionVocabulary", | ||
| "DisplayVocabulary", | ||
| "StorageVocabulary", | ||
| "MicroscopyVocabulary", | ||
| "TransformVocabulary", | ||
| ] | ||
|
|
||
| from ._base import Metadata | ||
| from ._operations import Indexed, Operation, Resampled | ||
| from ._report import ( | ||
| ConversionReport, | ||
| MetadataLossError, | ||
| MetadataLossWarning, | ||
| metadata_loss_policy, | ||
| ) | ||
| from ._sentinel import UNSUPPORTED | ||
| from ._terms import Channel, EncodingDirection, GeneratedBy | ||
| from ._vocabulary import ( | ||
| DiffusionVocabulary, | ||
| DisplayVocabulary, | ||
| MicroscopyVocabulary, | ||
| MRIVocabulary, | ||
| ProvenanceVocabulary, | ||
| Scope, | ||
| StorageVocabulary, | ||
| TransformVocabulary, | ||
| Vocabulary, | ||
| ) | ||
|
|
||
| # The public names keep the `__module__` of the private module that | ||
| # defines them: rewriting it to this package's name would break | ||
| # `inspect.getsource`, IPython's `??` and doctest discovery, which look | ||
| # the source up through `__module__`. Pickles name the private module, | ||
| # and load as well. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.