[med-svn] [Git][med-team/heudiconv][upstream] New upstream version 0.11.6
Yaroslav Halchenko (@yoh)
gitlab at salsa.debian.org
Mon Nov 21 21:48:02 GMT 2022
Yaroslav Halchenko pushed to branch upstream at Debian Med / heudiconv
Commits:
998cf601 by Yaroslav Halchenko at 2022-11-21T15:48:32-05:00
New upstream version 0.11.6
- - - - -
12 changed files:
- PKG-INFO
- README.rst
- heudiconv.egg-info/PKG-INFO
- heudiconv/_version.py
- heudiconv/bids.py
- heudiconv/convert.py
- heudiconv/heuristics/multires_7Tbold.py
- heudiconv/parser.py
- heudiconv/tests/test_bids.py
- heudiconv/tests/test_heuristics.py
- heudiconv/tests/test_queue.py
- heudiconv/utils.py
Changes:
=====================================
PKG-INFO
=====================================
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: heudiconv
-Version: 0.11.4
+Version: 0.11.6
Summary: Heuristic DICOM Converter
Author: HeuDiConv team and contributors
License: Apache 2.0
=====================================
README.rst
=====================================
@@ -54,7 +54,7 @@ Please file issues and suggest changes via Pull Requests.
HeuDiConv requires installation of
`dcm2niix <https://github.com/rordenlab/dcm2niix/>`_ and optionally
-`DataLad <https://datalad.org>`_.
+`DataLad`_.
For development you will need a non-shallow clone (so there is a
recent released tag) of the aforementioned repository. You can then
=====================================
heudiconv.egg-info/PKG-INFO
=====================================
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: heudiconv
-Version: 0.11.4
+Version: 0.11.6
Summary: Heuristic DICOM Converter
Author: HeuDiConv team and contributors
License: Apache 2.0
=====================================
heudiconv/_version.py
=====================================
@@ -1 +1 @@
-__version__ = "0.11.4"
+__version__ = "0.11.6"
=====================================
heudiconv/bids.py
=====================================
@@ -1,5 +1,7 @@
"""Handle BIDS specific operations"""
+__docformat__ = "numpy"
+
import hashlib
import os
import os.path as op
@@ -157,12 +159,12 @@ def populate_bids_templates(path, defaults={}):
def populate_aggregated_jsons(path):
- """Aggregate across the entire BIDS dataset .json's into top level .json's
+ """Aggregate across the entire BIDS dataset ``.json``\s into top level ``.json``\s
Top level .json files would contain only the fields which are
- common to all subject[/session]/type/*_modality.json's.
+ common to all ``subject[/session]/type/*_modality.json``\s.
- ATM aggregating only for *_task*_bold.json files. Only the task- and
+ ATM aggregating only for ``*_task*_bold.json`` files. Only the task- and
OPTIONAL _acq- field is retained within the aggregated filename. The other
BIDS _key-value pairs are "aggregated over".
@@ -415,15 +417,14 @@ def save_scans_key(item, bids_files):
def add_rows_to_scans_keys_file(fn, newrows):
- """
- Add new rows to file fn for scans key filename and generate accompanying json
- descriptor to make BIDS validator happy.
+ """Add new rows to the _scans file.
Parameters
----------
- fn: filename
- newrows: extra rows to add
- dict fn: [acquisition time, referring physician, random string]
+ fn: str
+ filename
+ newrows: dict
+ extra rows to add (acquisition time, referring physician, random string)
"""
if op.lexists(fn):
with open(fn, 'r') as csvfile:
@@ -527,11 +528,11 @@ def get_shim_setting(json_file):
Gets the "ShimSetting" field from a json_file.
If no "ShimSetting" present, return error
- Parameters:
+ Parameters
----------
json_file : str
- Returns:
+ Returns
-------
str with "ShimSetting" value
"""
@@ -552,13 +553,13 @@ def find_fmap_groups(fmap_dir):
By groups here we mean fmaps that are intended to go together
(with reversed PE polarity, magnitude/phase, etc.)
- Parameters:
+ Parameters
----------
fmap_dir : str or os.path
path to the session folder (or to the subject folder, if there are no
sessions).
- Returns:
+ Returns
-------
fmap_groups : dict
key: prefix common to the group (e.g. no "dir" entity, "_phase"/"_magnitude", ...)
@@ -598,14 +599,14 @@ def get_key_info_for_fmap_assignment(json_file, matching_parameter):
(Note: It is the responsibility of the calling function to make sure
the arguments are OK)
- Parameters:
+ Parameters
----------
json_file : str or os.path
path to the json file
matching_parameter : str in AllowedFmapParameterMatching
matching_parameter that will be used to match runs
- Returns:
+ Returns
-------
key_info : dict
part of the json file that will need to match between the fmap and
@@ -666,7 +667,7 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters):
(Note: It is the responsibility of the calling function to make sure
the arguments are OK)
- Parameters:
+ Parameters
----------
json_file : str or os.path
path to the json file
@@ -676,7 +677,7 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters):
matching_parameters : list of str from AllowedFmapParameterMatching
matching_parameters that will be used to match runs
- Returns:
+ Returns
-------
compatible_fmap_groups : dict
Subset of the fmap_groups which match json_file, according
@@ -720,7 +721,7 @@ def find_compatible_fmaps_for_session(path_to_bids_session, matching_parameters)
(Note: It is the responsibility of the calling function to make sure
the arguments are OK)
- Parameters:
+ Parameters
----------
path_to_bids_session : str or os.path
path to the session folder (or to the subject folder, if there are no
@@ -728,7 +729,7 @@ def find_compatible_fmaps_for_session(path_to_bids_session, matching_parameters)
matching_parameters : list of str from AllowedFmapParameterMatching
matching_parameters that will be used to match runs
- Returns:
+ Returns
-------
compatible_fmap : dict
Dict of compatible_fmaps_groups (values) for each non-fmap run (keys)
@@ -768,7 +769,7 @@ def select_fmap_from_compatible_groups(json_file, compatible_fmap_groups, criter
(Note: It is the responsibility of the calling function to make sure
the arguments are OK)
- Parameters:
+ Parameters
----------
json_file : str or os.path
path to the json file
@@ -777,7 +778,7 @@ def select_fmap_from_compatible_groups(json_file, compatible_fmap_groups, criter
criterion : str in ['First', 'Closest']
matching_parameters that will be used to decide which fmap to use
- Returns:
+ Returns
-------
selected_fmap_key : str or os.path
key from the compatible_fmap_groups for the selected fmap group
@@ -859,7 +860,7 @@ def populate_intended_for(path_to_bids_session, matching_parameters, criterion):
Because fmaps come in groups (with reversed PE polarity, or magnitude/
phase), we work with fmap_groups.
- Parameters:
+ Parameters
----------
path_to_bids_session : str or os.path
path to the session folder (or to the subject folder, if there are no
=====================================
heudiconv/convert.py
=====================================
@@ -1,3 +1,5 @@
+__docformat__ = "numpy"
+
import filelock
import os
import os.path as op
@@ -453,23 +455,6 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
dcmconfig=None, populate_intended_for_opts={}):
"""Perform actual conversion (calls to converter etc) given info from
heuristic's `infotodict`
-
- Parameters
- ----------
- items
- symlink
- converter
- scaninfo_suffix
- custom_callable
- with_prov
- is_bids
- sourcedir
- outdir
- min_meta
-
- Returns
- -------
- None
"""
prov_files = []
tempdirs = TempDirs()
@@ -624,10 +609,6 @@ def convert_dicom(item_dicoms, bids_options, prefix,
Create softlink to DICOMs - if False, create hardlink instead.
overwrite : bool
If True, allows overwriting of previous conversion
-
- Returns
- -------
- None
"""
if bids_options is not None:
# mimic the same hierarchy location as the prefix
@@ -666,18 +647,18 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids_options, tmpdir, dcmconf
Parameters
----------
- item_dicoms : List
+ item_dicoms : list
DICOM files to convert
- prefix : String
+ prefix : str
Heuristic output path
- with_prov : Bool
+ with_prov : bool
Store provenance information
- bids_options : List or None
+ bids_options : list or None
If not None then output BIDS sidecar JSONs
List may contain bids specific options
- tmpdir : Directory
+ tmpdir : str
Conversion working directory
- dcmconfig : File (optional)
+ dcmconfig : str, optional
JSON file used for additional Dcm2niix configuration
"""
import nipype
@@ -723,18 +704,19 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids_options, tmpdir, dcmconf
def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outname_bids, overwrite):
"""Copy converted files from tempdir to output directory.
+
Will rename files if necessary.
Parameters
----------
res : Node
Nipype conversion Node with results
- item_dicoms: list of filenames
- DICOMs converted
+ item_dicoms: list
+ Filenames of converted DICOMs
bids : list or None
If not list save to BIDS
List may contain bids specific options
- prefix : string
+ prefix : str
Returns
-------
@@ -877,15 +859,13 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
return bids_outfiles
-def add_taskname_to_infofile(infofiles):
+def add_taskname_to_infofile(infofiles):
"""Add the "TaskName" field to json files corresponding to func images.
Parameters
----------
- infofiles : list with json filenames or single filename
-
- Returns
- -------
+ infofiles: list or str
+ json filenames or a single filename.
"""
# in case they pass a string with a path:
@@ -908,15 +888,15 @@ def add_taskname_to_infofile(infofiles):
def bvals_are_zero(bval_file):
"""Checks if all entries in a bvals file are zero (or 5, for Siemens files).
- Returns True if that is the case, otherwise returns False
Parameters
----------
- bval_file : file with the bvals
+ bval_file : str
+ file with the bvals
Returns
-------
- True if all are zero; False otherwise.
+ True if all are all 0 or 5; False otherwise.
"""
with open(bval_file) as f:
=====================================
heudiconv/heuristics/multires_7Tbold.py
=====================================
@@ -27,7 +27,7 @@ def extract_moco_params(basename, outypes, dicoms):
dcm_times = [(d,
float(dcm_read(d, stop_before_pixels=True).AcquisitionTime))
for d in dicoms]
- # store MoCo info from image comments sorted by acqusition time
+ # store MoCo info from image comments sorted by acquisition time
moco = ['\t'.join(
[str(float(i)) for i in dcm_read(fn, stop_before_pixels=True).ImageComments.split()[1].split(',')])
for fn, t in sorted(dcm_times, key=lambda x: x[1])]
=====================================
heudiconv/parser.py
=====================================
@@ -29,6 +29,7 @@ _VCS_REGEX = r'%s\.(?:git|gitattributes|svn|bzr|hg)(?:%s|$)' % (op.sep, op.sep)
def find_files(regex, topdir=op.curdir, exclude=None,
exclude_vcs=True, dirs=False):
"""Generator to find files matching regex
+
Parameters
----------
regex: basestring
@@ -60,7 +61,8 @@ def find_files(regex, topdir=op.curdir, exclude=None,
def get_extracted_dicoms(fl):
- """Given a list of files, possibly extract some from tarballs
+ """Given a list of files, possibly extract some from tarballs.
+
For 'classical' heudiconv, if multiple tarballs are provided, they correspond
to different sessions, so here we would group into sessions and return
pairs `sessionid`, `files` with `sessionid` being None if no "sessions"
@@ -116,13 +118,15 @@ def get_extracted_dicoms(fl):
def get_study_sessions(dicom_dir_template, files_opt, heuristic, outdir,
session, sids, grouping='studyUID'):
- """Given options from cmdline sort files or dicom seqinfos into
- study_sessions which put together files for a single session of a subject
- in a study
- Two major possible workflows:
+ """Sort files or dicom seqinfos into study_sessions.
+
+ study_sessions put together files for a single session of a subject
+ in a study. Two major possible workflows:
+
- if dicom_dir_template provided -- doesn't pre-load DICOMs and just
loads files pointed by each subject and possibly sessions as corresponding
- to different tarballs
+ to different tarballs.
+
- if files_opt is provided, sorts all DICOMs it can find under those paths
"""
study_sessions = {}
=====================================
heudiconv/tests/test_bids.py
=====================================
@@ -199,12 +199,12 @@ def generate_scans_tsv(session_struct):
Currently, it will have the columns "filename" and "acq_time".
The acq_time will increase by one minute from run to run.
- Parameters:
+ Parameters
----------
session_struct : dict
structure for the session, as a dict with modality: files
- Returns:
+ Returns
-------
scans_file_content : str
multi-line string with the content of the file
@@ -231,12 +231,12 @@ def create_dummy_pepolar_bids_session(session_path):
The fmap files are pepolar
The json files have ShimSettings
- Parameters:
+ Parameters
----------
session_path : str or os.path
path to the session (or subject) level folder
- Returns:
+ Returns
-------
session_struct : dict
Structure of the directory that was created
@@ -407,12 +407,12 @@ def create_dummy_no_shim_settings_bids_session(session_path):
The fmap files are pepolar
The json files don't have ShimSettings
- Parameters:
+ Parameters
----------
session_path : str or os.path
path to the session (or subject) level folder
- Returns:
+ Returns
-------
session_struct : dict
Structure of the directory that was created
@@ -553,7 +553,7 @@ def create_dummy_no_shim_settings_custom_label_bids_session(session_path, label_
- TASK label for <func> modality
- ACQ label for any other modality (e.g. <dwi>)
- Parameters:
+ Parameters
----------
session_path : str or os.path
path to the session (or subject) level folder
@@ -562,7 +562,7 @@ def create_dummy_no_shim_settings_custom_label_bids_session(session_path, label_
label_seed : int, optional
seed for the random label creation
- Returns:
+ Returns
-------
session_struct : dict
Structure of the directory that was created
@@ -705,12 +705,12 @@ def create_dummy_magnitude_phase_bids_session(session_path):
We just need to test a very simple case to make sure the mag/phase have
the same "IntendedFor" field:
- Parameters:
+ Parameters
----------
session_path : str or os.path
path to the session (or subject) level folder
- Returns:
+ Returns
-------
session_struct : dict
Structure of the directory that was created
@@ -890,7 +890,7 @@ def test_find_compatible_fmaps_for_run(tmpdir, simulation_function, match_param)
"""
Test find_compatible_fmaps_for_run.
- Parameters:
+ Parameters
----------
tmpdir
simulation_function : function
@@ -939,7 +939,7 @@ def test_find_compatible_fmaps_for_session(
"""
Test find_compatible_fmaps_for_session.
- Parameters:
+ Parameters
----------
tmpdir
folder : str or os.path
@@ -1029,7 +1029,7 @@ def test_populate_intended_for(
):
"""
Test populate_intended_for.
- Parameters:
+ Parameters
----------
tmpdir
folder : str or os.path
=====================================
heudiconv/tests/test_heuristics.py
=====================================
@@ -45,7 +45,7 @@ def test_smoke_convertall(tmpdir):
@pytest.mark.parametrize('heuristic', ['reproin', 'convertall'])
@pytest.mark.parametrize(
'invocation', [
- "--files %s" % TESTS_DATA_PATH, # our new way with automated groupping
+ "--files %s" % TESTS_DATA_PATH, # our new way with automated grouping
"-d %s/{subject}/* -s 01-fmap_acq-3mm" % TESTS_DATA_PATH # "old" way specifying subject
# should produce the same results
])
@@ -106,7 +106,7 @@ def test_reproin_largely_smoke(tmpdir, heuristic, invocation):
@pytest.mark.parametrize(
'invocation', [
- "--files %s" % TESTS_DATA_PATH, # our new way with automated groupping
+ "--files %s" % TESTS_DATA_PATH, # our new way with automated grouping
])
def test_scans_keys_reproin(tmpdir, invocation):
args = "-f reproin -c dcm2niix -o %s -b " % (tmpdir)
=====================================
heudiconv/tests/test_queue.py
=====================================
@@ -10,7 +10,7 @@ import pytest
@pytest.mark.skipif(bool(which("sbatch")), reason="skip a real slurm call")
@pytest.mark.parametrize(
'invocation', [
- "--files %s/01-fmap_acq-3mm" % TESTS_DATA_PATH, # our new way with automated groupping
+ "--files %s/01-fmap_acq-3mm" % TESTS_DATA_PATH, # our new way with automated grouping
"-d %s/{subject}/* -s 01-fmap_acq-3mm" % TESTS_DATA_PATH # "old" way specifying subject
])
def test_queue_no_slurm(tmpdir, invocation):
=====================================
heudiconv/utils.py
=====================================
@@ -290,7 +290,7 @@ def update_json(json_file, new_data, pretty=False):
"""
Adds a given field (and its value) to a json file
- Parameters:
+ Parameters
-----------
json_file : str or Path
path for the corresponding json file
@@ -613,12 +613,12 @@ def remove_suffix(s, suf):
"""
Remove suffix from the end of the string
- Parameters:
+ Parameters
----------
s : str
suf : str
- Returns:
+ Returns
-------
s : str
string with "suf" removed from the end (if present)
@@ -632,12 +632,12 @@ def remove_prefix(s, pre):
"""
Remove prefix from the beginning of the string
- Parameters:
+ Parameters
----------
s : str
pre : str
- Returns:
+ Returns
-------
s : str
string with "pre" removed from the beginning (if present)
View it on GitLab: https://salsa.debian.org/med-team/heudiconv/-/commit/998cf601cdd1fe1126ed0c7b133237cdc0c8c8e5
--
View it on GitLab: https://salsa.debian.org/med-team/heudiconv/-/commit/998cf601cdd1fe1126ed0c7b133237cdc0c8c8e5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20221121/2e112815/attachment-0001.htm>
More information about the debian-med-commit
mailing list