Comments (9)
Yes, I would like that too but reading CSA headers is a bit of a pain (see e.g. this discussion) and CSA is on its way out (to be replaced by enhanced DICOM, i.e. in the XA series). So I put this to rest if I can
from bidscoin.
I understand that CSA header is a bit of a pain and will disappear in the future, however, many datasets are still using it and the transition will take time. I think if dicom_parser
or csa_header
would be used, reading it won't be such a big pain, the article mentions how dicom_parser
can be used, csa_header
cen be used like this:
from csa_header import CsaHeader
dcm = pydicom.dcmread("/path/to/file.dcm")
data_element = dcm.get((0x29, 0x1020)) # CSA Series Header Info
raw_csa = data_element.value
parsed_csa = CsaHeader(raw_csa).read() # Final CSA header attributes in dictionary of dictionaries
Do you think it can be pain because of performance?
Is there something we could do for our data, like reading it with our script beforehand and writing somewhere useful information from CSA header that bidscoin could see?
from bidscoin.
Ok, that doesn't look too painful indeed. It doesn't have to impact performance that much because it can be implemented such that the CSA header is only parsed if the regular header doesn't contain the tag
from bidscoin.
Mhh, if I try it out in my bidscoin venv I get:
(venv) marzwi@localhost:~/PycharmProjects/bidscoin> pip install csa_header
ERROR: Could not find a version that satisfies the requirement csa_header (from versions: none)
ERROR: No matching distribution found for csa_header
from bidscoin.
A more important issue is that the CSA header can have a nested structure, e.g. as in:
>>> parsed_csa["SliceArray"]["Slice"][instance_number]["Position"]["Tra"]
This poses a problem for bidscoin, as it doesn't have a notion of this and extracts single keys (attributes) from the header
from bidscoin.
Mhh, if I try it out in my bidscoin venv I get:
(venv) marzwi@localhost:~/PycharmProjects/bidscoin> pip install csa_header ERROR: Could not find a version that satisfies the requirement csa_header (from versions: none) ERROR: No matching distribution found for csa_header
Yes, I am really sorry about that. It seems the repo is not on pypi although it claims it. So it can be added via:
'csa_header @ git+https://github.com/open-dicom/csa_header.git' in pyproject.toml
dependencies. I tried it and it gives error that:
csa_header requires a different Python: 3.8.10 not in '>=3.9'
So this is not a way to go :(. Maybe if it would be updated.
dicom_parser
when added to dependencies works, Getting CSA header:
from dicom_parser import Image
image = Image("/path/to/siemens/csa.dcm")
csa = image.header.get("CSASeriesHeaderInfo") # Final CSA header attributes in dictionary of dictionaries
Other tags can be also extracted like this:
parsed_value = image.header.get('ImagingFrequency', '')
raw_value = image.header.raw['ImagingFrequency'].value
from bidscoin.
A more important issue is that the CSA header can have a nested structure, e.g. as in:
>>> parsed_csa["SliceArray"]["Slice"][instance_number]["Position"]["Tra"]This poses a problem for bidscoin, as it doesn't have a notion of this and extracts single keys (attributes) from the header
Maybe if user puts in attribute that is separated e.g by dots, it could be splitted and used like this:
key_string = 'SliceArray.Slice.instance_number.Position.Tra'
keys = key_string.split('.')
result = csa
for key in keys:
if isinstance(result, dict):
result = result.get(key, '')
else:
return ''
return key
from bidscoin.
If you want, you can open a PR with just 1 added line, e.g. on line 589 in bids.py
:
# Try a recursive search
if not value and value != 0:
for elem in dicomdata.iterall():
if tagname in (elem.name, elem.keyword, str(elem.tag), str(elem.tag).replace(', ',',')):
value = elem.value
break
# Try reading the CSA header
if not value and value != 0:
pass # TODO: Add some code here
if not value and value!=0 and 'Modality' not in dicomdata:
raise ValueError(f"Missing mandatory DICOM 'Modality' field in: {dicomfile}")
In this way we can work together on it (if I do the PR I think I then can't give you permission to commit)
from bidscoin.
If you want, you can open a PR with just 1 added line, e.g. on line 589 in
bids.py
:# Try a recursive search if not value and value != 0: for elem in dicomdata.iterall(): if tagname in (elem.name, elem.keyword, str(elem.tag), str(elem.tag).replace(', ',',')): value = elem.value break # Try reading the CSA header if not value and value != 0: pass # TODO: Add some code here if not value and value!=0 and 'Modality' not in dicomdata: raise ValueError(f"Missing mandatory DICOM 'Modality' field in: {dicomfile}")In this way we can work together on it (if I do the PR I think I then can't give you permission to commit)
Created :). I apologize, I will be unavailable throughout the day tomorrow. However, I will start working on it in the evening. Thank you for giving it a try!
from bidscoin.
Related Issues (20)
- cannot import name 'files' from 'importlib.resources' HOT 5
- ERROR | Could not parse required sub-<label> label HOT 57
- Using `PhaseEncodingDirection` field to distinguish sequences HOT 6
- Add easy to check output with information on what source was converted to what BIDS files HOT 13
- Derivatives data HOT 4
- bidscoiner function leaves out every sequence HOT 65
- Clicking on item in bidsmapper GUI crashes program HOT 1
- Make a bids2bids template bidsmap
- Bidsmap schema doesn't require meta key in plugin HOT 17
- Can path to .bidscoin be configured? HOT 62
- B0FieldSource as a list HOT 12
- Exclude sections behaves weirdly HOT 53
- IndexError: string index out of range in dcm2niix2bids.py HOT 6
- New BIDS feature of dcm2niix HOT 2
- Postfix error HOT 9
- typo in nibabel2bids.py HOT 1
- Quickly add common tags in BIDSMapper/editor HOT 2
- Unable to find dicoms in the tmp directory that the program creates HOT 2
- Merge all bidsapps to a single bidscoin bidsapp HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bidscoin.