GithubHelp home page GithubHelp logo

ismrmrd-python's Introduction

Build Status

ISMRM Raw Data Format (ISMRMRD)

A prerequisite for sharing magnetic resonance (imaging) reconstruction algorithms and code is a common raw data format. This repository describes such a common raw data format, which attempts to capture the data fields that are required to describe the magnetic resonance experiment with enough detail to reconstruct images. The repository also contains a C/C++ library for working with the format. This standard was developed by a subcommittee of the ISMRM Sedona 2013 workshop and is described in detail in:

Inati SJ, Naegele JD, Zwart NR, Roopchansingh V, Lizak MJ, Hansen DC, Liu CY, Atkinson D, Kellman P, Kozerke S, Xue H, Campbell-Washburn AE, Sørensen TS, Hansen MS. ISMRM Raw data format: A proposed standard for MRI raw datasets. Magn Reson Med. 2017 Jan;77(1):411-421.

Please cite this paper if you use the format.

Please the ISMRMRD documentation for details.

ismrmrd-python's People

Contributors

congzhangzh avatar dchansen avatar dependabot[bot] avatar fzimmermann89 avatar ghisvail avatar hansenms avatar inati avatar kspacekelvin avatar mmuckley avatar naegelejd avatar pehses avatar roopchansinghv avatar tomas-psorn avatar wuerflts avatar xueh2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ismrmrd-python's Issues

Package on conda-forge and conda osx-arm64

Hi,

I have realized that I can't install ismrmrd-python on an apple silicon device (conda platform osx-arm64). While one can pretend to be on x86-64 by creating the env with --platform osx-64, I don't think that this should be required (as ismrmrd-python is a pure python package).

Further, install from conda seems to require conda-forge channels anyway since xsdata is only available from there. Ismrmrd-python could also be distributed via conda-forge to simplify the installation as the currently required custom 'ismrmrd' channel for install is not well documented and I had to dig a bit in the repo to find it.

