This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
OpenPIV is a Python library for Particle Image Velocimetry (PIV) analysis of fluid flow images: it extracts velocity fields from pairs of particle-seeded flow images via cross-correlation.
Always reference these instructions first and fall back to search or bash commands only when you encounter unexpected information that does not match the info here.
- Use Poetry:
pip install poetrythenpoetry install(~10 seconds). All development commands should usepoetry run <command>.
- Run tests:
poetry run pytest openpiv -v— ~10 seconds, 216 tests pass. - Run a single test file:
poetry run pytest openpiv/test/test_process.py -v - Import test:
poetry run python -c "import openpiv; print('OpenPIV imported successfully')" - No linting tools are configured (no black, flake8, etc.).
python setup.py build_ext --inplaceis a legacy no-op: all Cython (.pyx) files have been removed and converted to pure Python, despite the package description still mentioning "Cython modules".
poetry run python openpiv/tutorials/tutorial1.py— demonstrates a complete PIV analysis workflow.- Sample test data lives at
openpiv/data/test1/(exp1_001_a.bmp,exp1_001_b.bmp), accessed viaimportlib.resources.files('openpiv.data').joinpath('test1/...')(stdlib, not the third-partyimportlib_resources).
piv.py— high-level entry points:simple_piv(),piv_example(),process_pair().pyprocess.py— core 2D cross-correlation algorithms:extended_search_area_piv(),get_coordinates().pyprocess3D.py— 3D PIV algorithms.windef.py— window-deformation iterative (multi-pass) PIV:multipass_img_deform(),piv(); driven by aPIVSettingsinstance fromsettings.py.settings.py—PIVSettingsdataclass; defaults point at the bundled test data. Key fields:filepath_images,frame_pattern_a/frame_pattern_b,windowsizes,overlap,num_iterations(tuples must align position-by-position across passes).validation.py— spurious vector detection:global_val(),global_std(),sig2noise_val().filters.py— outlier replacement:replace_outliers(), which calls intolib.replace_nans()for the actual NaN inpainting.lib.py— low-level NaN inpainting used byfilters.py.tools.py— I/O and visualization:imread(),save(),display_vector_field(),transform_coordinates()(always call before saving/displaying results — raw PIV output coordinates are in image/array convention, not physical/plot convention).scaling.py— coordinate scaling and transformation.preprocess.py— image preprocessing (background subtraction, masking).smoothn.py— robust spline smoothing; a Python port ofsmoothn.m(D. Garcia / Prof. Lewis) bundled for convenience — it is not covered by the OpenPIV license, see README for attribution.phase_separation.py— solid-phase / liquid-tracer separation utilities.
- Quick path:
piv.simple_piv(frame_a, frame_b, plot=False)→(x, y, u, v, s2n). - Full pipeline:
piv.process_pair(frame_a, frame_b)→(x, y, u, v, mask). - Manual pipeline:
pyprocess.extended_search_area_piv()for raw(u, v, s2n)→validation.sig2noise_val()/global_val()to flag spurious vectors →filters.replace_outliers()to fill them →tools.transform_coordinates()→tools.save(). - Batch/multi-pass: build a
PIVSettings, thenwindef.piv(settings).
openpiv/test/(~216 tests).conftest.pyforces theAggmatplotlib backend and patchesplt.showso tests run headless — keep that in mind if adding plotting code.
- Package name on PyPI is
OpenPIV; import name is lowercaseopenpiv. - Dependencies are declared in
pyproject.toml(Poetry) with a fallbacksetup.py; keep both in sync if changing dependencies or version. pyproject.tomlstill uses the deprecated[tool.poetry.dev-dependencies]section — this warns but is harmless, not a bug to fix incidentally.