Giter Club home page Giter Club logo

scikit-fmm's Introduction

Linux build Windows build PyPI versionDocumentation Status ContributorsDownloads

scikit-fmm: the fast marching method for Python

scikit-fmm is a Python extension module which implements the fast marching method. The fast marching method is used to model the evolution of boundaries and interfaces in a variety of application areas. More specifically, the fast marching method is a numerical technique for finding approximate solutions to boundary value problems of the Eikonal equation:

F(x) | grad T(x) | = 1

Typically, such a problem describes the evolution of a closed curve as a function of time T with speed F(x)>0 in the normal direction at a point x on the curve. The speed function is specified, and the time at which the contour crosses a point x is obtained by solving the equation.

scikit-fmm is a simple module which provides functions to calculate the signed distance and travel time to an interface described by the zero contour of the input array phi.

import skfmm
import numpy as np
phi = np.ones((3, 3))
phi[1, 1] = -1
skfmm.distance(phi)
 array([[ 1.20710678,  0.5       ,  1.20710678],
        [ 0.5       , -0.35355339,  0.5       ],
        [ 1.20710678,  0.5       ,  1.20710678]])

skfmm.travel_time(phi, speed = 3.0 * np.ones_like(phi))
array([[ 0.40236893,  0.16666667,  0.40236893],
       [ 0.16666667,  0.11785113,  0.16666667],
       [ 0.40236893,  0.16666667,  0.40236893]])

The input array can be of 1, 2, 3 or higher dimensions and can be a masked array. A function is provided to compute extension velocities.

Documentation

PyPI

Requirements

  • Numpy >= 1.0.2
  • Building requires a C/C++ compiler (gcc, MinGW, MSVC)

Bugs, questions, patches, feature requests, discussion & cetera

Installing

Running Tests

  • python -c "import skfmm; skfmm.test(True)"
  • When running the tests from the source directory use python setup.py develop
  • Tests are doctests in skfmm/__init__.py

Building documentation

  • Requires sphinx and numpydoc
  • make html

Publications using scikit-fmm

  • Akinola, I., J Varley, B. Chen, and P.K. Allen (2018) "Workspace Aware Online Grasp Planning" arXiv:1806.11402v1 [cs.RO] 29 Jun 2018 https://arxiv.org/pdf/1806.11402.pdf

  • Bortolussi, V., B. Figliuzzi, F. Willot, M. Faessel, M. Jeandin (2018) "Morphological modeling of cold spray coatings" Image Anal Stereol 2018;37:145-158 doi:10.5566/ias.1894 https://hal.archives-ouvertes.fr/hal-01837906/document

  • Chalmers, S., C.D. Saunter, J.M. Girkin and J.G. McCarron (2016) "Age decreases mitochondrial motility and increases mitochondrial size in vascular smooth muscle." Journal of Physiology, 594.15 pp 4283–4295.

  • Diogo Brandão Amorim (2014) "Efficient path planning of a mobile robot on rough terrain" Master's Thesis, Department of Aerospace Engineering, University of Lisbon.

  • Giometto, A., D.R. Nelson, and A.W. Murray (2018) "Physical interactions reduce the power of natural selection in growing yeast colonies", PNAS November 6, 2018 115 (45) 11448-11453; published ahead of print October 23, 2018 https://doi.org/10.1073/pnas.1809587115

  • Joshua A. Taillon, Christopher Pellegrinelli, Yilin Huang, Eric D. Wachsman, and Lourdes G. Salamanca-Riba (2014) "Three Dimensional Microstructural Characterization of Cathode Degradation in SOFCs Using Focused Ion Beam and SEM" ECS Trans. 2014 61(1): 109-120; https://www.joshuataillon.com/pdfs/2015-08-06%20jtaillon%203D%20SOFC%20cathode%20degradation.pdf

  • Marshak, C., I. Yanovsky, and L. Vese (2017) "Energy Minimization for Cirrus and Cumulus Cloud Separation in Atmospheric Images" IGARSS 2018 - 2018 IEEE International Geoscience and Remote Sensing Symposium DOI: 10.1109/IGARSS.2018.8517940 ftp://ftp.math.ucla.edu/pub/camreport/cam17-68.pdf

  • Moon, K. R., V. Delouille, J.J. Li, R. De Visscher, F. Watson and A.O. Hero III (2016) "Image patch analysis of sunspots and active regions." J. Space Weather Space Clim., 6, A3, DOI: 10.1051/swsc/2015043.

  • Tao, M., J. Solomon and A. Butscher (2016) "Near-Isometric Level Set Tracking." in Eurographics Symposium on Geometry Processing 2016 Eds: M. Ovsjanikov and D. Panozzo. Volume 35 (2016), Number 5

  • Thibaut, R., Laloy, E., Hermans, T., 2021. A new framework for experimental design using Bayesian Evidential Learning: The case of wellhead protection area. J. Hydrol. 603, 126903. https://doi.org/10.1016/j.jhydrol.2021.126903

  • Vargiu, Antioco, M. Marrocu, L. Massidda (2015) "Implementazione e valutazione su un caso reale del servizio di Cloud Computing per la simulazione di incendi boschivi in Sardegna" (Implementation and evaluation on a real case of Cloud computing service for simulation of Forest fires in Sardinia). Sardinia Department of Energy and Environment. CRS4 PIA 2010 D5.4.

  • Wronkiewicz, M. (2018) "Mapping buildings with help from machine learning" Medium article, June 29th 2018 https://medium.com/devseed/mapping-buildings-with-help-from-machine-learning-f8d8d221214a

  • Makki, K., Ben Salem, D., Ben Amor, B. (2021) "Toward the Assessment of Intrinsic Geometry of Implicit Brain MRI Manifolds" IEEE Access, volume 9, pages 131054 - 131071 (September 2021) DOI: 10.1109/ACCESS.2021.3113611 https://ieeexplore.ieee.org/abstract/document/9540688

Version History:

  • 0.0.1: February 13 2012
    • Initial release
  • 0.0.2: February 26th 2012
    • Including tests and docs in source distribution. Minor changes to documentation.
  • 0.0.3: August 4th 2012
    • Extension velocities.
    • Fixes for 64 bit platforms.
    • Optional keyword argument for point update order.
    • Bug reports and patches from three contributors.
  • 0.0.4: October 15th 2012
    • Contributions from Daniel Wheeler:
      • Bug fixes in extension velocity.
      • Many additional tests and migration to doctest format.
      • Additional optional input to extension_velocities() for FiPy compatibly.
  • 0.0.5: May 12th 2014
    • Fix for building with MSVC (Jan Margeta).
    • Corrected second-order point update.
  • 0.0.6: February 20th 2015
    • Documentation clarification (Geordie McBain).
    • Python 3 port (Eugene Prilepin).
    • Python wrapper for binary min-heap.
    • Freeze equidistant narrow-band points simultaneously.
  • 0.0.7: October 21st 2015
    • Bug fix to upwind finite difference approximation for negative phi from Lester Hedges.
  • 0.0.8: March 9th 2016
    • Narrow band capability: an optional "narrow" keyword argument limits the extent of the marching algorithm (Adrian Butscher).
  • 0.0.9: August 5th 2016
    • Periodic boundaries: an optional "periodic" keyword argument enables periodic boundaries in one or more directions (Wolfram Moebius).
  • 2019.1.30 January 30th 2019
    • Abrupt change to version numbering scheme.
    • Bugfix in setup.py to allow installing via pip with numpy (ManifoldFR).
    • Handle C++ exceptions during fast marching (Jens Glaser).
    • Accept a zero discriminant in travel time point update.
  • 2021.1.20 January 20th 2021
    • Fix divide by zero bugs in travel_time and extension_velocities
    • Contributions from Murray Cutforth, f-fanni, and okonrad
  • 2021.1.21 January 21st 2021
    • Minor C++ change (removed the auto keyword) to fix the compile on TravisCI.
  • 2021.2.2 February 2nd 2021
    • Add a pyproject.toml file to specify numpy as a build requirement, this is needed to build with new version of pip (David Parsson).
  • 2021.7.8 July 8th 2021
    • Add a pyproject.toml file to the MANIFEST.in file to fix the numpy build dependency (David Parsson). Fix numpy deprecation warnings and improve source code formatting (Robin Thibaut).
  • 2021.9.23 September 23rd 2021
    • Make the pyproject.toml file specify the oldest supported numpy as a build requirement, to allow using wheels with any numpy version. (David Parsson).
  • 2021.10.29 October 29th 2021
    • Fix for point update discriminant exactly equal to zero
    • Fall back calculation for point update when discriminant becomes negative
    • (Joshua Gehre)
  • 2022.02.02 February 2nd 2022
    • Fixes for Python 3.10 compatibility
    • (Amin Sadeghi, Xylar Asay-Davis, David Parsson)
  • 2022.03.26 March 26th 2022
    • Following the breaking changes in setuptools v61.0.0 it is suggested to set py_modules to disable auto-discovery behavior.
    • (Daniel Ammar)
  • 2022.08.15 August 15th 2022
    • Following the breaking changes in setuptools v65 pin setuptools to v64
    • (DorSSS)
  • 2022.04.02 April 2nd 2023
    • Build fixes for Python 3.11 (update pheap cython wrapper)
    • No solver changes

