Skip to content
Projects

Reading rock chemistry from a Mars rover’s laser

Master’s thesis
Aalborg University
Period
Sep 2023 to Jun 2024
Built with
Python, scikit-learn, Optuna

One pulse A 1067 nm laser, 1.6 m from the rock

Its spark’s light, across 6,144 channels from 240 to 906 nm

ChemCam in side elevation, and a schematic spectrum: lines at their NIST wavelengths over ChemCam’s three spectrometer ranges, with illustrative strengths. Test errors are from Table 19 of the thesis.

Curiosity carries a laser. ChemCam fires it at a rock, the spot turns to plasma, and three spectrometers record the light. For our master’s thesis, two classmates and I worked on the step after that: turning one of those spectra into the rock’s chemistry.

The problem

A spectrum has 6,144 channels, 2,048 from each spectrometer. From it, a model has to predict eight major oxides in weight percent, from SiO₂ to K₂O. We trained on ChemCam’s calibration data from NASA’s Planetary Data System: 408 rock samples the ChemCam team shot in a lab under Mars-like conditions, at five spots per sample and fifty shots per spot, all from 1.6 meters away. For LIBS, that is a big dataset. For machine learning, it is small.

Neighbouring channels move together. Matrix effects make an element’s line brighter or dimmer for reasons that have nothing to do with how much of it is there. And the samples with unusually high or low amounts of an oxide are rare, which makes them both the most important and the easiest to lose in a careless split.

Perseverance carries ChemCam’s successor, SuperCam, which faces the same problem. Our data and models are ChemCam’s.

Where we started

ChemCam’s calibration model, MOC, runs partial least squares sub-models and an ICA-based model side by side, then blends them with fixed weights per oxide. We had rebuilt it from the papers the semester before. For the thesis we changed how the replica uses the data and automated its outlier removal, and one of MOC’s original authors confirmed the changes were reasonable. That replica is our baseline.

Testing without fooling ourselves

A random split leaks: one rock’s five spectra end up on both sides. So we keep every sample in one fold, sort the samples by the oxide we are predicting, and deal them into five folds like cards, which spreads the range evenly. The top and bottom 5% only ever go into training folds. I built a small app to choose that 5% by watching where the extremes landed.

The cost is that the test set is easier than the full range, so test error (RMSEP) runs lower than cross-validation error (RMSECV). We report both.

Twelve models

We ran twelve models on the same input and the same folds with near-default settings. XGBoost had the lowest cross-validation error, with SVR and gradient boosting close behind. The two neural networks came last. With 408 samples they needed far more tuning than we could afford, so we dropped them. The more useful finding was that the best model changed from oxide to oxide.

Mean RMSECV over the eight oxides, relative to XGBoost at 100, so higher is worse. From Tables 7 and 8 of the thesis.

16,000 trials

So we stopped picking by hand. I wrote an Optuna search that builds a whole pipeline per trial (a scaler, an optional transform, optional PCA, then the model) and minimizes cross-validation error and its spread together. We set 200 trials for each of the ten remaining models on each of the eight oxides, 16,000 in all, and a server failure cut NGBoost on MgO short at 143. Every trial went to MLflow, and every new best went to a Discord channel.

ChemCam’s own normalization, which scales each spectrometer separately (Norm 3 in the thesis), was the most used scaler, in 5,090 trials. Neither PCA nor kernel PCA seemed to help, and 9,419 trials used neither.

Stacking

MOC blends its models with weights set by hand. A stacking regressor learns the blend instead. For each oxide we took the best two or three pipelines from different model families and trained a small meta-model on their out-of-fold predictions. SVR made it into all eight.

SiO₂ PLS, SVR, and gradient boosting, stacked by SVR

Test error 5.61 → 3.47 wt%, 38.1% lower than our MOC replica

Base pipelines from the thesis code, test errors from Tables 16 to 19. A stack’s two or three base pipelines come from different model families.

