Laboratory classification data from AGS4: plasticity charts, grading curves and maps in Python
Read the Atterberg limits (LLPL), moisture contents (LNMC) and particle size tests (GRAG, GRAT) from a real AGS4 file, find the geological unit of every specimen, classify the clays on the BS 5930 plasticity chart, draw grading curves by unit, and map the most plastic soil in each borehole by depth, ready for QGIS.
- Level
- Intermediate
- Tested with
- Python 3.12
- Source code
- Download scripts
Key takeaways
- 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.
- 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.
- 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.
- 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:
- download the contractor’s original AGS4 file and read its laboratory groups;
- find the depth, position and geological unit of every specimen;
- classify the fine soils on the BS 5930 plasticity chart;
- draw the grading curves for each unit;
- plot moisture content and the Atterberg limits against elevation;
- map the classification by borehole and depth;
- write the results to a GeoPackage.
The code is lab_classification.py. It uses a417_ags.py from Part 1 for the repaired borehole locations and geology.
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_IDs match the export, so the repaired positions from Part 1 still apply.
ORIGINAL = "Geodata file 1908.ags" # the contractor's AGS4 file, as deposited with the BGSACCESSIONS = "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()))=== Step 1: the deposited AGS4 file and its laboratory groups ===Geodata file 1908.ags: 23.2 MB, 62 groups, AGS 4.0.4, issue 19LNMC.LNMC_MC: 393 numbers; not numeric: '(blank)' x14LLPL.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 holesLLPL holes missing from the repaired LOCA: 0The 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.
LLPL holds one row per Atterberg test: LLPL_LL, LLPL_PL, LLPL_PI, the percentage passing 425 µm (LLPL_425) and how the specimen was prepared (LLPL_PREP). LNMC holds the natural moisture content LNMC_MC. GRAG is the summary of each grading test, with GRAG_GRAV, GRAG_SAND, GRAG_SILT, GRAG_CLAY and GRAG_FINE as percentages. GRAT has one row per sieve or sedimentation point: the size GRAT_SIZE in mm, the percentage passing GRAT_PERP and the method GRAT_TYPE.
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:
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"])=== Step 2: where each specimen came from === Atterberg moisture grading median_LL median_PI median_MCTopsoil 7 7 3 74.0 33.0 30.7Made ground 8 16 12 42.5 18.5 18.0Head 19 20 13 49.0 25.0 15.0Landslide deposits 133 145 48 43.0 22.0 20.9White Limestone Formation 0 1 0 - - 0.7Hampen Formation 0 1 0 - - 0.4Fuller's Earth Formation 42 66 15 59.0 36.0 19.3Salperton Limestone Formation 0 2 1 - - 15.3Aston Limestone Formation 0 1 0 - - 13.9Birdlip Limestone Formation 0 3 5 - - 15.0Bridport Sand Formation 36 39 7 35.0 13.5 14.7Whitby Mudstone Formation 53 62 0 48.0 25.0 15.2Dyrham Formation 16 16 0 44.0 24.0 14.9Charmouth Mudstone Formation 13 14 0 51.0 26.0 19.0specimens from 0.1 to 89.0 m deep; 313 of 327 Atterberg specimens washed on 425 µmThe 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.
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)]=== 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 489% 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
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:
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")=== 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.0Made ground 12 46.0 22.0 25.0Head 13 23.0 21.0 35.0Landslide deposits 48 39.0 10.0 47.0Fuller's Earth Formation 15 0.0 5.0 95.0Salperton Limestone Formation 1 34.0 40.0 26.0Birdlip Limestone Formation 5 61.0 17.0 10.0Bridport Sand Formation 7 0.0 21.0 79.0Every 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.
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:
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]=== 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 specimenwithin 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
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:
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 classificationholes = (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"=== 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 1more 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:
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 or its 3D map view from Part 3:
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")=== Step 7: write the results to a GeoPackage ===a417_lab_classification.gpkg | atterberg: 327 PointZ features in EPSG:27700a417_lab_classification.gpkg | moisture: 393 PointZ features in EPSG:27700a417_lab_classification.gpkg | grading: 104 PointZ features in EPSG:27700a417_lab_classification.gpkg | holes: 75 PointZ features in EPSG:27700figures: 01-plasticity-chart.png, 02-grading-curves.png, 03-index-properties-elevation.png, 04-plasticity-by-borehole-map.png, 05-plasticity-long-section.pngIn 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 uses the same join to put in-situ strength by unit next to these classifications.
- Part 4: a geological cross-section is a good place to add the plasticity classes along a section line.
- Back to Part 1: Reading and validating AGS4 files or Part 5: the ground model.
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. 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.pyanda417_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 · Donated AGS ground investigation data, Open Government Licence
Licences and formats for each source are listed in the GIS data sources catalogue.
Need this done on your own data? TechnicalGIS takes on consulting projects like this one, from a single analysis to a pipeline your team can rerun.