Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
Expand Down
69 changes: 65 additions & 4 deletions heudiconv/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BIDSError(Exception):
pass


BIDS_VERSION = "1.8.0"
BIDS_VERSION = "1.10.1"

# List defining allowed parameter matching for fmap assignment:
SHIM_KEY = "ShimSetting"
Expand Down Expand Up @@ -1067,17 +1067,33 @@ def populate_intended_for(


class BIDSFile:
"""as defined in https://bids-specification.readthedocs.io/en/stable/99-appendices/04-entity-table.html
which might soon become machine readable
order matters
"""Representation of a BIDS file with order of entities following BIDS

Full ordered list from
http://github.com/bids-standard/bids-specification/blob/HEAD/src/schema/rules/entities.yaml
while taking shortened versions from
https://github.com/bids-standard/bids-specification/blob/master/src/schema/objects/entities.yaml

Use

python -c 'from heudiconv.bids import BIDSFile; BIDSFile._print_entities()'

to print the current list of entities to plug in below.
"""

# For release 1.10.1
_known_entities = [
"sub",
"ses",
"sample",
"task",
"tracksys",
"acq",
"nuc",
"voi",
"ce",
"trc",
"stain",
"rec",
"dir",
"run",
Expand All @@ -1087,9 +1103,54 @@ class BIDSFile:
"inv",
"mt",
"part",
"proc",
"hemi",
"space",
"split",
"recording",
"chunk",
"seg",
"res",
"den",
"label",
"desc",
]

@staticmethod
def _get_entities(version: str = BIDS_VERSION) -> list[str]:
"""Load BIDS entity rules and print entity names to plug above."""

import json
from urllib.request import Request, urlopen

is_released = version and version[0].isdigit()
version_url = f"v{version}" if is_released else version

schema_url = (
f"https://bids-specification.readthedocs.io/en/{version_url}/schema.json"
)
headers = {
"User-Agent": "heudiconv/{__version__}",
}
with urlopen(Request(schema_url, headers=headers)) as response:
schema = json.loads(response.read().decode())

return [
schema["objects"]["entities"][key]["name"]
for key in schema["rules"]["entities"]
]

@staticmethod
def _print_entities(version: str = BIDS_VERSION) -> None:
# Print the name for each entity
is_released = version and version[0].isdigit()
if is_released:
print(f" # For release {version}")
print(" _known_entities = [")
for ent in BIDSFile._get_entities(version=version):
print(f' "{ent}",')
print(" ]")

def __init__(
self, entities: dict[str, str], suffix: str, extension: Optional[str]
) -> None:
Expand Down
4 changes: 4 additions & 0 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@ def rename_files() -> None:
# If we have failed to modify this_prefix_basename, because it didn't fall
# into any of the options above, just add the suffix at the end:
if this_prefix_basename == prefix_basename:
# TODO: never hit by tests! So what are the suffixes for?!
import pdb

pdb.set_trace()
this_prefix_basename += suffix

# Finally, form the outname by stitching the directory and outtype:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exclude = .*/,build/,dist/,test/data,venv/
hang-closing = False
unused-arguments-ignore-stub-functions = True
select = A,B,B902,C,E,E242,F,U100,W
ignore = A003,B005,E203,E262,E266,E501,W503
ignore = A003,A005,B005,E203,E262,E266,E501,W503

[isort]
atomic = True
Expand Down