Repository navigation
Populate per-asset dataStandard for BIDS, HED, NWB, and extensions #1811
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
base: master
Are you sure you want to change the base?
Changes from all commits
c1d1287
2c27226
8f75858
7cc351b
c9203dd
b7f73b8
e614733
b0440cf
7da23f4
d05dcca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ venv/ | |
| venvs/ | ||
| .DS_Store | ||
| .duct | ||
| uv.lock | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..upload import ZarrMode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dandischema.models import BareAsset, DigestType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dandischema.models import BareAsset, DigestType, StandardsType, ome_ngff_standard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic import BaseModel, ConfigDict, ValidationError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from zarr_checksum.tree import ZarrChecksumTree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -55,7 +55,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pre_upload_size_check, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .bases import LocalDirectoryAsset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .bases import LocalDirectoryAsset, _add_data_standard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Cyclic import Note
Import of module
dandi.files.bases Error loading related location Loading
Copilot AutofixAI about 12 hours ago To break the cycle without changing functionality, the best fix is to defer the import from In this file (
A robust cycle-breaking pattern is:
This preserves behavior while avoiding import-time cycles.
Suggested changeset
1
dandi/files/zarr.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
Check noticeCode scanning / CodeQL Unused import Note
Import of 'LocalDirectoryAsset' is not used.
Copilot AutofixAI about 12 hours ago Remove the unused symbol from the import statement in Best fix:
This preserves existing functionality and keeps only the actually used import.
Suggested changeset
1
dandi/files/zarr.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from ..validate._types import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ORIGIN_VALIDATION_DANDI_ZARR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MissingFileContent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -466,6 +466,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metadata = get_default_metadata(self.filepath, digest=digest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metadata.encodingFormat = ZARR_MIME_TYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metadata.path = self.path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.path.endswith(".ome.zarr"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _add_data_standard(metadata, StandardsType(**ome_ngff_standard)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_validation_errors( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import h5py | ||
| import hdmf | ||
| import numpy as np | ||
| from packaging.version import InvalidVersion, Version | ||
| import pynwb | ||
| from pynwb import NWBHDF5IO | ||
| from pynwb.base import ExternalImage | ||
|
|
@@ -153,6 +154,53 @@ def _sanitize(v: Any) -> str: | |
| return None | ||
|
|
||
|
|
||
| # Namespaces bundled with NWB/HDMF core — not extensions | ||
| _NWB_CORE_NAMESPACES = frozenset({"core", "hdmf-common", "hdmf-experimental"}) | ||
|
|
||
|
|
||
| def get_nwb_extensions(filepath: str | Path | Readable) -> dict[str, str]: | ||
| """Return NWB extensions embedded in an HDF5 file. | ||
|
|
||
| Reads the ``specifications`` group of an NWB HDF5 file and returns a | ||
| mapping of extension namespace names to their latest embedded version, | ||
| excluding core NWB/HDMF namespaces. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| filepath | ||
| Path to an NWB ``.nwb`` HDF5 file, or a :class:`Readable`. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict[str, str] | ||
| ``{namespace_name: latest_version}`` for each non-core namespace | ||
| found in the file's ``specifications`` group. Empty dict if no | ||
| extensions are present or the group does not exist. | ||
| """ | ||
| extensions: dict[str, str] = {} | ||
| with open_readable(filepath) as fp, h5py.File(fp, "r") as h5file: | ||
| specs = h5file.get("specifications") | ||
| if specs is None: | ||
| return extensions | ||
| for name in specs: | ||
| if name in _NWB_CORE_NAMESPACES: | ||
| continue | ||
| ns_group = specs[name] | ||
| if not isinstance(ns_group, h5py.Group) or not (versions := list(ns_group)): | ||
| continue | ||
| try: | ||
| extensions[name] = max(versions, key=Version) | ||
| except InvalidVersion: | ||
| lgr.debug( | ||
| "Cannot parse versions %s of NWB extension %s, taking the " | ||
| "lexicographically last", | ||
| versions, | ||
| name, | ||
| ) | ||
| extensions[name] = max(versions) | ||
| return extensions | ||
|
|
||
|
|
||
| def get_neurodata_types_to_modalities_map() -> dict[str, str]: | ||
| """Return a dict to map neurodata types known to pynwb to "modalities" | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.