Metadata-Version: 2.4
Name: cffdrs-fire
Version: 0.4.1
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Classifier: Typing :: Typed
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: psutil>=5.9
Requires-Dist: ruff>=0.5 ; extra == 'dev'
Requires-Dist: mypy>=1.8 ; extra == 'dev'
Requires-Dist: cupy ; extra == 'gpu'
Requires-Dist: rasterio>=1.3 ; extra == 'gpu'
Requires-Dist: certifi>=2026.10.19 ; extra == 'gpu'
Requires-Dist: rasterio>=1.3 ; extra == 'io'
Requires-Dist: pandas>=2.0 ; extra == 'io'
Requires-Dist: certifi>=2026.10.19 ; extra == 'io'
Requires-Dist: pytest>=7 ; extra == 'test'
Requires-Dist: pandas>=2.0 ; extra == 'test'
Requires-Dist: openpyxl>=3.1 ; extra == 'test'
Requires-Dist: rasterio>=1.3 ; extra == 'test'
Requires-Dist: certifi>=2026.10.19 ; extra == 'test'
Provides-Extra: dev
Provides-Extra: gpu
Provides-Extra: io
Provides-Extra: test
License-File: LICENSE
Summary: Canadian Forest Fire Danger Rating System (CFFDRS) tools: Fire Behaviour Prediction (FBP) and Fire Weather Index (FWI) systems.
Keywords: wildfire,fire behaviour,CFFDRS,FBP,FWI,forestry
Author: Gregory A. Greene
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/gagreene/cffdrs
Project-URL: Repository, https://github.com/gagreene/cffdrs

# cffdrs

Python tools for the **Canadian Forest Fire Danger Rating System (CFFDRS)**: the
Fire Behavior Prediction (FBP) System and the Fire Weather Index (FWI) System.

Calculations accept scalars or NumPy arrays (e.g. raster grids) through the same
API, propagate NoData/NaN cells via masked arrays, and include a block-based
multiprocessing driver for large rasters.

## Installation

Install from PyPI. The prebuilt wheel already contains the compiled Rust extension,
so no Rust compiler is needed:

```bash
pip install cffdrs-fire
```

The PyPI distribution is named `cffdrs-fire`; the import name is still `cffdrs`
(`from cffdrs.cffbps import FBP`).

Or build a **source checkout**, which builds the extension and needs the Rust
toolchain described below: `pip install .` or `uv sync` from the repository root.

Optional extras:

```bash
pip install "cffdrs-fire[io]"    # rasterio + pandas, for raster/tabular workflows
```

Core dependencies: `numpy>=1.24`, `scipy>=1.10`, `psutil>=5.9` (pip chooses newer
releases where an interpreter needs them).

### Supported versions

| Component | Supported | Checked by |
|---|---|---|
| CPython | 3.11, 3.12, 3.13, 3.14 (`requires-python >= 3.11`; Python 3.10 is no longer supported) | CI runs the full suite on 3.12 for every PR; the release workflow smoke-tests the wheel on 3.11-3.14 on each platform |
| Wheels | one `cp311-abi3` wheel per platform: Linux x86-64 and ARM64 (manylinux 2_17), macOS x86-64 and ARM64, Windows x86-64 and ARM64 | release workflow (manual dispatch or tag) |
| Rust, building from source | **1.78 or newer** (the MSRV) | CI builds with the MSRV toolchain on every PR; consumers of the wheel need no Rust |
| Rust crate `cffdrs-fire` | 1.78 or newer, no runtime dependencies | CI |
| PyO3 / rust-numpy | 0.27 | `Cargo.lock` |
| NumPy / SciPy | tested with NumPy 2.4-2.5 and SciPy 1.17-1.18 (see `uv.lock`); older NumPy 1.24+ is allowed by the metadata but not tested here | CI uses `uv.lock` |
| Free-threaded Python (3.14t) | not supported | n/a |

The abi3 wheel keeps working on later CPython versions, but that does not certify
future NumPy/SciPy releases or untested dependency combinations.

## Package layout

