Giter Club home page Giter Club logo

Comments (9)

marcelzwiers avatar marcelzwiers commented on June 17, 2024

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.

DominikaZ avatar DominikaZ commented on June 17, 2024

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.

marcelzwiers avatar marcelzwiers commented on June 17, 2024

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.

marcelzwiers avatar marcelzwiers commented on June 17, 2024

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.

marcelzwiers avatar marcelzwiers commented on June 17, 2024

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.

DominikaZ avatar DominikaZ commented on June 17, 2024

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.

DominikaZ avatar DominikaZ commented on June 17, 2024

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.

marcelzwiers avatar marcelzwiers commented on June 17, 2024

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.

DominikaZ avatar DominikaZ commented on June 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.