Copyright 2023 The scikit-fmm team.

BSD-style license. See LICENSE.txt in the source directory.

scikit-fmm's People

Contributors

bojanstef avatar danielammar avatar davidparsson avatar dorsss avatar espdev avatar f-fanni avatar fbordignon avatar gdmcbain avatar jakirkham avatar jkfurtney avatar jmargeta avatar joshuagehre avatar k16makki avatar lohedges avatar manifoldfr avatar murraycutforth avatar okonrad avatar robinthibaut avatar wd15 avatar wmoebius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scikit-fmm's Issues

distance calculations with point source

Hi,

I am trying to simulate a point source in a 2D homogeneous media but I am getting some unexpected results for distances compared with the analytical solution. I am using skfmm version 2019.1.30, python 3.7, and ubuntu 18.04.

A simple example:

import numpy as np
import skfmm

phi = np.ones([5, 5])
phi[0, 0] = 0  # set point source at origin

dx  = 1

dist = skfmm.distance(phi=phi, dx=dx)

The cells in the vertical and horizontal direction give me the expected answers:

assert np.all(dist[:, 0] == np.array([0, 1, 2, 3, 4]))
assert np.all(dist[0, :] == np.array([0, 1, 2, 3, 4]))

But the diagonal cells do not match the straight line distance from the center of the zero-contour cell:

print(np.diag(dist))  # array([0.        , 1.70710678, 3.15737528, 4.55895359, 5.95627062])
expected = np.sqrt(((np.arange(5) * dx) **2) * 2)  # array([0.        , 1.41421356, 2.82842712, 4.24264069, 5.65685425])

Is this the correct way to represent a point source?

Release a new version

Could you release a new version on pypi?
I'm getting errors similar to #38 and I see it's been already fixed on master, but the latest release is from two years ago (2019.1.30).

Memory leak in extension_velocities

Hi,

Thanks for a really useful library first of all! I'm using scikit-fmm in a medical imaging application, and I appear to have found a memory leak in extension_velocities. Because I'm working with 512^3 volumes, the amount of memory being consumed quickly becomes problematic.

Here's a trace of the memory usage of my code, running extension_velocities on 3 different volumes.

image

I convinced myself that the leak was occurring somewhere specifically in the extension_velocities function by running the exact same thing, but calling skfmm.distance instead, and seeing that the memory usage stays constant in that case.

After a fair amount of digging in the source code and Python C API documentation, I think I've fixed the issue, although I've never looked into the C API of Python before so I might have misunderstood something. In fmm.cpp, where the interface between Python and C++ is defined, there is a special case used to return the results of the extension velocity function:

scikit-fmm/skfmm/fmm.cpp

Lines 345 to 348 in ff8a467

if (mode == EXTENSION_VELOCITY)
{
return Py_BuildValue("OO", distance, f_ext);
}

From the documentation on this function (https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue) with format string "OO" the reference count of the objects are incremented. I think this must prevent the reference counts from ever reaching zero when they eventually go out of scope. Replacing the format string with "NN", which is identical except for the reference count not being incremented, gives the following memory profile:

image

If this sounds correct, I can submit a PR with this fix from my fork, or if it's easier one of the maintainers can implement it since it's just a single line change.

Second order issue with `KNOWN` and `TRIAL` values

This seems to be an issue with both LSMLIB and Scikit-fmm. The following test fails with LSMLIB, but passes (by luck) in Scikit-fmm.

>>> from skfmm import distance
>>> phi = distance([[-1, -1, -1, -1],
                 [ 1,  1, -1, -1],
                 [ 1,  1, -1, -1],
                 [ 1,  1, -1, -1]], order=2)
>>> print distance(phi, order=2)
[[-0.5        -0.58578644 -1.08578644 -1.85136395]
 [ 0.5         0.29289322 -0.58578644 -1.54389939]
 [ 1.30473785  0.5        -0.5        -1.5       ]
 [ 1.49547948  0.5        -0.5        -1.5       ]]

One gets a different answer with LSMLIB

>>> from pylsmlib import distance
>>> phi = distance([[-1, -1, -1, -1],
 ...           [ 1,  1, -1, -1],
...           [ 1,  1, -1, -1],
...           [ 1,  1, -1, -1]], order=2)
>>> print distance(phi, order=2)
[[-0.5        -0.58578644 -1.08578644 -1.85170563]
 [ 0.5         0.29289322 -0.58578644 -1.54468054]
 [ 1.30473785  0.5        -0.5        -1.5       ]
 [ 1.49547948  0.5        -0.5        -1.5       ]]

The issue is that newly created KNOWN values only update their closest neighbour's values. For second order schemes newly created KNOWN values need to update all values in the stencil. That is cells that are two steps away with a KNOWN value between.
Toy Problem

Take three cells lieing in a larger 2D array of cells. Say that 0.5 is the smallest value in the TRIAL cells

| TRIAL 0.5 | TRIAL 0.5 | TRIAL 0.51 |

One of the two values becomes updated to KNOWN, but that now information happens to lower the value of the left side cell.

| TRIAL 0.405 | KNOWN 0.5 | TRIAL 0.505 |

The left cell then becomes KNOWN

| KNOWN 0.405 | KNOWN 0.5 | TRIAL 0.505 |

TRIAL 0.51 is not reupdated when the left cell becomes KNOWN although the value is required for second order accuracy.

| KNOWN 0.405 | KNOWN 0.5 | KNOWN 0.505|

Ubuntu 16.04 and Anaconda on amd64. ImportError.

Hi,

Using Ubuntu 16.04 and Anaconda on amd64 I get an ImportError after attempting to run
python setup.py install
and then (outside the scikit-fmm directory) python -c "import skfmm"

It looks like:

Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/skfmm/init.py", line 51, in
File "build/bdist.linux-x86_64/egg/skfmm/pfmm.py", line 4, in
File "build/bdist.linux-x86_64/egg/skfmm/cfmm.py", line 7, in
File "build/bdist.linux-x86_64/egg/skfmm/cfmm.py", line 6, in bootstrap
ImportError: /home/bl/.cache/Python-Eggs/scikit_fmm-0.0.9-py2.7-linux-x86_64.egg-tmp/skfmm/cfmm.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm

Any help would be greatly appreciated. Thanks very much.

Best wishes,
cc

import error

I've tried in different virtual envs to run skfmm. Each time it says "ImportError: No module named skfmm". I tried doing "pip install scikit-fmm" and it says requirement already satisfied. To make sure it wasn't some weird problem with the python file I did "python -c "import skfmm; skfmm.test(True)"
" in my terminal which gave the output of "ImportError: No module named skfmm" again.

My python code:
from abc import abstractmethod

import numpy as np
import skfmm
from skimage import measure
from scipy.signal import savgol_filter
from scipy import interpolate

Numpy should be a build-system requirement

