Metadata-Version: 2.5
Name: refined-quads
Version: 0.4.0
Summary: Generate and refine refined quad meshes (locally halved axis-aligned squares) for D-Flow FM.
Project-URL: Documentation, https://hkv-products-services.github.io/refined-quads
Project-URL: Source, https://github.com/HKV-products-services/refined-quads
Project-URL: Changelog, https://github.com/HKV-products-services/refined-quads/blob/main/CHANGELOG.md
Author: HKV lijn in water, Svasek Hydraulics
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Keywords: d-flow-fm,hydrodynamics,mesh,quadtree,ugrid
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Hydrology
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: meshkernel>=8.3
Requires-Dist: netcdf4>=1.6
Requires-Dist: numpy>=1.26
Requires-Dist: pyogrio>=0.7
Requires-Dist: pyproj>=3.6
Requires-Dist: shapely>=2.0
Description-Content-Type: text/markdown

# refined-quads

Generate and refine *refined quad meshes* for D-Flow FM: axis-aligned squares on a
fixed lattice, locally refined by repeated halving, with transition cells only where
refinement levels meet.

```python
from shapely import Point, box

from refined_quads import check, generate, write_ugrid

quad_mesh = generate(
    box(155_000, 463_000, 155_640, 463_480),
    cell_size=32.0,
    refinement_areas=[(Point(155_250, 463_240).buffer(70), 3)],
    transition_rows=[1, 1, 1],
    crs="EPSG:28992",
)
print(check(quad_mesh).summary())
write_ugrid(quad_mesh, "mesh_net.nc")
```

> **Warning:** do not call the result `mesh` in a D-HyDAMO script. Those scripts usually import
> `from hydrolib.dhydamo.geometry import mesh` (the module with `mesh2d_clip`,
> `links1d2d_add_links_1d_to_2d` and so on); `mesh = generate(...)` replaces that module,
> and the next `mesh.<function>(...)` fails with an `AttributeError`. That is why the
> examples use `quad_mesh`.

The package also refines an existing mesh (also one made by another program), checks a
mesh for what D-Flow FM needs, reads its input from GIS layers and runs from a TOML file
on the command line. See the
[documentation](https://hkv-products-services.github.io/refined-quads).

> **Status:** pre-alpha. The API is not stable yet.

## Install

```console
pip install refined-quads
```

or, in a uv project, `uv add refined-quads`. All dependencies come as wheels; no separate
GDAL installation is needed. The package is tested on Windows and Linux; on macOS the
MeshKernel wheel needs OpenMP from Homebrew (`brew install libomp`).

## Development

The project uses [uv](https://docs.astral.sh/uv/), which also installs Python.

<details>
<summary>Install uv on Windows</summary>

```powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```

</details>

<details>
<summary>Install uv on Linux or macOS</summary>

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

</details>

```console
uv sync --locked              # create .venv with all dependency groups
uv run pre-commit install     # run the checks below on every commit
uv run pytest                 # fast test suite
uv run pytest -m benchmark    # also: slow, realdata
uv run pre-commit run --all-files   # file hygiene, yamllint, ruff check and format
uv run mypy                   # strict type check of src/
```

The source in `src/refined_quads/` is grouped by task: `_generate/`, `_refine/`,
`_check/`, `_io/` (GIS layers and UGRID files) and `_common/` (shared building blocks).
The public API is only what the top-level package exports. The tests in `tests/` use the
same folders; `tests/golden/` holds the golden masters that guard the output.

### Documentation

The site is built with [Quarto](https://quarto.org/), which is installed separately
(on Windows: `winget install Posit.Quarto`):

```console
cd docs
uv run quartodoc build           # API reference from the docstrings
uv run quarto preview            # live preview; `quarto render` builds docs/_site/
```

Quarto must be on your `PATH`. On Windows, make sure
`C:\Program Files\Quarto\bin` is included in the `Path` environment variable.
After updating it, open a new terminal or reload `PATH` in your current PowerShell
session, then start the preview from `docs/`:

```powershell
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
uv run quarto preview
```

### Releases

The version comes from Git tags (`v0.1.0` → `0.1.0`). Publishing a GitHub release
uploads the package to PyPI.

Domain terms are defined in
[CONTEXT.md](https://github.com/HKV-products-services/refined-quads/blob/main/CONTEXT.md);
architectural decisions are in
[docs/adr/](https://github.com/HKV-products-services/refined-quads/tree/main/docs/adr).

## Licence

refined-quads is developed by HKV lijn in water and Svasek Hydraulics and published under
the [GNU General Public License v3 or later](https://github.com/HKV-products-services/refined-quads/blob/main/LICENSE).
