Skip to content

Commit 621a7c4

Browse files
committed
Merge branch 'master' of https://github.com/nipy/heudiconv into multiecho
2 parents 3250283 + f3a7e50 commit 621a7c4

File tree

9 files changed

+227
-145
lines changed

9 files changed

+227
-145
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to this project will be documented (for humans) in this file
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.2] - Date
8+
9+
TODO Summary
10+
11+
### Added
12+
### Changed
13+
14+
- Reproin heuristic: `__dup` indices would now be assigned incrementally
15+
individually per each sequence, so there is a chance to properly treat
16+
associate for multi-file (e.g. `fmap`) sequences
17+
18+
### Deprecated
19+
### Fixed
20+
### Removed
21+
### Security
22+
23+
724
## [0.5.1] - 2018-07-05
825
Bugfix release
926

Dockerfile

Lines changed: 93 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,131 @@
1-
# Generated by Neurodocker v0.3.2.
2-
#
1+
# Generated by Neurodocker version 0.4.1-28-g83dbc15
2+
# Timestamp: 2018-11-01 22:00:14 UTC
3+
#
34
# Thank you for using Neurodocker. If you discover any issues
45
# or ways to improve this software, please submit an issue or
56
# pull request on our GitHub repository:
7+
#
68
# https://github.com/kaczmarj/neurodocker
7-
#
8-
# Timestamp: 2018-06-29 18:14:08
99

10-
FROM debian:stretch
10+
FROM neurodebian:stretch
1111

12-
ARG DEBIAN_FRONTEND=noninteractive
12+
ARG DEBIAN_FRONTEND="noninteractive"
1313

14-
#----------------------------------------------------------
15-
# Install common dependencies and create default entrypoint
16-
#----------------------------------------------------------
1714
ENV LANG="en_US.UTF-8" \
18-
LC_ALL="C.UTF-8" \
15+
LC_ALL="en_US.UTF-8" \
1916
ND_ENTRYPOINT="/neurodocker/startup.sh"
20-
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
21-
apt-utils bzip2 ca-certificates curl locales unzip \
17+
RUN export ND_ENTRYPOINT="/neurodocker/startup.sh" \
18+
&& apt-get update -qq \
19+
&& apt-get install -y -q --no-install-recommends \
20+
apt-utils \
21+
bzip2 \
22+
ca-certificates \
23+
curl \
24+
locales \
25+
unzip \
2226
&& apt-get clean \
2327
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
24-
&& localedef --force --inputfile=en_US --charmap=UTF-8 C.UTF-8 \
28+
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
29+
&& dpkg-reconfigure --frontend=noninteractive locales \
30+
&& update-locale LANG="en_US.UTF-8" \
2531
&& chmod 777 /opt && chmod a+s /opt \
2632
&& mkdir -p /neurodocker \
2733
&& if [ ! -f "$ND_ENTRYPOINT" ]; then \
28-
echo '#!/usr/bin/env bash' >> $ND_ENTRYPOINT \
29-
&& echo 'set +x' >> $ND_ENTRYPOINT \
30-
&& echo 'if [ -z "$*" ]; then /usr/bin/env bash; else $*; fi' >> $ND_ENTRYPOINT; \
31-
fi \
34+
echo '#!/usr/bin/env bash' >> "$ND_ENTRYPOINT" \
35+
&& echo 'set -e' >> "$ND_ENTRYPOINT" \
36+
&& echo 'if [ -n "$1" ]; then "$@"; else /usr/bin/env bash; fi' >> "$ND_ENTRYPOINT"; \
37+
fi \
3238
&& chmod -R 777 /neurodocker && chmod a+s /neurodocker
39+
3340
ENTRYPOINT ["/neurodocker/startup.sh"]
3441

