Skip to content

Commit c59ed62

Browse files
committed
STY: Added some pre-commit hooks
1 parent d67f2da commit c59ed62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+71928
-71934
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ bf298113da99079c9c7b5e1690e41879828cd472
1111
# Thu Dec 29 21:32:00 2022 -0500 - [email protected] - STY: isort
1212
0ab2856cac4d4baae7ab3e2f6d58421db55d807f
1313
# Thu Dec 29 21:30:29 2022 -0500 - [email protected] - STY: blue
14-
1a8dd302ff85b1136c81d492509b80e7748339f0
14+
1a8dd302ff85b1136c81d492509b80e7748339f0
15+
# Thu Dec 29 20:08:19 2022 +0200 - [email protected] - STY: Added some pre-commit hooks
16+
b42c9cad3dd247c930ae12b6de834c7424a3e658

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-json
9+
- id: check-toml
10+
- id: check-added-large-files
11+
- id: check-case-conflict
12+
- id: check-merge-conflict
13+
- id: check-vcs-permalinks
214
- repo: https://github.com/grantjenks/blue
315
rev: v0.9.1
416
hooks:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RELEASE_VERSION ?= $(SETUPPY_VERSION)
3838

3939
all: build
4040

41-
build:
41+
build:
4242
$(PYTHON) setup.py config --noisy
4343
$(PYTHON) setup.py build
4444

Makefile.win

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile NiBabel under Windows using a standard Python distribution
22

3-
installer:
3+
installer:
44
# now the installer
55
python setup.py bdist_wininst
66

doc/source/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Discover available make targets::
1616
make help
1717

1818
Clean up previous build::
19-
19+
2020
make clean
2121

2222
Build html documentation::

doc/source/_templates/indexsidebar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ <h3>Search mailing list archive</h3>
1919
<input name="userquery" size="18" type="text" /> <input type="submit" value="Go" />
2020
<input name="q" type="hidden" />
2121
</form>
22-

doc/source/devel/biaps/biap_0001.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,3 @@ How about the names in the proposal? ``is_proxy``; ``unproxy=True``?
297297

298298

299299
.. vim: ft=rst
300-

doc/source/devel/biaps/biap_0003.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ From `adding nifti extensions`_:
4141
* 4 = NIFTI_ECODE_AFNI = AFNI header attributes: The format of the AFNI
4242
extension in the NIfTI-1.1 format is described at
4343
http://nifti.nimh.nih.gov/nifti-1/AFNIextension1/
44-
* 6 = NIFTI_ECODE_COMMENT = comment: arbitrary non-NUL ASCII text, with no
44+
* 6 = NIFTI_ECODE_COMMENT = comment: arbitrary non-NUL ASCII text, with no
4545
additional structure implied
4646
* 8 = NIFTI_ECODE_XCEDE = XCEDE metadata:
4747
http://www.nbirn.net/Resources/Users/Applications/xcede/index.htm
@@ -369,7 +369,7 @@ apply to the Cartesian product of the image axis values. For example, if the
369369
values of ``applies_to`` == ``['slice', 'time']``, and the slice and time axes
370370
in the array are lengths (6, 10) respectively, then the values apply to all
371371
combinations of the 6 possible values for slice indices and the 10 possible
372-
values for the time indices (ie apply to all 6x10=60 values). The axis metadata
372+
values for the time indices (ie apply to all 6x10=60 values). The axis metadata
373373
values in this case can be:
374374

375375
* a scalar. The value applies to every combination of (slice, time)

doc/source/devel/biaps/biap_0004.rst

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ nibabel objects and functions.
1616
Motivation
1717
**********
1818

19-
It is very common to convert source DICOM images to another format, typically
20-
Nifti, before doing any image processing. The Nifti format is significantly
21-
easier to work with and has wide spread compatibility. However, the vast
19+
It is very common to convert source DICOM images to another format, typically
20+
Nifti, before doing any image processing. The Nifti format is significantly
21+
easier to work with and has wide spread compatibility. However, the vast
2222
amount of meta data stored in the source DICOM files will be lost.
2323