The meta-model matters more than it looks. With a strongly regularized ElasticNet on top, the TiO₂ predictions went flat, almost the same number for every rock. Most TiO₂ values sit between 0 and 2.5 wt%, and the penalty swamped them. Turning the regularization down took TiO₂’s test error from 0.571 to 0.319.

Results

On the held-out test set, every oxide has a stack that beats our MOC replica. Summed over the eight oxides, test error is 37.3% lower with ElasticNet (α = 1), 38.1% with ElasticNet (α = 0.1), and 39.5% with SVR. Per oxide, the ElasticNet (α = 1) stack ranges from 1.4% better on FeOT to 75.1% better on K₂O, and with α = 0.1, FeOT gets 1.2% worse.

RMSEP on the held-out test set, in weight percent, from Table 19 of the thesis. Each stack is an ElasticNet (α = 1 or 0.1) or SVR meta-learner over two or three tuned pipelines.

These are test-set numbers on lab samples. The two test sets were built differently but are similar in composition, which is what makes the comparison fair, and some single pipelines still beat the stacks on some metrics.

PyHAT

PyHAT is the USGS’s Python toolkit for this kind of spectral analysis. Dr. Ryan B. Anderson merged three of my merge requests: a faster ChemCam data loader (opens in a new tab) that took 2,068 files from 136.35 s to 39.28 s, a switch for a file-version check (opens in a new tab) that rejected real data, and an automated version of an outlier method (opens in a new tab) that used to be done by hand. Patrick contributed a function for reading ICA loadings (opens in a new tab), which is still open.

After we presented our results, the USGS team wrote us a letter:

These contributions stand to make a sizeable impact on the field of chemometrics as applied to the ChemCam and SuperCam emission spectroscopy instruments on two active missions as part of NASA’s Mars Exploration Program.

First, the team suggested the use of a Stacking Regressor to combine the results of several models into a final “meta model”. This is an alternative to the relatively crude and labor-intensive “submodel blending” approach that was used for the current ChemCam calibration. The team also suggested the use of a power transform as a preprocessing step. Both suggestions have been implemented and are showing promising results.

Dr. Ryan B. Anderson and Dr. Travis S.J. Gabriel, USGS Astrogeology Science Center

What’s left

The test set leaves out the extremes, so we never measured how the models do on the rarest compositions, and we only had data from one distance. We ran a grid search over stack combinations for TiO₂ alone, left the meta-learners at their defaults, and left the neural networks out of the search. Synthetic data, a separate test on extreme values, and a wider search over stacks are where I would go next.

History

  1. September 2023

    First commit. Rebuilding ChemCam’s calibration model from the papers.

  2. January 2024

    Our 9th-semester report on where that model falls short.

  3. May 2024

    Opened PyHAT merge requests 8, 9, and 10.

  4. May 17 to June 12, 2024

    The 16,000-trial search, then the stacking results.

  5. June 13, 2024

    The letter from the USGS team.

  6. June 26, 2024

    The automated outlier removal merged into PyHAT.

  7. March 3, 2025

    The faster loader and the file-check switch merged into PyHAT.

Credits

The thesis is joint work with Patrick Frostholm Østergaard and Ivik Lau Dalgas Hostrup. Our supervisors were Daniele Dell’Aglio and Juan Manuel Rodriguez, and Jens Frydenvang of the ChemCam team was our external supervisor.

Read the thesis, browse the code on GitHub (opens in a new tab), or see our PyHAT merge requests (opens in a new tab).

Search and commands

Keyboard shortcuts

Go to

gh Home
gb Writing
gp Projects
gl Books
gt Tools
ga About
gn Newsletter

Move

jk Next / previous item, or scroll
hl Left / right in the book grid
[] Previous / next section
du Half page down / up
gg First item, or the top
G Last item, or the bottom
↵ Open focused item
⌘↵ Open in new tab

Search

/ Search: books filter or palette
: Commands
⌘K Command palette
? This panel
esc Close, cancel, or leave a field