| Module | Contents |
|---|---|
| `cffdrs.cffbps` | Fire Behaviour Prediction using the package CPU engine |
| `cffdrs.cffbps.python` | Explicit Python FBP backend; `python/core.py` orchestrates `python/equations/` |
| `cffdrs.cffbps.common` | Shared constants, fuel-code conversion, and input validation |
| `cffdrs.cffbps.rust` | Explicit Rust FBP backend over the owned native grid |
| `cffdrs.cffbps.cupy` | Experimental CuPy GPU backend |
| `cffdrs.cffwis` | FWI System: FFMC/DMC/DC/ISI/BUI/FWI/DSR functions (hourly + daily) |
| `cffdrs.cffwis.python` | Explicit NumPy FWI reference backend |
| `cffdrs.cffwis.rust` | Explicit Rust FWI backend for scalars and arrays |
| `cffdrs.diurnal_ffmc_lawson` | Historical import path for the NumPy Lawson interpolation module |
| `cffdrs._rust` | Native FBP grid and FWI array bindings |

The repository is a mixed Python/Rust project. Python package sources live under
`src/cffdrs`; the top-level `rust/` directory is a Cargo workspace containing:

- `cffdrs-fire`: dependency-free Rust `cffbps` and `cffwis` modules.
- `cffdrs-py`: the PyO3 binding crate that builds `cffdrs._rust` for the
  `cffdrs-fire` Python wheel.

The Python implementation is the behavioral reference. The Python distribution
`cffdrs-fire` is **0.4.1** and imports as `cffdrs`. The independent
`cffdrs-fire` Rust core is **0.5.1**.
`cffdrs._rust.FbpGrid` is a low-level stateful grid in a private extension module;
normal Python callers use `FBP`, which prepares inputs and exports reference-compatible
results. Keeping `rust/` beside `src/` separates the Cargo workspace from Python imports.

Wheels use `cp311-abi3` (one per platform). The release workflow tests Python
3.11–3.14. Future CPython ABI compatibility does not certify future NumPy/SciPy
support or untested dependency combinations. Free-threaded Python is unsupported.

## Changes in Python 0.4.1 and Rust core 0.5.1

