Python wrappers for external BART computational imaging tools and internal libraries

Overview

bartpy

BART-logo

Python bindings for BART.

Overview

This repo contains code to generate an updated Python wrapper for the Berkeley Advance Reconstruction Toolbox. The repo aims to expose command line tools and internal library functions to Python users.

The command line tools can be listed by running bart from the command line:

tools

Each of these has been exposed to the command-line via the bartpy.tools library:

code img

For users looking to integrate BART functions into existing Python workflows, and work fluidly with Numpy, SigPy, or other scientific packages, bartpy.tools should suffice!

[In Development] For developers looking to build Python tools using BART's internal C functions, the internal library functions expose BART's development libraries to the user. This is currently under production and not accessible via the master branch.

Requirements

BART version 0.7.00. It is important that running a bart command with the --interface option is successful. For example, you should see something like the following for running bart fft --interface:

interface

Ensure you have Python >= 3.6 and run pip install -r requirements.txt to install necessary dependencies.

Installation.

Once BART and the required libraries are installed, clone this repo.

To support the growth of BART with minimal overhead, the Python code is autogenerated from a user's BART installation. Run python3 setup.py install to build the tools library and install it. If successful, you should be able to import bartpy.tools and interface with the tutorials located in the demos folder.

Before working with the demos folder, unzip data.zip; this file contains the necessary datasets for the demos.

For Developers

The build_tools folder contains the necessary code for generating the tools wrappers.

Low-Level

Documentation on SWIG exists in the doc/ folder along with several links to SWIG documentation for developers interested in working with the experimental wrappers.

You might also like...
Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like
Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like

Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like! It is designed to emulate some of Python's OpenCV image processing from scratch without reference.

A python program to generate ANSI art from images and videos
A python program to generate ANSI art from images and videos

ANSI Art Generator A python program that creates ASCII art (with true color support if enabled) from images and videos Dependencies The program runs u

Vignette is a Python library to create and manage thumbnails following the FreeDesktop standard.

Vignette Vignette is a Python library to create and manage thumbnails following the FreeDesktop standard. Thumbnails are stored in a shared directory

kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns
kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns

kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns. The library builds on the

HTML2Image is a lightweight Python package that acts as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.
HTML2Image is a lightweight Python package that acts as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

A Python package implementing various CFA (Colour Filter Array) demosaicing algorithms and related utilities.
A Python package implementing various CFA (Colour Filter Array) demosaicing algorithms and related utilities.

Colour - Demosaicing A Python package implementing various CFA (Colour Filter Array) demosaicing algorithms and related utilities. It is open source a

Using P5.js, Processing and Python to create generative art
Using P5.js, Processing and Python to create generative art

Experiments in Generative Art Using Python, Processing, and P5.js Quick Links Daily Sketches March 2021. | Gallery | Repo | Done using P5.js Genuary 2

View images in the terminal using ansi escape codes and python
View images in the terminal using ansi escape codes and python

terminal-photo-viewer view images in the terminal using ansi escape codes and python !! Only tested on Ubuntu 20.04.3 LTS with python version 3.8.10 D

