Skip to main content

rheofit

Fit flow curves — viscosity as a function of shear rate — to physically-based rheological models, and turn them into quantified material properties.

A flow curve is the fingerprint of a non-Newtonian fluid: shear thinning, yield stress, low-shear plateaus and relaxation times are all features of that one curve. Fitting it with a model whose parameters have physical meaning does three things:

  • Quantifies material properties — $\sigma_y$, $\eta_0$, $\lambda$, $n$ — instead of describing curve shapes.
  • Gives a concise description of the material — a handful of numbers replace hundreds of points, so samples, temperatures and batches become directly comparable.
  • Feeds back to formulators — when the properties are tied to the formulation, they say immediately which ingredient or level to move to hit a material-property target.
Parameter Reads as Usual formulation lever
$\sigma_y$ strength of the structured network structurant level, particle/fiber network
$\eta_0$ zero-shear / at-rest viscosity thickener or polymer concentration
$\lambda$ relaxation time, onset of thinning molecular weight, micelle length
$n$ how sharply it shear-thins polymer architecture, entanglement
$\eta_{bg}$ Newtonian background flow solvent / continuous phase

Data is read directly from TA Instruments TRIOS JSON, but fit() accepts any DataFrame with shear-rate and stress columns.

Fitting contract

Every fit minimises the relative residual $(f(\dot\gamma;p)-\sigma)/|\sigma|$, so each decade of stress counts equally and RedChi2 is dimensionless — comparable across steps, samples and models. Fits use log-space parameters, physics-informed starting values, ladder seeding from the nested parent model, a Sobol multi-start and a tight polish. Weakly identified parameters, near-degenerate Jacobians and nesting violations are reported as notes on the result.

Install

Clone and run — uv creates the virtual environment, installs the pinned dependencies from uv.lock and installs rheofit itself in editable mode:

git clone <repo-url>
cd rheofit
uv sync

Then prefix any command with uv run (no activation needed):

uv run rheofit --demo
uv run python -c "import rheofit; print(rheofit.list_models())"
uv run jupyter lab            # notebooks: pick the .venv kernel

uv sync also installs the dev group (ipykernel, python-pptx), so notebooks and PowerPoint output work out of the box. For a lean runtime-only environment use uv sync --no-default-groups.

Activate the environment instead, if you prefer: .venv\Scripts\Activate.ps1 (Windows) or source .venv/bin/activate.

With pip

pip install -e .
pip install -e ".[pptx]"   # adds PowerPoint output

Python API

import rheofit

rheofit.list_models()
# ['carreau', 'carreau_carreau', 'herschel_bulkley', 'power_law', 'tc', 'tc_carreau', 'tccc']

rheofit.print_steps("sample.json")            # which steps exist (0-based ResultsSteps index)

df = rheofit.load_step("sample.json", 0)      # one step as a DataFrame
res = rheofit.fit(df, "tc", effort="thorough")
res["params"]   # {'sigma_y': {'value': ..., 'stderr': ...}, ...}
res["redchi"], res["notes"]

a = rheofit.analyze(                          # load -> fit -> summarise -> save
    "sample.json", steps=[0, 2], model="tc", labels=["25C", "40C"], output="png_csv",
)
a.summary      # tidy DataFrame: step, parameter, value, stderr, rel_error_pct, redchi2, quality
a.outputs      # saved PNG / CSV / PPTX paths

analyze(..., output="none") fits without writing files. Inputs may be a local path or an HTTP(S) URL. rheofit.demo_source() returns the bundled demo flow-curve file.

CLI

uv run rheofit sample.json                                     # list steps
uv run rheofit sample.json --steps 0 2 --model tc --labels 25C 40C
uv run rheofit --demo --steps 0 2 --model tccc --output both

(python -m rheofit … is equivalent inside an activated environment.)

Flags: --steps, --model, --labels, --effort {fast,normal,thorough}, --seed, --sample-name, --output {png_csv,pptx,both,none}, --demo.

Models

No yield stress With yield stress
power_law tc, herschel_bulkley
carreau tc_carreau
carreau_carreau tccc

Within each family the models form a ladder. Prefer the simplest model that fits; climb only if the residuals show structure the simpler model missed. Extra parameters buy little once RedChi2 is below 0.01, and they cost identifiability.

Layout

src/rheofit/
  io.py         TRIOS JSON reading, URL download, demo data
  models/       one module per model + _fitcore.py (shared fitting engine)
  report.py     plots, PNG scorecard, parameter summary, PPTX
  analysis.py   analyze()
  cli.py        command-line front-end

Skill

.github/skills/flow-curve-analysis/SKILL.md is the agent-facing companion to this library: it documents the models, the fitting contract and a guided interview workflow (is the sample structured? which model? which steps?), and drives the same CLI. Use the library directly, or let the skill walk you through it — they are the same code. Keep the skill in sync when the library's models, flags or outputs change.

Metadata

Release files for rheofit 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rheofit 1.0.0
File Size Uploaded
rheofit-1.0.0.tar.gz 912.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rheofit 1.0.0
File Interpreter ABI Platform
rheofit-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / rheofit-1.0.0.tar.gz

Download URL rheofit-1.0.0.tar.gz
Size 912.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bc19dbc96c8c1411162116b632c410ff377b757e781e00d8d4c8840b75b63b37
BLAKE2b-256 checksum
How to use checksums
7481f955712ffe66aa455d916b05a4cd8d59990fe837b2080984788edcd7d16e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / rheofit-1.0.0-py3-none-any.whl

Download URL rheofit-1.0.0-py3-none-any.whl
Size 156.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4fd99c7004fed34e0b2a00d8299fc596c750d59e2fa81e4a86de94ad5267c1b
BLAKE2b-256 checksum
How to use checksums
02adb3a3a728bc0f9a745a632f266b1b6ac52aed1e9f23794ecc3f9c2459fa73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release history Release notifications | RSS feed

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

This release

1.0.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page