- **Cheney grass and wheat.** Fuel codes 30–32 add the natural, cut or grazed,
  and eaten-out grass spread models and their corresponding wheat applications.
  See [Cheney grass and wheat fuel types](#cheney-grass-and-wheat-fuel-types).
- **Grass curing.** Use `gc` for grass curing. The `gcf` alias is deprecated and
  is scheduled for removal in the next release.
- **Raster inputs.** A scalar fuel code applies across the weather raster.
  A foliar override can supply the grid shape, and Python multiprocessing
  returns a full raster for each requested output.

## Changes in Python 0.4.0 and Rust core 0.5.0

- **Native FWI.** The Rust crate implements all ten FWI functions. The Python
  functions keep their existing names and signatures and accept scalars, NumPy
  arrays, and masked arrays.
- **Package-wide backend selection.** Use `cffdrs.set_backend('auto')`,
  `cffdrs.set_backend('rust')`, or `cffdrs.set_backend('python')` for FWI calls
  and new FBP instances. Select the Python backend for custom FWI array arithmetic
  or modified Lawson tables.
- **Rust namespaces.** Import FBP through `cffdrs_fire::cffbps` and FWI through
  `cffdrs_fire::cffwis`. The earlier crate-root FBP module paths remain available.
- **FBP input validation.** The CPU backends reject out-of-range inputs by
  default. Use `out_of_range='clip'` to opt into clipping with diagnostics.

## Fire Behavior Prediction (`cffdrs.cffbps`)

The `FBP` class is a facade: initialize it with fuel, terrain, and weather inputs,
run the model, and request any of the 54 output variables. The underlying equations
live in `cffdrs.cffbps.python.equations` as pure, typed functions if you need them directly.

### Changes in 0.3.1

- **Linux ARM64 wheels.** The release workflow builds a native `aarch64` manylinux 2_17 wheel
  and smoke-tests it on Python 3.11–3.14. The Python API and Rust core version are unchanged.

### Breaking changes in 0.3.0

Python users are not affected: the distribution is `cffdrs-fire` 0.3.0, the import stays `cffdrs`, and the
public API is unchanged.

- **Rust crate renamed.** The pure Rust crate `cffbps-rust` is now `cffdrs-fire` (library `cffdrs_fire`, crate
  version 0.4.0), the name of the PyPI distribution. It was not on crates.io before 0.4.1. Rust consumers (a path or
  git dependency, or a vendored copy) rename the package and the `use` paths: `cffbps-rust` / `cffbps_rust` to
  `cffdrs-fire` / `cffdrs_fire`.
- **certifi floor in the extras.** The `io`, `gpu` and `test` extras now require `certifi>=2026.10.19`. certifi
  2026.10.18 removed the emSign root certificates after the eMudhra CA key compromise, and rasterio, which these
  extras pull in, requires certifi without a minimum. Installing an extra upgrades an older certifi.

### Breaking changes in 0.2.0

The public `from cffdrs.cffbps import FBP` import remains supported and now
selects a backend at initialization. Import from `cffdrs.cffbps.python` for
the explicit reference. The following previous paths are historical migration
references, not current import targets.

Deep imports move without compatibility shims:

| Previous import | New import |
|---|---|
| `cffdrs.cffbps.facade` | `cffdrs.cffbps.python.core` |
| `cffdrs.cffbps.equations` | `cffdrs.cffbps.python.equations` |
| `cffdrs.cffbps.parallel` | `cffdrs.cffbps.python.parallel` |
| `cffdrs.cffbps.constants` | `cffdrs.cffbps.common.constants` |
| `cffdrs.cffbps.inputs` | `cffdrs.cffbps.common.inputs` |
| `cffdrs.cffbps.cupy_backend` | `cffdrs.cffbps.cupy` (implementation: `cupy/core.py`) |

Inside `python.equations`, the module `fmc` is now `foliar_moisture`: `calc_fmc` no longer computes everything
(it gives the foliar moisture content from `nd`); `calc_foliar_moisture()` chains `calc_latn`, `calc_d0`,
`calc_dj`, `calc_nd`, `calc_fmc` and `calc_fme`, and returns a `FoliarMoistureResult` (was `FMCResult`).

Inside `python.equations`, `surface.py` is gone: `calc_sfc` and `calc_cfc` live in `consumption.py` (all fuel
consumption), and `calc_fire_type`, `calc_hfi` and `calc_fire_intensity_class` live in the new `behavior.py`
(`crown.py` keeps only the crown determination). The Rust crate has the same modules (`consumption.rs`,
`behavior.rs`).

The historical `calcC6hros` stage no longer exists. A custom stage sequence replaces it with `calcC6BlendCFB`,
`calcC6BlendCFC`, `calcC6CROS` and `calcC6HROS` (in that order), computes `calcPercentileCFB` before
`calcRosPercentileGrowth`, calls `calcCFB` again after growth, and runs `calcAccelParam` after the final CFB (see
[Upgrading PyroCell](https://github.com/gagreene/cffdrs/blob/master/docs/CODEBASE.md#upgrading-pyrocell)). Replacing only the old method name is not enough.

**C6 acceleration changes.** Acceleration is now computed from the final (post-blend) CFB, so for C-6 the head ROS is
unchanged but `cfb`, `accel` and `hfi` change. For C-6 at ws 20, flat ground, 49.48 N, 115.69 W, 100 m,
date 2023-07-15, ffmc 90, bui 80 (float32 1x1 grid): `cfb` 0.1286 -> 0.3676, `accel` 0.0751 -> 0.0336,
`hfi` 5752 -> 6843 (the earlier values are those of the previous stage order, reported from a PyroCell run; `hros` 8.448
is unchanged). Reference rasters or goldens of a model that accelerates C-6 fires need to be regenerated, after checking
the new values against `alpha = 0.115 - 18.8 * CFB^2.5 * exp(-8 * CFB)`.

### Choosing a backend

`cffdrs.set_backend('auto')` chooses Rust when the native extension provides both
FBP and FWI. Otherwise it selects Python for both. This is the default on first
use. Call `cffdrs.set_backend('rust')` to require the complete native engine or
`cffdrs.set_backend('python')` to use NumPy directly. A failed Rust selection
raises `ImportError` and preserves the previous setting. Previously imported FWI
functions use the new selection on their next call. Initialized FBP models keep
their engine.

```python
import cffdrs
from cffdrs import cffwis

cffdrs.set_backend('rust')
ffmc = cffwis.dailyFFMC(85., 20., 50., 10., 0.)
```

```python
from cffdrs.cffbps import FBP                  # automatic CPU selection
from cffdrs.cffbps.python import FBP as PythonFBP
from cffdrs.cffbps.rust import FBP as RustFBP  # requires the extension
```

`FBP.initialize(..., backend='auto', threads=4)` uses the package default.
An explicit instance-level setting overrides the package default for that FBP
instance. `backend='python'` uses the reference. `backend='rust'` requires the
native FBP bindings and raises `ImportError` if they are unavailable.
`backend_in_use` is `None` before initialization and then `'python'` or `'rust'`.
The backend stays fixed for that instance, including reinitialization. Create a
new instance to change it. Calculation errors do not trigger fallback or replay.
With the initial, unconfigured package default, accessing calibration tables before
initialization pins that instance to Python. If an explicit package selection resolves
to Rust, initialize the calibrated instance with `backend='python'`.
Explicit imports never dispatch and do not take a `backend=` selector.

Rust threads default to **1**; **0** uses all available cores. Keep 1 for many
simultaneous fires. Python ignores the automatic interface's `threads` argument.
Rust floating results agree with Python to **rtol 1e-9**, with matching missing
values; integer results agree exactly. Bit identity with NumPy is not promised.

On Rust, access computed results through `getParams(['hros', ...])`. Per-instance
lookup-table calibration (`rosParams`, `open_fuel_types`, etc.), result attribute
reads, `runFBP(block=...)`, and `getCBH_CFL(ftype=..., cbh=..., cfl=...)` overrides
require `backend='python'` on the FBP instance. For Python multiprocessing,
import `fbpMultiprocessArray` from `cffdrs.cffbps.python` or select the Python
package engine. For Rust canopy injection, run
`getCBH_CFL()` and then `setParams({'cbh': ..., 'cfl': ...})` in a staged pipeline.
Rust uses threads for parallel work. See [the lifecycle and stage reference](https://github.com/gagreene/cffdrs/blob/master/docs/CODEBASE.md)
for memory retention and supported update routes.

Every difference between the two backends that is known today is tracked in
[docs/BACKEND_DIFFERENCES.md](https://github.com/gagreene/cffdrs/blob/master/docs/BACKEND_DIFFERENCES.md); `tools/compare_backends.py`
re-checks them.

### FBP input ranges

The Python and Rust CPU backends raise `cffdrs.cffbps.InputRangeError`, a
`ValueError` subclass, when a caller supplies an out-of-range value at
initialization or through a checked input update. The error gives the input
name, valid bounds, invalid cell count, and up to five original cell coordinates
and values. Values such as `-9999` can indicate an undeclared raster nodata value.
Mask nodata cells or represent them with NaN before passing the grid to FBP.

| Inputs | Inclusive range | Absolute rounding tolerance |
|---|---|---|
| `ffmc` | 0–101 | 1e-5 |
| `pc`, `pdf`, `gc` (%) | 0–100 | 1e-5 |
| `wd`, `aspect` (°) | 0–360 | 5e-5° |
| `lat`, `long` (°) | −90–90 and −180–180, respectively | 5e-5° |
| `bui`, `ws`, `slope`, `gfl` | At least zero | 1e-6 |

Exactly `aspect=-1` marks flat terrain. The solver uses zero effective slope,
so the combined wind speed equals the original wind speed. Small roundoff
outside a bound snaps to the bound. For larger finite deviations, opt in with
`FBP.initialize(..., out_of_range='clip')` to receive an `InputRangeWarning`
per clipped field. Infinities raise in either mode. Use whole-field assignment
or `setParams` for checked edits. The Python backend also rechecks fuel array
edits when calculations resume. Other NumPy slice writes bypass range checks.

### Cheney grass and wheat fuel types

Use `gc` for grass curing (%) in each CFFBPS backend. The old Python keyword,
attribute, and `setParams` key `gcf` emit a `DeprecationWarning` and will be
removed in the next release.

Fuel codes 30–32 select the natural, cut or grazed, and eaten-out grass
rate-of-spread models of Cheney et al. (1998) in the Python, Rust, and
experimental CuPy backends. The models apply to the corresponding fully cured
wheat conditions in the table, as evaluated by Cruz, Hurley, Bessell and Sullivan
in 2020. [Cheney et al. (1998)](https://doi.org/10.1071/WF9980001) ·
[Fire behaviour in wheat crops – effect of fuel structure on rate of fire spread](https://doi.org/10.1071/WF19139)

| Code | Label | Cheney grass model | Corresponding wheat condition | Terrain reference | Wheat consumption default |
|---|---|---|---|---|---:|
| 30 | `WHEAT_UNHARVESTED` | Natural grass | Unharvested wheat | O-1b | 0.53 kg/m² |
| 31 | `WHEAT_HARVESTED` | Cut or grazed grass | Harvested wheat | O-1a | 0.39 kg/m² |
| 32 | `WHEAT_BALED` | Eaten-out grass | Harvested and baled wheat | O-1a | 0.32 kg/m² |

For grassland runs, select the code for the fuel structure and supply the
site's curing (`gc`) and consumed fuel load (`gfl`). The defaults apply
whenever these inputs are omitted and reflect the wheat application.

```python
import numpy as np
from cffdrs.cffbps import FBP

site = dict(wx_date=20240715, lat=55., long=-110., elevation=500.,
            slope=40., aspect=180., ws=20., wd=270.,
            out_request=['hros', 'bros', 'wsv', 'raz', 'hfi'])
wheat = FBP()
wheat.initialize(fuel_type=30, temp=30., rh=20., **site)
head, back, effective_wind, heading, intensity = wheat.runFBP()

mixed = FBP()
mixed.initialize(fuel_type=np.array([2, 30, 31, 32]),
                 ffmc=np.array([90., np.nan, np.nan, np.nan]),
                 bui=np.array([80., np.nan, np.nan, np.nan]),
                 cheney_mf_override=np.array([np.nan, 6., 6., 6.]), **site)
mixed.runFBP()
```

Supply air temperature `temp` in °C and relative humidity `rh` in percent for
the AM60 estimate. A finite `cheney_mf_override` gives measured standing
dead-fuel moisture in percent and takes precedence cell by cell. Relative
humidity and resolved moisture are clipped to 0–100% and 2–24%. Unavailable
weather stays missing. Wheat-only runs can omit FFMC and BUI. Mixed runs may
leave those inputs masked on wheat cells and wheat weather masked on other fuels.

Omitted `gc` uses 100% on wheat. The curing function accepts 20–100%, with
the empirical wheat comparison at 100%. Omitted or masked `gfl` uses the
crop-specific value in the table. Supply a measured estimate to override the
default. To restore the fuel-specific defaults after an override, set `gfl`
or `gc` to `None` via `setParams`. Zero load gives zero spread and intensity.
Final consumption also goes to zero when head spread goes to zero. Crown contributions are zero,
and FBP ISI and buildup diagnostics are missing on wheat.

This implementation follows the [ConPyro conventions](https://github.com/gagreene/conpyro/blob/b388db795b654c7ade80cf3ed342eb6e976ede67/docs/reference/cheney_cruz/REFERENCE.md)
for [Cruz et al. (2015) curing](https://doi.org/10.1071/WF14146), the Spark
low-wind and backing ellipse branches, and
[Alexander (1982) heat yield](https://doi.org/10.1139/b82-048). On slopes, the
specified O-1 reference curve supplies an equivalent wind for the Cheney head
and backing rates. This terrain method and the FBP open-fuel acceleration
parameter have no wheat-specific calibration. CuPy supports the same wheat
weather inputs on mixed rasters. Pass `return_array_as='cupy'` to CuPy's
`initialize` to keep raster outputs on the GPU. When changing fuel and its
required weather together, pass both in one `setParams` call.

### Scalar example

```python
from cffdrs.cffbps import FBP

fbp = FBP()
fbp.initialize(
    fuel_type=2,          # C-2 (or pass the string code 'C2')
    wx_date=20240516,     # YYYYMMDD, used for foliar moisture
    lat=62.245533, long=-133.840363, elevation=1180,
    slope=8, aspect=60,   # slope %, aspect degrees
    ws=24, wd=266,        # wind speed km/h, direction degrees
    ffmc=92, bui=31,      # CFFWIS codes
    out_request=['fire_type', 'hros', 'hfi'],
    backend='auto', threads=4,  # omit for auto selection and one thread
)
fire_type, hros, hfi = fbp.runFBP()
```

### Array / raster example

Any spatial input may be a NumPy array (all arrays must share one shape); outputs
come back as plain arrays. Missing floating values are NaN; integer outputs
have field-specific missing values (see below):

```python
import numpy as np
from cffdrs.cffbps import FBP

fuel_type = np.array([[2, 3, 7], [8, 14, 19]], dtype=np.int8)  # 19 = non-fuel
shape = fuel_type.shape

fbp = FBP()
fbp.initialize(
    fuel_type=fuel_type, wx_date=20240516,
    lat=np.full(shape, 62.2455), long=np.full(shape, -133.8404),
    elevation=np.full(shape, 1180.0), slope=np.full(shape, 8.0),
    aspect=np.full(shape, 60.0), ws=np.full(shape, 24.0),
    wd=np.full(shape, 266.0), ffmc=np.full(shape, 92.0),
    bui=np.full(shape, 31.0),
    out_request=['hros', 'hfi', 'fire_type'],
)
hros, hfi, fire_type = fbp.runFBP()
```

For large rasters, use Rust `threads=`. Python-only
`cffdrs.cffbps.python.fbpMultiprocessArray(...)` splits `(layers, rows, columns)`
inputs into worker blocks.
It returns a full raster for each requested field, including fields derived from
scalar inputs.

### Running stage by stage (and growth percentiles)

Both backends expose the 23 pipeline steps (`invertWindAspect`, `calcSF`, ...,
`calcFireIntensityClass`) in `runFBP()` order, plus `setParams` to inject a value
between steps and `getParams` to read results. `reset()` discards computed and injected
values and returns to the initialised inputs; `runFBP()` always starts from there.
On Rust, intermediate arrays that no later step needs are freed, so request what you
want to read afterwards in `out_request`:

```python
fbp = FBP()
fbp.initialize(fuel_type=2, wx_date=20240516, lat=62.2, long=-133.8, elevation=1180,
               slope=8, aspect=60, ws=24, wd=266, ffmc=92, bui=31,
               out_request=['fmc', 'hros'])
fbp.invertWindAspect(); fbp.calcSF(); fbp.calcISZ(); fbp.calcFMC()
fmc = fbp.getParams(['fmc'])[0]          # inspect, or override with fbp.setParams({'fmc': ...})
fbp.calcISI_RSI_BE(); fbp.calcROS()
hros = fbp.getParams(['hros'])[0]
```

In Python and Rust, `initialize(..., d0=..., dj=..., fmc=...)` (or `set_override`, `setParams`, `calcFMC(...)`) override the
calculated foliar moisture quantities: a value you give is used by every later `runFBP` until you replace
it, clear it with `None`, or call `initialize` again; anything you do not give is calculated. A given `fmc`
also gives the matching foliar moisture effect (`fme`), and NaN or masked cells are missing values.
If the other inputs each have one value, a multi-cell override supplied to
`initialize` can define the raster shape. Multiple override arrays must have
broadcast-compatible dimensions, and later overrides must broadcast to the
established grid shape.

In an override **array**, a negative value (please use -1) asks for that cell to be calculated while the other cells
take your values: `fmc=[95, -1, 110]` gives the cell 0 and 2 values and calculates cell 1 when `calcFMC` (or `runFBP`)
runs. A negative scalar is the same as `None`. Until `calcFMC` runs, calculated cells of `fmc` and `fme` are NaN (nothing
is calculated for you when you change a value: run the stages yourself). Other inputs are not given a calculate value.

CuPy accepts `d0` and `dj` rasters at initialization and uses the supplied day values directly.

**Missing data must be masked.** The package only knows masked cells (`np.ma` arrays) and NaN as missing; a nodata value
such as -999 is an ordinary number. Mask it before `initialize`, for example `np.ma.masked_equal(arr, -999)` or
rasterio's `src.read(1, masked=True)`. Negative `ws`, `ffmc`, `bui`, `pc`, `pdf` and `gfl` are set to 0, so an unmasked
-999 gives a plausible-looking wrong result.

**The fuel grid mask applies to every dataset.** Valid codes are 1–20 and 30–32. A cell whose fuel is masked or invalid is missing in every
input and override, so its outputs are as for an invalid fuel with all other inputs missing (floats NaN, `fire_type` 0,
`fi_class` -99, `dj` 0, and `fuel_type` 0). Non-fuel (19) and water (20) are valid codes and are not masked.

`initialize(..., percentile_growth=p)` takes a percentile (0-100) of the rate-of-spread
distribution of the Han & Braun (2014) model, not a percent change: 50 (the default)
is the unadjusted ROS, and for example 95 scales surface-fire ROS by about 4.6x.

### Available outputs

`out_request` accepts any of the names in `cffdrs.cffbps.valid_outputs` — including
final outputs (`hros`, `hfi`, `fire_type`, `cfb`, `tfc`, `fi_class`, …) and
intermediates (`isi`, `wsv`, `raz`, `sfc`, `fmc`, `csfi`, `rso`, `be`, …).

### Output contract

`runFBP()` and `getParams(names)` return a list in requested order. Array exports
are plain `numpy.ndarray`, never masked arrays. Most computed floats are
`float64`; retained integer inputs (`ws`, `wd`, `ffmc`, `bui`), integer `d0`/`nd`
and injected results can preserve their dtype. Prepared array fuel is normally
`int8`; scalar fuel mixed with arrays can retain `int64`. `fire_type` and
`fi_class` arrays are `int64` (masked values 0 and -99 respectively). `dj` is
`int64` when complete, `float64` with NaN when an override is missing. Masked
and invalid fuel cells export code 0. Missing values follow each
field's dependencies, not a blanket mask of every output, with one exception: fuel
consumption (`ffc`, `wfc`, `sfc`, `cfc`, `tfc`) follows the spread, so it is 0 where the head
rate of spread is 0 (for example D-2 with BUI below 70) and NaN where it is NaN.

All-scalar inputs export Python scalars. Legacy masked/non-modeled cases can
export floating zero even for nominal integer fields; missing explicit dates
export NaN. With raster inputs, a scalar fuel code applies to every cell.
Rust expands every result to the full grid shape. Python can keep scalar inputs
and fields derived from them at `(1,)` and has legacy 0-d export differences.
See [the detailed output contract](https://github.com/gagreene/cffdrs/blob/master/docs/CODEBASE.md#outputs-and-intentional-differences)
for these measured exceptions.

### Experimental GPU backend

An experimental CuPy (GPU) variant of the FBP model lives at
`cffdrs.cffbps.cupy`. Install the optional `gpu` extra (needs a
CUDA-capable environment):

```bash
pip install "cffdrs-fire[gpu]"
# On CUDA, prefer the version-matched wheel instead, e.g.:
#   pip install cupy-cuda12x
#   pip install cupy-cuda13x
# If CuPy fails with "Failed to find CUDA headers", add the CUDA component extra:
#   pip install "cupy-cuda13x[ctk]"
```

The CuPy backend was last run on one NVIDIA RTX 5090 (CUDA 13.3, Python 3.14, `cupy-cuda13x[ctk]`
14.2); no other GPU, CUDA version or platform has been tried.

```python
from cffdrs.cffbps.cupy import FBP   # requires cupy + CUDA
```

To reuse a CuPy model, edit its `fuel_type` array in place or use `setParams`
to replace it. Pass a fuel change and any required weather changes together
in one `setParams` call. Array updates can broadcast to the existing grid.
The next `runFBP()` recomputes spread, consumption, and intensity for the
current fuels and inputs.

> **Experimental GPU backend.** Legacy fuels retain the older CuPy
> implementation and its missing-data conventions. CuPy defaults to `float32`.
> The Cheney grass and wheat models are checked against the same ConPyro
> fixtures as the CPU backends.

## Fire Weather Index System (`cffdrs.cffwis`)

The ten FWI functions accept scalar or array inputs and use the selected package engine. Direct imports from `cffdrs.cffwis.python` and `cffdrs.cffwis.rust` select an implementation explicitly.

```python
from cffdrs import cffwis

ffmc = cffwis.dailyFFMC(ffmc0=85, temp=15, rh=50, wind=10, precip=0)
dmc  = cffwis.dailyDMC(dmc0=6, temp=15, rh=50, precip=0, month=6)
dc   = cffwis.dailyDC(dc0=15, temp=15, precip=0, month=6)
isi  = cffwis.dailyISI(wind=10, ffmc=ffmc)
bui  = cffwis.dailyBUI(dmc=dmc, dc=dc)
fwi  = cffwis.dailyFWI(isi=isi, bui=bui)
```

Hourly FFMC (Van Wagner 1977 / Alexander et al. 1984) is available via
`cffwis.hourlyFFMC`, and the Lawson diurnal interpolation via
`cffwis.diurnalFFMC_lawson` / `cffdrs.diurnal_ffmc_lawson`.

## Validation

FBP outputs are validated against the published test cases in Wotton, Alexander &
Taylor (2009), *Updates and revisions to the 1992 Canadian Forest Fire Behavior
Prediction System* (all 20 reference cases; fire type 20/20, core metrics within
cross-implementation rounding). The test suite locks all 54 outputs to golden
snapshots on both the scalar and array code paths, compared at float32 precision so
that last-bit libm/BLAS differences between platforms do not fail the tests.
The golden, missing-input and unit suites also run against the Rust backend, and a
bit-level oracle pins the scalar Rust core.

## Development

Development requires Python 3.11+ (3.11-3.14), `uv`, and Rust 1.78 or newer
(`rustup` stable works; CI also builds with 1.78). The main
project uses Maturin, so syncing the environment builds `cffdrs._rust` alongside
the editable Python package:

```bash
git clone https://github.com/gagreene/cffdrs.git
cd cffdrs
uv sync --extra test --extra dev   # editable mixed Python/Rust install + tooling
uv run --no-sync python -m pytest tests -q -p no:cacheprovider  # both backends
uv run --no-sync ruff check src/ tests/cffbps  # lint
uv run --no-sync mypy               # type-check the equation core
cargo test --manifest-path rust/Cargo.toml -p cffdrs-fire
uv run --no-sync python tools/compare_backends.py   # Python-vs-Rust differences
```

After a Rust-only change, rebuild the extension with
`uv sync --reinstall-package cffdrs-fire --extra test --extra dev`.

The Python distribution version comes from `rust/crates/cffdrs-py/Cargo.toml`;
update that crate version when preparing a release tag. The pure Rust core has
its own version in `rust/crates/cffdrs-fire/Cargo.toml` because it may be consumed
independently by Rust applications.

Existing golden fixtures are the behavior-preservation oracle. Do not regenerate
them to accommodate a refactor. Releases are published by the
`release` workflow (a `v*` tag publishes to PyPI); version tags and publication require owner authorization.

### Contributing

Read [`docs/CONTRIBUTION_PROCEDURES.md`](https://github.com/gagreene/cffdrs/blob/master/docs/CONTRIBUTION_PROCEDURES.md) before opening a pull request: it
covers branch routing (all version changes go through `pre_release`, then a release PR into `master`), commit rules, the
local checks and large tests that are recorded in every pull request, and the rules for numerical changes.
Tests are run locally and never automatically on a schedule.

## License

MIT — see [LICENSE](LICENSE). © 2024 Gregory A. Greene.