Comments
  • Installation not working

    Installation not working

    Hi,

    Thank you for making bart more accassible by wrapping it for python! Unfortunately, I cant install it though. It seems that some code that is pulled during python setup.py install is erroneous

    SyntaxError: duplicate argument 'llambda' in function definition The file the duplicate definition of llambda is /miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools/tools.py", line 3286.

    Full stacktrace
    [INFO] Complete
    [INFO] Installing Library
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/bartpy
    copying bartpy/__init__.py -> build/lib/bartpy
    creating build/lib/bartpy/utils
    copying bartpy/utils/__init__.py -> build/lib/bartpy/utils
    copying bartpy/utils/md_utils.py -> build/lib/bartpy/utils
    copying bartpy/utils/cfl.py -> build/lib/bartpy/utils
    creating build/lib/bartpy/tools
    copying bartpy/tools/__init__.py -> build/lib/bartpy/tools
    copying bartpy/tools/tools.py -> build/lib/bartpy/tools
    creating build/lib/bartpy/wrapper
    copying bartpy/wrapper/__init__.py -> build/lib/bartpy/wrapper
    copying bartpy/wrapper/bart.py -> build/lib/bartpy/wrapper
    running install_lib
    copying build/lib/bartpy/__init__.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy
    copying build/lib/bartpy/utils/__init__.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils
    copying build/lib/bartpy/utils/md_utils.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils
    copying build/lib/bartpy/utils/cfl.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils
    copying build/lib/bartpy/wrapper/__init__.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/wrapper
    copying build/lib/bartpy/wrapper/bart.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/wrapper
    copying build/lib/bartpy/tools/__init__.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools
    copying build/lib/bartpy/tools/tools.py -> /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/__init__.py to __init__.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils/__init__.py to __init__.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils/md_utils.py to md_utils.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/utils/cfl.py to cfl.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/wrapper/__init__.py to __init__.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/wrapper/bart.py to bart.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools/__init__.py to __init__.cpython-38.pyc
    byte-compiling /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools/tools.py to tools.cpython-38.pyc
    File "/home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy/tools/tools.py", line 3286
      def reconet(kspace, sensitivities, weights, ref_out, train=None, eval=None, apply=None, gpu=None, load=None, batch_size=None, iterations=None, normalize=None, network=None, resnet_block=None, varnet_block=None, unet=None, data_consistency=None, initial_reco=None, shared_weights=None, no_shared_weights=None, llambda=None, llambda=None, rss_norm=None, trajectory=None, pattern=None, adjoint=None, psf=None, export=None, mask=None, valid_data=None, train_loss=None, valid_loss=None, train_algo=None, adam=None, iPALM=None, load_memory=None, lowmem=None, test=None, export_graph=None, B=None):
      ^
    SyntaxError: duplicate argument 'llambda' in function definition
    
    running install_egg_info
    Removing /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy-1.0-py3.8.egg-info
    Writing /home/lukas/miniconda3/envs/cs/lib/python3.8/site-packages/bartpy-1.0-py3.8.egg-info```
    
    </details>
    opened by lukasfolle 2
  • Typo and none check

    Typo and none check

    Hi Max,

    I took a look at your (really great!) notebooks and was surprised by the quality of the result in the Non-Cartesian notebook, especially compared to the Matlab example (image here). I found one typo, where you assign to trad_rad2 instead of overwriting traj_rad2. Fixing this gets rid of the ugly part at the bottom of the phantom.

    Additionally, I think that is not None is more common in the python community. But feel free to regard this if you don't like it.

    All the best, Christian

    opened by hcmh 0
  • Update to pics broke wrapper

    Update to pics broke wrapper

    I'm not sure if this project is still in active development, but I just wanted to submit an issue as a couple of recent changes in BART broke this wrapper

    The first change I'm aware of was 2bf1f14. This change only affected the pics tool, which will either fail silently and return incorrect output, or with a FileNotFound-error.

    Using, set_debug(True) I can see the following command to bart

    bart pics -t /tmp/tmpgm0hxcp9t /tmp/tmpgm0hxcp9kspace /tmp/tmpgm0hxcp9sensitivities /tmp/tmpgm0hxcp9output /tmp/tmpgm0hxcp9psf_export
    

    Manually running this command gives the following error

    ERROR: cmdline: too few or too many arguments
    

    MWE:

    import bartpy.tools as bart
    import numpy as np
    
    traj = bart.traj(x=256, y=144, r=True)
    ksp = bart.phantom(t=traj, s=8)
    img = bart.nufft(traj, ksp, i=True, t=True)
    cart_ksp = bart.fft(img, u=True, bitmask=7)
    sens, _ = bart.ecalib(cart_ksp, m=1)
    pics_out = bart.pics(ksp, sens, t=traj, r=0.01)
    
    print(np.array_equal(cart_ksp, pics_out))
    

    The final check (array_equal) will return True. This highlights an issue related to https://github.com/malits/bartpy/issues/3 Since temp file names are global, and the files are not cleared, any tool can fail silently but still return an output that was created by another tool. In this case, pics returns the output of bart.fft.

    The second change was 5393516 which breaks the wrapper completely and gives this error on import.

    File "/content/bartpy/bartpy/tools/tools.py", line 1717
    def ictv(input, llambda, flags, flags, i=None, u=None):
    SyntaxError: duplicate argument 'flags' in function definition
    
    opened by fyrdahl 0
  • Tempfile cleanup

    Tempfile cleanup

    Problem: It appears that temp files are accumulating when repeatedly running scripts using bartpy. This behavior is different from the "old" Python wrapper found within BART.

    Expected outcome: The wrapper should delete temp files

    Observed outcome: Temp files are not deleted

    Proposed solution: Either using context managers or keeping track of created files and deleting manually. I believe the latter is how the old wrapper does it. I would be happy to work on a patch for this, but I felt like it may involve some substantial changes, so I decided to open an issue for potential discussions first.

    MWE:

    import bartpy.tools as bart
    phantom = bart.phantom()
    
    du -sh /tmp
    for i in {1..100}
    do
        python3 test.py
    done
    du -sh /tmp
    

    Output:

    264K    /tmp
    14M     /tmp
    

    The same problem does not occur if using the "old" Python wrapper:

    from bart import bart
    phantom = bart(1,'phantom')
    

    Output:

    264K    /tmp
    264K    /tmp
    
    opened by fyrdahl 0
Owner
Max Litster
Berkeley CS + Math
Max Litster
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Dec 31, 2022
Python-based tools for document analysis and OCR

ocropy OCRopus is a collection of document analysis programs, not a turn-key OCR system. In order to apply it to your documents, you may need to do so

OCRopus 3.2k Jan 4, 2023
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

null 24 Dec 20, 2022
Kainat 13 Mar 7, 2022
Tools for making image cutouts from sets of TESS full frame images

Cutout tools for astronomical images Astrocut provides tools for making cutouts from sets of astronomical images with shared footprints. It is under a

Space Telescope Science Institute 20 Dec 16, 2022
A suite of useful tools based on 3D interactivity in napari

napari-threedee A suite of useful tools based on 3D interactivity in napari This napari plugin was generated with Cookiecutter using @napari's cookiec

null 11 Dec 14, 2022
Seaborn-image is a Python image visualization library based on matplotlib and provides a high-level API to draw attractive and informative images quickly and effectively.

seaborn-image: image data visualization Description Seaborn-image is a Python image visualization library based on matplotlib and provides a high-leve

null 48 Jan 5, 2023
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 3, 2022
Bringing vtk.js into Dash and Python

Dash VTK Dash VTK lets you integrate the vtk.js visualization pipeline directly into your Dash app. It is powered by react-vtk-js. Docs Demo Explorer

Plotly 88 Nov 29, 2022
📷 Python package and CLI utility to create photo mosaics.

?? Python package and CLI utility to create photo mosaics.

Loic Coyle 7 Oct 29, 2022