csa-header 1.0.2__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {csa_header-1.0.2 → csa_header-2.0.0}/CHANGELOG.md +44 -0
  2. {csa_header-1.0.2 → csa_header-2.0.0}/PKG-INFO +92 -14
  3. {csa_header-1.0.2 → csa_header-2.0.0}/README.md +90 -13
  4. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/__about__.py +1 -1
  5. csa_header-2.0.0/csa_header/examples.py +197 -0
  6. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/header.py +25 -1
  7. {csa_header-1.0.2 → csa_header-2.0.0}/examples/README.md +52 -0
  8. csa_header-2.0.0/examples/basic_usage_example.py +235 -0
  9. {csa_header-1.0.2 → csa_header-2.0.0}/pyproject.toml +4 -4
  10. csa_header-2.0.0/tests/test_documentation_examples.py +275 -0
  11. csa_header-2.0.0/tests/test_examples.py +286 -0
  12. {csa_header-1.0.2 → csa_header-2.0.0}/tests/test_header.py +0 -18
  13. {csa_header-1.0.2 → csa_header-2.0.0}/.gitignore +0 -0
  14. {csa_header-1.0.2 → csa_header-2.0.0}/CODE_OF_CONDUCT.md +0 -0
  15. {csa_header-1.0.2 → csa_header-2.0.0}/CONTRIBUTING.md +0 -0
  16. {csa_header-1.0.2 → csa_header-2.0.0}/LICENSE.txt +0 -0
  17. {csa_header-1.0.2 → csa_header-2.0.0}/SECURITY.md +0 -0
  18. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/__init__.py +0 -0
  19. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/ascii/__init__.py +0 -0
  20. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/ascii/ascconv.py +0 -0
  21. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/ascii/header.py +0 -0
  22. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/ascii/messages.py +0 -0
  23. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/exceptions.py +0 -0
  24. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/messages.py +0 -0
  25. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/unpacker.py +0 -0
  26. {csa_header-1.0.2 → csa_header-2.0.0}/csa_header/utils.py +0 -0
  27. {csa_header-1.0.2 → csa_header-2.0.0}/examples/nibabel_integration.py +0 -0
  28. {csa_header-1.0.2 → csa_header-2.0.0}/tests/__init__.py +0 -0
  29. {csa_header-1.0.2 → csa_header-2.0.0}/tests/ascii/__init__.py +0 -0
  30. {csa_header-1.0.2 → csa_header-2.0.0}/tests/ascii/fixtures.py +0 -0
  31. {csa_header-1.0.2 → csa_header-2.0.0}/tests/ascii/test_ascconv_parsing.py +0 -0
  32. {csa_header-1.0.2 → csa_header-2.0.0}/tests/ascii/test_ascconv_sample.py +0 -0
  33. {csa_header-1.0.2 → csa_header-2.0.0}/tests/ascii/test_header.py +0 -0
  34. {csa_header-1.0.2 → csa_header-2.0.0}/tests/benchmarks/__init__.py +0 -0
  35. {csa_header-1.0.2 → csa_header-2.0.0}/tests/benchmarks/bench_parsing.py +0 -0
  36. {csa_header-1.0.2 → csa_header-2.0.0}/tests/files/__init__.py +0 -0
  37. {csa_header-1.0.2 → csa_header-2.0.0}/tests/files/ascconv_sample.txt +0 -0
  38. {csa_header-1.0.2 → csa_header-2.0.0}/tests/files/dwi_image_header_info +0 -0
  39. {csa_header-1.0.2 → csa_header-2.0.0}/tests/files/e11_series_header_info +0 -0
  40. {csa_header-1.0.2 → csa_header-2.0.0}/tests/files/rsfmri_series_header_info +0 -0
  41. {csa_header-1.0.2 → csa_header-2.0.0}/tests/fixtures.py +0 -0
  42. {csa_header-1.0.2 → csa_header-2.0.0}/tests/test_unpacker.py +0 -0
