Sentinel-2 change detection at an open-pit mine in Zambia (PCA-based pipeline with spatial database and visualization).
# Sentinel2-change-detection-zambiaa
Sentinel-2 Change Detection — Open-Pit Mine, Zambia
Detecting land-surface change at an open-pit copper mine in Zambia from two
Sentinel-2 images taken three weeks apart (2023-08-12 and 2023-09-02). Done for
the Solafune technical assessment.
The short version: load the imagery, line the two dates up, find where the ground
changed using PCA, clean up the result, turn it into polygons, save those to a
database, and map it.
Two notebooks
I ended up doing this two ways, so there are two notebooks:
3banded.ipynb — uses the three bands the assessment gives you (B02 blue,
B03 green, B04 red). This is the main one and runs straight off the provided
data.
solafune-assignment-11bands.ipynb — the same idea but on an 11-band image
I put together myself from Copernicus (more on that below). Having the extra
bands also let me compute NDVI.
I kept them separate because the two datasets don't line up cleanly — different
CRS, different resolution, different number of bands — so mixing them into one
notebook would've been messier than it's worth.
How it works
Loading & prep. Read the bands for each date, check the CRS / transform /
size actually match, and stack them into one multi-band image. If the two dates
sit on different grids, the second one gets resampled onto the first so every
pixel is comparing the same spot on the ground.
Change detection. Two methods:
the provided Euclidean-distance baseline (example_change_detection.py), applied
as-is, and
a PCA approach. First I match the after image to the before one band by band
(so the difference reflects real change and not just one date being brighter),
then run PCA on the per-pixel band difference and take the magnitude of the
leading components as the change signal. PCA pulls the real, coherent change into
the first few components and dumps the noise into the rest, which I drop.
Cleaning it up. I threshold the change magnitude at the 98th percentile —
P95 lit up way too much ( …