Code Monkey home page Code Monkey logo

brukerapi-python's Introduction

brukerapi-python

Documentation Status

A Python package providing I/O interface for Bruker data sets.

tl;dr

Install using pip:

pip install brukerapi

Load any data set:

from brukerapi.dataset import Dataset
dataset = Dataset('{path}/2dseq')    # create data set, works for fid, 2dseq, rawdata.x, ser
dataset.data                         # access data array
dataset.VisuCoreSize                 # get a value of a single parameter

Load an entire study:

from brukerapi.folders import Study
study = Study('{path_to_study_folder}')
dataset = study.get_dataset(exp_id='1', proc_id='1')

# get_dataset returns an empty dataset
# in order to load data into the data set, you can either use the context manager:

with dataset as d:
    d.data                         # access data array
    d.VisuCoreSize                 # get a value of a parameter

# or the load function
dataset.load()
dataset.data                       # access data array
dataset.VisuCoreSize               # get a value of a single parameter

Features

  • I/O interface for fid data sets
  • I/O interface for 2dseq data sets
  • I/O interface for ser data sets
  • I/O interface for rawdata data sets
  • Random access for fid and 2dseq data sets
  • Split operation implemented over 2dseq data sets
  • Filter operation implemented over Bruker folders (allowing you to work with a subset of your study only)

Examples

Documentation

Online documentation of the API is available at Read The Docs.

Install

Using pip:

pip install brukerapi

From source:

git clone https://github.com/isi-nmr/brukerapi-python.git
cd brukerapi-python
python setup.py build
python setup.py install

Testing

To ensure reliability, every commit to this repository is tested against the following, publicly available data sets:

Compatibility

The API was tested using various data sets obtained by ParaVision 5.1, 6.0.1 and 360. It it is compatible with the following data set types from individual ParaVision versions.

ParaVision v5.1

Compatible data set types:

  • fid
  • 2dseq
  • rawdata.job0
  • rawdata.Navigator

Compatible pulse sequences for fid data sets:

  • FLASH.ppg
  • MGE.ppg
  • MSME.ppg
  • RARE.ppg
  • FAIR_RARE.ppg
  • RAREVTR.ppg
  • RAREst.ppg
  • MDEFT.ppg
  • FISP.ppg
  • FLOWMAP.ppg
  • DtiStandard.ppg
  • EPI.ppg
  • FAIR_EPI.ppg
  • DtiEpi.ppg
  • T1_EPI.ppg
  • T2_EPI.ppg
  • T2S_EPI.ppg
  • SPIRAL.ppg
  • DtiSpiral.ppg
  • UTE.ppg
  • UTE3D.ppg
  • ZTE.ppg
  • CSI.ppg
  • FieldMap.ppg
  • NSPECT.ppg
  • PRESS.ppg
  • STEAM.ppg
  • igFLASH.ppg

ParaVision v6.0.1

Compatible data set types:

  • fid
  • 2dseq
  • rawdata.job0
  • rawdata.Navigator

Compatible pulse sequences for fid data sets:

  • FLASH.ppg,
  • FLASHAngio.ppg
  • IgFLASH.ppg
  • MGE.ppg
  • MSME.ppg
  • RARE.ppg
  • FAIR_RARE.ppg
  • RAREVTR.ppg
  • RAREst.ppg
  • MDEFT.ppg
  • FISP.ppg
  • FLOWMAP.ppg
  • DtiStandard.ppg
  • EPI.ppg
  • FAIR_EPI.ppg
  • CASL_EPI.ppg
  • DtiEpi.ppg
  • T1_EPI.ppg
  • T2_EPI.ppg
  • T2S_EPI.ppg
  • SPIRAL.ppg
  • DtiSpiral.ppg
  • UTE.ppg
  • UTE3D.ppg
  • ZTE.ppg
  • CSI.ppg
  • FieldMap.ppg
  • SINGLEPULSE.ppg
  • NSPECT.ppg
  • EPSI.ppg
  • PRESS.ppg
  • STEAM.ppg
  • ISIS.ppg
  • CPMG.ppg
  • RfProfile.ppg

ParaVision v360

Compatible data set types:

  • 2dseq
  • rawdata.job0
  • rawdata.Navigator

brukerapi-python's People

Contributors

tomas-psorn avatar wtclarke avatar

Stargazers

 avatar  avatar Martin Krämer avatar Tim avatar Ryan Boyce avatar Mario Corral avatar Cecil Yen avatar Septem avatar Beata Wereszczyńska avatar Christoph A. Müller avatar Alex Waters avatar Heather Hsu avatar Jérémie Fouquet avatar Wolfgang Gottwald avatar Ricardo Rios avatar Laurel Dieckhaus avatar Ougen avatar  avatar