As stated in #23 (comment), building a wheel during installation of scikit-fmm fails if numpy is not already installed. If so pip will fallback to using the legacy setup.py install method, and as of pip 21.0 which was released about a week ago, this is deprecated.

Scipy has recently solved this problem by specifying numpy as a build-system dependency in a pyproject.toml file: https://github.com/scipy/scipy/blob/master/pyproject.toml

I'm on Python 3.7.9 and pip 20.3.1 on MacOS 11, and for me this can be reproduced easily on a fresh Python installation/virtualenv:

$ pip install wheel
$ pip install scikit-fmm numpy

The installation will then continue successfully, but with this deprecation warning:

DEPRECATION: scikit-fmm was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at pypa/pip#8368.

cannot import skfmm due to arm64 incompatibility?

Hello, thanks for the work. I get the following error when I try to use skfmm inside this other package call scikit-traveltim. It owrked a year ago on the same computer. Any idea how to resolve it?
problem

Compute Voronoi?

Can the algorithm be used to compute the Voronoi distribution of labels where phi==0?

We'd like to embedded the source code in a C++ class and provide an array where labels are set for all voxels with phi==0. A resulting array should contain the Voronoi distribution of those initial labels.

We managed to encapsulate the code in a C++ class and to use the fmm's interface. So far, we can compute geodesic distance images (we only use the distance_marcher). We also provide a label array from which we compute the phi input image.

Now it is not obvious to us how to 'transport' the labels 'along the shortest distances' through the image. Do you know if this is possible and if so, how?

about cfmm

when trying to run test, popped the message "ModuleNotFoundError: No module named 'skfmm.cfmm'"

PyPI build seems to be broken

