PROJECT STUDY

Rock & Coal Field Scanner

Screen in the field and let the lab decide.

An offline field app and screening API for coal and mineral sites: rock prediction sets on the phone, calorific ranges on every basis and handheld XRF flags, recalibrated from lab results.

Explore the build
Field Scanner illustration: a phone frames a coal sample with a scale bar under an 'Indicative screening, not an assay' banner, beside a two-class prediction set and an indicative calorific range.
Original interface illustration · Synthetic demo data.View larger

At a glance

Industry
Mining
Capabilities
7
Technologies
12
Year
2026

The challenge

Field geologists and quality-control staff at Indonesian coal and mineral sites wait days for laboratory assays, yet they decide on site which faces to keep sampling, which bags are worth the lab's queue and which veins deserve a fire assay.

They need a first read in the field: what rock this is, the likely coal rank and calorific range, and whether a sample shows signs of gold, copper or nickel worth an assay.

A phone photo cannot measure calorific value or gold grade, so a useful screen has to say how much it knows. It has to combine the photo with field kit measurements and handheld XRF readings, state its uncertainty, work where there is no signal, keep each sample's chain of custody to the lab, and learn from the lab results that come back.

What we built

Rock & Coal Field Scanner pairs an offline-first Expo app with a Python screening API, and every value it returns carries its basis, its unit and its uncertainty.

Offline capture

A photo from the camera or the library, a sample ID typed or scanned from the bag's QR code or barcode, GPS with its reported accuracy, optional field kit values and an optional handheld XRF export are saved to a queue on the phone, which syncs when signal returns

Offline capture

A photo from the camera or the library, a sample ID typed or scanned from the bag's QR code or barcode, GPS with its reported accuracy, optional field kit values and an optional handheld XRF export are saved to a queue on the phone, which syncs when signal returns

A first read on the phone

The rock classifier runs offline in TypeScript the moment a photo is chosen and shows its prediction set as "Screened on this phone". The server screens the photo again on sync, and its result is the one recorded

Rock type as a prediction set

Eight classes cover coal of low, medium and high rank appearance, sandstone, claystone, limestone, quartz vein and laterite. The API returns every class that passes its conformal threshold at 90 per cent target coverage, with the model's scores, a check for photos unlike any rock it was trained on and photo quality hints

Coal quality with its basis and interval

GAR, GAD, NAR, dry and dry, ash-free values in kcal/kg and MJ/kg come as ranges from the site's own calibration, beside the field values they came from and every ASTM D388 rank the interval reaches. Until a site has enough lab pairs there is no calorific number, only the reason

Mineral flags from handheld XRF

Readings keep their detection limits and errors, and gold, copper, nickel, zinc, iron, sulfur, arsenic and lead are flagged against thresholds each site can set. A gold flag is a request for fire assay, never a grade

Chain of custody and the lab loop

Each sample is recorded as captured, synced, sent to the lab under a batch number and assayed. Lab results imported by sample ID close the chain, refit the site calibration as a new version and feed a reconciliation view with a drift check

Built for the field team

The app's own text reads in English or Bahasa Indonesia, switchable in Settings, with Indonesian number and date formats, and layouts run from 390 px phones to 1440 px desktops, where the tab bar becomes a sidebar

How it works

  1. Capture without signal

    Each capture is written to a local queue under two client-generated IDs, in SQLite through expo-sqlite in the native app and in browser storage in the web export. The queue syncs in capture order every 30 seconds or on demand, waits from 30 seconds up to 15 minutes after a transient failure, and marks a refused capture as needing attention instead of retrying it blindly.

  2. Screen on the phone

    As soon as a photo is chosen, the app decodes it, with jpeg-js for a JPEG, cuts the centre square, box-resizes it to 128 by 128 pixels with a port of Pillow's resampling and computes 54 texture features. The classifier, its conformal thresholds and the feature guard then run from a bundle exported from the served ONNX graph, so the set appears without any signal.

  3. Screen again on sync

    The FastAPI service keys each sync on its capture ID, so a retry returns the stored result, and refuses a different capture that reuses a sample ID, because two bags must never share a label. It scores the eight classes with ONNX Runtime, returns the prediction set with the guard's verdict and quality hints, stores the photo by its SHA-256, flags the XRF readings and records each custody step.

  4. Estimate coal quality

    The site calibration predicts GAR from dry, ash-free volatile matter, total moisture and as-received ash, with a Student-t prediction interval that widens away from the values the site has measured. Other bases follow the ISO 1170 relationships, NAR the ISO 1928 net value and rank ASTM D388 with the Parr formulas, and Dulong's formula is shown as a cross-check when an ultimate analysis comes with the sample.

  5. Reconcile with the lab

    Samples go to the lab under a batch number and come back as a CSV matched by sample ID, row by row. Each import closes the chain of custody and refits the calibration as a new version with a leave-one-pit-block-out check. The lab view compares every assay with the estimate the field team actually saw, checks prediction sets against logged lithology, reports the field kit's moisture and ash bias, and flags drift when the last ten results fall inside their intervals less often than the stated level allows or share a large, clear bias.

  6. Train, calibrate, bundle

    The ml package renders 4,960 procedural rock-surface photos across the eight classes, with wet, dusty and shadowed surfaces and phone-camera effects, and sends them through the same JPEG decode and resize as a field photo. It fits a standardiser and a multinomial logistic regression, exports them to ONNX with skl2onnx and computes the conformal thresholds from the exported graph's own probabilities on a held-out calibration split.

Engineering insights

The scanner never returns a bare answer: rock type is a set, calorific value is an interval, rank lists every ASTM D388 group the interval allows, and the phone and the server run the same model.

