Metadata-Version: 2.5
Name: laterite-outcrop
Version: 0.1.0
Summary: Matplotlib plots for AGS4 geotechnical data: a borehole log, a strip log and a plasticity chart.
Project-URL: Repository, https://github.com/niko86/laterite-outcrop
Project-URL: Changelog, https://github.com/niko86/laterite-outcrop/blob/main/CHANGELOG.md
License-Expression: MIT
License-File: LICENSE
Keywords: AGS4,borehole,geotechnical,matplotlib,plasticity
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: matplotlib>=3.8
Provides-Extra: laterite
Requires-Dist: laterite>=0.17.1; extra == 'laterite'
Description-Content-Type: text/markdown

# laterite-outcrop

An outcrop is where the ground shows itself. This library is where AGS4 data does: `import outcrop`.

Matplotlib plots for AGS4 geotechnical data.

- `borehole_log(geol, proj=..., tracks=[...])`: a
  one-page borehole log with a project header and test results against depth.
  `borehole_log_pages` draws the same at a true scale over several sheets.

- `plasticity_chart(llpl)`: plasticity index against liquid limit, with the
  A-line, the U-line and the BS 5930 plasticity zones.
- `strip_log(geol)`: one borehole's strata as a column against
  depth, with sample depths marked. Strata described as CLAY, SILT, SAND or
  GRAVEL are hatched with that soil's pattern.

All default to the AGS4 heading names, and return what they drew so you can keep
styling: the axes from `plasticity_chart` and `strip_log`, the figure from
`borehole_log`. A missing value (a null, an empty string or NaN) is never
drawn as a value. Numbers typed as text are read as numbers; rows that cannot be
plotted are left out and counted under the plot.

**Status: early release.** The API may still change between 0.x versions.

```bash
pip install laterite-outcrop
```

## Try it with uv

Draw all three plots from a public dataset, with nothing installed first:

```bash
uv run https://raw.githubusercontent.com/niko86/laterite-outcrop/main/examples/hkz3.py
```

The script declares its own dependencies, so uv builds a throwaway
environment for it. It writes `borehole_log.png`, `striplog.png` and
`plasticity.png` to the current directory.

Add it to a uv project:

```bash
uv add laterite-outcrop laterite   # laterite reads the AGS4 files
```

Or use it for one command without a project:

```bash
uv run --with laterite --with laterite-outcrop python my_plot.py
```

## Use

```python
import laterite
from outcrop import Track, borehole_log, plasticity_chart, strip_log

ags = laterite.read("site.ags")
frames = ags.at("LOCA", ["BH01"]).frames()  # {group: frame} for one hole

borehole_log(
    frames,
    proj=ags["PROJ"],
    tracks=[Track(frames["ISPT"], "ISPT_TOP", "ISPT_NVAL", "SPT N")],
).savefig("log.pdf")

strip_log(frames).figure.savefig("strip.png", dpi=200)
plasticity_chart(ags["LLPL"], by="LOCA_ID").figure.savefig("plasticity.png", dpi=200)
```

Each plot takes either one group's frame or the whole `{group: frame}` dict
that laterite's `.frames()` returns, and finds `GEOL`, `LOCA`, `SAMP`, `PROJ`
or `LLPL` in it. A log is of one hole: if the data holds several, pass
`hole="BH01"`.

### Straight from a file

With the optional `laterite` extra, the same plots take a file and a hole ID:

```bash
uv add "laterite-outcrop[laterite]"     # or: pip install "laterite-outcrop[laterite]"
```

```python
from outcrop import Track, ags

ags.borehole_log(
    "site.ags", "BH01", tracks=[Track("ISPT", "ISPT_TOP", "ISPT_NVAL", "SPT N")]
).savefig("BH01.pdf")
ags.strip_log("site.ags", "BH01")
ags.plasticity_chart("site.ags", by="LOCA_ID")
```

A `Track` can name its group by code, as above, whenever the log is drawn from
a file or a dict of groups.

Without the extra, outcrop does not import laterite. It reads named columns from whatever it is
given, so laterite's polars frames work, as do the pandas frames and pyarrow
tables from `laterite.compat`, and a plain dict of lists.

## Gallery

`borehole_log` draws a log sheet: a ruled header of project and hole details
from `PROJ` and `LOCA`, then depth, a hatched legend, the descriptions, levels,
samples, groundwater strikes from `WSTG`, and any test results you add as
columns. The legend is hatched by each stratum's principal soil or rock;
`colour=True` also tints it by legend code.

| The whole hole on one sheet | Sheet 2 of 4 at 1:100 |
|---|---|
| ![Borehole log](https://raw.githubusercontent.com/niko86/laterite-outcrop/main/docs/borehole_log.png) | ![Sheet 2 of a paged log](https://raw.githubusercontent.com/niko86/laterite-outcrop/main/docs/borehole_log_sheet2.png) |

| `plasticity_chart` | `strip_log` |
|---|---|
| ![Plasticity chart](https://raw.githubusercontent.com/niko86/laterite-outcrop/main/docs/plasticity.png) | ![Borehole strip log](https://raw.githubusercontent.com/niko86/laterite-outcrop/main/docs/striplog.png) |

Data in all three: Netherlands Enterprise Agency (RVO) / Fugro, Hollandse Kust
(zuid) Wind Farm Site III.

`examples/hkz3.py` is the script behind the gallery. It fetches its data with
[laterite-quarry](https://github.com/niko86/laterite-quarry).

## Deep holes: a log over several sheets

`borehole_log` fits the whole hole on one sheet. For a hole too deep to read
that way, `borehole_log_pages` draws it at a true scale over as many A4 sheets
as it needs:

```python
from outcrop import borehole_log_pages, save_pages

sheets = borehole_log_pages(frames, proj=ags["PROJ"], scale=50)  # 1:50, 10 m a sheet
save_pages(sheets, "BH01.pdf")
```

Each sheet is numbered and carries the header. A stratum that crosses a sheet
boundary is marked "(continued)" on the next sheet, its base is printed once,
where it lies, and the last sheet rules off the end of the hole. Hatching and
the test columns' value scales carry on unbroken from sheet to sheet.

## What this is not

A drawing-office log. A description too long for its stratum is cut short and
counted, not carried over to a continuation sheet. The legend has patterns for
made ground, topsoil, concrete, clay, silt, sand, gravel, cobbles, boulders,
peat, chalk, limestone, mudstone, siltstone and sandstone, chosen by the
principal constituent alone: a "sandy CLAY" is hatched as clay.

## Related

- [laterite](https://github.com/niko86/laterite): read, validate and query AGS4.
- [laterite-quarry](https://github.com/niko86/laterite-quarry): fetch public AGS4 datasets.
- [laterite-forge](https://github.com/niko86/laterite-forge): generate synthetic AGS4.

## Developing

```bash
uv sync
uv run ruff check . && uv run ruff format --check . && uv run ty check && uv run pytest -q
uv run examples/hkz3.py docs   # redraw the gallery
```

To release: bump `version` in `pyproject.toml`, date the changelog entry,
merge to `main`, then run the **Release** workflow from the Actions tab. It
publishes to PyPI and then tags the commit.

MIT licensed.
