Cleaning Scientific Data · Lesson 6 of 6
Unit Conversion & Consistency
~12 min
The Concept
Bluewater Basin's water quality network has been running for eleven years. Three years ago, the team switched from one dissolved oxygen probe model to another. The old probe reported in percent saturation; the new one reports in mg/L. Nobody flagged this in the sensor metadata. Half the dataset is in one unit; half is in the other. The two halves look completely different when plotted, there appears to be a dramatic drop in dissolved oxygen exactly when the probe was replaced.
This is a unit consistency error: not a sensor failure, not a calibration drift, but a change in the quantity being reported. It's one of the most common silent errors in long-term environmental datasets.
Percent saturation and mg/L both measure dissolved oxygen, but they're not the same number. Percent saturation tells you what fraction of the water's maximum possible oxygen content is actually present; mg/L tells you the absolute mass of oxygen per litre. The conversion between them depends on water temperature, warm water holds less oxygen, so 100% saturation in summer corresponds to fewer mg/L than 100% saturation in winter.
Before combining data from multiple instruments, multiple sites, or multiple time periods, you must verify that every column represents the same quantity in the same units. If not, convert everything to one standard unit before doing any analysis.
The Analogy
It is like two people arguing about who ran farther, but one measured in miles and the other in kilometers, and both are quietly assuming the numbers already mean the same thing. Until you convert them onto the same scale, you are not comparing distances, you are just comparing two different units that happen to look like numbers.
The Math (optional)
Converting dissolved oxygen from percent saturation to mg/L:
DO conversion (simplified)
DO_sat(T) is the saturation concentration at temperature T (°C), approximately 14.6 mg/L at 0°C and 7.6 mg/L at 30°C. Multiply percent saturation by this temperature-dependent maximum.
Code (optional)
import pandas as pd
import numpy as np
df = pd.read_csv("WQ09_DO_combined.csv", parse_dates=["timestamp"])
# DO saturation concentration as a function of temperature (simplified)
def do_sat_mgL(temp_C):
# Benson & Krause (1984) approximation
return 14.621 - 0.3898 * temp_C + 0.006969 * temp_C**2 - 0.00005898 * temp_C**3
# Flag which rows use old probe (percent saturation) vs new probe (mg/L)
old_probe_mask = df["timestamp"] < "2022-07-14"
# Convert old probe readings from % to mg/L
df.loc[old_probe_mask, "DO_mgL"] = (
df.loc[old_probe_mask, "DO_raw"] / 100.0
* do_sat_mgL(df.loc[old_probe_mask, "temp_C"])
)
# New probe readings are already in mg/L
df.loc[~old_probe_mask, "DO_mgL"] = df.loc[~old_probe_mask, "DO_raw"]
print("Units harmonised. DO range after conversion:")
print(df["DO_mgL"].describe())Line by line
- do_sat_mgL() uses a polynomial approximation of the oxygen saturation curve, DO_sat depends on temperature, so we need the concurrent temperature record.
- We use the probe swap date (July 14, 2022, from the calibration log) to separate old and new measurements.
- Old readings are converted by multiplying (percent/100) × DO_sat(T); new readings pass through unchanged.
- After conversion, both halves of the dataset live in the same unit, mg/L, and the artificial 'drop' at the swap date disappears.
Why Real Researchers Care
Unit inconsistency errors have appeared in peer-reviewed papers and caused retractions. The Mars Climate Orbiter spacecraft was lost in 1999 because one engineering team used metric units and another used imperial, the same category of error that causes real harm in environmental datasets when different time periods or instruments record the same variable in different units without documentation.
Quick Check
Q1. A long-term dissolved oxygen dataset shows an apparent 30% drop on the exact date the probe model was replaced. The most likely explanation is:
Your Goal
The old WQ-09 probe recorded 88% saturation at a water temperature of 18°C. Using the formula from this lesson, convert this to mg/L. (Use the simplified DO_sat values: at 18°C, DO_sat ≈ 9.5 mg/L.)
Hint: DO_mg/L ≈ (88/100) × 9.5
Teach It Back
Explain why a unit conversion error is more dangerous than an obvious sensor failure, and what you'd put in a monitoring plan to prevent it.