feat: add CsaHeader.from_dicom() convenience method#37
Open
feat: add CsaHeader.from_dicom() convenience method#37
Conversation
Implement direct DICOM integration for CSA header extraction. The new from_dicom() class method automatically locates and extracts CSA headers from DICOM datasets without requiring users to know exact DICOM tag numbers. Features: - Automatic CSA header location using DICOM private tag protocol - Support for both 'image' and 'series' CSA header types - Case-insensitive csa_type parameter - Returns None gracefully when CSA headers not present - Comprehensive test coverage (19 new tests, 96% overall coverage) Implementation inspired by nibabel's get_csa_header() function, adapted to csa_header's API design and coding standards. Changes: - Added CsaHeader.from_dicom() classmethod to csa_header/header.py - Added CsaHeader.CSA_TAGS class constant mapping header types to tags - Added CsaHeader._extract_csa_bytes() private helper method - Created comprehensive test suite in tests/test_dicom_integration.py - Updated README.md with usage examples and Related Projects section - Updated CHANGELOG.md with feature announcement and acknowledgments - Added pydicom to lint environment for proper type checking Documentation: - Updated Quickstart section with from_dicom() examples - Added Related Projects section acknowledging nibabel and PyDICOM - Enhanced Integration with NiBabel section - Comprehensive docstring with examples and nibabel attribution Suggested-by: Matthew Brett <matthew.brett@gmail.com> Closes #16 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #37 +/- ##
==========================================
- Coverage 94.88% 92.77% -2.12%
==========================================
Files 11 11
Lines 313 360 +47
Branches 41 51 +10
==========================================
+ Hits 297 334 +37
- Misses 10 16 +6
- Partials 6 10 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6240f2d to
88a2952
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements issue #16 by adding a
CsaHeader.from_dicom()convenience method for extracting CSA headers directly from DICOM datasets without requiring knowledge of exact DICOM tag numbers.Features
'image'and'series'CSA header typescsa_typeparameter, returnsNonegracefully when headers not presentLiteral['image', 'series']for IDE autocompleteImplementation Details
Core Changes
CsaHeader.from_dicom(dcm_data, csa_type='image')classmethodCsaHeader.CSA_TAGSclass constant mapping header types to DICOM tagsCsaHeader._extract_csa_bytes()private helper methodget_csa_header()functionTesting
tests/test_dicom_integration.pyheader.pycoverage: 99%Documentation
from_dicom()Build Configuration
pydicom>=2.2.0to lint environment for proper type checkingUsage Example
Quality Metrics
Attribution
get_csa_header()approachBreaking Changes
None - this is a new feature that doesn't affect existing functionality.
Closes
Closes #16
🤖 Generated with Claude Code