@@ -7,6 +7,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0] - 2025-11-01
11
+
12
+ ### 🔥 Breaking Changes
13
+
14
+ #### Removed redundant 'index' field from parsed CSA tags
15
+
16
+ **What changed:**
17
+ - The `'index'` field has been removed from each tag dictionary returned by `CsaHeader.read()`
18
+ - Tags now contain only: `'VR'` (Value Representation), `'VM'` (Value Multiplicity), and `'value'`
19
+
20
+ **Why:**
21
+ - The `'index'` field was redundant with Python's guaranteed dict ordering (Python 3.7+)
22
+ - Since the minimum supported Python version is 3.9, dict insertion order is guaranteed by the language
23
+ - This simplifies the API and follows the DRY (Don't Repeat Yourself) principle
24
+ - Resolves issue #15
25
+
26
+ **Migration guide:**
27
+
28
+ Before (v1.x):
29
+ ```python
30
+ parsed = CsaHeader(raw_csa).read()
31
+ for tag_name, tag_data in parsed.items():
32
+ idx = tag_data['index'] # Direct access to index field
33
+ print(f"Tag {idx}: {tag_name}")
34
+ ```
35
+
36
+ After (v2.0):
37
+ ```python
38
+ parsed = CsaHeader(raw_csa).read()
39
+ for idx, (tag_name, tag_data) in enumerate(parsed.items(), 1):
40
+ print(f"Tag {idx}: {tag_name}")
41
+ ```
42
+
43
+ **Note:** Tag ordering is preserved via Python's dict insertion order (guaranteed since Python 3.7). Tags appear in the same sequential order as they do in the CSA header.
44
+
45
+ ### Added
46
+ - Comprehensive docstring for `CsaHeader.read()` method explaining dict ordering guarantees
47
+ - Migration examples in CHANGELOG showing how to enumerate tags if explicit indices are needed
48
+
49
+ ### Changed
50
+ - Simplified tag structure from `{'index': int, 'VR': str, 'VM': int, 'value': Any}` to `{'VR': str, 'VM': int, 'value': Any}`
51
+ - Updated README examples to reflect new tag structure without 'index' field
52
+ - Updated test suite to verify tags no longer contain 'index' field
53
+
10
54
  ## [1.0.1] - 2025-10-28
11
55
 
12
56
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csa_header
3
- Version: 1.0.2
3
+ Version: 2.0.0
4
4
  Summary: Parse Siemens CSA header information
5
5
  Project-URL: Documentation, https://github.com/open-dicom/csa_header#readme
6
6
  Project-URL: Issues, https://github.com/open-dicom/csa_header/issues
@@ -25,17 +25,29 @@ Requires-Dist: ipython; extra == 'dev'
25
25
  Requires-Dist: pre-commit; extra == 'dev'
26
26
  Provides-Extra: examples
27
27
  Requires-Dist: nibabel>=3.0.0; extra == 'examples'
28
+ Requires-Dist: pooch>=1.6.0; extra == 'examples'
28
29
  Description-Content-Type: text/markdown
29
30
 
30
31
  # CSA Header
31
32
 
32
33
  Parse CSA header information from Siemens MRI acquisitions with Python.
33
34
 
35
+ ### Package & Distribution
34
36
  [![PyPI - Version](https://img.shields.io/pypi/v/csa_header.svg)](https://pypi.org/project/csa_header)
35
37
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/csa_header.svg)](https://pypi.org/project/csa_header)
38
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/csa_header.svg)](https://pypi.org/project/csa_header)
39
+
40
+ ### Build & Quality Assurance
36
41
  [![Tests](https://github.com/open-dicom/csa_header/actions/workflows/tests.yml/badge.svg)](https://github.com/open-dicom/csa_header/actions/workflows/tests.yml)
37
42
  [![codecov](https://codecov.io/gh/open-dicom/csa_header/branch/main/graph/badge.svg)](https://codecov.io/gh/open-dicom/csa_header)
38
43
  [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/open-dicom/csa_header/main.svg)](https://results.pre-commit.ci/latest/github/open-dicom/csa_header/main)
44
+
45
+ ### Code Quality & Style
46
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
47
+ [![Mypy checked](https://img.shields.io/badge/types-Checked%20with%20mypy-blue.svg)](http://mypy-lang.org/)
48
+
49
+ ### Citation & License
50
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17474448.svg)](https://doi.org/10.5281/zenodo.17474448)
39
51
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
40
52
 
41
53
  ---
@@ -78,6 +90,7 @@ The _CSA Image Header Info_ and _CSA Series Header Info_ elements contain encode
78
90
  - [Examples](#examples)
79
91
  - [Tests](#tests)
80
92
  - [Contributing](#contributing)
93
+ - [Citation](#citation)
81
94
  - [License](#license)
82
95
 
83
96
  ## Installation
@@ -88,12 +101,16 @@ pip install csa_header
88
101
 
89
102
  ### Optional Dependencies
90
103
 
91
- For working with the provided [NiBabel integration examples](#integration-with-nibabel):
104
+ For working with the provided examples and automatic example data downloading:
92
105
 
93
106
  ```console
94
107
  pip install csa_header[examples]
95
108
  ```
96
109
 
110
+ This installs:
111
+ - `nibabel` for NiBabel integration examples
112
+ - `pooch` for automatic downloading of example DICOM files
113
+
97
114
  For development (includes pre-commit hooks and IPython):
98
115
 
99
116
  ```console
@@ -102,6 +119,33 @@ pip install csa_header[dev]
102
119
 
103
120
  ## Quickstart
104
121
 
122
+ ### Option 1: Using Example Data (Easiest!)
123
+
124
+ The quickest way to get started is using the built-in example data:
125
+
126
+ ```python
127
+ >>> # Install with examples support
128
+ >>> # pip install csa_header[examples]
129
+ >>>
130
+ >>> from csa_header.examples import fetch_example_dicom
131
+ >>> from csa_header import CsaHeader
132
+ >>> import pydicom
133
+ >>>
134
+ >>> # Fetch example DICOM (downloads once, then cached)
135
+ >>> dicom_path = fetch_example_dicom()
136
+ >>> dcm = pydicom.dcmread(dicom_path)
137
+ >>>
138
+ >>> # Parse CSA Series Header
139
+ >>> raw_csa = dcm[(0x29, 0x1020)].value
140
+ >>> parsed_csa = CsaHeader(raw_csa).read()
141
+ >>> len(parsed_csa)
142
+ 79
143
+ ```
144
+
145
+ The example file is an anonymized Siemens MPRAGE scan hosted on Zenodo: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17482132.svg)](https://doi.org/10.5281/zenodo.17482132)
146
+
147
+ ### Option 2: Using Your Own DICOM Files
148
+
105
149
  Use [`pydicom`](https://github.com/pydicom/pydicom) to read a DICOM header:
106
150
 
107
151
  ```python
@@ -132,20 +176,18 @@ Parse the contents of the CSA header with the `CsaHeader` class:
132
176
  >>> parsed_csa = CsaHeader(raw_csa).read()
133
177
  >>> parsed_csa
134
178
  {
135
- 'NumberOfPrescans': {'index': 1, 'VR': 'IS', 'VM': 1, 'value': 0},
136
- 'TransmitterCalibration': {'index': 2, 'VR': 'DS', 'VM': 1, 'value': 247.102},
137
- 'PhaseGradientAmplitude': {'index': 3, 'VR': 'DS', 'VM': 1, 'value': 0.0},
138
- 'ReadoutGradientAmplitude': {'index': 4, 'VR': 'DS', 'VM': 1, 'value': 0.0},
139
- 'SelectionGradientAmplitude': {'index': 5, 'VR': 'DS', 'VM': 1, 'value': 0.0},
140
- 'GradientDelayTime': {'index': 6,
141
- 'VR': 'DS',
179
+ 'NumberOfPrescans': {'VR': 'IS', 'VM': 1, 'value': 0},
180
+ 'TransmitterCalibration': {'VR': 'DS', 'VM': 1, 'value': 247.102},
181
+ 'PhaseGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
182
+ 'ReadoutGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
183
+ 'SelectionGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
184
+ 'GradientDelayTime': {'VR': 'DS',
142
185
  'VM': 3,
143
186
  'value': [36.0, 35.0, 31.0]},
144
- 'RfWatchdogMask': {'index': 7, 'VR': 'IS', 'VM': 1, 'value': 0},
145
- 'RfPowerErrorIndicator': {'index': 8, 'VR': 'DS', 'VM': 1, 'value': None},
146
- 'SarWholeBody': {'index': 9, 'VR': 'DS', 'VM': 3, 'value': None},
147
- 'Sed': {'index': 10,
148
- 'VR': 'DS',
187
+ 'RfWatchdogMask': {'VR': 'IS', 'VM': 1, 'value': 0},
188
+ 'RfPowerErrorIndicator': {'VR': 'DS', 'VM': 1, 'value': None},
189
+ 'SarWholeBody': {'VR': 'DS', 'VM': 3, 'value': None},
190
+ 'Sed': {'VR': 'DS',
149
191
  'VM': 3,
150
192
  'value': [1000000.0, 324.74800987, 324.74800832]}
151
193
  ...
@@ -237,6 +279,12 @@ See [examples/nibabel_integration.py](examples/nibabel_integration.py) for compl
237
279
 
238
280
  The [examples/](examples/) directory contains comprehensive usage examples:
239
281
 
282
+ - **[basic_usage_example.py](examples/basic_usage_example.py)**: Beginner-friendly introduction using example data
283
+ - Automatic download of example DICOM files
284
+ - Basic CSA header parsing
285
+ - Accessing specific CSA tags
286
+ - Perfect for first-time users!
287
+
240
288
  - **[nibabel_integration.py](examples/nibabel_integration.py)**: Complete workflow combining csa_header with NiBabel
241
289
  - Extract DWI parameters (b-values, gradients)
242
290
  - Extract fMRI parameters (slice timing, TR/TE)
@@ -245,6 +293,10 @@ The [examples/](examples/) directory contains comprehensive usage examples:
245
293
 
246
294
  Run examples:
247
295
  ```bash
296
+ # Basic example with automatic data download
297
+ python examples/basic_usage_example.py
298
+
299
+ # NiBabel integration with your own DICOM
248
300
  python examples/nibabel_integration.py path/to/siemens_dicom.dcm
249
301
  ```
250
302
 
@@ -307,6 +359,32 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for complete development guidelines inclu
307
359
  - Commit message conventions
308
360
  - Pull request process
309
361
 
362
+ ## Citation
363
+
364
+ If you use `csa_header` in your research, please cite it using the following:
365
+
366
+ **BibTeX:**
367
+ ```bibtex
368
+ @software{baratz_2025_csa_header,
369
+ author = {Baratz, Zvi and Brett, Matthew},
370
+ title = {csa_header: Parse CSA header information from Siemens MRI acquisitions},
371
+ year = 2025,
372
+ publisher = {Zenodo},
373
+ version = {v1.0.2},
374
+ doi = {10.5281/zenodo.17474448},
375
+ url = {https://doi.org/10.5281/zenodo.17474448}
376
+ }
377
+ ```
378
+
379
+ **APA:**
380
+ ```
381
+ Baratz, Z., & Brett, M. (2025). csa_header: Parse CSA header information from Siemens MRI acquisitions (v1.0.2). Zenodo. https://doi.org/10.5281/zenodo.17474448
382
+ ```
383
+
384
+ For the specific version you're using, please check the [Zenodo record](https://doi.org/10.5281/zenodo.17474448) for the appropriate DOI and citation information.
385
+
386
+ Alternatively, you can use the [CITATION.cff](CITATION.cff) file in this repository, which is automatically recognized by GitHub and can be imported into reference managers.
387
+
310
388
  ## License
311
389
 
312
390
  `csa_header` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -2,11 +2,22 @@
2
2
 
3
3
  Parse CSA header information from Siemens MRI acquisitions with Python.
4
4
 
5
+ ### Package & Distribution
5
6
  [![PyPI - Version](https://img.shields.io/pypi/v/csa_header.svg)](https://pypi.org/project/csa_header)
6
7
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/csa_header.svg)](https://pypi.org/project/csa_header)
8
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/csa_header.svg)](https://pypi.org/project/csa_header)
9
+
10
+ ### Build & Quality Assurance
7
11
  [![Tests](https://github.com/open-dicom/csa_header/actions/workflows/tests.yml/badge.svg)](https://github.com/open-dicom/csa_header/actions/workflows/tests.yml)
8
12
  [![codecov](https://codecov.io/gh/open-dicom/csa_header/branch/main/graph/badge.svg)](https://codecov.io/gh/open-dicom/csa_header)
9
13
  [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/open-dicom/csa_header/main.svg)](https://results.pre-commit.ci/latest/github/open-dicom/csa_header/main)
14
+
15
+ ### Code Quality & Style
16
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
17
+ [![Mypy checked](https://img.shields.io/badge/types-Checked%20with%20mypy-blue.svg)](http://mypy-lang.org/)
18
+
19
+ ### Citation & License
20
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17474448.svg)](https://doi.org/10.5281/zenodo.17474448)
10
21
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
22
 
12
23
  ---
@@ -49,6 +60,7 @@ The _CSA Image Header Info_ and _CSA Series Header Info_ elements contain encode
49
60
  - [Examples](#examples)
50
61
  - [Tests](#tests)
51
62
  - [Contributing](#contributing)
63
+ - [Citation](#citation)
52
64
  - [License](#license)
53
65
 
54
66
  ## Installation
@@ -59,12 +71,16 @@ pip install csa_header
59
71
 
60
72
  ### Optional Dependencies
61
73
 
62
- For working with the provided [NiBabel integration examples](#integration-with-nibabel):
74
+ For working with the provided examples and automatic example data downloading:
63
75
 
64
76
  ```console
65
77
  pip install csa_header[examples]
66
78
  ```
67
79
 
80
+ This installs:
81
+ - `nibabel` for NiBabel integration examples
82
+ - `pooch` for automatic downloading of example DICOM files
83
+
68
84
  For development (includes pre-commit hooks and IPython):
69
85
 
70
86
  ```console
@@ -73,6 +89,33 @@ pip install csa_header[dev]
73
89
 
74
90
  ## Quickstart
75
91
 
92
+ ### Option 1: Using Example Data (Easiest!)
93
+
94
+ The quickest way to get started is using the built-in example data:
95
+
96
+ ```python
97
+ >>> # Install with examples support
98
+ >>> # pip install csa_header[examples]
99
+ >>>
100
+ >>> from csa_header.examples import fetch_example_dicom
101
+ >>> from csa_header import CsaHeader
102
+ >>> import pydicom
103
+ >>>
104
+ >>> # Fetch example DICOM (downloads once, then cached)
105
+ >>> dicom_path = fetch_example_dicom()
106
+ >>> dcm = pydicom.dcmread(dicom_path)
107
+ >>>
108
+ >>> # Parse CSA Series Header
109
+ >>> raw_csa = dcm[(0x29, 0x1020)].value
110
+ >>> parsed_csa = CsaHeader(raw_csa).read()
111
+ >>> len(parsed_csa)
112
+ 79
113
+ ```
114
+
115
+ The example file is an anonymized Siemens MPRAGE scan hosted on Zenodo: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17482132.svg)](https://doi.org/10.5281/zenodo.17482132)
116
+
117
+ ### Option 2: Using Your Own DICOM Files
118
+
76
119
  Use [`pydicom`](https://github.com/pydicom/pydicom) to read a DICOM header:
77
120
 
78
121
  ```python
@@ -103,20 +146,18 @@ Parse the contents of the CSA header with the `CsaHeader` class:
103
146
  >>> parsed_csa = CsaHeader(raw_csa).read()
104
147
  >>> parsed_csa
105
148
  {
106
- 'NumberOfPrescans': {'index': 1, 'VR': 'IS', 'VM': 1, 'value': 0},
107
- 'TransmitterCalibration': {'index': 2, 'VR': 'DS', 'VM': 1, 'value': 247.102},
108
- 'PhaseGradientAmplitude': {'index': 3, 'VR': 'DS', 'VM': 1, 'value': 0.0},
109
- 'ReadoutGradientAmplitude': {'index': 4, 'VR': 'DS', 'VM': 1, 'value': 0.0},
110
- 'SelectionGradientAmplitude': {'index': 5, 'VR': 'DS', 'VM': 1, 'value': 0.0},
111
- 'GradientDelayTime': {'index': 6,
112
- 'VR': 'DS',
149
+ 'NumberOfPrescans': {'VR': 'IS', 'VM': 1, 'value': 0},
150
+ 'TransmitterCalibration': {'VR': 'DS', 'VM': 1, 'value': 247.102},
151
+ 'PhaseGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
152
+ 'ReadoutGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
153
+ 'SelectionGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
154
+ 'GradientDelayTime': {'VR': 'DS',
113
155
  'VM': 3,
114
156
  'value': [36.0, 35.0, 31.0]},
115
- 'RfWatchdogMask': {'index': 7, 'VR': 'IS', 'VM': 1, 'value': 0},
116
- 'RfPowerErrorIndicator': {'index': 8, 'VR': 'DS', 'VM': 1, 'value': None},
117
- 'SarWholeBody': {'index': 9, 'VR': 'DS', 'VM': 3, 'value': None},
118
- 'Sed': {'index': 10,
119
- 'VR': 'DS',
157
+ 'RfWatchdogMask': {'VR': 'IS', 'VM': 1, 'value': 0},
158
+ 'RfPowerErrorIndicator': {'VR': 'DS', 'VM': 1, 'value': None},
159
+ 'SarWholeBody': {'VR': 'DS', 'VM': 3, 'value': None},
160
+ 'Sed': {'VR': 'DS',
120
161
  'VM': 3,
121
162
  'value': [1000000.0, 324.74800987, 324.74800832]}
122
163
  ...
@@ -208,6 +249,12 @@ See [examples/nibabel_integration.py](examples/nibabel_integration.py) for compl
208
249
 
209
250
  The [examples/](examples/) directory contains comprehensive usage examples:
210
251
 
252
+ - **[basic_usage_example.py](examples/basic_usage_example.py)**: Beginner-friendly introduction using example data
253
+ - Automatic download of example DICOM files
254
+ - Basic CSA header parsing
255
+ - Accessing specific CSA tags
256
+ - Perfect for first-time users!
257
+
211
258
  - **[nibabel_integration.py](examples/nibabel_integration.py)**: Complete workflow combining csa_header with NiBabel
212
259
  - Extract DWI parameters (b-values, gradients)
213
260
  - Extract fMRI parameters (slice timing, TR/TE)
@@ -216,6 +263,10 @@ The [examples/](examples/) directory contains comprehensive usage examples:
216
263
 
217
264
  Run examples:
218
265
  ```bash
266
+ # Basic example with automatic data download
267
+ python examples/basic_usage_example.py
268
+
269
+ # NiBabel integration with your own DICOM
219
270
  python examples/nibabel_integration.py path/to/siemens_dicom.dcm
220
271
  ```
221
272
 
@@ -278,6 +329,32 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for complete development guidelines inclu
278
329
  - Commit message conventions
279
330
  - Pull request process
280
331
 
332
+ ## Citation
333
+
334
+ If you use `csa_header` in your research, please cite it using the following:
335
+
336
+ **BibTeX:**
337
+ ```bibtex
338
+ @software{baratz_2025_csa_header,
339
+ author = {Baratz, Zvi and Brett, Matthew},
340
+ title = {csa_header: Parse CSA header information from Siemens MRI acquisitions},
341
+ year = 2025,
342
+ publisher = {Zenodo},
343
+ version = {v1.0.2},
344
+ doi = {10.5281/zenodo.17474448},
345
+ url = {https://doi.org/10.5281/zenodo.17474448}
346
+ }
347
+ ```
348
+
349
+ **APA:**
350
+ ```
351
+ Baratz, Z., & Brett, M. (2025). csa_header: Parse CSA header information from Siemens MRI acquisitions (v1.0.2). Zenodo. https://doi.org/10.5281/zenodo.17474448
352
+ ```
353
+
354
+ For the specific version you're using, please check the [Zenodo record](https://doi.org/10.5281/zenodo.17474448) for the appropriate DOI and citation information.
355
+
356
+ Alternatively, you can use the [CITATION.cff](CITATION.cff) file in this repository, which is automatically recognized by GitHub and can be imported into reference managers.
357
+
281
358
  ## License
282
359
 
283
360
  `csa_header` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2023-present Zvi Baratz <z.baratz@gmail.com>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "1.0.2"
4
+ __version__ = "2.0.0"
@@ -0,0 +1,197 @@
1
+ """Example data fetching using Pooch.
2
+
3
+ This module provides functions to download example DICOM files with Siemens CSA headers
4
+ for demonstration and testing purposes. The example data is hosted on Zenodo and
5
+ downloaded on first use, then cached locally.
6
+
7
+ Installation
8
+ ------------
9
+ To use this module, install csa_header with the examples optional dependency::
10
+
11
+ pip install csa_header[examples]
12
+
13
+ Usage
14
+ -----
15
+ >>> from csa_header.examples import fetch_example_dicom
16
+ >>> dicom_path = fetch_example_dicom('mprage_example_anon.dcm')
17
+ >>> import pydicom
18
+ >>> dcm = pydicom.dcmread(dicom_path)
19
+ >>> from csa_header import CsaHeader
20
+ >>> csa = CsaHeader(dcm.get((0x29, 0x1020)).value)
21
+ >>> result = csa.read()
22
+ """
23
+
24
+ try:
25
+ import pooch # type: ignore[import-not-found]
26
+
27
+ POOCH_AVAILABLE = True
28
+ except ImportError: # pragma: no cover
29
+ POOCH_AVAILABLE = False # pragma: no cover
30
+
31
+
32
+ # Zenodo DOI and record information
33
+ ZENODO_DOI = "10.5281/zenodo.17482132"
34
+ ZENODO_RECORD_ID = "17482132"
35
+ # Note: Zenodo API requires /content suffix to download actual file content
36
+ ZENODO_BASE_URL = f"https://zenodo.org/api/records/{ZENODO_RECORD_ID}/files/{{fpath}}/content"
37
+
38
+ # File registry with SHA256 checksums
39
+ REGISTRY = {
40
+ "mprage_example_anon.dcm": "sha256:831fa610f8853fbd7f5602e896824480af701dfc7286f9df30d1cc2302c2022e",
41
+ }
42
+
43
+ # Available example files
44
+ AVAILABLE_FILES = list(REGISTRY.keys())
45
+
46
+
47
+ def fetch_example_dicom(filename="mprage_example_anon.dcm"):
48
+ """Fetch an example DICOM file with Siemens CSA headers.
49
+
50
+ Downloads example DICOM files from Zenodo on first use and caches them locally
51
+ for subsequent uses. All example files have been anonymized to remove Protected
52
+ Health Information (PHI).
53
+
54
+ Parameters
55
+ ----------
56
+ filename : str, optional
57
+ Name of the example file to fetch. Default is 'mprage_example_anon.dcm'.
58
+ Use `list_example_files()` to see all available files.
59
+
60
+ Returns
61
+ -------
62
+ str
63
+ Path to the downloaded and cached DICOM file.
64
+
65
+ Raises
66
+ ------
67
+ ImportError
68
+ If pooch is not installed. Install with: pip install csa_header[examples]
69
+ ValueError
70
+ If the specified filename is not available in the registry.
71
+
72
+ Examples
73
+ --------
74
+ >>> from csa_header.examples import fetch_example_dicom
75
+ >>> dicom_path = fetch_example_dicom()
76
+ >>> print(dicom_path)
77
+ /home/user/.cache/pooch/...mprage_example_anon.dcm
78
+
79
+ >>> # Use with pydicom and csa_header
80
+ >>> import pydicom
81
+ >>> from csa_header import CsaHeader
82
+ >>> dcm = pydicom.dcmread(dicom_path)
83
+ >>> csa_bytes = dcm.get((0x29, 0x1020)).value
84
+ >>> csa = CsaHeader(csa_bytes)
85
+ >>> tags = csa.read()
86
+
87
+ Notes
88
+ -----
89
+ The example data is hosted on Zenodo at https://doi.org/10.5281/zenodo.17482132
90
+ and is licensed under CC0 (Public Domain).
91
+
92
+ The MPRAGE example file contains:
93
+ - Modality: MR (Magnetic Resonance)
94
+ - Sequence: MPRAGE (Enhanced Contrast)
95
+ - Image dimensions: 224 x 224
96
+ - CSA Image Header: 11,196 bytes
97
+ - CSA Series Header: 139,232 bytes
98
+ """
99
+ if not POOCH_AVAILABLE: # pragma: no cover
100
+ msg = (
101
+ "Example data fetching requires the 'pooch' package. "
102
+ "Install it with:\n\n"
103
+ " pip install csa_header[examples]\n\n"
104
+ "or install pooch directly:\n\n"
105
+ " pip install pooch"
106
+ )
107
+ raise ImportError(msg)
108
+
109
+ if filename not in REGISTRY:
110
+ available = ", ".join(AVAILABLE_FILES)
111
+ msg = (
112
+ f"File '{filename}' not found in registry. "
113
+ f"Available files: {available}. "
114
+ f"Use list_example_files() to see all options."
115
+ )
116
+ raise ValueError(msg)
117
+
118
+ # Create Pooch instance for fetching data
119
+ # Zenodo API requires special URL handling - we provide full URLs
120
+ fetcher = pooch.create( # pragma: no cover
121
+ path=pooch.os_cache("csa_header"),
122
+ base_url="", # Empty base_url since we provide full URLs
123
+ registry={filename: REGISTRY[filename]}, # Include hash in registry
124
+ urls={filename: f"https://zenodo.org/api/records/{ZENODO_RECORD_ID}/files/{filename}/content"},
125
+ )
126
+
127
+ # Fetch the file (downloads if not cached, validates checksum)
128
+ return fetcher.fetch(filename) # pragma: no cover
129
+
130
+
131
+ def list_example_files():
132
+ """List all available example DICOM files.
133
+
134
+ Returns
135
+ -------
136
+ list of str
137
+ Names of all available example files.
138
+
139
+ Examples
140
+ --------
141
+ >>> from csa_header.examples import list_example_files
142
+ >>> files = list_example_files()
143
+ >>> print(files)
144
+ ['mprage_example_anon.dcm']
145
+ """
146
+ return AVAILABLE_FILES.copy()
147
+
148
+
149
+ def get_example_info(filename="mprage_example_anon.dcm"):
150
+ """Get information about an example file.
151
+
152
+ Parameters
153
+ ----------
154
+ filename : str, optional
155
+ Name of the example file. Default is 'mprage_example_anon.dcm'.
156
+
157
+ Returns
158
+ -------
159
+ dict
160
+ Dictionary containing information about the file including:
161
+ - name: filename
162
+ - checksum: SHA256 checksum
163
+ - url: Zenodo download URL
164
+ - doi: Zenodo DOI
165
+
166
+ Raises
167
+ ------
168
+ ValueError
169
+ If the specified filename is not available.
170
+
171
+ Examples
172
+ --------
173
+ >>> from csa_header.examples import get_example_info
174
+ >>> info = get_example_info()
175
+ >>> print(info['doi'])
176
+ 10.5281/zenodo.17482132
177
+ """
178
+ if filename not in REGISTRY:
179
+ available = ", ".join(AVAILABLE_FILES)
180
+ msg = f"File '{filename}' not found in registry. Available files: {available}"
181
+ raise ValueError(msg)
182
+
183
+ return {
184
+ "name": filename,
185
+ "checksum": REGISTRY[filename],
186
+ "url": ZENODO_BASE_URL + filename,
187
+ "doi": ZENODO_DOI,
188
+ }
189
+
190
+
191
+ __all__ = [
192
+ "AVAILABLE_FILES",
193
+ "ZENODO_DOI",
194
+ "fetch_example_dicom",
195
+ "get_example_info",
196
+ "list_example_files",
197
+ ]
@@ -262,7 +262,6 @@ class CsaHeader:
262
262
  vr = decode_latin1(vr_result)
263
263
  tag: dict[str, Any] = {
264
264
  "name": name,
265
- "index": i_tag,
266
265
  "VR": vr,
267
266
  "VM": vm,
268
267
  }
@@ -275,6 +274,31 @@ class CsaHeader:
275
274
  return tag
276
275
 
277
276
  def read(self) -> dict[str, dict[str, Any]]:
277
+ """
278
+ Parse the CSA header and return tag information as a dictionary.
279
+
280
+ Returns
281
+ -------
282
+ dict[str, dict[str, Any]]
283
+ Dictionary mapping tag names to tag information. Keys are ordered
284
+ by tag appearance in the CSA header (Python 3.7+ dict ordering
285
+ guarantee). Each tag dictionary contains:
286
+
287
+ - 'VR' : str
288
+ Value Representation (DICOM standard)
289
+ - 'VM' : int
290
+ Value Multiplicity (DICOM standard)
291
+ - 'value' : Any
292
+ Parsed tag value (type depends on VR)
293
+
294
+ Notes
295
+ -----
296
+ Tag ordering is preserved via Python's dict insertion order guarantee
297
+ (Python 3.7+). To enumerate tags with explicit indices:
298
+
299
+ >>> for idx, (name, tag) in enumerate(parsed.items(), 1):
300
+ ... print(f"Tag {idx}: {name}")
301
+ """
278
302
  unpacker = Unpacker(self.raw, endian=self.ENDIAN)
279
303
  self.skip_prefix(unpacker)
280
304
  n_tags, _ = unpacker.unpack(self.PREFIX_FORMAT)