isosurfaces
raw JSON → 0.1.2 verified Mon Apr 27 auth: no python
Construct isolines/isosurfaces over a 2D/3D scalar field defined by a function (not a uniform grid). Current version: 0.1.2. Release cadence: irregular, minor patches.
pip install isosurfaces Common errors
error ImportError: cannot import name 'marching_squares' from 'isosurfaces' ↓
cause Outdated version or incorrect import path.
fix
Upgrade to latest: pip install --upgrade isosurfaces. Use: from isosurfaces import marching_squares
error TypeError: marching_squares() missing 1 required positional argument: 'level' ↓
cause The second argument is the contour level (isovalue), not optional.
fix
Call marching_squares(values, level) where level is a float, e.g., 0.0.
Warnings
gotcha The input to marching_squares/marching_cubes must be a 2D/3D numpy array of scalar values on a rectangular grid, not a function. The library does not handle adaptive sampling; you must pre-sample the field. ↓
fix Generate a regular grid of values (e.g., using np.meshgrid) before calling the function.
gotcha The output vertices are in pixel/grid coordinates (indices), not world coordinates. You must scale/transform them yourself if needed. ↓
fix Map indices to world coordinates: x_world = x_min + (idx / (shape[0]-1)) * (x_max - x_min).
gotcha Library is in early development (v0.1.x); API may change without notice. Expect breaking changes in minor versions. ↓
fix Pin version in requirements: isosurfaces==0.1.2
Imports
- marching_squares wrong
from isosurfaces.marching_squares import marching_squarescorrectfrom isosurfaces import marching_squares - marching_cubes wrong
from isosurfaces.marching_cubes import marching_cubescorrectfrom isosurfaces import marching_cubes
Quickstart
from isosurfaces import marching_squares
import numpy as np
def f(x, y):
return x**2 + y**2 - 1
# Sample the function on a grid
xs = np.linspace(-2, 2, 100)
ys = np.linspace(-2, 2, 100)
values = np.array([[f(x, y) for x in xs] for y in ys])
# Extract isoline at value 0
verts, edges = marching_squares(values, 0)
print(f"Found {len(verts)} vertices, {len(edges)} edges")