Skip to main content

Code to perform raytracing for geophysical applications

Project description


pypi License: GPL v3 DOI Build status Documentation Status Downloads

This repo contains C++ and python codes for raytracing on regular and unstructured meshes. Matlab wrappers are provided as well.

Python package

ttcrpy is a package for computing traveltimes and raytracing that was developed with geophysical applications in mind, e.g. ray-based seismic/GPR tomography and microseismic event location (joint hypocenter-velocity inversion). The package contains code to perform computation on 2D and 3D rectilinear grids, as well as 2D triangular and 3D tetrahedral meshes. Three different algorithms have been implemented: the Fast-Sweeping Method, the Shortest-Path Method, and the Dynamic Shortest-Path Method. Calculations can be run in parallel on a multi-core machine.

The core computing code is written in C++, and has been wrapped with cython.

Documentation can be found on Read The Docs

If you use ttcrpy, please cite

Giroux B. 2021. ttcrpy: A Python package for traveltime computation and raytracing.
SoftwareX, vol. 16, 100834. doi: 10.1016/j.softx.2021.100834

Stand-alone command-line programs

There are three programs that can be called from the command line:

  • ttcr2d : raytracing on planar 2D meshes
  • ttcr2ds : raytracing on undulated surfaces
  • ttcr3d : raytracing in 3D

See documentation for command-line programs options and file formats.


Look at the files in the examples directory for some samples.


The programs are coded in C++ and follow the C++11 standard. You must have VTK ( installed on your system, to benefit from full functionalities. Files from the eigen3 ( and boost ( libraries are distributed with the source to facilitate compilation. These codes were compiled and tested on macs with the default compiler (clang). They were also tested to some extent under linux with g++ version 4.8.

Matlab wrappers

To compile the mexfiles, you will need:

  • a C++ compiler that conforms to the C++11 standard
  • the source codes of the ttcr package

On my OS X machine, I use this command to compile from a terminal:


$MATLAB/bin/mex -O CXXFLAGS='$CXXFLAGS -std=c++11 -stdlib=libc++' \
LDFLAGS='$LDFLAGS -std=c++11 -stdlib=libc++' -largeArrayDims -v \
-I$HOME/src/ttcr/ttcr -I$HOME/src/ttcr/boost_1_81_0 \
-I$HOME/src/ttcr/eigen-3.4.0 grid2dunsp_mex.cpp

3D classes must be compiled with verbose.cpp in the list of source files, i.e.

$MATLAB/bin/mex -O CXXFLAGS='$CXXFLAGS -std=c++11 -stdlib=libc++' \
LDFLAGS='$LDFLAGS -std=c++11 -stdlib=libc++' -largeArrayDims -v \
-I$HOME/src/ttcr/ttcr -I$HOME/src/ttcr/boost_1_81_0 \
-I$HOME/src/ttcr/eigen-3.4.0 grid3dunfs_mex.cpp verbose.cpp

On a windows machine with intel compiler installed, I could compile it from the matlab prompt with:

mex -v -O COMPFLAGS='$COMPFLAGS /Qstd=c++11' -largeArrayDims -I../ttcr -I../boost_1_81_0 -I../eigen-3.4.0 grid2dunsp_mex.cpp

Unfortunately, I cannot offer extensive support for compiling on other platforms, especially windows variants.

Please report bugs to


  author = {Nasr, Maher and Giroux, Bernard and Dupuis, J. Christian},
  title = {A hybrid approach to compute seismic travel times in three-dimensional tetrahedral meshes},
  journal = {Geophysical Prospecting},
  volume = {n/a},
  number = {n/a},
  pages = {},
  keywords = {Travel time, Seismic modelling, Ray tracing, Seismics, Computing aspects},
  doi = {10.1111/1365-2478.12930},
  url = {},
  eprint = {},

  author = { Maher Nasr  and  Bernard Giroux  and  J. Christian Dupuis },
  title = {An optimized approach to compute traveltimes in 3D unstructured meshes},
  booktitle = {SEG Technical Program Expanded Abstracts 2018},
  chapter = {},
  pages = {5073-5077},
  year = {2018},
  doi = {10.1190/segam2018-2997918.1},
  URL = {},
  eprint = {}

  Title = {Comparison of grid-based methods for raytracing on unstructured meshes},
  Author = {Bernard Giroux},
  Booktitle = {SEG Technical Program Expanded Abstracts},
  Year = {2014},
  Pages = {3388-3392},
  Chapter = {649},
  DOI = {10.1190/segam2014-1197.1},
  Eprint = {},
  URL = {}

  author = {Bernard Giroux and Beno\^{\i}t Larouche},
  title = {Task-parallel implementation of {3D} shortest path raytracing for
	geophysical applications},
  journal = {Computers & Geosciences},
  year = {2013},
  volume = {54},
  pages = {130--141},
  number = {0},
  doi = {10.1016/j.cageo.2012.12.005}
  url = {}

  author = {Bernard Giroux},
  title = {Shortest path raytracing on tetrahedral meshes},
  booktitle = {75$^{th}$ EAGE Conference \& Exhibition},
  year = {2013},
  address = {London},
  organization = {EAGE},
  doi = {10.3997/2214-4609.20130236}
  url = {}

  author = {Leli\`evre, Peter G. and Farquharson, Colin G. and Hurich, Charles A.},
  title = {Computing first-arrival seismic traveltimes on unstructured 3-{D}
	tetrahedral grids using the Fast Marching Method},
  journal = {Geophysical Journal International},
  year = {2011},
  volume = {184},
  pages = {885-896},
  number = {2},
  doi = {10.1111/j.1365-246X.2010.04880.x}
  url = {}

  author = {Qian, Jianliang and Zhang, Yong-Tao and Zhao, Hong-Kai},
  title = {Fast Sweeping Methods for Eikonal Equations on Triangular Meshes},
  journal = {SIAM Journal on Numerical Analysis},
  year = {2007},
  volume = {45},
  pages = {83--107},
  number = {1},
  doi = {10.1137/050627083},
  publisher = {Society for Industrial and Applied Mathematics},
  url = {}

  Title                    = {High Order Fast Sweeping Methods for Static {H}amilton–{J}acobi Equations},
  Author                   = {Yong-Tao Zhang and Hong-Kai Zhao and Jianliang Qian},
  Journal                  = {Journal of Scientific Computing},
  Year                     = {2006},
  Number                   = {1},
  Pages                    = {25--56},
  Volume                   = {29},
  DOI                      = {10.1007/s10915-005-9014-3},
  URL                      = {}

  Title                    = {A Fast Sweeping Method for Eikonal Equations},
  Author                   = {Zhao, Hongkai},
  Journal                  = {Mathematics of Computation},
  Year                     = {2005},
  Month                    = apr,
  Number                   = {250},
  Pages                    = {603--627},
  Volume                   = {74},
  Publisher                = {American Mathematical Society},
  URL                      = {}

Project details

Download files

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

Source Distribution

ttcrpy-1.3.1.tar.gz (96.0 MB view hashes)

Uploaded source

Built Distributions

ttcrpy-1.3.1-cp311-cp311-win_amd64.whl (1.3 MB view hashes)

Uploaded cp311

ttcrpy-1.3.1-cp310-cp310-win_amd64.whl (1.3 MB view hashes)

Uploaded cp310

ttcrpy-1.3.1-cp39-cp39-win_amd64.whl (1.3 MB view hashes)

Uploaded cp39

ttcrpy-1.3.1-cp38-cp38-win_amd64.whl (1.3 MB view hashes)

Uploaded cp38

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page