I can no longer install scikit-fmm using pip install scikit-fmm, it throws the following error:

  ERROR: Command errored out with exit status 1:
   command: /home/amin/mambaforge/envs/test/bin/python3.8 /home/amin/mambaforge/envs/test/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmp7uo_91ce
       cwd: /tmp/pip-install-snqxq1_q/scikit-fmm_c291e66706194664aaca1f52b0ea2f62
  Complete output (149 lines):
  running bdist_wheel
  running build
  running config_cc
  unifing config_cc, config, build_clib, build_ext, build commands --compiler options
  running config_fc
  unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
  running build_src
  build_src
  building extension "skfmm.cfmm" sources
  building extension "skfmm.pheap" sources
  build_src: building npy-pkg config files
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/setup.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/pfmm.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/__init__.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/heap.py -> build/lib.linux-x86_64-3.8/skfmm
  running build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  building 'skfmm.cfmm' extension
  compiling C++ sources
  C compiler: g++ -pthread -B /home/amin/mambaforge/envs/test/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
  
  creating build/temp.linux-x86_64-3.8/skfmm
  compile options: '-Iskfmm -I/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include -I/home/amin/mambaforge/envs/test/include/python3.8 -c'
  g++: skfmm/fmm.cpp
  g++: skfmm/heap.cpp
  g++: skfmm/base_marcher.cpp
  g++: skfmm/distance_marcher.cpp
  g++: skfmm/extension_velocity_marcher.cpp
  g++: skfmm/travel_time_marcher.cpp
  In file included from /tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830,
                   from /tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                   from /tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/noprefix.h:9,
                   from skfmm/fmm.cpp:5:
  /tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
     17 | #warning "Using deprecated NumPy API, disable it with " \
        |  ^~~~~~~
  skfmm/travel_time_marcher.cpp: In member function ‘virtual double travelTimeMarcher::updatePointOrderTwo(int, std::set<int>)’:
  skfmm/travel_time_marcher.cpp:87:25: warning: comparison of integer expressions of different signedness: ‘std::set<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
     87 |     if(avoid_dim.size() == dim_) return std::numeric_limits<double>::infinity(); //end of the recursion, use inf so that it is discarded selecting the minimum
        |        ~~~~~~~~~~~~~~~~~^~~~~~~
  In file included from skfmm/base_marcher.cpp:6:
  skfmm/base_marcher.h: In member function ‘void baseMarcher::solve()’:
  skfmm/base_marcher.h:77:25: warning: ‘#‘target_mem_ref’ not supported by dump_expr#<expression error>’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     77 |     int newc = coord[dim]+dir;
        |                ~~~~~~~~~^
  g++ -pthread -shared -B /home/amin/mambaforge/envs/test/compiler_compat -L/home/amin/mambaforge/envs/test/lib -Wl,-rpath=/home/amin/mambaforge/envs/test/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/fmm.o build/temp.linux-x86_64-3.8/skfmm/heap.o build/temp.linux-x86_64-3.8/skfmm/base_marcher.o build/temp.linux-x86_64-3.8/skfmm/distance_marcher.o build/temp.linux-x86_64-3.8/skfmm/travel_time_marcher.o build/temp.linux-x86_64-3.8/skfmm/extension_velocity_marcher.o -o build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so
  building 'skfmm.pheap' extension
  compiling C++ sources
  C compiler: g++ -pthread -B /home/amin/mambaforge/envs/test/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
  
  compile options: '-I/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/core/include -I/home/amin/mambaforge/envs/test/include/python3.8 -c'
  g++: skfmm/pheap.cpp
  g++: skfmm/heap.cpp
  g++ -pthread -shared -B /home/amin/mambaforge/envs/test/compiler_compat -L/home/amin/mambaforge/envs/test/lib -Wl,-rpath=/home/amin/mambaforge/envs/test/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/pheap.o build/temp.linux-x86_64-3.8/skfmm/heap.o -o build/lib.linux-x86_64-3.8/skfmm/pheap.cpython-38-x86_64-linux-gnu.so
  installing to build/bdist.linux-x86_64/wheel
  running install
  running install_lib
  creating build/bdist.linux-x86_64
  creating build/bdist.linux-x86_64/wheel
  creating build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/setup.py -> build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/pfmm.py -> build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/__init__.py -> build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/pheap.cpython-38-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/wheel/skfmm
  copying build/lib.linux-x86_64-3.8/skfmm/heap.py -> build/bdist.linux-x86_64/wheel/skfmm
  running install_egg_info
  running egg_info
  writing scikit_fmm.egg-info/PKG-INFO
  writing dependency_links to scikit_fmm.egg-info/dependency_links.txt
  writing requirements to scikit_fmm.egg-info/requires.txt
  writing top-level names to scikit_fmm.egg-info/top_level.txt
  Traceback (most recent call last):
    File "/home/amin/mambaforge/envs/test/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/home/amin/mambaforge/envs/test/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/amin/mambaforge/envs/test/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 230, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 215, in _build_with_temp_dir
      self.run_setup()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 267, in run_setup
      super(_BuildMetaLegacyBackend,
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 158, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 121, in <module>
      setup_package()
    File "setup.py", line 117, in setup_package
      setup(**metadata)
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/distutils/core.py", line 171, in setup
      return old_setup(**new_attr)
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 159, in setup
      return distutils.core.setup(**attrs)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 335, in run
      self.run_command('install')
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/distutils/command/install.py", line 62, in run
      r = self.setuptools_run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/distutils/command/install.py", line 36, in setuptools_run
      return distutils_install.run(self)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/command/install.py", line 557, in run
      self.run_command(cmd_name)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/install_egg_info.py", line 34, in run
      self.run_command('egg_info')
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/numpy/distutils/command/egg_info.py", line 27, in run
      _egg_info.run(self)
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 299, in run
      self.find_sources()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 306, in find_sources
      mm.run()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 541, in run
      self.add_defaults()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 578, in add_defaults
      sdist.add_defaults(self)
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/command/sdist.py", line 226, in add_defaults
      self._add_defaults_python()
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/sdist.py", line 113, in _add_defaults_python
      self._add_data_files(self._safe_data_files(build_py))
    File "/tmp/pip-build-env-5l4r6iyd/overlay/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 621, in _safe_data_files
      return build_py.get_data_files_without_manifest()
    File "/home/amin/mambaforge/envs/test/lib/python3.8/distutils/cmd.py", line 103, in __getattr__
      raise AttributeError(attr)
  AttributeError: get_data_files_without_manifest
  ----------------------------------------
  ERROR: Failed building wheel for scikit-fmm
Failed to build scikit-fmm
ERROR: Could not build wheels for scikit-fmm, which is required to install pyproject.toml-based projects

We use scikit-fmm as a dependency in our package porespy, which gets shipped via PyPI. Currently, our builds are broken due to this issue. We'd really appreciate it if you could look into it.

Many thanks!

Accurate distance without manually setting the dx

Hi,

I have an unstructured mesh and I would like to compute the distance from a zero level set for all nodes.

The distances seem to be right only for the 'optimal grid spacing' dx=2/(n-1), so this only works for structured meshes?

Any recommendations?

[Enhancement] GIL release

As we briefly discussed in pull request #35, it could be beneficial to release the GIL during the computation, to allow other threads to run concurrently.

However, I'm opening a issue instead of a new pull request, because I realized that in the current state my previous commit is not thread safe. Indeed, even though the marcher does not write in any shared memory, it reads directly from the python variables passed as arguments. This means, for example, that while thread A is computing the SDF for phi, thread B could change the content in phi.

This lead to the following possibilities:

  1. Do not release the GIL. It limit performances in multi-threaded applications, but has good performances in single-thread.
  2. Copy the parameters and then release the GIL. It allows for safe multithreading, but the copy of the parameters could be slow, and could finish the memory available, if the matrices are big enough. The parameters copy can cause a loss in performances in single thread.
  3. Release the GIL without copying the parameters, and leave on the programmer the responsibility for thread safeness. It looks like a bad idea, and is what my previous commit does.
  4. Add a parameter to select a behavior among the previous 3 points. This would be the most flexible choice, but would need to be well documented.

Bug in distance computation ?

Running the example below :

import skfmm
import numpy as np
phi = np.ones((3, 3))
phi[1, 1] = 0
skfmm.distance(phi)

Results :

array([[ 1.70710678,  1.       ,  1.70710678],
        [ 1.       , -0.35355339,  1.      ],
        [ 1.70710678,  1.       ,  1.70710678]])

Can someone explain me why the diagonal distance is equal to 1.70710678 and not equal to sqrt(2) ?

Thank you for your answer.

Abed

last version doesn't pass any test

I tried to install and execute the test but i does not pass any test.
I fixed the problem using this patch on fmm.cpp:
73c73

< flag = (PyArrayObject *)PyArray_FROMANY(pflag, PyArray_INT, 1,

flag = (PyArrayObject *)PyArray_FROMANY(pflag, PyArray_LONG, 1,

best regards,
Luigi

cannot install it on Azure Web App or Function

Python Version is
3.7.10
Linux

pip install scikit-fmm
    
    Collecting scikit-fmm
      Using cached scikit-fmm-2021.2.2.tar.gz (419 kB)
    Requirement already satisfied: numpy>=1.0.2 in /usr/local/lib/python3.7/site-packages (from scikit-fmm) (1.18.1)
    Building wheels for collected packages: scikit-fmm
      Building wheel for scikit-fmm (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9
    d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"',
     open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-
    5ebu19pu
           cwd: /tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/
      Complete output (32 lines):
      running bdist_wheel
      running build
      running config_cc
      unifing config_cc, config, build_clib, build_ext, build commands --compiler options
      running config_fc
      unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
      running build_src
      build_src
      building extension "skfmm.cfmm" sources
      building extension "skfmm.pheap" sources
      build_src: building npy-pkg config files
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.7
      creating build/lib.linux-x86_64-3.7/skfmm
      copying skfmm/pfmm.py -> build/lib.linux-x86_64-3.7/skfmm
      copying skfmm/setup.py -> build/lib.linux-x86_64-3.7/skfmm

      copying skfmm/heap.py -> build/lib.linux-x86_64-3.7/skfmm
      copying skfmm/__init__.py -> build/lib.linux-x86_64-3.7/skfmm
      running build_ext
      customize UnixCCompiler
      customize UnixCCompiler using build_ext
      customize UnixCCompiler
      customize UnixCCompiler using build_ext
      building 'skfmm.cfmm' extension
      compiling C++ sources
      C compiler: g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
    
      creating build/temp.linux-x86_64-3.7/skfmm
      compile options: '-Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include/python3.7m -c'
      g++: skfmm/fmm.cpp
      error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/
    core/include -I/usr/local/include/python3.7m -c skfmm/fmm.cpp -o build/temp.linux-x86_64-3.7/skfmm/fmm.o -MMD -MF build/temp.linux-x86_64-3.7/skfmm/fmm.o.d"
     failed with exit status 127
      ----------------------------------------
      ERROR: Failed building wheel for scikit-fmm
      Running setup.py clean for scikit-fmm
    Failed to build scikit-fmm
    Installing collected packages: scikit-fmm
        Running setup.py install for scikit-fmm ... error
        ERROR: Command errored out with exit status 1:
         command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3
    e9d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"
    ', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-re
    cord-gku3heb3/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/scikit-fmm
             cwd: /tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/
        Complete output (28 lines):
    Note: if you need to uninstall you should `pip install scikit-fmm` instead of using `setup.py install`
        running install
        running build
        running config_cc
        unifing config_cc, config, build_clib, build_ext, build commands --compiler options
        running config_fc
        unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
        running build_src
        build_src
        building extension "skfmm.cfmm" sources
        building extension "skfmm.pheap" sources
        build_src: building npy-pkg config files
        running build_py
        running build_ext
        customize UnixCCompiler
        customize UnixCCompiler using build_ext
        customize UnixCCompiler
        customize UnixCCompiler using build_ext
        building 'skfmm.cfmm' extension
        compiling C++ sources
        C compiler: g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
    
        creating build/temp.linux-x86_64-3.7/skfmm
        compile options: '-Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include/python3.7m -c'
        g++: skfmm/fmm.cpp
        error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Iskfmm -I/usr/local/lib/python3.7/site-packages/nump
    y/core/include -I/usr/local/include/python3.7m -c skfmm/fmm.cpp -o build/temp.linux-x86_64-3.7/skfmm/fmm.o -MMD -MF build/temp.linux-x86_64-3.7/skfmm/fmm.o.
    d" failed with exit status 127
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/s
    cikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';
    f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"
    '))' install --record /tmp/pip-record-gku3heb3/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3
    .7m/scikit-fmm Check the logs for full command output.





Conceptual: Description of the chosen boundary curve

Hi! I'm trying to understand the boundary curve of the algorithm used.

I've made a few plots:

image

image

For the first plot, since there is no white area, it seems that there's no space for any putative boundary to live (which in turn suggests that the algorithms is buggy)

For the second plot, it looks like this configuration might actually be feasible, in that there exists a curve that never enters any grey area and touches all the black circles at least once (it'd have to essentially follow the "extremal points" of the white area), but it's a rather awkward boundary to choose.

How would you describe the chosen boundary curve?

Support for python 3.11

It appears that skfmm/pheap.cpp needs to be re-Cythonized for python 3.11 support. When I attempt to pip install, there is no binary, and the build fails with the following error:

     INFO: compile options: '-I/tmp/pip-build-env-hs0al687/overlay/lib/python3.11/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.11/numpy/distutils/include -I/home/jsoishi/miniforge3/envs/scikit-test/include/python3.11 -c'
      extra options: '-msse -msse2 -msse3'
      INFO: g++: skfmm/pheap.cpp
      INFO: g++: skfmm/heap.cpp
      skfmm/pheap.cpp: In function ‘void __Pyx_AddTraceback(const char*, int, int, const char*)’:
      skfmm/pheap.cpp:446:62: error: invalid use of incomplete type ‘PyFrameObject’ {aka ‘struct _frame’}
        446 |   #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
            |                                                              ^~
      skfmm/pheap.cpp:3360:5: note: in expansion of macro ‘__Pyx_PyFrame_SetLineNumber’
       3360 |     __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
            |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      In file included from /home/jsoishi/miniforge3/envs/scikit-test/include/python3.11/Python.h:42,
                       from skfmm/pheap.cpp:6:
      /home/jsoishi/miniforge3/envs/scikit-test/include/python3.11/pytypedefs.h:22:16: note: forward declaration of ‘PyFrameObject’ {aka ‘struct _frame’}
         22 | typedef struct _frame PyFrameObject;
            |                ^~~~~~
      error: Command "g++ -pthread -B /home/jsoishi/miniforge3/envs/scikit-test/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/jsoishi/miniforge3/envs/scikit-test/include -fPIC -O2 -isystem /home/jsoishi/miniforge3/envs/scikit-test/include -fPIC -I/tmp/pip-build-env-hs0al687/overlay/lib/python3.11/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.11/numpy/distutils/include -I/home/jsoishi/miniforge3/envs/scikit-test/include/python3.11 -c skfmm/pheap.cpp -o build/temp.linux-x86_64-cpython-311/skfmm/pheap.o -MMD -MF build/temp.linux-x86_64-cpython-311/skfmm/pheap.o.d -msse -msse2 -msse3" failed with exit status 1

Error on pip install (Red Hat Linux)

Hi,

scikit-fmm is one of the dependencies of our project (https://github.com/QuakeMigrate/QuakeMigrate). We have had reports from a user that they are getting the following error when installing:

Collecting scikit-fmm
  Downloading scikit-fmm-2019.1.30.tar.gz (418 kB)
     |████████████████████████████████| 418 kB 381 kB/s
Requirement already satisfied: numpy>=1.0.2 in /share/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages (from scikit-fmm) (1.17.3)
Building wheels for collected packages: scikit-fmm
  Building wheel for scikit-fmm (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-14799q9q
       cwd: /tmp/pip-install-mfsx4cs8/scikit-fmm/
  Complete output (47 lines):
  running bdist_wheel
  running build
  running config_cc
  unifing config_cc, config, build_clib, build_ext, build commands --compiler options
  running config_fc
  unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
  running build_src
  build_src
  building extension "skfmm.cfmm" sources
  building extension "skfmm.pheap" sources
  build_src: building npy-pkg config files
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/setup.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/__init__.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/heap.py -> build/lib.linux-x86_64-3.8/skfmm
  copying skfmm/pfmm.py -> build/lib.linux-x86_64-3.8/skfmm
  running build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  building 'skfmm.cfmm' extension
  compiling C++ sources
  C compiler: g++ -pthread -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC  creating build/temp.linux-x86_64-3.8/skfmm
  compile options: '-Iskfmm -I/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include -I/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/include/python3.8 -c'
  g++: skfmm/fmm.cppg++: skfmm/heap.cpp
  g++: skfmm/base_marcher.cpp  g++: skfmm/travel_time_marcher.cpp
  g++: skfmm/distance_marcher.cppg++: skfmm/extension_velocity_marcher.cpp  In file included from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
                   from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                   from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/noprefix.h:9,
                   from skfmm/fmm.cpp:5:
  /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   #warning "Using deprecated NumPy API, disable it with " \
    ^
  g++ -pthread -shared -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -L/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,-rpath=/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/fmm.o build/temp.linux-x86_64-3.8/skfmm/heap.o build/temp.linux-x86_64-3.8/skfmm/base_marcher.o build/temp.linux-x86_64-3.8/skfmm/distance_marcher.o build/temp.linux-x86_64-3.8/skfmm/travel_time_marcher.o build/temp.linux-x86_64-3.8/skfmm/extension_velocity_marcher.o -o build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so
  /usr/bin/ld: this linker was not configured to use sysroots
  collect2: error: ld returned 1 exit status
  error: Command "g++ -pthread -shared -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -L/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,-rpath=/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/fmm.o build/temp.linux-x86_64-3.8/skfmm/heap.o build/temp.linux-x86_64-3.8/skfmm/base_marcher.o build/temp.linux-x86_64-3.8/skfmm/distance_marcher.o build/temp.linux-x86_64-3.8/skfmm/travel_time_marcher.o build/temp.linux-x86_64-3.8/skfmm/extension_velocity_marcher.o -o build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so" failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for scikit-fmm
  Running setup.py clean for scikit-fmm
Failed to build scikit-fmm
Installing collected packages: scikit-fmm
    Running setup.py install for scikit-fmm ... error
    ERROR: Command errored out with exit status 1:
     command: /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-j3p8l5f2/install-record.txt --single-version-externally-managed --compile --install-headers /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/include/python3.8/scikit-fmm
         cwd: /tmp/pip-install-mfsx4cs8/scikit-fmm/
    Complete output (43 lines):                Note: if you need to uninstall you should `pip install scikit-fmm` instead of using `setup.py install`    running install
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    running build_src
    build_src
    building extension "skfmm.cfmm" sources
    building extension "skfmm.pheap" sources
    build_src: building npy-pkg config files
    running build_py
    running build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    building 'skfmm.cfmm' extension
    compiling C++ sources
    C compiler: g++ -pthread -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC    creating build/temp.linux-x86_64-3.8/skfmm
    compile options: '-Iskfmm -I/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include -I/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/include/python3.8 -c'
    g++: skfmm/fmm.cpp
    g++: skfmm/distance_marcher.cpp
    g++: skfmm/travel_time_marcher.cpp
    g++: skfmm/base_marcher.cpp
    g++: skfmm/extension_velocity_marcher.cpp
    g++: skfmm/heap.cpp
    In file included from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
                     from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                     from /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/noprefix.h:9,
                     from skfmm/fmm.cpp:5:
    /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
     #warning "Using deprecated NumPy API, disable it with " \
      ^
    g++ -pthread -shared -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -L/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,-rpath=/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/fmm.o build/temp.linux-x86_64-3.8/skfmm/heap.o build/temp.linux-x86_64-3.8/skfmm/base_marcher.o build/temp.linux-x86_64-3.8/skfmm/distance_marcher.o build/temp.linux-x86_64-3.8/skfmm/travel_time_marcher.o build/temp.linux-x86_64-3.8/skfmm/extension_velocity_marcher.o -o build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so
    /usr/bin/ld: this linker was not configured to use sysroots
    collect2: error: ld returned 1 exit status
    error: Command "g++ -pthread -shared -B /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/compiler_compat -L/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,-rpath=/home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/skfmm/fmm.o build/temp.linux-x86_64-3.8/skfmm/heap.o build/temp.linux-x86_64-3.8/skfmm/base_marcher.o build/temp.linux-x86_64-3.8/skfmm/distance_marcher.o build/temp.linux-x86_64-3.8/skfmm/travel_time_marcher.o build/temp.linux-x86_64-3.8/skfmm/extension_velocity_marcher.o -o build/lib.linux-x86_64-3.8/skfmm/cfmm.cpython-38-x86_64-linux-gnu.so" failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"'; __file__='"'"'/tmp/pip-install-mfsx4cs8/scikit-fmm/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-j3p8l5f2/install-record.txt --single-version-externally-managed --compile --install-headers /home1/-/Tools/Anaconda/anaconda/envs/QuakeMigrate/include/python3.8/scikit-fmm Check the logs for full command output.

This error only occurs when installing from this yml:

name: QuakeMigrate
channels:
  - conda-forge
  - defaults
dependencies:
  - ffmpeg
  - ipython
  - jupyter
  - numpy
  - obspy
  - pandas
  - pip
  - python
  - pyproj
  - scipy
  - pip:
    - scikit-fmm==2019.1.30

There is no error when installing from:

name: QuakeMigrate
channels:
  - conda-forge
  - defaults
dependencies:
  - ffmpeg=3.4.1*=2
  - ipython
  - jupyter
  - libgcc-ng
  - matplotlib
  - numpy
  - obspy
  - pandas=0.19.*
  - pip
  - pyqt
  - python
  - scipy
  - pyproj
  - pip:
    - cython==0.24.1
    - scikit-fmm==2019.1.30

The operating system is Red Hat Enterprise Linux.

However, I am unable to replicate the issue. Installing on my Ubuntu 18.04 works completely fine. Let me know if you need any more information and I can try get it.

Thanks!

No wheels for python3.9

Hi,
There are no wheels for windows python3.9 on PyPI, even of the latest version, it would be nice to upload such a wheel 😃
If you're lazy you can use the wheel I've built: scikit_fmm_whl.zip
Thanks!

Numerical issue?

Probably related to #18 and or #15
From: Weilun Sun

import skfmm
import numpy as np

phi = np.array([[ 1, 1, -1, -1, -1, -1, 1],
                         [ 1, 1, 1, 1, 1, 1, 1],
                         [ 1, 1, 1, 1, 1, 1, 3],
                         [ 1, 1, 1, 3, 3, 3, 3],
                         [ 3, 3, 3, 1, 3, 3, 3]])

speed = np.array([[ 1. , 1. , 1, 1, 1, 1, 1. ],
                             [ 1. , 1. , 0.2, 0.5, 0.997, 0.678, 1. ],
                             [ 1. , 1. , 1. , 1. , 1. , 1. , 1. ],
                             [ 1. , 1. , 1. , 1. , 1. , 1. , 1. ],
                             [ 1. , 1. , 1. , 1. , 1. , 1. , 1. ]])

skfmm.travel_time(phi,speed)

Try this one?
The input looks legit to me. zero boundary is clear and speed is all positive.
If I change that 0.2 to 0.5 (something larger) in speed, there's no error. So I'm guessing it could be some numerical issues.

GIL is held while marching

It would be nice if the marching could be done while the interpreter lock is released, to allow skfmm to run in its own thread. I assume it's not as simple as

diff --git a/skfmm/fmm.cpp b/skfmm/fmm.cpp
index 351a51d..3ae18cf 100644
--- a/skfmm/fmm.cpp
+++ b/skfmm/fmm.cpp
@@ -304,7 +304,9 @@ static PyObject *distance_method(PyObject *self, PyObject *args)
   }
 
   try {
+      Py_BEGIN_ALLOW_THREADS
       marcher->march();
+      Py_END_ALLOW_THREADS
       error = marcher->getError();
       delete marcher;
     } catch (const std::exception& exn) {

because the marcher works on memory owned by Python objects, but I don't know enough to write a complete solution

AppVeyor test fails, masked array __repr__ changes?

The AppVeyor build fails. It seems like the __repr__() of masked numpy arrays changed at some point. Should be an easy fix, opening an issue so I do not forget!

File "C:\projects\scikit-fmm\skfmm\__init__.py", line 769, in skfmm.testing
Failed example:
    d
Expected:
    masked_array(data = [-- -- -0.5 0.5 -- --],
                 mask = [ True  True False False  True  True],
           fill_value = 1e+20)
    <BLANKLINE>
Got:
    masked_array(data=[--, --, -0.5, 0.5, --, --],
                 mask=[ True,  True, False, False,  True,  True],
           fill_value=1e+20)
**********************************************************************
1 items had failures:
   1 of 348 in skfmm.testing
***Test Failed*** 1 failures.

Pip install broken on CIs

Hello,
I just wanted to make you aware of the fact that we are experiencing some problems when running our CIs (started today), and the error seems to come from scikit-fmm (see error below):

2022-08-15T18:27:15.3770605Z   × Building wheel for scikit-fmm (pyproject.toml) did not run successfully.
2022-08-15T18:27:15.3771164Z   │ exit code: 1
2022-08-15T18:27:15.3771794Z   ╰─> [24 lines of output]
2022-08-15T18:27:15.3772238Z       Traceback (most recent call last):
2022-08-15T18:27:15.3780989Z         File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
2022-08-15T18:27:15.3781816Z Failed to build scikit-fmm
2022-08-15T18:27:15.3782814Z           main()
2022-08-15T18:27:15.3783737Z         File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
2022-08-15T18:27:15.3784869Z           json_out['return_val'] = hook(**hook_input['kwargs'])
2022-08-15T18:27:15.3785734Z         File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
2022-08-15T18:27:15.3786565Z           return _build_backend().build_wheel(wheel_directory, config_settings,
2022-08-15T18:27:15.3787414Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 404, in build_wheel
2022-08-15T18:27:15.3788282Z           return self._build_with_temp_dir(['bdist_wheel'], '.whl',
2022-08-15T18:27:15.3789117Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 389, in _build_with_temp_dir
2022-08-15T18:27:15.3789875Z           self.run_setup()
2022-08-15T18:27:15.3790641Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 474, in run_setup
2022-08-15T18:27:15.3791792Z           super(_BuildMetaLegacyBackend,
2022-08-15T18:27:15.3792452Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 334, in run_setup
2022-08-15T18:27:15.3792820Z           exec(code, locals())
2022-08-15T18:27:15.3793087Z         File "<string>", line 122, in <module>
2022-08-15T18:27:15.3793439Z         File "<string>", line 116, in setup_package
2022-08-15T18:27:15.3794010Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/numpy/distutils/core.py", line 26, in <module>
2022-08-15T18:27:15.3794450Z           from numpy.distutils.command import config, config_compiler, \
2022-08-15T18:27:15.3795072Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/numpy/distutils/command/config.py", line 20, in <module>
2022-08-15T18:27:15.3795539Z           from numpy.distutils.mingw32ccompiler import generate_manifest
2022-08-15T18:27:15.3796222Z         File "/tmp/pip-build-env-0opf3fkf/overlay/lib/python3.8/site-packages/numpy/distutils/mingw32ccompiler.py", line 34, in <module>
2022-08-15T18:27:15.3796727Z           from distutils.msvccompiler import get_build_version as get_build_msvc_version
2022-08-15T18:27:15.3797211Z       ModuleNotFoundError: No module named 'distutils.msvccompiler'
2022-08-15T18:27:15.3797672Z       [end of output]
2022-08-15T18:27:15.3797867Z   
2022-08-15T18:27:15.3798151Z   note: This error originates from a subprocess, and is likely not a problem with pip.
2022-08-15T18:27:15.3798553Z   ERROR: Failed building wheel for scikit-fmm
2022-08-15T18:27:15.3799028Z ERROR: Could not build wheels for scikit-fmm, which is required to install pyproject.toml-based projects
2022-08-15T18:27:15.7557728Z ##[error]The operation was canceled.

ModuleNotFoundError: No module named 'numpy' still happens in 2021.2.2

I'm trying to deploy my project on Deta,

my project has dependency on scikit-fmm, and error happened:

.....
Collecting setuptools>=3.0
  Downloading setuptools-56.2.0-py3-none-any.whl (785 kB)
Using legacy 'setup.py install' for scikit-fmm, since package 'wheel' is not installed.
Installing collected packages: six, typing-extensions, python-dateutil, pyparsing, Pillow, numpy, kiwisolver, decorator, cycler, tifffile, starlette, setuptools, scipy, PyWavelets, pydantic, networkx, matplotlib, MarkupSafe, imageio, h11, click, uvloop, uvicorn, scikit-image, scikit-fmm, opencv-python, jinja2, httptools, gunicorn, fastapi, aiofiles
    Running setup.py install for scikit-fmm: started
    Running setup.py install for scikit-fmm: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-py90hsi3/install-record.txt --single-version-externally-managed --home /tmp/pip-target-17_449op --compile --install-headers /tmp/pip-target-17_449op/include/python/scikit-fmm
         cwd: /tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/
    Complete output (10 lines):
    
                Note: if you need to uninstall you should `pip install scikit-fmm` instead of using `setup.py install`
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py", line 121, in <module>
        setup_package()
      File "/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py", line 115, in setup_package
        from numpy.distutils.core import setup
    ModuleNotFoundError: No module named 'numpy'
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fa1k6349/scikit-fmm_d4cd460f8fc34bf7a732ae31a736e7ee/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-py90hsi3/install-record.txt --single-version-externally-managed --home /tmp/pip-target-17_449op --compile --install-headers /tmp/pip-target-17_449op/include/python/scikit-fmm Check the logs for full command output.

Error: failed to update dependecies: error on one or more dependencies, no dependencies were added, see output for details

I did notice that this error was mentioned here: #49

but seems it is still there.

Inside my requirements.txt I have tried both using
scikit-fmm
or
scikit-fmm==2021.2.2

But both failed with same error.

How to reproduce?

  1. create a python app with dependency on scikit-fmm
  2. deploy it to Deta with command deta deploy (you need to register and create a Micro first)

Please help

Visualize shortest path

Hi, thanks for the great code base!

I can get an approximate distance between two points but is a way to extract (and visualize) the shortest path between a 'source' (value of 1) and 'target' (value of -1) using scikit-fmm?

Vanishing velocity

Thanks a lot for making this fast marching code available.
I am trying to use this code to compute shortest distances in my 3D models, and curious about what is physical meaning of vanishing velocity. Is it some sort of boundary condition (e.g. free surface?)

If I want to know bit more theoretical basis of this code what is a good reference? Also, if I would like to cite this code, what is a good reference?

wheel files not working on Conda with Windows

pip install scikit-fmm
python -c "import skfmm"

gives this error:

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\jason\Anaconda3\lib\site-packages\skfmm\__init__.py", line 51, in <module>
    from .pfmm import distance, travel_time, extension_velocities
  File "C:\Users\jason\Anaconda3\lib\site-packages\skfmm\pfmm.py", line 4, in <module>
    from .cfmm import cFastMarcher
ImportError: numpy.core.multiarray failed to import

For now the fix is to uninstall the wheel and build from source:

pip uninstall scikit-fmm
pip install --no-binary :all: scikit-fmm

travel_time() gives spurious results

phi=arange(-5,5)+0.499

skfmm.distance(phi)
array([-4.501, -3.501, -2.501, -1.501, -0.501, 0.499, 1.499, 2.499,
3.499, 4.499])
skfmm.travel_time(phi,speed=ones_like(phi))
array([ 4.00816049, 3.02048148, 2.05744444, 1.16833333, 0.501 ,
0.499 , 1.499 , 2.499 , 3.499 , 4.499 ])

Marching issue in a skeleton

If input array phi is a skeleton where some adjacent pixels are not 4 neighbourhood (they are 8 neighbourhood), fmm method may stop marching. How to deal with this problem?

RuntimeError: Negative discriminant in time marcher quadratic.

Hi all,

The below simple code generate the below error message (order=2)
RuntimeError: Negative discriminant in time marcher quadratic.

import numpy as np
import skfmm
img=np.zeros((512,512),dtype=np.float64)
seeds=np.ones((512,512),dtype=np.float64)
seeds[254:255,254:255]=0
img=np.random.uniform(low=0,high=1,size=(512,512));
dist1=skfmm.travel_time(seeds,img,order=2);

Image has to be highly smoothed in order for the error to disappear or order needs to be 1.

But many times I need order=2 and I can not guarantee a smoothed image.

Would you please help.

Thanks

Problem with pip-installing from requirements.txt

Installing dependencies with pip install -r requirements.txt using scikit-fmm and the following requirements file

numpy==1.10
numba==0.35
scikit-fmm==0.0.9

fails with the following traceback :

Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-hsbtpkmm/scikit-fmm/setup.py", line 65, in <module>
        setup_package()
      File "/tmp/pip-build-hsbtpkmm/scikit-fmm/setup.py", line 42, in setup_package
        from numpy.distutils.core import setup
    ModuleNotFoundError: No module named 'numpy'

This means there's a problem with the setup.py.

I discovered this while building an FMM-based app on Travis CI.

Suggestion: Adding support for unstructured grids

How difficult would it be to add support for unstructured grids? I understand the calculation of spatial gradients becomes more difficult and is likely beyond the scope of this code. However, suppose the user is able to provide the spatial gradients at each point and coordinates of each point. If you accepted these as two optional arguments into the various functions, how difficult would it be to implement the support for unstructured grids?

div by zero error in scikit-fmm extension velocity

I am testing this package with random data and got this error message below:

terminate called after throwing an instance of 'std::runtime_error'
what(): div by zero error in scikit-fmm extension velocity

I am not sure whether there is any bugs or limitations of fast marching method. I attached my code.

Thanks
Code.zip

Scikit-fmm not building on mac os x with new numpy (1.18.0)

Hi,
I have scikit-fmm as one of the dependencies of my project (http://github.com/equinor/pylops) and a couple of days ago my azure pipeline on mac os x stopped working with the following error when trying to build the wheels of scikit-fmm:

2019-12-29T22:22:39.9026630Z   Building wheel for scikit-fmm (setup.py): started
2019-12-29T22:22:44.5801050Z   Building wheel for scikit-fmm (setup.py): finished with status 'error'
2019-12-29T22:22:44.5805430Z   ERROR: Command errored out with exit status 1:
2019-12-29T22:22:44.5807000Z    command: /Users/runner/hostedtoolcache/Python/3.7.5/x64/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-install-8oodt2vp/scikit-fmm/setup.py'"'"'; __file__='"'"'/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-install-8oodt2vp/scikit-fmm/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-wheel-z495mm6n --python-tag cp37
2019-12-29T22:22:44.5808100Z        cwd: /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-install-8oodt2vp/scikit-fmm/
2019-12-29T22:22:44.5808440Z   Complete output (43 lines):
2019-12-29T22:22:44.5808630Z   running bdist_wheel
2019-12-29T22:22:44.5809250Z   running build
2019-12-29T22:22:44.5809450Z   running config_cc
2019-12-29T22:22:44.5810170Z   unifing config_cc, config, build_clib, build_ext, build commands --compiler options
2019-12-29T22:22:44.5810470Z   running config_fc
2019-12-29T22:22:44.5811160Z   unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
2019-12-29T22:22:44.5811460Z   running build_src
2019-12-29T22:22:44.5811680Z   build_src
2019-12-29T22:22:44.5811900Z   building extension "skfmm.cfmm" sources
2019-12-29T22:22:44.5812140Z   building extension "skfmm.pheap" sources
2019-12-29T22:22:44.5812800Z   build_src: building npy-pkg config files
2019-12-29T22:22:44.5813090Z   running build_py
2019-12-29T22:22:44.5813320Z   creating build
2019-12-29T22:22:44.5813980Z   creating build/lib.macosx-10.13-x86_64-3.7
2019-12-29T22:22:44.5814700Z   creating build/lib.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5815420Z   copying skfmm/__init__.py -> build/lib.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5816240Z   copying skfmm/heap.py -> build/lib.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5817000Z   copying skfmm/pfmm.py -> build/lib.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5817780Z   copying skfmm/setup.py -> build/lib.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5818110Z   running build_ext
2019-12-29T22:22:44.5818360Z   customize UnixCCompiler
2019-12-29T22:22:44.5818630Z   customize UnixCCompiler using build_ext
2019-12-29T22:22:44.5818880Z   customize UnixCCompiler
2019-12-29T22:22:44.5819150Z   customize UnixCCompiler using build_ext
2019-12-29T22:22:44.5820080Z   building 'skfmm.cfmm' extension
2019-12-29T22:22:44.5820380Z   compiling C++ sources
2019-12-29T22:22:44.5821150Z   C compiler: g++ -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99
2019-12-29T22:22:44.5821500Z   
2019-12-29T22:22:44.5822200Z   creating build/temp.macosx-10.13-x86_64-3.7/skfmm
2019-12-29T22:22:44.5823120Z   compile options: '-Iskfmm -I/Users/runner/hostedtoolcache/Python/3.7.5/x64/lib/python3.7/site-packages/numpy/core/include -I/Users/runner/hostedtoolcache/Python/3.7.5/x64/include/python3.7m -c'
2019-12-29T22:22:44.5823500Z   g++: skfmm/fmm.cpp
2019-12-29T22:22:44.5823790Z   g++: skfmm/heap.cppg++: skfmm/base_marcher.cpp
2019-12-29T22:22:44.5824060Z   
2019-12-29T22:22:44.5824310Z   g++: skfmm/distance_marcher.cpp
2019-12-29T22:22:44.5825040Z   errorerror: : invalid argument '-std=c99' not allowed with 'C++'error:
2019-12-29T22:22:44.5825860Z   error: invalid argument '-std=c99' not allowed with 'C++'invalid argument '-std=c99' not allowed with 'C++'
2019-12-29T22:22:44.5826630Z   invalid argument '-std=c99' not allowed with 'C++'
2019-12-29T22:22:44.5826950Z   
2019-12-29T22:22:44.5827200Z   g++: skfmm/travel_time_marcher.cpp
2019-12-29T22:22:44.5827480Z   g++: skfmm/extension_velocity_marcher.cpp
2019-12-29T22:22:44.5828200Z   error: invalid argument '-std=c99' not allowed with 'C++'
2019-12-29T22:22:44.5828960Z   error: invalid argument '-std=c99' not allowed with 'C++'
2019-12-29T22:22:44.5830150Z   error: Command "g++ -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Iskfmm -I/Users/runner/hostedtoolcache/Python/3.7.5/x64/lib/python3.7/site-packages/numpy/core/include -I/Users/runner/hostedtoolcache/Python/3.7.5/x64/include/python3.7m -c skfmm/base_marcher.cpp -o build/temp.macosx-10.13-x86_64-3.7/skfmm/base_marcher.o -MMD -MF build/temp.macosx-10.13-x86_64-3.7/skfmm/base_marcher.o.d" failed with exit status 1
2019-12-29T22:22:44.5831030Z   ----------------------------------------
2019-12-29T22:22:44.5831790Z   ERROR: Failed building wheel for scikit-fmm
2019-12-29T22:22:44.5832520Z   Running setup.py clean for scikit-fmm

I tried to reproduce this error locally on my mac and after some digging I found out that this one works fine

pip install numpy==1.17.3
pip install scikit-fmm --no-cache-dir

while this one leads to the above mentioned error:

pip install numpy==1.18.0
pip install scikit-fmm --no-cache-dir

Note that the latter is the latest numpy which you would also get if simply doing pip install numpy and so it will quickly be used by most people. As I see from your setup.py file that you use numpy.distutils.misc_util I wonder if some change in the new release of numpy could be responsible for this?

Thank you!

spurious type error

First problem! I installed and then this...

In [1]: import skfmm

In [2]: import numpy as np

In [3]: phi = np.ones((3, 3))

In [4]: phi[1, 1] = -1

In [5]: skfmm.distance(phi)

ValueError Traceback (most recent call last)
/users/wd15/packages/ in ()
----> 1 skfmm.distance(phi)

/users/wd15/.virtualenvs/lsmlib/lib/python2.6/site-packages/skfmm/pfmm.pyc
in distance(phi, dx, self_test)
71 """
72 phi, dx, flag = pre_process_args(phi, dx)
---> 73 d = cFastMarcher(phi, dx, flag, None, int(self_test))
74 d = post_process_result(d)
75 return d

ValueError: flag must be a 1D to 12-D array of integers

Any ideas?

Fast marching method through diagonal pixels?

I am not sure if this is possible within the confines of the fast marching algorithm but can the existing method be adjusted to move through a diagonal as in the image below where the blue indicates the masked areas (obstacle)?

image

The "movement" must occur vertically / horizontally only and requires the channel to be

image

Thanks for your help.

Unable to use wheel with older versions of numpy

Now when #49 and #55 has been resolved, I now see a new unforeseen issue. I use a version of numpy that is not the latest, but the wheel seems to always build with the latest version of all build dependencies, including numpy. When running, this gives the error seen in #27 (but on every platform).

ImportError: numpy.core.multiarray failed to import

This is probably not an issue that only applies to scikit-fmm, but rather for any library with wheels that depend on numpy.

This can reproduce the issue (with docker installed):

docker run --rm -it python:3.7.9 /bin/bash -c 'pip install wheel; pip install numpy==1.19.0 scikit-fmm; python -c "import skfmm"'

Seemingly erroneous 0 in travel time

Take the following phi and speed arrays:

import numpy as np
import skfmm
phi = np.array([[ 1,  1, -1, -1, -1, -1,  1],
                [ 3,  1, -1, -1, -1, -1,  1],
                [ 3,  3,  1,  1,  1,  1,  3],
                [ 3,  3,  3,  3,  3,  3,  3],
                [ 3,  3,  3,  3,  3,  3,  3]])
speed = np.array([[ 1.   ,  1.   ,  0.057,  0.128,  0.037,  0.039,  1.   ],
                  [ 1.   ,  1.   ,  0.199,  0.408,  0.997,  0.688,  1.   ],
                  [ 1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ],
                  [ 1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ],
                  [ 1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ,  1.   ]])

The returned value for the fourth element in the first row when executing skfmm.travel_time(phi, speed) is given as zero, even though it is 'surrounded' by inaccessible values with speeds less than 1.

My output is:

In : skfmm.travel_time(phi, speed)
Out: 
array([[  1.5  ,   0.5  ,   8.772,   0.   ,  11.557,  12.821,   0.5  ],
       [  1.5  ,   0.5  ,   1.777,   1.225,   0.502,   0.514,   0.5  ],
       [  1.748,   0.971,   0.5  ,   0.5  ,   0.5  ,   0.5  ,   0.971],
       [  2.301,   1.748,   1.5  ,   1.5  ,   1.5  ,   1.5  ,   1.748],
       [  3.055,   2.655,   2.5  ,   2.5  ,   2.5  ,   2.5  ,   2.655]])

In : skfmm.distance(phi, 1)
Out : 
array([[ 1.499,  0.5  , -0.5  , -1.305, -1.305, -0.5  ,  0.5  ],
       [ 1.451,  0.5  , -0.354, -0.5  , -0.5  , -0.354,  0.5  ],
       [ 1.762,  0.971,  0.5  ,  0.5  ,  0.5  ,  0.5  ,  0.971],
       [ 2.337,  1.762,  1.451,  1.499,  1.499,  1.451,  1.762],
       [ 3.099,  2.673,  2.435,  2.498,  2.498,  2.435,  2.673]])

Getting direction to nearest zero point

The distance() method returns the signed distance to the nearest point on the contour given by phi, but is it also possible to somehow get an angle or vector indicating the direction of this nearest point? I'm assuming this is already computed internally when the fast marching algorithm is implemented, but can I somehow access this?

I guess it could also be done by taking the gradient of the signed distance, but it just seems like additional overhead.

Installation went well, but unable to import

Hi, I installed scikit-fmm and it went well. But when I try to import it shows error regarding numpy version. But my numpy version is 1.22.4, which seems to be well above required (as mentioned in the instructions).
could you please help-

import skfmm
`---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf


ImportError Traceback (most recent call last)
in
----> 1 import skfmm

~\Anaconda3\lib\site-packages\skfmm_init_.py in
49 docformat = 'restructuredtext'
50
---> 51 from .pfmm import distance, travel_time, extension_velocities
52 from .heap import heap
53

~\Anaconda3\lib\site-packages\skfmm\pfmm.py in
2 import numpy as np
3
----> 4 from .cfmm import cFastMarcher
5
6 FAR, NARROW, FROZEN, MASK = 0, 1, 2, 3

ImportError: numpy.core.multiarray failed to import
`

Linux build broken in master

skfmm/travel_time_marcher.cpp:92:9: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
auto ret = tempset.insert(ind);
^
skfmm/travel_time_marcher.cpp:92:14: error: ‘ret’ does not name a type
auto ret = tempset.insert(ind);
^
skfmm/travel_time_marcher.cpp:93:13: error: ‘ret’ was not declared in this scope
if(!ret.second) continue; //avoid recursive call on identical parameter
^
error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -Iskfmm -I/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/numpy/core/include -I/opt/python/3.7.1/include/python3.7m -I/opt/python/3.7.1/include/python3.7m -c skfmm/travel_time_marcher.cpp -o build/temp.linux-x86_64-3.7/skfmm/travel_time_marcher.o -MMD -MF build/temp.linux-x86_64-3.7/skfmm/travel_time_marcher.o.d" failed with exit status 1
The command "python setup.py develop" failed and exited with 1 during .
Your build has been stopped.

Negative Discriminant Error

Hello,

I am using the the travel_time() function and receiving a negative discriminant error. I have seen multiple issues regarding this error message, but have not been able to determine a clear method/way to resolve this issue. Is this a known bug and is it being worked on?

Thanks,
Alec

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.