csa-header 1.0.2__tar.gz → 2.0.1__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.1}/CHANGELOG.md +58 -0
  2. {csa_header-1.0.2 → csa_header-2.0.1}/PKG-INFO +95 -16
  3. {csa_header-1.0.2 → csa_header-2.0.1}/README.md +91 -14
  4. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/__about__.py +1 -1
  5. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/ascii/ascconv.py +26 -6
  6. csa_header-2.0.1/csa_header/examples.py +197 -0
  7. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/header.py +25 -1
  8. {csa_header-1.0.2 → csa_header-2.0.1}/examples/README.md +52 -0
  9. csa_header-2.0.1/examples/basic_usage_example.py +235 -0
  10. {csa_header-1.0.2 → csa_header-2.0.1}/pyproject.toml +6 -5
  11. {csa_header-1.0.2 → csa_header-2.0.1}/tests/ascii/test_ascconv_sample.py +18 -0
  12. csa_header-2.0.1/tests/test_documentation_examples.py +275 -0
  13. csa_header-2.0.1/tests/test_examples.py +286 -0
  14. {csa_header-1.0.2 → csa_header-2.0.1}/tests/test_header.py +0 -18
  15. {csa_header-1.0.2 → csa_header-2.0.1}/.gitignore +0 -0
  16. {csa_header-1.0.2 → csa_header-2.0.1}/CODE_OF_CONDUCT.md +0 -0
  17. {csa_header-1.0.2 → csa_header-2.0.1}/CONTRIBUTING.md +0 -0
  18. {csa_header-1.0.2 → csa_header-2.0.1}/LICENSE.txt +0 -0
  19. {csa_header-1.0.2 → csa_header-2.0.1}/SECURITY.md +0 -0
  20. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/__init__.py +0 -0
  21. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/ascii/__init__.py +0 -0
  22. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/ascii/header.py +0 -0
  23. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/ascii/messages.py +0 -0
  24. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/exceptions.py +0 -0
  25. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/messages.py +0 -0
  26. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/unpacker.py +0 -0
  27. {csa_header-1.0.2 → csa_header-2.0.1}/csa_header/utils.py +0 -0
  28. {csa_header-1.0.2 → csa_header-2.0.1}/examples/nibabel_integration.py +0 -0
  29. {csa_header-1.0.2 → csa_header-2.0.1}/tests/__init__.py +0 -0
  30. {csa_header-1.0.2 → csa_header-2.0.1}/tests/ascii/__init__.py +0 -0
  31. {csa_header-1.0.2 → csa_header-2.0.1}/tests/ascii/fixtures.py +0 -0
  32. {csa_header-1.0.2 → csa_header-2.0.1}/tests/ascii/test_ascconv_parsing.py +0 -0
  33. {csa_header-1.0.2 → csa_header-2.0.1}/tests/ascii/test_header.py +0 -0
  34. {csa_header-1.0.2 → csa_header-2.0.1}/tests/benchmarks/__init__.py +0 -0
  35. {csa_header-1.0.2 → csa_header-2.0.1}/tests/benchmarks/bench_parsing.py +0 -0
  36. {csa_header-1.0.2 → csa_header-2.0.1}/tests/files/__init__.py +0 -0
  37. {csa_header-1.0.2 → csa_header-2.0.1}/tests/files/ascconv_sample.txt +0 -0
  38. {csa_header-1.0.2 → csa_header-2.0.1}/tests/files/dwi_image_header_info +0 -0
  39. {csa_header-1.0.2 → csa_header-2.0.1}/tests/files/e11_series_header_info +0 -0
  40. {csa_header-1.0.2 → csa_header-2.0.1}/tests/files/rsfmri_series_header_info +0 -0
  41. {csa_header-1.0.2 → csa_header-2.0.1}/tests/fixtures.py +0 -0
  42. {csa_header-1.0.2 → csa_header-2.0.1}/tests/test_unpacker.py +0 -0
