---
title: "Laboratory classification data from AGS4: plasticity charts, grading curves and maps in Python"
description: "Read Atterberg limits, moisture content and grading from AGS4 (LLPL, LNMC, GRAG), plot a BS 5930 plasticity chart and PSD curves, and map soil class."
url: https://www.technicalgis.com/tutorials/ags-laboratory-classification-python/
author: Sean Blaney (https://www.technicalgis.com/about/#sean-blaney)
publisher: TechnicalGIS (https://www.technicalgis.com/about/)
published: 2026-11-26
updated: 2026-11-26
language: en-GB
---

# Laboratory classification data from AGS4: plasticity charts, grading curves and maps in Python

> Read Atterberg limits, moisture content and grading from AGS4 (LLPL, LNMC, GRAG), plot a BS 5930 plasticity chart and PSD curves, and map soil class.

- Level: Intermediate
- Tested with: Python 3.12
- Source code: [Download scripts](https://www.technicalgis.com/code/ags-laboratory-classification-python/)

Series · Part 8 of 13

## [AGS data in GIS](https://www.technicalgis.com/tutorials/series/ags-data-in-gis/)

1.  [Read and validate AGS4 ground investigation data with Python](https://www.technicalgis.com/tutorials/read-validate-ags4-python/)
2.  [Boreholes on a map: AGS4 locations in British National Grid with QGIS](https://www.technicalgis.com/tutorials/ags4-boreholes-map-qgis/)
3.  [3D borehole logs from AGS4 data in PyVista and QGIS](https://www.technicalgis.com/tutorials/3d-borehole-logs-pyvista-qgis/)
4.  [A geological cross-section from AGS4 boreholes and LIDAR in Python and QGIS](https://www.technicalgis.com/tutorials/geological-cross-section-ags4-python/)
5.  [A 3D ground model from AGS4 boreholes: kriged stratum surfaces in Python](https://www.technicalgis.com/tutorials/geological-ground-model-surfaces-python/)
6.  [Visualising SPT N-values from AGS4 data in Python](https://www.technicalgis.com/tutorials/spt-n-values-ags-python/)
7.  [3D-print a geological ground model: one watertight STL per stratum](https://www.technicalgis.com/tutorials/3d-print-geological-ground-model/)
8.  Laboratory classification data from AGS4: plasticity charts, grading curves and maps in Python

Part 9 is out 3 December 2026. [See the whole series](https://www.technicalgis.com/tutorials/series/ags-data-in-gis/)

## Key takeaways

1.  The laboratory results live in their own AGS4 groups: LLPL for liquid and plastic limits, LNMC for moisture content, GRAG for the grading summary and GRAT for every point on the grading curve. They are keyed to a specimen by LOCA\_ID and the SAMP and SPEC fields, so you can place every test at its hole and depth.
2.  Some columns arrive as text. In this file the plastic limit holds 20 'NP' entries for non-plastic soils and the moisture content is typed as text, so convert them yourself and count what would not convert.
3.  On the BS 5930 chart, 89% of the 327 A417 specimens are clays, mostly of intermediate (CI) and high (CH) plasticity. The Fuller's Earth Formation is the most plastic, with a median liquid limit of 59.
4.  Mapping the most plastic class in each hole by depth band shows high plasticity clays in 25 of the 42 holes tested below 10 m, mostly in the Lias mudstones under the escarpment.

## Before you start

-   Part 1 of this series, or at least its helper module a417\_ags.py
-   Python 3.10+ with python-ags4, pandas, GeoPandas, rasterio, requests and matplotlib
-   Part 6 is useful background for joining tests to GEOL units

**The field log says “firm grey clay”; the laboratory says how plastic that clay is, and how much of it is really silt, sand and gravel.** In Parts 1 to 7 we built the A417 Missing Link ground investigation into maps, 3D logs, a ground model and a 3D print, all from the field groups. This part reads the laboratory classification tests from the same investigation and puts them back on the map.

There are 327 Atterberg limit tests, 393 moisture contents and 104 grading curves. By the end you will have a BS 5930 plasticity chart, grading curves for each geological unit, the index properties against elevation, a map of the most plastic soil in every borehole at three depths, and a GeoPackage of all of it for QGIS.

The steps are:

1.  download the contractor’s original AGS4 file and read its laboratory groups;
2.  find the depth, position and geological unit of every specimen;
3.  classify the fine soils on the BS 5930 plasticity chart;
4.  draw the grading curves for each unit;
5.  plot moisture content and the Atterberg limits against elevation;
6.  map the classification by borehole and depth;
7.  write the results to a GeoPackage.

The code is [`lab_classification.py`](https://www.technicalgis.com/code/ags-laboratory-classification-python/). It uses `a417_ags.py` from Part 1 for the repaired borehole locations and geology.

![Three maps of Crickley Hill side by side on a grey LIDAR hillshade with 10 m contours, for 0 to 3 m, 3 to 10 m and more than 10 m below ground. Each borehole with an Atterberg test at those depths is a circle coloured by its most plastic BS 5930 class, from pale green CL through teal CI and blue CH to navy CV and CE, with orange and brown for the silts. The deepest panel is mostly blue CH along the escarpment, while the shallow panel has navy CV circles on the plateau to the east. Small grey dots mark holes with no test at that depth.](https://www.technicalgis.com/_astro/04-plasticity-by-borehole-map.Cz1YWgvf_2kgmq3.webp)

_The most plastic soil found in each borehole on Crickley Hill at three depths below ground, classified on the BS 5930 plasticity chart. Topsoil is left out._

## Step 1: download the original AGS4 file and read its laboratory groups

Parts 1 to 7 used the BGS’s export of this investigation, which holds the location, geology, sample and in-situ test groups. The laboratory results are only in the file the contractor deposited with the BGS, so this part downloads that as well. It is the same investigation, BGS item 173984, and its `LOCA_ID`s match the export, so the repaired positions from Part 1 still apply.

`lab_classification.py`

```python
ORIGINAL = "Geodata file 1908.ags"                      # the contractor's AGS4 file, as deposited with the BGS
ACCESSIONS = "https://webservices.bgs.ac.uk/accessions"

path = fetch(f"{ACCESSIONS}/download/{A.ITEM}?fileName={quote(ORIGINAL)}", DATA / ORIGINAL)
tables, headings = AGS4.AGS4_to_dataframe(str(path))
lab = A.numeric({g: tables[g] for g in ["LLPL", "LNMC", "GRAG", "GRAT"]})    # numbers as numbers, as in Part 1
# The file types LNMC_MC as X (text) and LLPL_PL as XN (text or number), so convert those two by hand.
for g, col in [("LNMC", "LNMC_MC"), ("LLPL", "LLPL_PL")]:
    raw = lab[g][col].astype(str).str.strip()
    lab[g][col] = pd.to_numeric(raw, errors="coerce")
    text = raw[lab[g][col].isna()].replace("", "(blank)").value_counts()
    print(f"{g}.{col}: {lab[g][col].notna().sum()} numbers; not numeric: "
          + ", ".join(f"{v!r} x{n}" for v, n in text.items()))
```

`Output`

```text
=== Step 1: the deposited AGS4 file and its laboratory groups ===
Geodata file 1908.ags: 23.2 MB, 62 groups, AGS 4.0.4, issue 19
LNMC.LNMC_MC: 393 numbers; not numeric: '(blank)' x14
LLPL.LLPL_PL: 307 numbers; not numeric: 'NP' x20
  LLPL:   327 rows from 75 holes
  LNMC:   407 rows from 78 holes
  GRAG:   104 rows from 63 holes
  GRAT:  2163 rows from 63 holes
LLPL holes missing from the repaired LOCA: 0
```

The file has 62 groups against the export’s handful. `A.numeric` from Part 1 converts every column whose AGS type is numeric, using the TYPE row. Two columns need help: the moisture content is typed `X` (text) and the plastic limit `XN` (text or number). Printing what would not convert shows exactly what you are losing: 14 blank moisture contents, and 20 plastic limits recorded as `NP`, for **non-plastic**. Those 20 are real results, soils too silty or sandy to roll into a thread, and we keep them as their own class.

## Step 2: find where every specimen came from

Each laboratory row carries the sample keys (`LOCA_ID`, `SAMP_TOP`, `SAMP_REF`, `SAMP_TYPE`, `SAMP_ID`) and the specimen keys (`SPEC_REF`, `SPEC_DPTH`). The specimen depth is the most precise, with the sample top as a fallback. Joining the hole’s coordinates and ground level gives each specimen a position and an elevation, and the same interval join as Part 6 gives it a geological unit:

`lab_classification.py`

```python
def place(df):
    """Specimen depth (SPEC_DPTH, else the sample top), position, elevation and GEOL unit."""
    df = df.copy()
    df["depth"] = df.SPEC_DPTH.fillna(df.SAMP_TOP)
    df = df.join(loca[["LOCA_NATE", "LOCA_NATN", "LOCA_GL"]], on="LOCA_ID")
    df["mOD"] = df.LOCA_GL - df.depth
    m = df.reset_index().merge(geol, on="LOCA_ID")
    m = m[(m.GEOL_TOP <= m.depth) & (m.depth < m.GEOL_BASE + 1e-6)].drop_duplicates("index").set_index("index")
    df["UNIT"] = m.UNIT.reindex(df.index).fillna("NR")
    return df

ll = place(lab["LLPL"]).rename(columns={"LLPL_LL": "LL", "LLPL_PL": "PL", "LLPL_PI": "PI", "LLPL_425": "p425"})
mc = place(lab["LNMC"]).rename(columns={"LNMC_MC": "MC"})
grag = place(lab["GRAG"])
```

`Output`

```text
=== Step 2: where each specimen came from ===
                               Atterberg  moisture  grading  median_LL  median_PI  median_MC
Topsoil                                7         7        3       74.0       33.0       30.7
Made ground                            8        16       12       42.5       18.5       18.0
Head                                  19        20       13       49.0       25.0       15.0
Landslide deposits                   133       145       48       43.0       22.0       20.9
White Limestone Formation              0         1        0          -          -        0.7
Hampen Formation                       0         1        0          -          -        0.4
Fuller's Earth Formation              42        66       15       59.0       36.0       19.3
Salperton Limestone Formation          0         2        1          -          -       15.3
Aston Limestone Formation              0         1        0          -          -       13.9
Birdlip Limestone Formation            0         3        5          -          -       15.0
Bridport Sand Formation               36        39        7       35.0       13.5       14.7
Whitby Mudstone Formation             53        62        0       48.0       25.0       15.2
Dyrham Formation                      16        16        0       44.0       24.0       14.9
Charmouth Mudstone Formation          13        14        0       51.0       26.0       19.0
specimens from 0.1 to 89.0 m deep; 313 of 327 Atterberg specimens washed on 425 µm
```

**The testing follows the problem.** Two in five Atterberg tests are on the landslide deposits that cover the escarpment, the ground the scheme had to cut through and stabilise. The limestones have moisture contents and a few gradings but no Atterberg tests, because you cannot do one on rock. The Fuller’s Earth stands out straight away, with a median liquid limit of 59.

## Step 3: classify the fine soils on the BS 5930 plasticity chart

The plasticity chart plots PI against LL. The A-line, PI = 0.73 (LL − 20), separates clays (C) above it from silts (M) below, and the liquid limit gives the second letter: L (below 35), I (35 to 50), H (50 to 70), V (70 to 90) and E (above 90). A specimen with no plastic limit is non-plastic, NP.

`lab_classification.py`

```python
LL_EDGES = [0, 35, 50, 70, 90, np.inf]
LL_LETTERS = ["L", "I", "H", "V", "E"]

def plasticity_class(ll, pi):
    """BS 5930 symbol: C above the A-line, M below it, then the liquid limit letter. NP if non-plastic."""
    if np.isnan(pi):
        return "NP"
    letter = LL_LETTERS[np.searchsorted(LL_EDGES, ll, side="right") - 1]
    return ("C" if pi >= 0.73 * (ll - 20) else "M") + letter

ll["CLASS"] = [plasticity_class(a, b) for a, b in zip(ll.LL, ll.PI)]
```

`Output`

```text
=== Step 3: the BS 5930 plasticity chart ===
class counts: CI 143, CH 92, CL 31, CV 20, NP 20, MH 7, MI 6, MV 4, CE 4
89% plot above the A-line; 20 non-plastic (no plastic limit could be measured)
most common class by unit:
  Topsoil                        MV
  Made ground                    CI
  Head                           CI
  Landslide deposits             CI
  Fuller's Earth Formation       CH
  Bridport Sand Formation        CI
  Whitby Mudstone Formation      CI
  Dyrham Formation               CH
  Charmouth Mudstone Formation   CH
```

![BS 5930 plasticity chart with liquid limit from 0 to 120% on the horizontal axis and plasticity index from 0 to 85% on the vertical. Dashed verticals at 35, 50, 70 and 90 divide it into low, intermediate, high, very high and extremely high plasticity, and the black A-line rises from LL 20. 327 specimens coloured by geological unit form a band just above the A-line, from LL 30 to 60, with green Fuller's Earth points reaching LL 100 and PI 71. Dark brown topsoil points sit below the line. Non-plastic specimens are open triangles along the bottom between LL 27 and 45.](https://www.technicalgis.com/_astro/01-plasticity-chart.DZfYv2hH_fPWFq.webp)

_All 327 Atterberg tests from the A417 Missing Link on the BS 5930 plasticity chart, coloured by the geological unit each specimen came from. Non-plastic specimens are drawn as triangles at PI = 1._

**Almost everything is a clay, and the points hug the A-line.** That tight band just above the line is typical of British clays and mudstones. The units sort themselves along it: the Bridport Sand specimens are low to intermediate plasticity, the Lias mudstones (Whitby, Dyrham and Charmouth) intermediate to high, and the Fuller’s Earth reaches very and extremely high plasticity. Fuller’s Earth is named for the smectite clay once used to clean wool, and smectite gives soils their highest liquid limits and their largest shrinking and swelling. The topsoil plots below the A-line because organic matter raises the liquid limit without adding plasticity, which is why we leave it out of the maps in Step 6.

## Step 4: draw the grading curves for each unit

A grading curve is the `GRAT` rows for one specimen, sorted by size. To find each curve’s unit, merge the `GRAT` points with the placed `GRAG` rows on the full set of sample and specimen keys:

`lab_classification.py`

```python
KEYS = ["LOCA_ID", "SAMP_TOP", "SAMP_REF", "SAMP_TYPE", "SAMP_ID", "SPEC_REF", "SPEC_DPTH"]

grat = lab["GRAT"].dropna(subset=["GRAT_SIZE", "GRAT_PERP"])
curves = grat.merge(grag[KEYS + ["UNIT"]], on=KEYS, how="inner").sort_values(KEYS + ["GRAT_SIZE"])
for ax, u in zip(axes.flat, panels):
    sub = curves[curves.UNIT == u] if u != "other" else curves[~curves.UNIT.isin(panels)]
    for _, c in sub.groupby(KEYS):
        ax.plot(c.GRAT_SIZE, c.GRAT_PERP, color=A.UNITS.colour[c.UNIT.iloc[0]], lw=1.1, alpha=0.85)
    ax.set_xscale("log")
```

`Output`

```text
=== Step 4: grading curves by unit ===
2163 sieve and sedimentation points; 104 curves matched to a GRAG specimen; types: WS 1872, PP 291
                               specimens  gravel %  sand %  fines %
Topsoil                                3      39.0    20.0     26.0
Made ground                           12      46.0    22.0     25.0
Head                                  13      23.0    21.0     35.0
Landslide deposits                    48      39.0    10.0     47.0
Fuller's Earth Formation              15       0.0     5.0     95.0
Salperton Limestone Formation          1      34.0    40.0     26.0
Birdlip Limestone Formation            5      61.0    17.0     10.0
Bridport Sand Formation                7       0.0    21.0     79.0
```

Every one of the 104 curves matched its summary row, which is a good check that the keys are complete. `GRAT_TYPE` tells you the method: WS for wet sieving and PP for pipette sedimentation, which measures the silt and clay sizes.

![Six panels of particle size distribution curves, percentage passing from 0 to 100 against particle size on a log scale from 0.001 to 200 mm, with grey vertical lines at the clay, silt, sand, gravel and cobble boundaries. Made ground and head curves are spread across the whole chart. The 48 landslide deposit curves split into two families: fine curves passing almost 100% at sand size and coarse curves that only rise steeply in the gravel range. The Fuller's Earth curves are almost all fine, passing 95% or more at 0.063 mm. The seven Bridport Sand curves are tightly bunched, rising steeply through the silt and fine sand sizes. The last panel shows topsoil, Salperton Limestone and Birdlip Limestone curves, mostly gravelly.](https://www.technicalgis.com/_astro/02-grading-curves.C1kiohBo_Z10H6MB.webp)

_Grading curves for the 104 particle size tests, one panel for each of the five most tested units and one for the rest. Grey lines mark the BS EN ISO 14688-1 boundaries between clay, silt, sand, gravel and cobbles._

**The landslide deposits are two soils.** Half of their 48 curves are mostly clay and silt, and 18 are mostly gravel with some fines, the broken limestone that slid down from the top of the escarpment with the clay. Their median of 47% fines is the average of two quite different materials, which is exactly why you draw the curves rather than trusting the summary. The Bridport Sand curves, by contrast, are almost identical: a silty fine sand, with a median of 79% passing 63 µm.

## Step 5: plot moisture content and the Atterberg limits against elevation

Plotting the three index properties against elevation, side by side, shows how the ground changes down the hill. Comparing the natural moisture content with the limits says whether the clay is stiff or soft. Few specimens have both tests, so `merge_asof` pairs each moisture content with the nearest Atterberg test in the same hole within 1 m, and works out the liquidity index:

`lab_classification.py`

```python
pair = ll.merge(mc[KEYS + ["MC"]], on=KEYS, how="inner")
nearby = pd.merge_asof(mc.sort_values("depth"), ll.sort_values("depth")[["LOCA_ID", "depth", "PL", "LL"]],
                       on="depth", by="LOCA_ID", direction="nearest", tolerance=1.0).dropna(subset=["PL"])
nearby["LI"] = (nearby.MC - nearby.PL) / (nearby.LL - nearby.PL)
wet = nearby[nearby.LI > 0]
```

`Output`

```text
=== Step 5: moisture content, plastic limit and liquid limit against elevation ===
moisture content: 393 tests from 78 holes, 0.2 to 69.4% (median 18.0%)
31 specimens have a moisture content and Atterberg limits on the same specimen
within 1 m of an Atterberg test: 331 moisture contents, liquidity index median -0.16; 97 wetter than the plastic limit, from: Landslide deposits 57, Fuller's Earth Formation 23, Whitby Mudstone Formation 6, Head 4, Made ground 2, Topsoil 2, Charmouth Mudstone Formation 2, Bridport Sand Formation 1
```

![Three scatter plots sharing a vertical axis of specimen elevation from 100 to 300 m OD: moisture content from 0 to 70%, plastic limit from 0 to 60% and liquid limit from 0 to 120%, with points coloured by geological unit. Green Fuller's Earth points cluster at 240 to 290 m OD with liquid limits of 50 to 100. Below 225 m, orange landslide deposits and blue Lias mudstones fill the plots with moisture contents of 10 to 30% and liquid limits of 35 to 60. The plastic limits sit in a narrow column around 20 to 25% at every elevation.](https://www.technicalgis.com/_astro/03-index-properties-elevation.CMC4Ns7v_ZkkeIj.webp)

_Natural moisture content, plastic limit and liquid limit of every specimen against its elevation, coloured by geological unit._

**Most of the clay is stiff, but not all of it.** The median liquidity index is −0.16, slightly drier than the plastic limit, which is what you expect of overconsolidated Jurassic clays. The 97 specimens wetter than their plastic limit are mostly in the landslide deposits and the Fuller’s Earth: the softened, sheared clay that makes the escarpment move, and a weathered, very plastic clay near the top of the plateau. The plastic limit hardly changes with elevation; the liquid limit does, and that is what separates the units.

## Step 6: map the classification by borehole and depth

A map needs one value per hole. For each of three depth bands, take every specimen below the topsoil, keep the most plastic class (the one with the highest liquid limit), and mark holes where only non-plastic soil was tested as NP:

`lab_classification.py`

```python
DEPTHS = [(0, 3, "0 to 3 m"), (3, 10, "3 to 10 m"), (10, 100, "more than 10 m")]

soil = ll[ll.UNIT != "TOPS"]                 # topsoil is organic, so leave it out of the mapped classification
holes = (ll.groupby("LOCA_ID").agg(tests=("LL", "size"), deepest=("depth", "max"))
         .join(loca[["LOCA_NATE", "LOCA_NATN", "LOCA_GL"]]))
for lo, hi, label in DEPTHS:
    band = soil[(soil.depth >= lo) & (soil.depth < hi)]
    plastic = band[band.CLASS != "NP"].sort_values("LL").groupby("LOCA_ID").CLASS.last()
    holes[f"class_{lo}_{hi}m"] = plastic.reindex(holes.index)
    holes.loc[holes.index.isin(band.LOCA_ID) & holes[f"class_{lo}_{hi}m"].isna(), f"class_{lo}_{hi}m"] = "NP"
```

`Output`

```text
=== Step 6: the classification by borehole and depth ===
      0 to 3 m: 48 holes tested, 29 reach high plasticity or above; most plastic: CI 16, CH 13, CV 11, MH 3, CL 2, CE 2, NP 1
     3 to 10 m: 38 holes tested, 18 reach high plasticity or above; most plastic: CI 15, CH 14, CL 4, CV 2, MH 1, NP 1, MV 1
more than 10 m: 42 holes tested, 25 reach high plasticity or above; most plastic: CH 24, CI 12, CL 3, MH 1, NP 1, MI 1
  west of 393,100 E (escarpment): 203 specimens below topsoil, median LL 45, high plasticity or above 34%
  east of 393,100 E (plateau): 117 specimens below topsoil, median LL 46, high plasticity or above 44%
```

The map at the top of this page is the result, drawn over the same LIDAR hillshade as Parts 2 and 6. Read the three panels left to right and you go down through the hill. **Near the surface, the very high plasticity (CV and CE) holes are on the plateau to the east**, where the Fuller’s Earth clay lies close to the surface between the limestones. **Below 10 m, the escarpment holes are blue CH almost throughout**: by then most of them are through the landslide deposits and into the Lias mudstones. The 3 to 10 m panel is the mix in between, with intermediate plasticity landslide clays on the slope.

A map hides depth within each band, so the script also draws a long section, with every specimen at its hole’s easting and its own elevation:

![Long section with easting from 392,000 to 394,800 m on the horizontal axis and elevation from 100 to 300 m OD on the vertical. Each borehole is a black dash at ground level with a thin grey line down to its deepest specimen, and every Atterberg specimen is a circle coloured by its BS 5930 class. Ground level climbs from 127 m in the west to about 290 m on the plateau. The western holes are dense columns of teal CI and blue CH specimens from 110 to 230 m. On the plateau to the east, the specimens are close to ground level, with navy CV and orange MH circles among the blue.](https://www.technicalgis.com/_astro/05-plasticity-long-section.DlI4seeX_IwQX7.webp)

_The plasticity class of every Atterberg specimen at its borehole's easting and its own elevation, from the foot of the Crickley Hill escarpment in the west to the Cotswold plateau in the east._

The section shows the scale of the escarpment. Ground level rises 160 m over less than 3 km, and the holes on the face are long, densely sampled columns through the landslide deposits and into the mudstone. A handful of deep holes near the crest, around 393,200 to 393,500 E, go down through the limestone into the Bridport Sand, whose specimens are the pale green CL, teal CI and white NP circles at 180 to 225 m OD. Further east on the plateau, half the specimens are within 2.3 m of ground level, mostly in the Fuller’s Earth and the head above it.

## Step 7: write the results to a GeoPackage for QGIS

Each table becomes a layer of PointZ features in British National Grid, with the specimen’s elevation as Z, ready for the QGIS project from [Part 2](https://www.technicalgis.com/tutorials/ags4-boreholes-map-qgis/) or its 3D map view from [Part 3](https://www.technicalgis.com/tutorials/3d-borehole-logs-pyvista-qgis/):

`lab_classification.py`

```python
layers = {
    "atterberg": ll[["LOCA_ID", "depth", "mOD", "UNIT", "LL", "PL", "PI", "p425", "CLASS", "SPEC_DESC",
                     "LOCA_NATE", "LOCA_NATN"]],
    "moisture": mc[["LOCA_ID", "depth", "mOD", "UNIT", "MC", "LOCA_NATE", "LOCA_NATN"]],
    "grading": grag[["LOCA_ID", "depth", "mOD", "UNIT", "GRAG_GRAV", "GRAG_SAND", "GRAG_SILT", "GRAG_CLAY",
                     "GRAG_FINE", "LOCA_NATE", "LOCA_NATN"]],
    "holes": holes.reset_index(),
}
for name, df in layers.items():
    df = df.assign(unit_name=df.UNIT.map(A.UNITS.name)) if "UNIT" in df else df
    zcol = df.mOD if "mOD" in df else df.LOCA_GL
    gdf = gpd.GeoDataFrame(df.drop(columns=["LOCA_NATE", "LOCA_NATN"]),
                           geometry=gpd.points_from_xy(df.LOCA_NATE, df.LOCA_NATN, zcol), crs="EPSG:27700")
    gdf.to_file(gpkg, layer=name, driver="GPKG")
```

`Output`

```text
=== Step 7: write the results to a GeoPackage ===
a417_lab_classification.gpkg | atterberg: 327 PointZ features in EPSG:27700
a417_lab_classification.gpkg | moisture: 393 PointZ features in EPSG:27700
a417_lab_classification.gpkg | grading: 104 PointZ features in EPSG:27700
a417_lab_classification.gpkg | holes: 75 PointZ features in EPSG:27700
figures: 01-plasticity-chart.png, 02-grading-curves.png, 03-index-properties-elevation.png, 04-plasticity-by-borehole-map.png, 05-plasticity-long-section.png
```

In QGIS, style the `holes` layer with a categorised renderer on `class_10_100m` to rebuild the deepest map panel, or filter the `atterberg` layer with an expression such as `"CLASS" IN ('CH', 'CV', 'CE')` to find every high plasticity specimen. The `SPEC_DESC` field keeps the laboratory’s own description of each specimen, which is worth reading next to the class.

## Frequently asked questions

### Where are Atterberg limits in an AGS4 file?

In the LLPL group, one row per test, keyed to the specimen by `LOCA_ID`, the sample fields and `SPEC_REF` and `SPEC_DPTH`. The liquid limit is `LLPL_LL`, the plastic limit `LLPL_PL` and the plasticity index `LLPL_PI`. The plastic limit may hold `NP` for a non-plastic soil, so do not let a blanket numeric conversion silently turn those into blanks.

### How do I draw a grading curve from AGS4?

Take the GRAT rows for one specimen, sort them by `GRAT_SIZE`, and plot `GRAT_PERP` against size on a log axis. Group by every key field, not just `LOCA_ID` and depth, because one sample can have more than one specimen. The GRAG row for the same keys gives the gravel, sand, silt, clay and fines percentages.

### Why does the BGS export not include the laboratory results?

The BGS AGS index exports a standard set of field groups for every investigation it holds. The full laboratory data stays in the file the contractor deposited, which you can download from the same BGS record. Check what the original file contains before assuming a test was never done.

### Should I use the BS 5930 or the Casagrande chart?

They are the same chart. BS 5930 uses Casagrande’s A-line and splits the liquid limit into five ranges, L to E, where the Unified Soil Classification System uses two. Use the one your project specifies; the code only needs `LL_EDGES` and `LL_LETTERS` changed.

### Can I use this with any AGS file?

Yes, if the file has LLPL, LNMC or GRAG and GRAT, plus LOCA and GEOL. Change the depth bands and the topsoil code to suit your site, and the map and section work for any investigation.

## Next steps

-   Part 9 of the series reads the groundwater monitoring from the same AGS file, to see where the water sits in these clays.
-   [Part 6: SPT N-values](https://www.technicalgis.com/tutorials/spt-n-values-ags-python/) uses the same join to put in-situ strength by unit next to these classifications.
-   [Part 4: a geological cross-section](https://www.technicalgis.com/tutorials/geological-cross-section-ags4-python/) is a good place to add the plasticity classes along a section line.
-   Back to [Part 1: Reading and validating AGS4 files](https://www.technicalgis.com/tutorials/read-validate-ags4-python/) or [Part 5: the ground model](https://www.technicalgis.com/tutorials/geological-ground-model-surfaces-python/).

## Data and licences

-   **A417 Missing Link ground investigation** (BGS deposited data item 173984; client Highways England, now National Highways; contractor Geotechnical Engineering Ltd). The laboratory groups come from the original AGS4 file deposited with the BGS, and the repaired locations and geology from the BGS AGS export used in Part 1. Contains British Geological Survey materials © UKRI 2026, licensed under the [Open Government Licence v3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/). Every figure carries the credit.
-   **Environment Agency LIDAR Composite DTM 1 m**, requested at 5 m from the Defra Data Services Platform WCS. © Environment Agency copyright and/or database right, licensed under the Open Government Licence v3.0. It is the hillshade and contours in the map, which carries the credit. No other basemap is used.
-   Code: [`lab_classification.py`](https://www.technicalgis.com/code/ags-laboratory-classification-python/) and `a417_ags.py`, tested with Python 3.12.0, python-ags4 1.2.0, pandas 2.3.3, GeoPandas 1.2.0, rasterio 1.5.2 and matplotlib 3.11.2.

## Key terms

- **Atterberg limits**: The moisture contents at which a fine soil changes state. The liquid limit (LL) is where it starts to flow, and the plastic limit (PL) is where it stops being mouldable and starts to crumble.
- **Plasticity index (PI)**: The liquid limit minus the plastic limit: the range of moisture content over which the soil is plastic. Clays have a high PI and silts a low one.
- **A-line**: The line PI = 0.73 (LL − 20) on the plasticity chart. Soils plotting above it are classed as clays (C) and below it as silts (M).
- **Liquidity index (LI)**: (w − PL) / (LL − PL), where w is the natural moisture content. Below 0 the soil is drier than its plastic limit and stiff; between 0 and 1 it is plastic; above 1 it is wetter than its liquid limit.
- **Particle size distribution (PSD)**: The percentage of a soil passing each sieve size, from wet sieving for sand and gravel and from sedimentation (pipette or hydrometer) for silt and clay, plotted as a grading curve on a log scale.

## Data for this tutorial

-   [BGS AGS borehole data](https://www.technicalgis.com/data-sources/united-kingdom/#src-bgs-ags-borehole-data) · Donated AGS ground investigation data, Open Government Licence

Licences and formats for each source are listed in the [GIS data sources catalogue](https://www.technicalgis.com/data-sources/).

[← Part 7 3D-print a geological ground model: one watertight STL per stratum](https://www.technicalgis.com/tutorials/3d-print-geological-ground-model/)

---

Source: https://www.technicalgis.com/tutorials/ags-laboratory-classification-python/
