Skip to content

Commit

Permalink
Merge pull request #314 from UNFmontreal/dev
Browse files Browse the repository at this point in the history
Update master to 3.2.0
  • Loading branch information
SamGuay authored Jul 26, 2024
2 parents 56a6c1e + 58f3c72 commit 41e09f5
Show file tree
Hide file tree
Showing 35 changed files with 828 additions and 160 deletions.
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

0 comments on commit 41e09f5

Please sign in to comment.