I would thus propose to publish also to conda-forge. My initial tests with building a noarch python conda package (https://docs.anaconda.com/reference/glossary/?highlight=noarch#noarch-package) for ismrmrd-python were successful, although I could not build directly from the sources released on PyPI, because they don't include all source files (crucially schema/.xsdata.xml is absent, and then the xsdata code generation will default to PascalCase instead of camelCase for classes). Also examples are not present.

The are two options that worked for me for building, including tests:

  1. Build either from github source release.
  2. Build from PyPI wheel (which contains the xsd-generated python module): https://docs.conda.io/projects/conda-build/en/3.27.x/user-guide/wheel-files.html.
    If building from PyPI wheel, we need to download the PyPI sources still, because LICENSE and tests/ are only contained therein. I have tested this, it works on my apple silicon machine, but it makes the recipe more complicated.

Conda-forge prefers source builds over builds from wheels.
Preferably, sources uploaded to PyPI are identical with those in github releases to avoid confusion. Then it also wouldn't matter anymore where the sources are taken from. It should also be possible for to setup automatic conda-forge packaging regardless of where the sources are from (https://conda-forge.org/docs/maintainer/updating_pkgs.html#how-does-regro-cf-autotick-bot-create-automatic-version-updates), but I have no personal experience with this.

I wanted to ask for the ismrmrd-python maintainers' opinions on this.
I'd be happy to submit a PR to https://github.com/conda-forge/staged-recipes to get the process started.

setup error

Could you please help me to solve it? Thanks!

(pytorch1.7.1) jiale@gdp-SYS-7049GP-TRT:~/ismrmrd-python-master$ python setup.py install
running install
running bdist_egg
running egg_info
writing ismrmrd.egg-info/PKG-INFO
writing dependency_links to ismrmrd.egg-info/dependency_links.txt
writing requirements to ismrmrd.egg-info/requires.txt
writing top-level names to ismrmrd.egg-info/top_level.txt
reading manifest file 'ismrmrd.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'ismrmrd.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
/data3/jiale/anaconda3/envs/pytorch1.7.1/bin/python: No module named xsdata
error: [Errno 2] No such file or directory: 'ismrmrdschema/init.py'

Opening and closing MRD file via File interface updates file modified time

Hi,

I noticed some strange behavior:

Just opening and closing again an MRD file via ismrmrd.File() as below updates the file modified timestamp.

import ismrmrd

with ismrmrd.File("mymrd.h5"):
    pass

After this, the mymrd.h5 file shows the current time as the time modified, which is surprising.
The sha256 checksum indicates no change in the file.

Opening and closing with ismrmrd.File(..., "r") does not show this behavior, which is reassuring.

I would expect the file modification timestamp to remain unchanged if the file is not modified.

Currently, this throws some of our tools off that take action based on updated files that it determines from modification timestamps.
It's not a critical issue as there is the workaround with the "r" flag, however it may be a cause for concern if readonly operations start changing file modification timestamps, especially on raw data that one would like to keep for archival purposes.

I spotted this behavior on Windows with python 3.10 and ismrmrd 1.14.1 installed via pip.
Due to a peculiarity in our setup, python will run as admin, which may or may not be relevant to this issue.

Incompatibility with xsdata >=23

xsdata version >= 23 seems to be incompatible with error:

× Building wheel for ismrmrd (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      INFO:root:running bdist_wheel
      INFO:root:running build
      INFO:root:running build_py
      Install cli requirements "pip install xsdata[cli]"
      error: [Errno 2] No such file or directory: 'ismrmrdschema/__init__.py'
      [end of output]

meta.yaml is temporarily modified to limit the version in #70 until a proper fix is made.

usage issue

Hello,

I have obtained my raw/lab/sin files from the scanner. Converted these to ismrmrd-.h5 format with the philips_to_ismrmrd commandline tool provided by this repo as well.

Next, my idea was to inspect the content of these .h5-files using the ismrmrd-python library. From the python/example.. I assumed that it would "as easy as" executing

f = ismrmrd.Dataset(i_file, '/dataset', True)
f.read_image('data', 0)

However, this is not the case. The function read_image does not check whether the 'header' and 'attributes' key are there. Neither does it do anything to take action when they are not there. So I ended up with an error there.

Taking a closer look at the code.. I thought maybe I can fix this myself. Since the following code executed perfectly

f.read_acquisition(0)
f.read_xml_header()

And since those two things are what is "missing", I thought maybe I can come up with a substitute myself.

It seems that the part to 'read in the data' is done by declaring the following variable

self.__data = np.empty(shape=(self.__head.channels, self.__head.matrix_size[2],
self.__head.matrix_size[1], self.__head.matrix_size[0]),
dtype=get_dtype_from_data_type(self.__head.data_type))

Which is later used as

im.data[:] = self._dataset[impath]['data'][imnum]

But even if I got the definition of self._data right (for example.. (24, 1, 256, 256)). Then still, running the line above would result in a broadcasting error. Only a line like

im.data.ravel()[:] = self._dataset[impath]['data'][imnum]

would be able to do it correctly, since the data coming from the .h5 file is a 1-dimensional vector.

Enfin. I can't read in the data provided by the philips_to_ismrmrd with the ismrmrd-python tool. Probably Im on a wrong track. But I don't know enough HOW the data is stored inside the .h5 tool to fix it myself.
The datastructure looks quite daunting to figure it out myself.. so maybe you have some pointers on where to start...

pip installation fails on Ubuntu 14.04

The installation procedure tries to use pyxb before checking if it is installed:

$ pip install ismrmrd
Downloading/unpacking ismrmrd
Downloading ismrmrd-1.2.3.tar.bz2
Running setup.py (path:/tmp/pip_build_root/ismrmrd/setup.py) egg_info for package ismrmrd
Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "/tmp/pip_build_root/ismrmrd/setup.py", line 6, in <module>
    import pyxb.binding.generate
ImportError: No module named pyxb.binding.generate
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/ismrmrd/setup.py", line 6, in <module>
import pyxb.binding.generate
ImportError: No module named pyxb.binding.generate

After installing it manually ($ sudo pip install pyxb) the installation can proceed a bit further but then fails:

Running setup.py install for ismrmrd
ERROR:pyxb.utils.utility:open /tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyxb/utils/utility.py", line 740, in DataFromURI
    stream = open(uri, 'rb')
IOError: [Errno 2] No such file or directory: '/tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd'
error: [Errno 2] No such file or directory: '/tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd'
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/ismrmrd/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-vSlIrP-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
ERROR:pyxb.utils.utility:open /tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd
Traceback (most recent call last):
 File "/usr/local/lib/python2.7/dist-packages/pyxb/utils/utility.py", line 740, in DataFromURI
stream = open(uri, 'rb')
IOError: [Errno 2] No such file or directory: '/tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd'
error: [Errno 2] No such file or directory: '/tmp/pip_build_root/ismrmrd/schema/ismrmrd.xsd'

Import fails due to TypeError

Just recently, after installation with "pip install ismrmrd", the ismrmrd import fails with a TypeError in the ismrmrdschema (see Traceback below). I assume this is due to problems with xsdata. One solution is to manually install xsdata with "pip install xsdata[cli]==21.11" and afterwards install the ismrmrd-python with "python setup.py install".

 File "/home/ehsesp/miniconda3/bin/ismrmrdviewer", line 5, in <module>
   from ismrmrdviewer.__main__ import main
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrdviewer/__main__.py", line 3, in <module>
   import ismrmrdviewer.ui as ui
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrdviewer/ui/__init__.py", line 2, in <module>
   from .MainWindow import MainWindow
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrdviewer/ui/MainWindow.py", line 8, in <module>
   from .FileWidget import FileWidget
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrdviewer/ui/FileWidget.py", line 2, in <module>
   import ismrmrd
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/__init__.py", line 7, in <module>
   from .file import File
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/file.py", line 8, in <module>
   from .xsd import ToXML
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/xsd/__init__.py", line 1, in <module>
   from .pyxb_compat import (CreateFromDocument, ToXML, ToDOM)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/xsd/pyxb_compat.py", line 1, in <module>
   from .ismrmrdschema import ismrmrdHeader
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/xsd/ismrmrdschema/__init__.py", line 1, in <module>
   from .ismrmrd import (
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py", line 142, in _import
   return original_import(name, *args, **kwargs)
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/xsd/ismrmrdschema/ismrmrd.py", line 606, in <module>
   class encodingSpaceType:
 File "/home/ehsesp/miniconda3/lib/python3.8/site-packages/ismrmrd/xsd/ismrmrdschema/ismrmrd.py", line 615, in encodingSpaceType
   fieldOfViewMm: Optional[fieldOfViewMm] = field(
 File "/home/ehsesp/miniconda3/lib/python3.8/typing.py", line 261, in inner
   return func(*args, **kwds)
 File "/home/ehsesp/miniconda3/lib/python3.8/typing.py", line 364, in __getitem__
   arg = _type_check(parameters, "Optional[t] requires a single type.")
 File "/home/ehsesp/miniconda3/lib/python3.8/typing.py", line 149, in _type_check
   raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Optional[t] requires a single type. Got Field(name=None,type=None,default=None,default_factory=<dataclasses._MISSING_TYPE object at 0x7fdddb.```

Pre-generate XML bindings prior to next release

Rather than forcing ismrmrd-python users to have PyXB installed to generate the XML bindings from the ISMRMRD schema, we should just pre-generate the bindings using PyXB and add the results to the package prior to uploading the next release.

ImportError: cannot import name 'OutputFormat' from 'xsdata.models.config'

The current code using xsdata fails to pass setup install with the error message:

  File "/opt/code/ismrmrd-python/setup.py", line 25, in run
    generate_schema(schema_file, config_file, outloc)
  File "/opt/code/ismrmrd-python/setup.py", line 48, in generate_schema
    from xsdata.models.config import OutputFormat
ImportError: cannot import name 'OutputFormat' from 'xsdata.models.config' (/usr/local/lib/python3.9/site-packages/xsdata/models/config.py)

To replicate, use the following Dockerfile:

FROM python:3.9-slim

RUN apt-get update && apt-get install -y git
RUN pip install --no-cache-dir h5py xsdata jinja2 toposort docformatter
RUN mkdir -p /opt/code

RUN  cd /opt/code \
     && git clone https://github.com/ismrmrd/ismrmrd-python.git \
     && cd /opt/code/ismrmrd-python \
     && python3 setup.py install

@dchansen Is there something obvious that I'm missing in getting this to run? Removing this import and manually setting config.output.format to "pydata" doesn't seem to fix this either.

@hansenms Should we also set up a Github build workflow for this to make sure that we can catch these in the future? Happy to copy from the siemens_to_ismrmrd one so I can learn how to do so.

installation instructions

I cannot find any installation instructions nor list of dependencies. It'd be great to have a place somewhere that says to install pyxb and Cython. The following worked for me on Ubuntu 12.04

sudo pip install pyxb
sudo pip install Cython --upgrade
sudo python setup.py install 

(I needed to upgrade Cython as the Ubuntu 12.04 cython package didn't compile ismrmrd-pythom)

acquisition.resize() corrupts the data

If the acquisition data is resized to a bigger number of samples, the data in the acquisition is corrupted as np.resize() just continuously repeats the data. I would suggest to use np.hstack together with np.zeros to fill the extended data array with zeros instead of the repeated data.

Add typing_extensions version to requirements

Hi team,

With an old typing_extensions version (4.5.0) I got this error when importing ismrmrd:

Traceback (most recent call last):
File "examples/demo.py", line 1, in
import ismrmrd
File "/home/jhutter/.local/lib/python3.8/site-packages/ismrmrd/init.py", line 7, in
from .file import File
File "/home/jhutter/.local/lib/python3.8/site-packages/ismrmrd/file.py", line 8, in
from .xsd import ToXML
File "/home/jhutter/.local/lib/python3.8/site-packages/ismrmrd/xsd/init.py", line 1, in
from .pyxb_compat import (CreateFromDocument, ToXML, ToDOM)
File "/home/jhutter/.local/lib/python3.8/site-packages/ismrmrd/xsd/pyxb_compat.py", line 3, in
from xsdata.formats.dataclass.parsers import XmlParser
File "/home/jhutter/.local/lib/python3.8/site-packages/xsdata/formats/dataclass/parsers/init.py", line 1, in
from xsdata.formats.dataclass.parsers.dict import DictDecoder
File "/home/jhutter/.local/lib/python3.8/site-packages/xsdata/formats/dataclass/parsers/dict.py", line 9, in
from xsdata.formats.dataclass.context import XmlContext
File "/home/jhutter/.local/lib/python3.8/site-packages/xsdata/formats/dataclass/context.py", line 7, in
from xsdata.formats.dataclass.models.builders import XmlMetaBuilder
File "/home/jhutter/.local/lib/python3.8/site-packages/xsdata/formats/dataclass/models/builders.py", line 23, in
from xsdata.formats.dataclass.typing import (
File "/home/jhutter/.local/lib/python3.8/site-packages/xsdata/formats/dataclass/typing.py", line 18, in
from typing_extensions import ForwardRef
ImportError: cannot import name 'ForwardRef' from 'typing_extensions' (/home/jhutter/.local/lib/python3.8/site-packages/typing_extensions.py)

It was fixed after upgrading typing_extensions to 4.12.0.

Installation Error Ubuntu/Windows

Hi there,

I'm running into an issue trying to install ismrmrd-python into my anaconda. I've tried both on Windows and Ubuntu and got the same error twice. Apparently the package ismrmrdschema is missing from the repository (see bellow).

Sorry if it is an obvious fix, I'm pretty new with Python.

Thank you,

Kevin.

 >>python setup.py install
running install
running bdist_egg
running egg_info
writing ismrmrd.egg-info\PKG-INFO
writing dependency_links to ismrmrd.egg-info\dependency_links.txt
writing requirements to ismrmrd.egg-info\requires.txt
writing top-level names to ismrmrd.egg-info\top_level.txt
reading manifest file 'ismrmrd.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'ismrmrd.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
Install cli requirements "pip install xsdata[cli]"
error: [Errno 2] No such file or directory: 'ismrmrdschema/__init__.py'

Creating header object from converted GE data fails

Hi,

The following behavior is not observed with ismrmrd datasets created with siemens_to_ismrmrd from Siemens raw data. There seems to be an inconsistency with the xml header related routines.

I have created a ismrmrd file from a GE scanarchive using the ge_to_ismrmrd converter. When I try to create a header object in python with

    dset = ismrmrd.Dataset(filename, 'dataset', create_if_needed=False)
    hdr = ismrmrd.xsd.CreateFromDocument(dset.read_xml_header())

the code fails with the following traceback:

hdr = ismrmrd.xsd.CreateFromDocument(dset.read_xml_header())
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/ismrmrd-1.6.6-py3.8.egg/ismrmrd/xsd.py", line 65, in CreateFromDocument
saxer.parse(io.BytesIO(xmld))
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/xml/sax/expatreader.py", line 111, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/xml/sax/xmlreader.py", line 125, in parse
self.feed(buffer)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/xml/sax/expatreader.py", line 217, in feed
self._parser.Parse(data, isFinal)
File "/tmp/build/80754af9/python_1596615979580/work/Modules/pyexpat.c", line 461, in EndElement
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/xml/sax/expatreader.py", line 381, in end_element_ns
self._cont_handler.endElementNS(pair, None)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/saxer.py", line 388, in endElementNS
binding_object = this_state.endBindingElement()
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/saxer.py", line 226, in endBindingElement
self.__constructElement(self.__delayedConstructor, self.__attributes, args)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/saxer.py", line 116, in __constructElement
self.__bindingInstance = new_object_factory(*content, **kw)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 1632, in call
rv = self.typeDefinition().Factory(*args, **kw)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 306, in Factory
rv = cls._DynamicCreate(*args, **kw)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 696, in DynamicCreate
return ctor(*args, **kw)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 961, in init
self.xsdConstraintsOK(location)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 1087, in xsdConstraintsOK
return self.XsdConstraintsOK(self, location)
File "/gpfs/home/riemeb01/.conda/envs/ismrmrd-pytorch/lib/python3.8/site-packages/pyxb/binding/basis.py", line 1082, in XsdConstraintsOK
raise pyxb.SimpleFacetValueError(cls, value, f, location)
pyxb.exceptions
.SimpleFacetValueError: Type <class 'ismrmrd.xsd.STD_ANON'> pattern constraint violated by value F

Reading entire mrd file without loop

Hi,

I am trying to import a whole brain data with 13 repetitions (almost a large rawdata). It is pretty slow when I use for loop and read acquisitions one by one. Is there an alternative to read entire acquisitions without looping? ismrmrd MATLAB wrapper simply does it if readAcquisition() is called without an argument. Can we do something similar in ismrmrd Python interface? if not, can you please advise how to import a large mrd file faster?
in my experiment, importing entire data in MATLAB is ~20x faster than for loop in Python.

Thank you.
Ali

tag 1.3.3?

As is, the latest release for ismrmrd-python (1.3.2) is incompatible with the latest tagged version of ismrmrd (1.3.3). I see that this is fixed in master where the version number has been bumped to 1.3.3. Would you mind making a tag for 1.3.3 so that everything is in sync?

Compatibility issues with xsdata==21.12 and h5py==2.9.0

There appears to be an backend dependency on xsdata 22.2 that conflicts with our pinned 21.12 version.

This can be reproduced with

docker run -it --rm python:3.10.2-slim  /bin/bash
apt-get update && apt-get install --no-install-recommends -y git
mkdir -p /opt/code && cd /opt/code && git clone https://github.com/ismrmrd/ismrmrd-python.git && cd /opt/code/ismrmrd-python
pip3 install --no-cache-dir .

which produces the error:

ERROR: Some build dependencies for file:///opt/code/ismrmrd-python conflict with the backend dependencies: xsdata==22.2 is incompatible with xsdata[cli]==21.12.

There also appears to be an issue with h5py==2.9.0 on Debian-based images (like python above):

docker run -it --rm python:3.10.2-slim  /bin/bash
apt-get update && apt-get install --no-install-recommends -y gcc
pip install h5py==2.9.0

which produces error:

    In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                     from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                     from /usr/local/include/python3.10/Python.h:11,
                     from /tmp/pip-install-zqc5v665/h5py_816fe9a0a47c42d2863dea3f6f7d4c14/h5py/defs.c:47:
    /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195:15: fatal error: limits.h: No such file or directory
      195 | #include_next <limits.h>  /* recurse down to the real one */
          |               ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/gcc' failed with exit code 1

ERROR: Could not build wheels for ismrmrd which use PEP 517 and cannot be installed directly :: windows 10

Hi,

I get the error below when trying to install in windows 10 with pip install .

Any suggestions?

Windows 10
miniconda python 3.9

Building wheels for collected packages: ismrmrd
  Building wheel for ismrmrd (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\adminUser\miniconda3\envs\fire\python.exe' 'C:\Users\adminUser\miniconda3\envs\fire\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel 'C:\Users\ADMINU~1\AppData\Local\Temp\tmpofzgn431'
       cwd: C:\Users\adminUser\AppData\Local\Temp\pip-req-build-b_2k0b92
  Complete output (37 lines):
  running bdist_wheel
  running build
  running build_py
  Parsing schema ismrmrd.xsd
  Compiling schema ismrmrd.xsd
  Builder: 30 main and 1 inner classes
  Analyzer input: 30 main and 1 inner classes
  Analyzer output: 30 main and 0 inner classes
  Traceback (most recent call last):
    File "C:\Users\adminUser\miniconda3\envs\fire\lib\runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "C:\Users\adminUser\miniconda3\envs\fire\lib\runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\__main__.py", line 15, in <module>
      main()
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\__main__.py", line 8, in main
      cli()
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\click\core.py", line 1137, in __call__
      return self.main(*args, **kwargs)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\click\core.py", line 1062, in main
      rv = self.invoke(ctx)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\click\core.py", line 1668, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\click\core.py", line 1404, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\click\core.py", line 763, in invoke
      return __callback(*args, **kwargs)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\cli.py", line 191, in generate
      transformer.process(list(uris))
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\codegen\transformer.py", line 103, in process
      self.process_classes()
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\codegen\transformer.py", line 180, in process_classes
      writer = CodeWriter.from_config(self.config)
    File "C:\Users\adminUser\AppData\Local\Temp\pip-build-env-n9c8za34\overlay\Lib\site-packages\xsdata\codegen\writer.py", line 53, in from_config
      raise CodeGenerationError(
  xsdata.exceptions.CodeGenerationError: Unknown output format: 'pydata'
  error: [Errno 2] No such file or directory: 'ismrmrdschema/__init__.py'
  ----------------------------------------
  ERROR: Failed building wheel for ismrmrd
Failed to build ismrmrd
ERROR: Could not build wheels for ismrmrd which use PEP 517 and cannot be installed directly

Consider Migrating away from Nose

As mentioned in #69 (comment), the nose test library is no longer maintained, and the last release is 9 years old. It currently prevents running tests on python 3.12, which will probably become a problem in the future.

There is an actively maintained fork of nose, pynose: https://pypi.org/project/pynose/, but it is not available from conda, which will complicate building conda packages.

From a very superficial look at the code, nose is mainly used for setup, which should be available from other python unit test libraries.

Calling hdf5 Dataset.read_acquisition() results in segmentation fault

When loading any acquistion from an HD5 ISMRMRD dataset, python crashes with a segmentation fault in numpy. The acquisitions load fine in a program written using the C++ ismrmrd library. Multiple raw data files from different pulse sequences were tested with the same result.

Python code:

#!/usr/bin/env python

import ismrmrd
import sys
import xmltodict

def main(argv):
    rd = ismrmrd.Dataset(argv[1])
    header_xml = rd.read_xml_header()
    header = xmltodict.parse(header_xml)
    print "Dataset contains %d acquisitions" % rd.number_of_acquisitions()

    acq = rd.read_acquisition(0) ## seg fault here
    print "acquisition 0 has %d samples" % acquisition.number_of_samples

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Python output:

Dataset contains 1089 acquisitions

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff61144a8 in PyArray_Item_XDECREF (data=0x121c138 "\377\177",
descr=0x7fffef193ed0)
    at numpy/core/src/multiarray/refcount.c:71
71      numpy/core/src/multiarray/refcount.c: No such file or
directory.
(gdb) bt
#0  0x00007ffff61144a8 in PyArray_Item_XDECREF (data=0x121c138
"\377\177", descr=0x7fffef193ed0)
    at numpy/core/src/multiarray/refcount.c:71
#1  0x00007ffff6114467 in PyArray_Item_XDECREF (data=0x121bfe0 "\001",
descr=0x7fffef193f90)
    at numpy/core/src/multiarray/refcount.c:87
#2  0x00007ffff6114976 in PyArray_XDECREF (mp=mp@entry=0x7fffef197ee0)
at numpy/core/src/multiarray/refcount.c:173
#3  0x00007ffff60435b4 in array_dealloc (self=0x7fffef197ee0) at
numpy/core/src/multiarray/arrayobject.c:418
#4  0x00007ffff6118373 in void_dealloc (v=0x7fffef1fd7d8) at
numpy/core/src/multiarray/scalartypes.c.src:2501
#5  0x00007ffff604357b in array_dealloc (self=0x7fffef1979e0) at
numpy/core/src/multiarray/arrayobject.c:411
#6  0x00007ffff604357b in array_dealloc (self=0x7fffef197f30) at
numpy/core/src/multiarray/arrayobject.c:411
#7  0x00007ffff6118373 in void_dealloc (v=0x7fffef1fd7a0) at
numpy/core/src/multiarray/scalartypes.c.src:2501
#8  0x00000000004cdb00 in PyEval_EvalFrameEx ()
#9  0x00000000004cd4e2 in PyEval_EvalFrameEx ()
#10 0x00000000004cd4e2 in PyEval_EvalFrameEx ()
#11 0x00000000004cb6b1 in PyEval_EvalCodeEx ()
#12 0x000000000050481f in ?? ()
#13 0x00000000004fc182 in PyRun_FileExFlags ()
#14 0x00000000004fb247 in PyRun_SimpleFileExFlags ()
#15 0x000000000049aa6e in Py_Main ()
#16 0x00007ffff7811a40 in __libc_start_main (main=0x49a500 <main>,
argc=3, argv=0x7fffffffd518, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffd508) at libc-start.c:289
#17 0x000000000049a429 in _start ()

pip freeze:

Pil-Lite==0.0.6
PyXB==1.2.5
Pygments==2.1.3
argparse==1.2.1
backports.shutil-get-terminal-size==1.0.0
decorator==4.0.10
enum34==1.1.6
h5py==2.6.0
ipdb==0.10.1
ipython==5.1.0
ipython-genutils==0.1.0
ismrmrd==1.3.3
mpmath==0.19
nibabel==2.1.0
nipy==0.5.0.dev0
numpy==1.11.2
pathlib2==2.1.0
pexpect==4.2.1
pickleshare==0.7.4
prompt-toolkit==1.0.9
ptyprocess==0.5.1
pydicom==0.9.9
scipy==0.18.1
simplegeneric==0.8.1
six==1.10.0
sympy==1.0
traitlets==4.3.1
wcwidth==0.1.7
wsgiref==0.1.2
xmltodict==0.10.2

Operational C++ code:

#include <iostream>
#include <string>

#include "ismrmrd/ismrmrd.h"
#include "ismrmrd/dataset.h"

using std::cout;
using std::endl;
using std::string;

int main(int argc, char** argv) {

    string filename(argv[1]);

    ISMRMRD::Dataset dataset(filename.c_str(), "dataset");

    cout << "Dataset contains " << dataset.getNumberOfAcquisitions()
         << " acquisitions" << endl;

    ISMRMRD::Acquisition acq;
    dataset.readAcquisition(0, acq);

    cout << "acquisition 0 has " << acq.number_of_samples() << " samples"
         << endl;

    return 0;
}

Package depends on PyXB which is at end-of-life

One of the dependencies includes pyxb, which as noted by the maintainer is at end-of-life, and other solutions are recommended.

Perhaps the most pressing item is that pyxb has a deprecated idiom for importing from collections: PR 111. This is a warning that has been showing up in my tests.

I just tested ISMRMRD in Python 3.9 and I think it's still working despite the deprecation, but long-term stability of the Python ISMRMRD package could still be threatened by this dependency.

The best solution would probably be to remove the need for pyxb from ismrmrd. If this isn't possible, then perhaps ismrmrd could create its own fork of pyxb and merge PR 111.

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.