Stack by layer

Frontend
  • Expo
  • React Native
  • TypeScript
  • Expo Router
  • React Native for Web
  • react-native-svg
  • expo-camera
  • expo-image-picker
  • expo-location
  • expo-document-picker
Backend
  • Python
  • FastAPI
  • Pydantic
  • Uvicorn
Data
  • SQLite
  • expo-sqlite
  • NumPy
  • SciPy
AI
  • ONNX Runtime
  • scikit-learn
  • skl2onnx
  • ONNX
  • Pillow
  • jpeg-js
Infrastructure
  • uv
  • pytest
  • Hypothesis
  • Vitest
  • Playwright
  • Ruff
  • mypy
  • Biome
  • Docker Compose
  • GitHub Actions
  1. A prediction set, never a single label

    Conformal thresholds are computed per class, so a rare, decisive class cannot hide behind a good average, and a class with too few calibration photos for a finite threshold is always included rather than dropped. When no class passes, the result says so instead of showing a confident label. On 1,200 synthetic test photos, a 90 per cent target reached 93.6 per cent coverage with 1.05 classes per set

  2. Thresholds locked to their graph

    Conformal thresholds are valid only for the probabilities they were computed on, so they come from the exported ONNX graph itself. The graph, its thresholds and the feature guard are pinned by SHA-256 in a model card, and the API refuses to start on a mismatched graph, feature recipe or class order

  3. The same model offline on the phone

    The phone's weights are read out of the served ONNX graph, and the TypeScript port reproduces Pillow's fixed-point box resampling and the server's features at float32 precision. The server's grey image is written as three products summed left to right, because a BLAS matrix product may use fused multiply-adds that JavaScript cannot repeat. On the 40 synthetic demo photos, the phone's set matched the server's for 38

  4. Calibrated on field-to-lab pairs

    Calorific value is a least-squares fit of lab GAR on field kit values, so its interval absorbs the kit's own error, and each refit is checked with whole pit blocks held out, because neighbouring samples are correlated. In a simulation on a synthetic seam, 90 per cent intervals held 92.3 per cent of lab values with 20 pairs and 90.7 per cent with 60, while fitting the dry, ash-free value and converting it with field moisture fell to 84.7 and 77.6 per cent

  5. Every value carries its basis

    NAR is never scaled from GAR, because it needs hydrogen: without an ultimate analysis it becomes a range drawn from the site's own hydrogen history. Rank uses Parr mineral-matter-free values at the site's equilibrium moisture when the lab has measured it, and returns both candidates when unknown agglomerating character decides

  6. Censored XRF stays censored

    A reading below its detection limit keeps its limit instead of becoming zero, a flag is indicative only when the reading minus its reported error clears the threshold, and a detection limit above the threshold reads inconclusive rather than clear. Arsenic is marked uncertain where lead is as high or higher, because their main X-ray lines overlap

Design system

Field kit treats the app as a field instrument rather than an office app: high contrast for direct sunlight, controls sized for gloved hands and one primary action per screen, under a permanent "Indicative screening, not an assay" banner, because the most dangerous failure of this product is a screening result mistaken for a lab result.

Colour palette

  • Basalt#1c1917All text and icons, including labels on lime and gold fills, and the outlines of inputs and buttons
  • Chalk#fafaf9Screen background, the callouts that carry red text and the banner text on coal
  • Sandstone light#efe7d3Card surfaces and the active tab
  • Sandstone#d6c7a1Input fills under a basalt outline, inactive segments, neutral chips and interval bands
  • Coal#262626The permanent indicative banner, dark status chips and photo placeholders
  • Ore gold#b8860bMineral flags only, as a fill behind basalt text and never as text
  • Signal lime#65a30dThe one primary action on each screen, with basalt text and a 2 px basalt outline
  • Alert red#dc2626Errors, refusals, results outside their interval and drift, with red text only on chalk
  • Colour

    Basalt text on chalk, with colour reserved for meaning: signal lime only for the next action, ore gold only for mineral flags and alert red only for problems, each paired with an icon and a word. Sandstone inputs carry a basalt outline, because sandstone barely stands off chalk

  • Typography

    Atkinson Hyperlegible, designed by the Braille Institute for low-vision readers and bundled with the app so it works offline, sets all text from 15 px captions to 27 px headlines, with bold values. Its distinct 0 and O, 1 and l keep sample IDs such as CP-26-0190 unambiguous, and every number prints with its basis and unit

  • Components

    A small in-house set on React Native primitives with no UI kit: a lime primary button pinned in a footer, segmented choices instead of dropdowns, fields that show their unit and accept a decimal comma, status chips with an icon and a word, chalk callouts, range bars that mark the lab value as a ring, and loading, empty and error states that name the cause

  • Layout

    A 16 px gutter and content capped at 1,180 px. From 900 px, screens split into two columns, and from 1,100 px the bottom tab bar becomes a 232 px sidebar with the footer action aligned right

  • Accessibility

    Every control is at least 48 dp and the primary action 56 dp. Tests check every text pairing against the WCAG 4.5:1 minimum, and because lime against chalk falls just under the 3:1 non-text minimum, the primary button always carries a 2 px basalt outline

Where this fits

Mining, quarrying and exploration teams that wait on assays can use the same pattern: a fast first read in the field, clear about its uncertainty and tied to the lab results that confirm it. Explore our mobile apps, AI solutions and computer vision services, or talk to us about your field workflow.

talk to us about your field workflow

Let’s connect the dots

Let's put these ideas to work.

Share a process, product, or problem you want to improve. We will work through the possibilities together.

Discuss your project