Skip to main content

trx-python

Tests Code Format codecov PyPI version

A Python implementation of the TRX file format for tractography data.

For details, please visit the documentation.

Installation

From PyPI

pip install trx-python

From Source

git clone https://github.com/tee-ar-ex/trx-python.git
cd trx-python
pip install .

Quick Start

Loading and Saving Tractograms

from trx.io import load, save

# Load a tractogram (supports .trx, .trk, .tck, .vtk, .fib, .dpy)
trx = load("tractogram.trx")

# Save to a different format
save(trx, "output.trk")

Command-Line Interface

TRX-Python provides a unified CLI (trx) for common operations:

# Show all available commands
trx --help

# Display TRX file information (header, groups, data keys, archive contents)
trx info data.trx

# Convert between formats
trx convert input.trk output.trx

# Concatenate tractograms
trx concatenate tract1.trx tract2.trx merged.trx

# Validate a TRX file
trx validate data.trx

Individual commands are also available for backward compatibility:

trx_info data.trx
trx_convert_tractogram input.trk output.trx
trx_concatenate_tractograms tract1.trx tract2.trx merged.trx
trx_validate data.trx

Development

We use spin for development workflow.

First-Time Setup

# Clone the repository (or your fork)
git clone https://github.com/tee-ar-ex/trx-python.git
cd trx-python

# Install with all dependencies
pip install -e ".[all]"

# Set up development environment (fetches upstream tags)
spin setup

Common Commands

spin setup      # Set up development environment
spin install    # Install in editable mode
spin test       # Run all tests
spin test -m memmap  # Run tests matching pattern
spin lint       # Run linting (ruff)
spin lint --fix # Auto-fix linting issues
spin docs       # Build documentation
spin clean      # Clean temporary files

Run spin without arguments to see all available commands.

Code Quality

We use ruff for linting and formatting:

# Check for issues
spin lint

# Auto-fix issues
spin lint --fix

# Format code
ruff format .

Pre-commit Hooks

# Install hooks
pre-commit install

# Run on all files
pre-commit run --all-files

Temporary Directory

The TRX file format uses memory-mapped files to limit RAM usage. When dealing with large files, several gigabytes may be required on disk.

By default, temporary files are stored in:

  • Linux/macOS: /tmp
  • Windows: C:\WINDOWS\Temp

To change the directory:

# Use a specific directory (must exist)
export TRX_TMPDIR=/path/to/tmp

# Use current working directory
export TRX_TMPDIR=use_working_dir

Temporary folders are automatically cleaned, but if the code crashes unexpectedly, ensure folders are deleted manually.

Troubleshooting

If the trx command is not working as expected, run trx --debug to print diagnostic information about the Python interpreter, package location, and whether all required and optional dependencies are installed.

Documentation

Full documentation is available at https://tee-ar-ex.github.io/trx-python/

To build locally:

spin docs --open

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

BSD License - see LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trx_python-0.5.0.tar.gz (122.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trx_python-0.5.0-py3-none-any.whl (59.5 kB view details)

Uploaded Python 3

File details

Details for the file trx_python-0.5.0.tar.gz.

File metadata

  • Download URL: trx_python-0.5.0.tar.gz
  • Upload date:
  • Size: 122.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for trx_python-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e09c9288fce2c31952f561e9d2061ce49be26be14b1175f9d8251c30cfd3d406
MD5 c27c885fe744c878e22c1f54295036b7
BLAKE2b-256 2de5c0694afca5b55ad7f7850b21778c71a869a915bca643146dfb0622434433

See more details on using hashes here.

File details

Details for the file trx_python-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: trx_python-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 59.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for trx_python-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92247806b84d98a18526baa51bb8013c2f3c625488a852a1fa5843ae192ae229
MD5 1198b43082db2c1798ef76fe23967ba1
BLAKE2b-256 40ccf2c9402853f2559d59a1a374dea5a87fa2be97d8baa2f196fa50a0c17039

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.1.2

2 files

0.1

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page