2424
After implementing this proposal, users will be able to preserve all of the
@@ -32,7 +32,7 @@ private elements. The meta data will then be easily accessible through the
3232
(256, 256, 24, 8)
3333
>>> print nii.get_meta('RepetitionTime')
3434
3500.0
35-
>>> echo_times = [nii.get_meta('EchoTime', (0, 0, 0, idx))
35+
>>> echo_times = [nii.get_meta('EchoTime', (0, 0, 0, idx))
3636
for idx in xrange(data.shape[-1])]
3737
>>> print echo_times
3838
[16.4, 32.8, 49.2, 65.6, 82.0, 98.4, 114.8, 131.2]
@@ -50,25 +50,25 @@ Overview
5050
********
5151

5252
dcmstack reads a series of DICOM images, works out their relationship in terms
53-
of slices and volumes, and compiles them into multidimensional volumes. It can
54-
produce the corresponding data volume and affine, or a Nifti image (with any
53+
of slices and volumes, and compiles them into multidimensional volumes. It can
54+
produce the corresponding data volume and affine, or a Nifti image (with any
5555
additional header information set appropriately).
5656

57-
In the course of the read, dcmstack creates a `DcmMeta` object for
58-
each input file. This object is an ordered mapping that can contain a copy
59-
of all the meta data in the DICOM header. By default some filtering is
60-
applied to reduce the chance of including PHI. The set of DcmMeta objects are
61-
then merged together in the same order as the image data to create a single
57+
In the course of the read, dcmstack creates a `DcmMeta` object for
58+
each input file. This object is an ordered mapping that can contain a copy
59+
of all the meta data in the DICOM header. By default some filtering is
60+
applied to reduce the chance of including PHI. The set of DcmMeta objects are
61+
then merged together in the same order as the image data to create a single
6262
DcmMeta object that summarizes all of the meta data for the series.
6363

64-
To summarize the meta data, each element is classified based on how the values
65-
repeat (e.g. const, per_slice, per_volume, etc.). Each element has a name (the
66-
keyword from the DICOM standard) and one or more values (the number of values
67-
depends on the classification and the shape of the image). Each classification's
64+
To summarize the meta data, each element is classified based on how the values
65+
repeat (e.g. const, per_slice, per_volume, etc.). Each element has a name (the
66+
keyword from the DICOM standard) and one or more values (the number of values
67+
depends on the classification and the shape of the image). Each classification's
6868
meta data is stored stored in a separate nested dictionary.
6969

70-
While creating the Nifti image output, the `DcmMeta` is stored in a
71-
`DcmMetaExtension` which can be added as a header extension. This extension
70+
While creating the Nifti image output, the `DcmMeta` is stored in a
71+
`DcmMetaExtension` which can be added as a header extension. This extension
7272
simply does a JSON encoding directly on the `DcmMeta` object.
7373

7474
When working with these images, it's possible to keep track of the
@@ -78,7 +78,7 @@ slice, and remove information for other slices. Or when merging 3D volumes to
7878
a 4D time series, we want to merge together the meta data too.
7979

8080
At the moment, dcmstack only creates Nifti images. There's no reason that this
81-
should be so, and the relationship of dcmstack to other spatial images should be
81+
should be so, and the relationship of dcmstack to other spatial images should be
8282
more flexible.
8383

8484
******
@@ -105,10 +105,10 @@ wrapping the `DcmMeta` in the Extension API?
105105
Status
106106
------
107107

108-
Resolved. We now have a separate `DcmMeta` object which inherits from
109-
`OrderedDict` and contains all of the functionality previously in
110-
`DcmMetaExtension` except those related to acting as a Nifti1Extension.
111-
The `DcmMetaExtension` now provides just the functionality for being
108+
Resolved. We now have a separate `DcmMeta` object which inherits from
109+
`OrderedDict` and contains all of the functionality previously in
110+
`DcmMetaExtension` except those related to acting as a Nifti1Extension.
111+
The `DcmMetaExtension` now provides just the functionality for being
112112
a Nifti1Extension.
113113

114114
Keeping track of metadata when manipulating images
@@ -117,13 +117,13 @@ Keeping track of metadata when manipulating images
117117
When slicing images, it is good to be able to keep track of the relevant DICOM
118118
metadata for the particular slice. Or when merging images, it is good to be
119119
able to compile the metadata across slices into the (e.g) volume metadata. Or,
120-
say, when coregistering an image, it is good to be able to know that the
121-
metadata that is per-slice no longer directly corresponds to a slice of the
122-
data array.
120+
say, when coregistering an image, it is good to be able to know that the
121+
metadata that is per-slice no longer directly corresponds to a slice of the
122+
data array.
123123

124124
At the moment, dcmstack deals with this by wrapping the image with DICOM meta
125125
information in `NiftiWrapper` object : see
126-
https://github.com/moloney/dcmstack/blob/master/src/dcmstack/dcmmeta.py#L1185 .
126+
https://github.com/moloney/dcmstack/blob/d1577412860fecd93365e0e0e097f6f87e14aee0/src/dcmstack/dcmmeta.py#L1232.
127127
This object accepts a Nifti image as input, that usually contains a
128128
`DcmMetaExtension`, and has methods `get_meta` (to get metadata from extension),
129129
`split` (for taking slice specific metadata into the split parts), `meta_valid`
@@ -146,8 +146,8 @@ Put the `DcmMeta` data into the `extra` object that is input to the
146146
Add a `get_meta` method to `SpatialImage` that uses the to-be-defined API of the
147147
`extra` object. Maybe, by default, this would just get keys out of the mapping.
148148

149-
Define an API for the `extra` object to give back metadata that is potentially
150-
varying (per slice or volume). We also need a way to populate the `extra` object
149+
Define an API for the `extra` object to give back metadata that is potentially
150+
varying (per slice or volume). We also need a way to populate the `extra` object
151151
when loading an image that has an associated `DcmMeta` object.
152152

153153
Use this API to get metadata. Try and make this work with functions outside the
@@ -179,57 +179,57 @@ Add `create_dcmmeta` method to the nibabel DICOM wrapper objects, that can be
179179
specialized for each known DICOM format variation. Put the rules for slice
180180
information etc into each class.
181181

182-
For the Siemens files, we will need to make a list of elements from the private
183-
CSA headers that are known to be slice specific. For the multiframe DICOM files
184-
we should be able to do this in a programmatic manner, since the varying data
185-
should live in the PerFrameFunctionalSequence DICOM element. Each element that
186-
is reclassified should be simplified with the `DcmMeta.simplify` method so that
187-
it can be classified appropriately.
182+
For the Siemens files, we will need to make a list of elements from the private
183+
CSA headers that are known to be slice specific. For the multiframe DICOM files
184+
we should be able to do this in a programmatic manner, since the varying data
185+
should live in the PerFrameFunctionalSequence DICOM element. Each element that
186+
is reclassified should be simplified with the `DcmMeta.simplify` method so that
187+
it can be classified appropriately.
188188

189189
Meta data in nested DICOM sequences can not be independently classified
190190
=======================================================================
191191

192-
The code for summarizing meta data only works on the top level of key/value
193-
pairs. Any value that is a nested dataset is treated as a single entity,
194-
which prevents us from classifying its individual elements differently.
192+
The code for summarizing meta data only works on the top level of key/value
193+
pairs. Any value that is a nested dataset is treated as a single entity,
194+
which prevents us from classifying its individual elements differently.
195195

196-
In a DICOM data set, any element that is a sequence contains one or more
197-
nested DICOM data sets. For most MRI images this is not an issue since
198-
they rarely contain many sequences, and the ones they do are usually small
199-
and relatively unimportant. However in multiframe DICOM files make heavy
196+
In a DICOM data set, any element that is a sequence contains one or more
197+
nested DICOM data sets. For most MRI images this is not an issue since
198+
they rarely contain many sequences, and the ones they do are usually small
199+
and relatively unimportant. However in multiframe DICOM files make heavy
200200
use of nested sequences to store data.
201201

202202
Plan
203203
----
204-
This same issue was solved for the translated Siemens CSA sub headers by
205-
unpacking each nested dataset by joining the keys from each level with a
206-
dotted notation. For example, in the `CsaSeries` subheader there is a nested
207-
`MrPhoenixProtocol` dataset which has an element `ulVersion` so the key we
208-
use after unpacking is `CsaSeries.MrPhoenixProtocol.ulVersion`.
204+
This same issue was solved for the translated Siemens CSA sub headers by
205+
unpacking each nested dataset by joining the keys from each level with a
206+
dotted notation. For example, in the `CsaSeries` subheader there is a nested
207+
`MrPhoenixProtocol` dataset which has an element `ulVersion` so the key we
208+
use after unpacking is `CsaSeries.MrPhoenixProtocol.ulVersion`.
209209

210-
We can take the same approach for DICOM sequence elements. One additional
210+
We can take the same approach for DICOM sequence elements. One additional
211211
consideration is that each of these element is actually a list of data sets,
212212
so we would need to add an index number to the key somehow.
213213

214-
The alternative is to handle nested data sets recursively in the meta data
215-
summarizing code. This would be fairly complex and you would no longer be
216-
able to refer to each element with a single string, at least not without
214+
The alternative is to handle nested data sets recursively in the meta data
215+
summarizing code. This would be fairly complex and you would no longer be
216+
able to refer to each element with a single string, at least not without
217217
some mini-language for traversing the nested datasets.
218218

219219
Improving access to varying meta data through the Nifti
220220
=======================================================
221221

222-
Currently, when accessing varying meta data through the `get_meta` method
222+
Currently, when accessing varying meta data through the `get_meta` method
223223
you can only get one value at a time::
224224

225-
>>> echo_times = [nii.get_meta('EchoTime', (0, 0, 0, idx))
225+
>>> echo_times = [nii.get_meta('EchoTime', (0, 0, 0, idx))
226226
for idx in xrange(data.shape[-1])]
227227

228-
You can easily get multiple values from the `DcmMeta` object itself, but
229-
then you lose the capability to automatically check if the meta data is
228+
You can easily get multiple values from the `DcmMeta` object itself, but
229+
then you lose the capability to automatically check if the meta data is
230230
valid in relation to the current image.
231231

232232

233233
.. _dcmstack : https://github.com/moloney/dcmstack
234-
.. _DcmMetaExtension : https://github.com/moloney/dcmstack/blob/master/src/dcmstack/dcmmeta.py#L92
234+
.. _DcmMetaExtension : https://github.com/moloney/dcmstack/blob/d1577412860fecd93365e0e0e097f6f87e14aee0/src/dcmstack/dcmmeta.py#L112
235235
.. vim: ft=rst

doc/source/devel/biaps/biap_0006.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ In NIfTI:
194194
We saw above that the MGH format refers to a volume (in our sense) as a
195195
*frame*. ECAT has the same usage - a frame is a 3D volume. The fmristat
196196
software uses frame in the same sense, e.g., `line 32 of example.m
197-
<https://github.com/matthew-brett/fmristat/blob/master/fmristat/example.m#L32>`_.
197+
<https://github.com/matthew-brett/fmristat/blob/64ad8bf35eeb7142395659a1ff6bdcf3e69c202f/fmristat/example.m#L32>`_.
198198

199199
Unfortunately DICOM appears to use "frame" to mean a 2D slice. For example,
200200
here is the definition of a "multi-frame image"::

0 commit comments

Comments
 (0)