Skip to content
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

Update master to 3.2.0 #314

Merged
merged 48 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
aee3749
update entities and auto entities validation
arnaudbore Jun 13, 2024
c833933
Add docker, fix subprocess and update to bids 1.9.0
arnaudbore Jun 17, 2024
4532d44
fix typos and pep8
arnaudbore Jun 17, 2024
9ae71ff
add a way to show error or warning during dcm2niix execution
arnaudbore Jun 18, 2024
83ede5a
fix error message and remove pydeface from default conda env
arnaudbore Jun 18, 2024
d103f68
answer Sam comments
arnaudbore Jun 27, 2024
53f39f5
first_working_version
arnaudbore Jun 27, 2024
cfbd3a4
fix typo
arnaudbore Jun 27, 2024
b66bf98
working version
arnaudbore Jun 27, 2024
dfb87fc
Add a more useful message when entities have not been found
arnaudbore Jul 2, 2024
d7e2edb
typo
arnaudbore Jul 2, 2024
95f1327
Merge pull request #301 from UNFmontreal/update_to_bids_1.9
SamGuay Jul 4, 2024
fa01aba
Update dcm2bids/cli/dcm2bids.py
arnaudbore Jul 4, 2024
3902f89
add tests for no reorder entities
arnaudbore Jul 4, 2024
892f8aa
Merge branch 'allow_disable_reorder' of github.com:UNFmontreal/Dcm2Bi…
arnaudbore Jul 4, 2024
66c62cd
fix reorder and do not accept it with auto_extract_entities
arnaudbore Jul 17, 2024
6fc1fdf
Merge pull request #303 from UNFmontreal/allow_disable_reorder
SamGuay Jul 17, 2024
ab4e0cc
Merge branch 'master' into allow_user_to_use_old_way_intendedFor
arnaudbore Jul 17, 2024
260aea5
merge dev and add tests
arnaudbore Jul 17, 2024
5a00d3f
add data test
arnaudbore Jul 17, 2024
e1bd13c
Merge pull request #306 from UNFmontreal/master
arnaudbore Jul 17, 2024
989b185
Merge pull request #304 from UNFmontreal/allow_user_to_use_old_way_in…
SamGuay Jul 17, 2024
1d74109
Update GHA to use setup-python@v5 instead of v1 (#309)
SamGuay Jul 18, 2024
cd163b3
add --do_not_reorder_entities doc
SamGuay Jul 24, 2024
3a3bf7f
add bids_uri doc
SamGuay Jul 24, 2024
e9da2c5
fix gha + order main commands
SamGuay Jul 24, 2024
e723e1b
add readme me doc
SamGuay Jul 24, 2024
eeb7d61
add do_not_reorder to advance comm
SamGuay Jul 24, 2024
9cf58f9
up py3.7 to 3.8
SamGuay Jul 24, 2024
41fdaab
long due update for changelog
SamGuay Jul 24, 2024
3ab67f0
fix log and output folder for dcm2bids_helper (#312)
arnaudbore Jul 24, 2024
027d5fb
add container doc
SamGuay Jul 24, 2024
5f7aee6
bump version
SamGuay Jul 24, 2024
89445ca
update container with links
arnaudbore Jul 25, 2024
d8f3482
fix typo
arnaudbore Jul 25, 2024
8f6d1bf
Update docs/how-to/container.md
arnaudbore Jul 25, 2024
d656c17
Update docs/how-to/container.md
arnaudbore Jul 25, 2024
88383c2
fix check folder (#313)
arnaudbore Jul 25, 2024
27dd27e
Update docs/how-to/create-config-file.md
arnaudbore Jul 25, 2024
5e645fd
Apply suggestions from code review
SamGuay Jul 26, 2024
0a30af6
Update docs/get-started/install.md
SamGuay Jul 26, 2024
17e8205
Apply ${VERSION} everywhere for consistency
SamGuay Jul 26, 2024
74f749b
add missing -e --containall
SamGuay Jul 26, 2024
e4b7123
add export version to containers
SamGuay Jul 26, 2024
fbb7384
Merge pull request #311 from UNFmontreal/doc_new-features
arnaudbore Jul 26, 2024
ce10d47
Update publish_doc.yaml
arnaudbore Jul 26, 2024
449bfb1
Update publish_doc.yaml
arnaudbore Jul 26, 2024
58f3c72
Update publish_doc.yaml
arnaudbore Jul 26, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Codespell

on:
push:
branches: [master]
branches: [master, dev]
pull_request:
branches: [master]
branches: [master, dev]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.11
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/make_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Check-out repository
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11' # Version range or exact version of a Python version to use, using SemVer's version range syntax
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
Expand Down Expand Up @@ -95,4 +95,4 @@ jobs:
files: |
download/artifact/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/publish_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- master
- dev
tags:
- '[0-9]+.[0-9]+.[0-9]+'
release:
Expand All @@ -22,7 +23,7 @@ jobs:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down Expand Up @@ -50,6 +51,7 @@ jobs:
dcm2bids -h > docs_helper/help.txt
dcm2bids_helper -h > docs_helper/helper.txt
dcm2bids_scaffold -h > docs_helper/help_scaffold.txt
echo "export VERSION=$(dcm2bids -v | awk '/dcm2bids/ {print $3}')" > docs_helper/version.txt

- name: Set git credentials
run: |
Expand All @@ -76,8 +78,9 @@ jobs:
mike deploy -p ${{ github.ref_name }}

- name: Deploy dev version
if: ${{ github.ref == 'refs/heads/master' }}
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
VERSION=$(dcm2bids -v | awk '/dcm2bids/ {print $3}')
echo "Version: $VERSION"
mike deploy -p $VERSION dev -u
echo "Version: ${VERSION}-dev"
mike delete dev
mike deploy -p dev
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ tests/data/*
docs_helper/help.txt
docs_helper/help_scaffold.txt
docs_helper/helper.txt
docs_helper/version.txt
200 changes: 200 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Conda image for installing FSL tools
FROM continuumio/miniconda3 AS build

# Install FSL tools with conda
COPY environment.yml /tmp/environment.yml
RUN conda env create -f /tmp/environment.yml

# Install and use conda-pack
RUN conda install -c conda-forge conda-pack
RUN conda-pack -n fsl -o /tmp/env.tar && \
mkdir /venv && cd /venv && tar xf /tmp/env.tar && \
rm /tmp/env.tar
RUN /venv/bin/conda-unpack

# Runtime image for executing FSL tools
FROM debian:stable AS runtime

# Copy the conda env from previous stage
COPY --from=build /venv /venv

# Point to conda executables
ENV PATH="/venv/bin:$PATH"

# Set FSL variables
ENV FSLDIR="/venv"
ENV FSLCONFDIR="${FSLDIR}/config"
ENV FSLOUTPUTTYPE="NIFTI"
ENV FSLMULTIFILEQUIT="TRUE"
ENV FSLTCLSH="${FSLDIR}/bin/fsltclsh"
ENV FSLWISH="${FSLDIR}/bin/fslwish"
ENV FSLGECUDAQ="cuda.q"

# Update and install some utils
RUN apt-get -y update && apt-get -y install dc wget npm unzip

# Fetch data
RUN wget -P ${FSLDIR}/data https://git.fmrib.ox.ac.uk/fsl/data_standard/-/raw/master/MNI152_T1_1mm_brain.nii.gz

# Install bids-validator
RUN npm install -g bids-validator

# Install dcm2niix
WORKDIR /
RUN wget https://github.com/rordenlab/dcm2niix/releases/download/v1.0.20240202/dcm2niix_lnx.zip
RUN unzip dcm2niix_lnx.zip
RUN mv dcm2niix /usr/bin/

# Install dcm2bids

WORKDIR /
ADD . /dcm2bids
WORKDIR /dcm2bids
RUN pip install -e .

RUN pip install pydeface

ENTRYPOINT ["dcm2bids"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Please take a look at the [documentation][dcm2bids-doc] to:

* [Learn about bids][bids-spec] with some dataset [examples][bids-examples]
* [Install dcm2bids][dcm2bids-install]
* [Follow the tutorial][dcm2bids-tutorial]
* [Use docker and Apptainer/Singularity][dcm2bids-container]
* [Follow the tutorials][dcm2bids-tutorial]
* [Seek for more advanced usage][dcm2bids-advanced]

## Issues and Questions
Expand All @@ -68,6 +69,7 @@ Before posting your question, you may want to first browse through questions tha
[dcm2bids-install]: https://unfmontreal.github.io/Dcm2Bids/latest/get-started/install/
[dcm2bids-tutorial]: https://unfmontreal.github.io/Dcm2Bids/latest/tutorial/first-steps/#tutorial-first-steps
[dcm2bids-advanced]: https://unfmontreal.github.io/Dcm2Bids/latest/advanced/
[dcm2bids-container]: https://unfmontreal.github.io/Dcm2Bids/latest/how-to/container/
[dcm2bids-upgrade]: https://unfmontreal.github.io/Dcm2Bids/dev/upgrade/
[dcm2bids-issues]: https://github.com/UNFmontreal/Dcm2Bids/issues
[dcm2niix-install]: https://github.com/rordenlab/dcm2niix#install
Expand Down
26 changes: 0 additions & 26 deletions containers/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions containers/singularity.def

This file was deleted.

52 changes: 34 additions & 18 deletions dcm2bids/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
from os.path import join as opj
from os import sep

from dcm2bids.utils.utils import DEFAULT
from dcm2bids.version import __version__
Expand All @@ -30,6 +31,8 @@ def __init__(
id=None,
src_sidecar=None,
sidecar_changes=None,
bids_uri=None,
do_not_reorder_entities=None,
**kwargs
):
self.logger = logging.getLogger(__name__)
Expand All @@ -43,6 +46,8 @@ def __init__(
self.suffix = suffix
self.custom_entities = custom_entities
self.src_sidecar = src_sidecar
self.bids_uri = bids_uri
self.do_not_reorder_entities = do_not_reorder_entities

if sidecar_changes is None:
self.sidecar_changes = {}
Expand Down Expand Up @@ -156,8 +161,8 @@ def setExtraDstFile(self, new_entities):
"""
Return:
The destination filename formatted following
the v1.8.0 BIDS entity key table
https://bids-specification.readthedocs.io/en/v1.8.0/99-appendices/04-entity-table.html
the v1.9.0 BIDS entity key table
https://bids-specification.readthedocs.io/en/v1.9.0/99-appendices/04-entity-table.html
"""

if self.custom_entities.strip() == "":
Expand Down Expand Up @@ -196,11 +201,14 @@ def setExtraDstFile(self, new_entities):
"compliant. Make sure you know what "
"you are doing.")

if current_name != new_name:
self.logger.warning(
f"""✅ Filename was reordered according to BIDS entity table order:
from: {current_name}
to: {new_name}""")
if not self.do_not_reorder_entities:
if current_name != new_name:
self.logger.warning(
f"""✅ Filename was reordered according to BIDS entity table order:
from: {current_name}
to: {new_name}""")
else:
new_name = current_name

self.extraDstFile = opj(self.participant.directory,
self.datatype,
Expand All @@ -210,8 +218,8 @@ def setDstFile(self):
"""
Return:
The destination filename formatted following
the v1.8.0 BIDS entity key table
https://bids-specification.readthedocs.io/en/v1.8.0/99-appendices/04-entity-table.html
the v1.9.0 BIDS entity key table
https://bids-specification.readthedocs.io/en/v1.9.0/99-appendices/04-entity-table.html
"""
current_name = self.participant.prefix + self.build_suffix
new_name = ''
Expand Down Expand Up @@ -241,13 +249,15 @@ def setDstFile(self):
"compliant. Make sure you know what "
"you are doing.")

if current_name != new_name:
self.logger.warning(
f"""✅ Filename was reordered according to BIDS entity table order:
from: {current_name}
to: {new_name}""")
self.dstFile = current_name
if not self.do_not_reorder_entities:
if current_name != new_name:
self.logger.warning(
f"""✅ Filename was reordered according to BIDS entity table order:
from: {current_name}
to: {new_name}""")
self.dstFile = new_name

self.dstFile = new_name

def dstSidecarData(self, idList):
"""
Expand Down Expand Up @@ -277,10 +287,16 @@ def dstSidecarData(self, idList):
else:
values.append(idList.get(val, val))
if values[-1] != val:
if isinstance(values[-1], list):
values[-1] = ["bids::" + img_dest for img_dest in values[-1]]
if self.bids_uri == DEFAULT.bids_uri:
if isinstance(values[-1], list):
values[-1] = ["bids::" + img_dest for img_dest in values[-1]]
else:
values[-1] = "bids::" + values[-1]
else:
values[-1] = "bids::" + values[-1]
if isinstance(values[-1], list):
values[-1] = [img_dest.replace(self.participant.name + sep, "") for img_dest in values[-1]]
else:
values[-1] = values[-1].replace(self.participant.name + sep, "")

# handle if nested list vs str
flat_value_list = []
Expand Down
12 changes: 11 additions & 1 deletion dcm2bids/cli/dcm2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,21 @@ def _build_arg_parser():
default=DEFAULT.output_dir,
help="Output BIDS directory. [%(default)s]")

p.add_argument("--auto_extract_entities",
g = p.add_mutually_exclusive_group()
g.add_argument("--auto_extract_entities",
action='store_true',
help="If set, it will automatically try to extract entity"
"information [task, dir, echo] based on the suffix and datatype."
" [%(default)s]")

g.add_argument("--do_not_reorder_entities",
action='store_true',
help="If set, it will not reorder entities according to the relative "
"ordering indicated in the BIDS specification and use the "
"order defined in custom_entities by the user.\n"
"Cannot be used with --auto_extract_entities. "
" [%(default)s]")

p.add_argument("--bids_validate",
action='store_true',
help="If set, once your conversion is done it "
Expand Down Expand Up @@ -120,6 +129,7 @@ def main():
logger.info(f"config: {os.path.realpath(args.config)}")
logger.info(f"BIDS directory: {os.path.realpath(args.output_dir)}")
logger.info(f"Auto extract entities: {args.auto_extract_entities}")
logger.info(f"Reorder entities: {not args.do_not_reorder_entities}")
logger.info(f"Validate BIDS: {args.bids_validate}\n")

app = Dcm2BidsGen(**vars(args)).run()
Expand Down
23 changes: 15 additions & 8 deletions dcm2bids/cli/dcm2bids_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from dcm2bids.utils.utils import DEFAULT
from dcm2bids.utils.tools import dcm2niix_version, check_latest
from dcm2bids.utils.logger import setup_logging
from dcm2bids.utils.args import assert_dirs_empty
from dcm2bids.version import __version__


Expand Down Expand Up @@ -59,12 +58,22 @@ def main():
"""Let's go"""
parser = _build_arg_parser()
args = parser.parse_args()
out_dir = Path(args.output_dir)
log_file = (Path(DEFAULT.output_dir)
/ DEFAULT.tmp_dir_name
/ "log"
/ f"helper_{datetime.now().strftime('%Y%m%d-%H%M%S')}.log")

out_dir = Path(args.output_dir)
if args.output_dir != parser.get_default('output_dir'):
out_dir = (Path(args.output_dir)
/ DEFAULT.tmp_dir_name
/ DEFAULT.helper_dir)

log_file = (Path(args.output_dir)
/ DEFAULT.tmp_dir_name
/ "log"
/ f"helper_{datetime.now().strftime('%Y%m%d-%H%M%S')}.log")
else:
log_file = (Path(DEFAULT.output_dir)
/ DEFAULT.tmp_dir_name
/ "log"
/ f"helper_{datetime.now().strftime('%Y%m%d-%H%M%S')}.log")
if args.nest:
if isinstance(args.nest, str):
log_file = Path(
Expand Down Expand Up @@ -94,8 +103,6 @@ def main():
check_latest("dcm2bids")
check_latest("dcm2niix")

assert_dirs_empty(parser, args, out_dir)

app = Dcm2niixGen(dicom_dirs=args.dicom_dir, bids_dir=out_dir, helper=True)

rsl = app.run(force=args.overwrite)
Expand Down
Loading
Loading