35-
#------------------------
36-
# Install dcm2niix v1.0.20180622
37-
#------------------------
38-
WORKDIR /tmp
39-
RUN deps='cmake g++ gcc git make pigz zlib1g-dev' \
40-
&& apt-get update -qq && apt-get install -yq --no-install-recommends $deps \
42+
ENV PATH="/opt/dcm2niix-v1.0.20180622/bin:$PATH"
43+
RUN apt-get update -qq \
44+
&& apt-get install -y -q --no-install-recommends \
45+
cmake \
46+
g++ \
47+
gcc \
48+
git \
49+
make \
50+
pigz \
51+
zlib1g-dev \
4152
&& apt-get clean \
4253
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
43-
&& mkdir dcm2niix \
44-
&& curl -sSL https://github.com/rordenlab/dcm2niix/tarball/v1.0.20180622 | tar xz -C dcm2niix --strip-components 1 \
45-
&& mkdir dcm2niix/build && cd dcm2niix/build \
46-
&& cmake .. && make \
54+
&& git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \
55+
&& cd /tmp/dcm2niix \
56+
&& git fetch --tags \
57+
&& git checkout v1.0.20180622 \
58+
&& mkdir /tmp/dcm2niix/build \
59+
&& cd /tmp/dcm2niix/build \
60+
&& cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/dcm2niix-v1.0.20180622 .. \
61+
&& make \
4762
&& make install \
48-
&& rm -rf /tmp/* \
49-
&& apt-get purge -y --auto-remove $deps
50-
51-
#--------------------------------------------------
52-
# Add NeuroDebian repository
53-
# Please note that some packages downloaded through
54-
# NeuroDebian may have restrictive licenses.
55-
#--------------------------------------------------
56-
RUN apt-get update -qq && apt-get install -yq --no-install-recommends dirmngr gnupg \
57-
&& apt-get clean \
58-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
59-
&& curl -sSL http://neuro.debian.net/lists/stretch.us-nh.full \
60-
> /etc/apt/sources.list.d/neurodebian.sources.list \
61-
&& curl -sSL https://dl.dropbox.com/s/zxs209o955q6vkg/neurodebian.gpg \
62-
| apt-key add - \
63-
&& (apt-key adv --refresh-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 || true) \
64-
&& apt-get update
65-
66-
# Install NeuroDebian packages
67-
RUN apt-get update -qq && apt-get install -yq --no-install-recommends git-annex-standalone \
68-
&& apt-get clean \
69-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
63+
&& rm -rf /tmp/dcm2niix
7064

7165
RUN apt-get update -qq \
72-
&& apt-get install -y -q --no-install-recommends git \
73-
gcc \
74-
pigz \
66+
&& apt-get install -y -q --no-install-recommends \
67+
git \
68+
gcc \
69+
pigz \
70+
liblzma-dev \
71+
libc-dev \
72+
git-annex-standalone \
7573
&& apt-get clean \
7674
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
7775

7876
COPY [".", "/src/heudiconv"]
7977

80-
#------------------
81-
# Install Miniconda
82-
#------------------
83-
ENV CONDA_DIR=/opt/conda \
84-
PATH=/opt/conda/bin:$PATH
85-
RUN echo "Downloading Miniconda installer ..." \
86-
&& miniconda_installer=/tmp/miniconda.sh \
87-
&& curl -sSL --retry 5 -o $miniconda_installer https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
88-
&& /bin/bash $miniconda_installer -b -p $CONDA_DIR \
89-
&& rm -f $miniconda_installer \
78+
ENV CONDA_DIR="/opt/miniconda-latest" \
79+
PATH="/opt/miniconda-latest/bin:$PATH"
80+
RUN export PATH="/opt/miniconda-latest/bin:$PATH" \
81+
&& echo "Downloading Miniconda installer ..." \
82+
&& conda_installer="/tmp/miniconda.sh" \
83+
&& curl -fsSL --retry 5 -o "$conda_installer" https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
84+
&& bash "$conda_installer" -b -p /opt/miniconda-latest \
85+
&& rm -f "$conda_installer" \
86+
&& conda update -yq -nbase conda \
9087
&& conda config --system --prepend channels conda-forge \
9188
&& conda config --system --set auto_update_conda false \
9289
&& conda config --system --set show_channel_urls true \
93-
&& conda clean -tipsy && sync
94-
95-
#-------------------------
96-
# Create conda environment
97-
#-------------------------
98-
RUN conda create -y -q --name neuro python=2 \
99-
traits=4.6.0 \
10090
&& sync && conda clean -tipsy && sync \
101-
&& /bin/bash -c "source activate neuro \
102-
&& pip install -q --no-cache-dir https://github.com/moloney/dcmstack/tarball/master \
103-
/src/heudiconv[all]" \
104-
&& sync \
105-
&& sed -i '$isource activate neuro' $ND_ENTRYPOINT
91+
&& conda install -y -q --name base \
92+
python=3.6 \
93+
traits>=4.6.0 \
94+
scipy \
95+
numpy \
96+
nomkl \
97+
&& sync && conda clean -tipsy && sync \
98+
&& bash -c "source activate base \
99+
&& pip install --no-cache-dir --editable \
100+
/src/heudiconv[all]" \
101+
&& rm -rf ~/.cache/pip/* \
102+
&& sync
106103

107-
ENTRYPOINT ["/neurodocker/startup.sh", "heudiconv"]
104+
ENTRYPOINT ["heudiconv"]
108105

109-
#--------------------------------------
110-
# Save container specifications to JSON
111-
#--------------------------------------
112106
RUN echo '{ \
113107
\n "pkg_manager": "apt", \
114-
\n "check_urls": true, \
115108
\n "instructions": [ \
116109
\n [ \
117110
\n "base", \
118-
\n "debian:stretch" \
111+
\n "neurodebian:stretch" \
119112
\n ], \
120113
\n [ \
121114
\n "dcm2niix", \
122115
\n { \
123-
\n "version": "v1.0.20180622" \
124-
\n } \
125-
\n ], \
126-
\n [ \
127-
\n "neurodebian", \
128-
\n { \
129-
\n "os_codename": "stretch", \
130-
\n "download_server": "usa-nh", \
131-
\n "pkgs": "git-annex-standalone" \
116+
\n "version": "v1.0.20180622", \
117+
\n "method": "source" \
132118
\n } \
133119
\n ], \
134120
\n [ \
135121
\n "install", \
136122
\n [ \
137123
\n "git", \
138124
\n "gcc", \
139-
\n "pigz" \
125+
\n "pigz", \
126+
\n "liblzma-dev", \
127+
\n "libc-dev", \
128+
\n "git-annex-standalone" \
140129
\n ] \
141130
\n ], \
142131
\n [ \
@@ -149,17 +138,23 @@ RUN echo '{ \
149138
\n [ \
150139
\n "miniconda", \
151140
\n { \
152-
\n "env_name": "neuro", \
153-
\n "conda_install": "python=2 traits=4.6.0", \
154-
\n "activate": true, \
155-
\n "pip_install": "https://github.com/moloney/dcmstack/tarball/master /src/heudiconv[all]" \
141+
\n "use_env": "base", \
142+
\n "conda_install": [ \
143+
\n "python=3.6", \
144+
\n "traits>=4.6.0", \
145+
\n "scipy", \
146+
\n "numpy", \
147+
\n "nomkl" \
148+
\n ], \
149+
\n "pip_install": [ \
150+
\n "/src/heudiconv[all]" \
151+
\n ], \
152+
\n "pip_opts": "--editable" \
156153
\n } \
157154
\n ], \
158155
\n [ \
159156
\n "entrypoint", \
160-
\n "/neurodocker/startup.sh heudiconv" \
157+
\n "heudiconv" \
161158
\n ] \
162-
\n ], \
163-
\n "generation_timestamp": "2018-06-29 18:14:08", \
164-
\n "neurodocker_version": "0.3.2" \
159+
\n ] \
165160
\n}' > /neurodocker/neurodocker_specs.json

heudiconv/bids.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Handle BIDS specific operations"""
22

3+
import hashlib
34
import os
45
import os.path as op
56
import logging
@@ -217,7 +218,7 @@ def save_scans_key(item, bids_files):
217218
"""
218219
Parameters
219220
----------
220-
items:
221+
item:
221222
bids_files: str or list
222223
223224
Returns
@@ -235,7 +236,7 @@ def save_scans_key(item, bids_files):
235236
# get filenames
236237
f_name = '/'.join(bids_file.split('/')[-2:])
237238
f_name = f_name.replace('json', 'nii.gz')
238-
rows[f_name] = get_formatted_scans_key_row(item)
239+
rows[f_name] = get_formatted_scans_key_row(item[-1][0])
239240
subj_, ses_ = find_subj_ses(f_name)
240241
if not subj_:
241242
lgr.warning(
@@ -300,7 +301,7 @@ def add_rows_to_scans_keys_file(fn, newrows):
300301
writer.writerows([header] + data_rows_sorted)
301302

302303

303-
def get_formatted_scans_key_row(item):
304+
def get_formatted_scans_key_row(dcm_fn):
304305
"""
305306
Parameters
306307
----------
@@ -312,25 +313,27 @@ def get_formatted_scans_key_row(item):
312313
[ISO acquisition time, performing physician name, random string]
313314
314315
"""
315-
dcm_fn = item[-1][0]
316-
from heudiconv.external.dcmstack import ds
317-
mw = ds.wrapper_from_data(dcm.read_file(dcm_fn,
318-
stop_before_pixels=True,
319-
force=True))
316+
dcm_data = dcm.read_file(dcm_fn, stop_before_pixels=True, force=True)
320317
# we need to store filenames and acquisition times
321318
# parse date and time and get it into isoformat
322319
try:
323-
date = mw.dcm_data.ContentDate
324-
time = mw.dcm_data.ContentTime.split('.')[0]
320+
date = dcm_data.ContentDate
321+
time = dcm_data.ContentTime.split('.')[0]
325322
td = time + date
326323
acq_time = datetime.strptime(td, '%H%M%S%Y%m%d').isoformat()
327324
except AttributeError as exc:
328325
lgr.warning("Failed to get date/time for the content: %s", str(exc))
329326
acq_time = None
330327
# add random string
331-
randstr = ''.join(map(chr, sample(k=8, population=range(33, 127))))
328+
# But let's make it reproducible by using all UIDs
329+
# (might change across versions?)
330+
randcontent = u''.join(
331+
[getattr(dcm_data, f) or '' for f in sorted(dir(dcm_data))
332+
if f.endswith('UID')]
333+
)
334+
randstr = hashlib.md5(randcontent.encode()).hexdigest()[:8]
332335
try:
333-
perfphys = mw.dcm_data.PerformingPhysicianName
336+
perfphys = dcm_data.PerformingPhysicianName
334337
except AttributeError:
335338
perfphys = ''
336339
row = [acq_time, perfphys, randstr]

0 commit comments

Comments
 (0)