Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cff-version: 1.2.0
title: "PorousDiff: Conditional 3D Diffusion Surrogate Modelling for Compressed Porous Battery Electrodes"
message: "If you use PorousDiff in your research, please cite this software using the metadata below."
type: software
version: 0.5.2
date-released: "2026-11-22"
license: BSD-3-Clause
repository-code: "https://github.com/BASE-Laboratory/PorousDiff"
authors:
- family-names: Ali
given-names: Asif
affiliation: "BASE Laboratory, School of Engineering, University of Greenwich, United Kingdom"
- family-names: Le Houx
given-names: James
orcid: "https://orcid.org/0000-0002-1576-0673"
affiliation: "BASE Laboratory, School of Engineering, University of Greenwich; ISIS Neutron and Muon Source, Rutherford Appleton Laboratory; The Faraday Institution"
keywords:
- porous media
- diffusion models
- battery electrodes
- x-ray computed tomography
- synchrotron
- virtual compression
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Developed by [BASE Laboratory](https://github.com/BASE-Laboratory) using NVIDIA GH200 Grace Hopper accelerators on Isambard-AI.

**Maintainer:** James Le Houx ([BASE Laboratory](https://github.com/BASE-Laboratory))

---

## Overview
Expand All @@ -16,7 +18,7 @@ PorousDiff is designed to evaluate two core hypotheses on held-out synchrotron c

---

### Key Capabilities (`v0.5` Multi-Electrode & Native OpenImpala v4.6 Pipeline)
### Key Capabilities (`v0.5.2` Multi-Electrode, Calibrated `basecoat` OME-Zarr & `OpenImpala` v5.1 Pipeline)

1. **Calibrated 2-Phase & 3-Phase XCT Segmentation, Partial-Volume Halo Cleanup & Mirror-Free Baseline Slabs** (`porousdiff/preprocessing.py`, `scripts/preprocessing/prepare_local_drive_bundle.py`)
- Masks exterior air outside the circular electrode punch (`--roi-radius-fraction 0.70`), subtracts pore-mode-clamped background, applies shared per-`(material, beamline)` lowest-load thresholds (`delta_carbon`, `delta_coating`), and strips Paganin/PSF partial-volume "carbon rind" blur shells at `0–2` pore–coating boundaries (`--strip-halo-px 1`) while preserving $\ge 3\text{ px}$ carbon fibres and `0–1–2` triple-phase junctions.
Expand All @@ -30,8 +32,8 @@ PorousDiff is designed to evaluate two core hypotheses on held-out synchrotron c
- **Eulerian DDIM (`--mode eulerian_ddim`) & Zero-Leakage Lagrangian Slab (`--mode lagrangian_slab` / `--include-lagrangian-slab`):** Supports both fixed-box conditional DDIM ODE inversion (`invert_strength = 0.60`) and mass-conserving Lagrangian slab compression (`virtual_compress_lagrangian_slab`, affine Z-prewarping $Z_0 \to Z(\sigma)$ + `refine_strength = 0.35` 3D Hann MultiDiffusion refinement). On held-out synchrotron loads, `lagrangian_slab` never peeks at held-out XCT porosity (using PorousDiff blind $\hat{\phi}_s(\sigma)$, mechanical `strain_z`, or non-heldout PCHIP), while tagging `affine_z_squash` / `pillar_pore_deletion` as explicit oracle-porosity upper bounds.
- **Seamless $>96^3$ 3D MultiDiffusion & OpenImpala REV (`--tiled-shape`, `--run-rev-study`):** Synthesizes larger 3D domains (e.g. `96 × 96 × 192` or `160³`) via 3D raised-cosine (Hann) overlapped denoising with automated OpenImpala sub-volume REV convergence and Z-profile uniformity audits.

4. **Per-Realization `OpenImpala` v4.6 PDE Coupling, Cauchy–Crofton Morphology, Constriction $\beta_Z(\sigma)$ & Static-Cell 1D Newman ASR ($\sigma^*$)** (`porousdiff/transport_and_xrd.py`, `porousdiff/metrics.py`, `porousdiff/optimization.py`)
- **Per-realization in-process OpenImpala v4.6 Python API (`--run-openimpala`):** Solves steady-state PDE diffusivity/conductivity directly in Python (`tortuosity_all`, composite 3-phase `phase_diffusivities`, optional $3 \times 3$ `effective_diffusivity`, `rev_study`), pairing each OpenImpala solve 1-to-1 with its exact 3D realization (including `porousdiff_dense` sweeps) to preserve genuine within-load spatial bootstrap CIs on $\sigma^*$.
4. **Per-Realization `OpenImpala` v5.1 PDE Coupling (`porousdiff_workflows`), Cauchy–Crofton Morphology, Constriction $\beta_Z(\sigma)$ & Static-Cell 1D Newman ASR ($\sigma^*$)** (`porousdiff_workflows/transport_and_xrd.py`, `porousdiff/metrics.py`, `porousdiff/optimization.py`)
- **Per-realization in-process OpenImpala v5.1 Python API (`--run-openimpala`):** Solves steady-state PDE diffusivity/conductivity directly in Python over calibrated `basecoat.Volume` / OME-Zarr v0.4 stores (`tortuosity_all`, composite 3-phase `phase_diffusivities`, optional $3 \times 3$ `effective_diffusivity`, `rev_study`), pairing each OpenImpala solve 1-to-1 with its exact 3D realization (including `porousdiff_dense` sweeps) to preserve genuine within-load spatial bootstrap CIs on $\sigma^*$.
- **Static Swagelok/coin/pouch Newman ASR & unbiased 3D stereology:** Defaults primary 1D Newman–Tobias ASR curves to static Swagelok/coin/pouch cells (`pump_penalty = 0`, thickness-scaled Nernst salt-depletion $R_{\text{mt}}(\sigma) = R_{\text{mt},0}\frac{L(\sigma)/L_0}{D_{\text{eff},Z}(\sigma)/D_0}$, pure $2/3$ Cauchy–Crofton `ssa_*_cc` kinetic area, with in-plane $K_{XY}$ pumping isolated as `flow_pumped_sensitivity`), alongside 3D cubical Euler density (`euler_density`), EDT pore radii, constriction $\beta_Z(\sigma)$, and $W_1$ / KS distances.

---
Expand Down
16 changes: 15 additions & 1 deletion porousdiff/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import math
import warnings
from pathlib import Path
from typing import Mapping, Sequence

Expand Down Expand Up @@ -563,6 +564,7 @@ def export_openimpala_tiff(
pore_label: int = 0,
solid_label: int = 1,
preserve_multiphase: bool = False,
voxel_size_um: float | None = None,
) -> Path:
"""Export a 3D multi-page `uint8` TIFF stack formatted for OpenImpala transport solvers.

Expand All @@ -572,6 +574,13 @@ def export_openimpala_tiff(
"""
import basecoat

warnings.warn(
"export_openimpala_tiff is deprecated under ECOSYSTEM.md and scheduled for removal; "
"prefer porousdiff.io.export_volume_ome_zarr (or basecoat.write_ome_zarr) so physical "
"spacing and labels/phase travel directly into OpenImpala v5.1+ and SMS.",
DeprecationWarning,
stacklevel=2,
)
vol = np.asarray(volume)
if vol.ndim != 3:
raise ValueError(f"Expected 3D volume (Z, Y, X), got shape {vol.shape}")
Expand All @@ -581,5 +590,10 @@ def export_openimpala_tiff(
mapped = np.where(vol > 0, solid_label, pore_label).astype(np.uint8)
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
basecoat.write_volume( basecoat.Volume.from_array(mapped), output_path )
bc_vol = (
basecoat.Volume.from_array(mapped, voxel_size_um=float(voxel_size_um))
if voxel_size_um is not None
else basecoat.Volume.from_array(mapped)
)
basecoat.write_volume(bc_vol, output_path)
return output_path
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ description = "Conditional 3D Diffusion Surrogate Modelling for Compressed Porou
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.10"
authors = [
{ name = "Asif Ali" },
{ name = "James Le Houx" },
]
maintainers = [
{ name = "James Le Houx" },
{ name = "BASE Laboratory" },
]
dependencies = [
"basecoat @ git+https://github.com/BASE-Laboratory/[email protected]",
"numpy>=1.24",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_basecoat_layer2_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ def test_direct_openimpala_v51_handoff_and_si_ssa_calibration(tmp_path: Path) ->
)
assert len(rows) == 4
assert (suite_dir / "parity.csv").is_file()


def test_deprecated_export_openimpala_tiff_warns_and_calibrates(tmp_path: Path) -> None:
"""`export_openimpala_tiff` emits a DeprecationWarning and optionally embeds `voxel_size_um`."""
from porousdiff.metrics import export_openimpala_tiff

vol = np.zeros((8, 8, 8), dtype=np.uint8)
vol[:, 2:6, 2:6] = 1
out_tif = tmp_path / "legacy_cal.tif"
with pytest.warns(DeprecationWarning, match="export_openimpala_tiff is deprecated"):
export_openimpala_tiff(vol, out_tif, voxel_size_um=1.25)
loaded = basecoat.read_volume(out_tif)
assert np.array_equal(loaded.data, vol)
assert loaded.spacing_in("um") == pytest.approx((1.25, 1.25, 1.25))

Loading