---
name: "tff_generate_trx_from_scratch.py"
section: "1"
platform: "linux"
package: "python3-trx-python"
version: "0.3-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/tff_generate_trx_from_scratch.py"
---

# tff\_generate\_trx\_from\_scratch.py(1)

generate a TRX file from CSV, TXT or NPY files

## NAME

tff\_generate\_trx\_from\_scratch.py - generate a TRX file from CSV, TXT or NPY files

## DESCRIPTION

usage: tff\_generate\_trx\_from\_scratch.py \[-h\] \[--positions POSITIONS\]

- \[--offsets OFFSETS\]

  \[--positions\_csv POSITIONS\] \[--space {RASMM,VOXMM,VOX}\] \[--origin {NIFTI,TRACKVIS}\] \[--positions\_dtype {float16,float32,float64}\] \[--offsets\_dtype {uint32,uint64}\] \[--dpv FILE DTYPE\] \[--dps FILE DTYPE\] \[--groups FILE DTYPE\] \[--dpg GROUP FILE DTYPE\] \[--verify\_invalid\] \[-f\] reference OUT\_TRACTOGRAM

Generate TRX file from a collection of CSV, TXT or NPY files by individually specifying positions, offsets, data\_per\_vertex, data\_per\_streamlines, groups and data\_per\_group. Each file must have its data type specified by the users.

A reference file must be provided (NIFTI) and the option **--verify\_invalid** will remove invalid streamlines (outside of the bounding box in VOX space).

All dimensions (nbr\_vertices and nbr\_streamlines) and groups/dpg must match otherwise the script will (likely) crash.

Each instance of **--dps**, **--dpv**, **--groups** require 2 arguments (FILE, DTYPE). **--dpg** requires 3 arguments (GROUP, FILE, DTYPE). The choice of DTYPE are:

-

  \- (u)int8, (u)int16, (u)int32, (u)int64 - float16, float32, float64 - bool

Example command: tff\_generate\_trx\_from\_scratch.py fa.nii.gz generated.trx **-f**     **--positions** test\_npy/positions.npy **--positions\_dtype** float16     **--offsets** test\_npy/offsets.npy **--offsets\_dtype** uint32     **--dpv** test\_npy/dpv\_cx.npy uint8     **--dpv** test\_npy/dpv\_cy.npy uint8     **--dpv** test\_npy/dpv\_cz.npy uint8     **--dps** test\_npy/dps\_algo.npy uint8     **--dps** test\_npy/dps\_cw.npy float64     **--groups** test\_npy/g\_AF\_L.npy int32     **--groups** test\_npy/g\_AF\_R.npy int32     **--dpg** g\_AF\_L test\_npy/dpg\_AF\_L\_mean\_fa.npy float32     **--dpg** g\_AF\_R test\_npy/dpg\_AF\_R\_mean\_fa.npy float32     **--dpg** g\_AF\_L test\_npy/dpg\_AF\_L\_volume.npy float32

### positional arguments:

- reference

  Reference anatomy for tck/vtk/fib/dpy file support (.nii or .nii.gz).

- OUT\_TRACTOGRAM

  Output filename. Format must be one of trk, tck, vtk, fib, dpy, trx.

### options:

- **-h**, **--help**

  show this help message and exit

- **--verify\_invalid**

  Verify that the positions are all valid. None outside of the bounding box in VOX space. Requires Dipy (due to use of SFT).

- **-f**

  Force overwriting of the output files.

### Positions options:

- **--positions** POSITIONS

  Binary file containing the streamlines coordinates. Must be Nx3 (.npy)

- **--offsets** OFFSETS

  Binary file containing the streamlines offsets (.npy)

- **--positions\_csv** POSITIONS

  CSV file containing the streamlines coordinates. Rows for each streamlines organized as x1,y1,z1, x2,y2,z2,...,xN,yN,zN

- **--space** {RASMM,VOXMM,VOX}

  Space in which the coordinates are declared.\[RASMM\] Non-default option requires Dipy.

- **--origin** {NIFTI,TRACKVIS}

  Origin in which the coordinates are declared. \[NIFTI\] Non-default option requires Dipy.

### Data type options:

- **--positions\_dtype** {float16,float32,float64}

  Specify the datatype for positions for trx. \[float32\]

- **--offsets\_dtype** {uint32,uint64}

  Specify the datatype for offsets for trx. \[uint64\]

### Streamlines metadata options:

- **--dpv** FILE DTYPE

  Binary file containing data\_per\_vertex. Must haveNB\_VERTICES as first dimension (.npy)

- **--dps** FILE DTYPE

  Binary file containing data\_per\_vertex. Must haveNB\_STREAMLINES as first dimension (.npy)

- **--groups** FILE DTYPE

  Binary file containing a sparse group (indices). Indices should be lower than NB\_STREAMLINES (.npy)

- **--dpg** GROUP FILE DTYPE

  Binary file containing data\_per\_group.

-

  Must have(1,) as first dimension (.npy)