@@ -7,6 +7,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.1] - 2026-12-03
11
+
12
+ ### Fixed
13
+ - **Python 3.14 compatibility**: parsing an ASCCONV protocol (such as `MrPhoenixProtocol` in a series CSA header)
14
+ no longer fails with `AttributeError: module 'ast' has no attribute 'Num'`. Python 3.14 removed the `ast.Num` and
15
+ `ast.Str` aliases, so literal values are now read from `ast.Constant`. The fix follows Julia's
16
+ ([@juliam98](https://github.com/juliam98)) fix for the same code in dicom_parser
17
+ ([open-dicom/dicom_parser#127](https://github.com/open-dicom/dicom_parser/pull/127)).
18
+
19
+ ### Changed
20
+ - Python 3.14 is now tested in CI and listed in the package classifiers.
21
+
22
+ ## [2.0.0] - 2025-11-01
23
+
24
+ ### 🔥 Breaking Changes
25
+
26
+ #### Removed redundant 'index' field from parsed CSA tags
27
+
28
+ **What changed:**
29
+ - The `'index'` field has been removed from each tag dictionary returned by `CsaHeader.read()`
30
+ - Tags now contain only: `'VR'` (Value Representation), `'VM'` (Value Multiplicity), and `'value'`
31
+
32
+ **Why:**
33
+ - The `'index'` field was redundant with Python's guaranteed dict ordering (Python 3.7+)
34
+ - Since the minimum supported Python version is 3.9, dict insertion order is guaranteed by the language
35
+ - This simplifies the API and follows the DRY (Don't Repeat Yourself) principle
36
+ - Resolves issue #15
37
+
38
+ **Migration guide:**
39
+
40
+ Before (v1.x):
41
+ ```python
42
+ parsed = CsaHeader(raw_csa).read()
43
+ for tag_name, tag_data in parsed.items():
44
+ idx = tag_data['index'] # Direct access to index field
45
+ print(f"Tag {idx}: {tag_name}")
46
+ ```
47
+
48
+ After (v2.0):
49
+ ```python
50
+ parsed = CsaHeader(raw_csa).read()
51
+ for idx, (tag_name, tag_data) in enumerate(parsed.items(), 1):
52
+ print(f"Tag {idx}: {tag_name}")
53
+ ```
54
+
55
+ **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.
56
+
57
+ ### Added
58
+ - Comprehensive docstring for `CsaHeader.read()` method explaining dict ordering guarantees
59
+ - Migration examples in CHANGELOG showing how to enumerate tags if explicit indices are needed
60
+
61
+ ### Changed
62
+ - Simplified tag structure from `{'index': int, 'VR': str, 'VM': int, 'value': Any}` to `{'VR': str, 'VM': int, 'value': Any}`
63
+ - Updated README examples to reflect new tag structure without 'index' field
64
+ - Updated test suite to verify tags no longer contain 'index' field
65
+
10
66
  ## [1.0.1] - 2025-10-28
11
67
 
12
68
  ### Fixed
@@ -177,6 +233,8 @@ Potential features for future releases:
177
233
 
178
234
  ---
179
235
 
236
+ [2.0.1]: https://github.com/open-dicom/csa_header/compare/v2.0.0...v2.0.1
237
+ [2.0.0]: https://github.com/open-dicom/csa_header/compare/v1.0.2...v2.0.0
180
238
  [1.0.1]: https://github.com/open-dicom/csa_header/compare/v1.0.0...v1.0.1
181
239
  [1.0.0]: https://github.com/open-dicom/csa_header/compare/v0.0.1...v1.0.0
182
240
  [0.0.1]: https://github.com/open-dicom/csa_header/releases/tag/v0.0.1
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: csa_header
3
- Version: 1.0.2
3
+ Version: 2.0.1
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
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
21
  Requires-Python: >=3.9
21
22
  Requires-Dist: numpy>=1.20.0
@@ -25,17 +26,29 @@ Requires-Dist: ipython; extra == 'dev'
25
26
  Requires-Dist: pre-commit; extra == 'dev'
26
27
  Provides-Extra: examples
27
28
  Requires-Dist: nibabel>=3.0.0; extra == 'examples'
29
+ Requires-Dist: pooch>=1.6.0; extra == 'examples'
28
30
  Description-Content-Type: text/markdown
29
31
 
30
32
  # CSA Header
31
33
 
32
34
  Parse CSA header information from Siemens MRI acquisitions with Python.
33
35
 
36
+ ### Package & Distribution
34
37
  [![PyPI - Version](https://img.shields.io/pypi/v/csa_header.svg)](https://pypi.org/project/csa_header)
35
38
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/csa_header.svg)](https://pypi.org/project/csa_header)
39
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/csa_header.svg)](https://pypi.org/project/csa_header)
40
+
41
+ ### Build & Quality Assurance
36
42
  [![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
43
  [![codecov](https://codecov.io/gh/open-dicom/csa_header/branch/main/graph/badge.svg)](https://codecov.io/gh/open-dicom/csa_header)
38
44
  [![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)
45
+
46
+ ### Code Quality & Style
47
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
48
+ [![Mypy checked](https://img.shields.io/badge/types-Checked%20with%20mypy-blue.svg)](http://mypy-lang.org/)
49
+
50
+ ### Citation & License
51
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17474448.svg)](https://doi.org/10.5281/zenodo.17474448)
39
52
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
40
53
 
41
54
  ---
@@ -62,7 +75,7 @@ The _CSA Image Header Info_ and _CSA Series Header Info_ elements contain encode
62
75
  - **ASCCONV Support**: Automatic parsing of embedded ASCCONV protocol parameters
63
76
  - **Type-Safe**: Complete type hints for all public APIs
64
77
  - **Well-Tested**: 96% test coverage with 161 tests
65
- - **Python 3.9+**: Modern Python with support through Python 3.13
78
+ - **Python 3.9+**: Modern Python with support through Python 3.14
66
79
  - **NiBabel Compatible**: Integrates seamlessly with neuroimaging workflows
67
80
 
68
81
  **Table of Contents**
@@ -78,6 +91,7 @@ The _CSA Image Header Info_ and _CSA Series Header Info_ elements contain encode
78
91
  - [Examples](#examples)
79
92
  - [Tests](#tests)
80
93
  - [Contributing](#contributing)
94
+ - [Citation](#citation)
81
95
  - [License](#license)
82
96
 
83
97
  ## Installation
@@ -88,12 +102,16 @@ pip install csa_header
88
102
 
89
103
  ### Optional Dependencies
90
104
 
91
- For working with the provided [NiBabel integration examples](#integration-with-nibabel):
105
+ For working with the provided examples and automatic example data downloading:
92
106
 
93
107
  ```console
94
108
  pip install csa_header[examples]
95
109
  ```
96
110
 
111
+ This installs:
112
+ - `nibabel` for NiBabel integration examples
113
+ - `pooch` for automatic downloading of example DICOM files
114
+
97
115
  For development (includes pre-commit hooks and IPython):
98
116
 
99
117
  ```console
@@ -102,6 +120,33 @@ pip install csa_header[dev]
102
120
 
103
121
  ## Quickstart
104
122
 
123
+ ### Option 1: Using Example Data (Easiest!)
124
+
125
+ The quickest way to get started is using the built-in example data:
126
+
127
+ ```python
128
+ >>> # Install with examples support
129
+ >>> # pip install csa_header[examples]
130
+ >>>
131
+ >>> from csa_header.examples import fetch_example_dicom
132
+ >>> from csa_header import CsaHeader
133
+ >>> import pydicom
134
+ >>>
135
+ >>> # Fetch example DICOM (downloads once, then cached)
136
+ >>> dicom_path = fetch_example_dicom()
137
+ >>> dcm = pydicom.dcmread(dicom_path)
138
+ >>>
139
+ >>> # Parse CSA Series Header
140
+ >>> raw_csa = dcm[(0x29, 0x1020)].value
141
+ >>> parsed_csa = CsaHeader(raw_csa).read()
142
+ >>> len(parsed_csa)
143
+ 79
144
+ ```
145
+
146
+ 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)
147
+
148
+ ### Option 2: Using Your Own DICOM Files
149
+
105
150
  Use [`pydicom`](https://github.com/pydicom/pydicom) to read a DICOM header:
106
151
 
107
152
  ```python
@@ -132,20 +177,18 @@ Parse the contents of the CSA header with the `CsaHeader` class:
132
177
  >>> parsed_csa = CsaHeader(raw_csa).read()
133
178
  >>> parsed_csa
134
179
  {
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',
180
+ 'NumberOfPrescans': {'VR': 'IS', 'VM': 1, 'value': 0},
181
+ 'TransmitterCalibration': {'VR': 'DS', 'VM': 1, 'value': 247.102},
182
+ 'PhaseGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
183
+ 'ReadoutGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
184
+ 'SelectionGradientAmplitude': {'VR': 'DS', 'VM': 1, 'value': 0.0},
185
+ 'GradientDelayTime': {'VR': 'DS',
142
186
  'VM': 3,
143
187
  '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',
188
+ 'RfWatchdogMask': {'VR': 'IS', 'VM': 1, 'value': 0},
189
+ 'RfPowerErrorIndicator': {'VR': 'DS', 'VM': 1, 'value': None},
190
+ 'SarWholeBody': {'VR': 'DS', 'VM': 3, 'value': None},
191
+ 'Sed': {'VR': 'DS',
149
192
  'VM': 3,
150
193
  'value': [1000000.0, 324.74800987, 324.74800832]}
151
194
  ...
@@ -237,6 +280,12 @@ See [examples/nibabel_integration.py](examples/nibabel_integration.py) for compl
237
280
 
238
281
  The [examples/](examples/) directory contains comprehensive usage examples:
239
282
 
283
+ - **[basic_usage_example.py](examples/basic_usage_example.py)**: Beginner-friendly introduction using example data
284
+ - Automatic download of example DICOM files
285
+ - Basic CSA header parsing
286
+ - Accessing specific CSA tags
287
+ - Perfect for first-time users!
288
+
240
289
  - **[nibabel_integration.py](examples/nibabel_integration.py)**: Complete workflow combining csa_header with NiBabel
241
290
  - Extract DWI parameters (b-values, gradients)
242
291
  - Extract fMRI parameters (slice timing, TR/TE)
@@ -245,6 +294,10 @@ The [examples/](examples/) directory contains comprehensive usage examples:
245
294
 
246
295
  Run examples:
247
296
  ```bash
297
+ # Basic example with automatic data download
298
+ python examples/basic_usage_example.py
299
+
300
+ # NiBabel integration with your own DICOM
248
301
  python examples/nibabel_integration.py path/to/siemens_dicom.dcm
249
302
  ```
250
303
 
@@ -307,6 +360,32 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for complete development guidelines inclu
307
360
  - Commit message conventions
308
361
  - Pull request process
309
362
 
363
+ ## Citation
364
+
365
+ If you use `csa_header` in your research, please cite it using the following:
366
+
367
+ **BibTeX:**
368
+ ```bibtex
369
+ @software{baratz_2025_csa_header,
370
+ author = {Baratz, Zvi and Brett, Matthew},
371
+ title = {csa_header: Parse CSA header information from Siemens MRI acquisitions},
372
+ year = 2025,
373
+ publisher = {Zenodo},
374
+ version = {v1.0.2},
375
+ doi = {10.5281/zenodo.17474448},
376
+ url = {https://doi.org/10.5281/zenodo.17474448}
377
+ }
378
+ ```
379
+
380
+ **APA:**
381
+ ```
382
+ 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
383
+ ```
384
+
385
+ 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.
386
+
387
+ 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.
388
+
310
389
  ## License
311
390
 
312
391
  `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
  ---
@@ -33,7 +44,7 @@ The _CSA Image Header Info_ and _CSA Series Header Info_ elements contain encode
33
44
  - **ASCCONV Support**: Automatic parsing of embedded ASCCONV protocol parameters
34
45
  - **Type-Safe**: Complete type hints for all public APIs
35
46
  - **Well-Tested**: 96% test coverage with 161 tests
36
- - **Python 3.9+**: Modern Python with support through Python 3.13
47
+ - **Python 3.9+**: Modern Python with support through Python 3.14
37
48
  - **NiBabel Compatible**: Integrates seamlessly with neuroimaging workflows
38
49
 
39
50
  **Table of Contents**
@@ -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.1"
@@ -59,6 +59,12 @@ TERMINAL_DIGIT_PATTERN = r"^(.*)\.(\d+)(\s+=)"
59
59
  #: Regular expression to replace terminal integer identifiers.
60
60
  TERMINAL_DIGIT_RE = re.compile(TERMINAL_DIGIT_PATTERN, re.M)
61
61
 
62
+ #: Types of the literal values an ASCCONV assignment may hold.
63
+ LITERAL_VALUE_TYPES = (int, float, str)
64
+
65
+ #: Types of the literal values an ASCCONV assignment may negate.
66
+ NUMERIC_VALUE_TYPES = (int, float)
67
+
62
68
 
63
69
  class AscconvParseError(Exception):
64
70
  """
@@ -203,13 +209,27 @@ def obj_from_atoms(
203
209
 
204
210
 
205
211
  def _get_value(assign: ast.Assign) -> int | float | str:
212
+ """
213
+ Return the literal value assigned by one ASCCONV line.
214
+
215
+ Every literal parses as ``ast.Constant`` (Python 3.8+); the ``ast.Num``
216
+ and ``ast.Str`` aliases this used to check were removed in Python 3.14.
217
+
218
+ Raises
219
+ ------
220
+ AscconvParseError
221
+ The assigned value is not a number, a string or a negated number
222
+ """
206
223
  value = assign.value
207
- if isinstance(value, ast.Num):
208
- return value.n # type: ignore[return-value]
209
- if isinstance(value, ast.Str):
210
- return value.s # type: ignore[return-value]
211
- if isinstance(value, ast.UnaryOp) and isinstance(value.op, ast.USub):
212
- return -value.operand.n # type: ignore[attr-defined,no-any-return]
224
+ if isinstance(value, ast.Constant) and isinstance(value.value, LITERAL_VALUE_TYPES):
225
+ return value.value
226
+ if (
227
+ isinstance(value, ast.UnaryOp)
228
+ and isinstance(value.op, ast.USub)
229
+ and isinstance(value.operand, ast.Constant)
230
+ and isinstance(value.operand.value, NUMERIC_VALUE_TYPES)
231
+ ):
232
+ return -value.operand.value
213
233
  message = messages.UNEXPECTED_RHS.format(value=value)
214
234
  raise AscconvParseError(message)
215
235