Watchers

James Cloos avatar  avatar

brukerapi-python's Issues

np.float

In the latest numpy version (1.24.1) the use of 'np.float' raises an error. 'np.float' is e.g. used in brukerapi/schemas.py: line 580.

According to the DepricationWarning from an earlier numpy version, this is a quick fix:
DeprecationWarning: np.float is a deprecated alias for the builtin float. To silence this warning, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Can't read in complex 2dseq

Hi,
I'm trying to load 2dseq files that are complex (got them from a custom reco in ParaVision), but in the end the data I get is magnitude data.
I think it one could try to test if the data 2x the expected size in the deserialize function of Schema2dseq and then perform either complex reco or just continue.

Two test errors due to request fixture issues

python3.11 -m venv _e
. _e/bin/activate
pip install -e .
pip install pytest
python -m pytest
================================================ test session starts =================================================
platform linux -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/ben/src/forks/brukerapi-python
collected 7 items                                                                                                    

test/test_dataset.py s.EE                                                                                      [ 57%]
test/test_jcampdx.py s                                                                                         [ 71%]
test/test_random_access.py s                                                                                   [ 85%]
test/test_split.py s                                                                                           [100%]

======================================================= ERRORS =======================================================
__________________________________________ ERROR at setup of test_data_load __________________________________________

request = <SubRequest 'test_data' for <Function test_data_load>>

    @pytest.fixture()
    def test_data(request):
>       return request.param
E       AttributeError: 'SubRequest' object has no attribute 'param'

test/conftest.py:60: AttributeError
__________________________________________ ERROR at setup of test_data_save __________________________________________

request = <SubRequest 'test_data' for <Function test_data_save>>

    @pytest.fixture()
    def test_data(request):
>       return request.param
E       AttributeError: 'SubRequest' object has no attribute 'param'

test/conftest.py:60: AttributeError
================================================== warnings summary ==================================================
[…]
============================================== short test summary info ===============================================
ERROR test/test_dataset.py::test_data_load - AttributeError: 'SubRequest' object has no attribute 'param'
ERROR test/test_dataset.py::test_data_save - AttributeError: 'SubRequest' object has no attribute 'param'
================================ 1 passed, 4 skipped, 15 warnings, 2 errors in 4.72s =================================

spec2nii / Bruker / Paravision6.0.1

Hello,

I came across spec2nii, and we are interested to use it in order to extract the MRS voxel into the nifti format. Trying to use it I have stumbled along the following errors:
spec2nii bruker -m FID 8/fid
Traceback (most recent call last):
File "/home/spectro/anaconda3/bin/spec2nii", line 10, in
sys.exit(main())
File "/home/spectro/anaconda3/lib/python3.7/site-packages/spec2nii/spec2nii.py", line 666, in main
spec2nii(*args)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/spec2nii/spec2nii.py", line 283, in init
args.func(args)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/spec2nii/spec2nii.py", line 635, in bruker
self.imageOut, self.fileoutNames = read_bruker(args)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/spec2nii/bruker.py", line 44, in read_bruker
for data, orientation, dwelltime, meta, name in yield_bruker(args):
File "/home/spectro/anaconda3/lib/python3.7/site-packages/spec2nii/bruker.py", line 79, in yield_bruker
parameter_files=['method'])
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/dataset.py", line 199, in init
self.load()
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/dataset.py", line 273, in load
self.load_data()
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/dataset.py", line 521, in load_data
self._data = self._read_data()
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/dataset.py", line 531, in _read_data
return self._schema.deserialize(data, self._schema.layouts)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/schemas.py", line 162, in deserialize
data = self._acquisitions_to_encode(data, layouts)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/brukerapi/schemas.py", line 200, in _acquisitions_to_encode
return np.reshape(data, layouts['encoding_space'], order='F')
File "<array_function internals>", line 6, in reshape
File "/home/spectro/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 299, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
File "/home/spectro/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 58, in _wrapfunc
return bound(*args, **kwds)
ValueError: cannot reshape array of size 16384 into shape (4096,1)

On another dataset the last line of the message was:
ValueError: cannot reshape array of size 8192 into shape (2048,1)

The other lines being similar. Any hint?

Thank you,

Benoit

Interest in man pages?

I’m working on packaging this project as python-brukerapi for Fedora Linux. We try to offer man pages for command-line tools whenever possible.

I can easily write a set of man pages for the bruker executable by hand in groff_man(7) format and maintain them downstream in Fedora. However:

  • Would you like to include hand-written man pages (which I could supply) in this repository so that others can benefit from them?
  • Alternatively, would you be interested in a PR to automatically generate man pages using argparse-manpage, similar to Donders-Institute/multiecho#19?

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.