# DEM spikes: a despike filter for the horizons (C3) and terrain patches (C4) > AI-generated with Claude Code (Anthropic), directed and reviewed by the Moonat team. > Reproduce: `uv run python scripts/data/scan_dem_spikes.py` (the scan, `docs/validation/dem_spikes.json`), > `uv run python scripts/data/plot_dem_spikes.py` (figures, `docs/validation/dem_spikes_figures.json`), > `uv run python scripts/data/build_terrain.py` (rebuild), `uv run pytest tests/test_despike.py` (21 tests: synthetic > grids with exact answers, plus real-data checks when the DEM blocks are cached). ## Summary A DEM cell is replaced by the median of its 8 neighbours only when it stands out from them by more than the tip of a cone with 60° flanks (2.09 cells: 124 m in SLDEM2015, 42 m in LOLA 20 m), by more than 6 times their own spread, and alone (clusters of up to 2 × 2 cells; anything larger is left whole). | Check | Before | After | |---|---|---| | Apollo 17 catalog horizon at azimuth 316.5° (the SLDEM2015 cell +365 m at 20.4170°N, 30.5420°E) | 5.94° (needle) | **4.33°**; every other azimuth identical | | AS17-137-20870 / 20871 skyline RMS (photo vs Moonat, same fitted cameras) | 0.133° / 0.129° (2 outliers each) | **0.038° / 0.037°** (no outlier) | | Real relief, 30 km windows: cells replaced at Apollo 15 (Hadley Delta) / Apollo 17 (massifs) / Shackleton rim | | **0 / 1 (the spike) / 32** isolated LOLA cells, none on the rim crest; horizons identical except at the spike | | Catalog scan, 42 sites, all layers: horizons changed by more than 0.01° | | **2**: Apollo 17 (1.61°), IM-2 (0.08°) | | Cells replaced (unique) | | SLDEM2015 15; LOLA 20 m 309; LOLA 30/60/240 m, LDEM_64, LDEM_16: 0 | | Gläser et al. 2014, CR1 spots 1 (2 m) and 3 (10 m) | 86.0 % / 92.7 % | **identical** (horizons identical) | | Bussey et al. 2010 Malapert (catalog `art_malapert`, C3 Sun visibility 2027) | 75.9 % (published 74 %) | **identical** | | Pan-calibrated focal length / Earth elevation with it (real_photos.md §4) | 61.48 mm / +0.02° | 61.43 mm / +0.04° (two more frames enter the calibration) | ## 1. The problem [real_photos.md](real_photos.md) §9 found a needle in Moonat's Apollo 17 horizon at azimuth 316.3°, on the south-west slope of the North Massif, where the photos AS17-137-20870 and 20871 show a smooth slope. It is one SLDEM2015 cell: | Cell (SLDEM2015, 512 px/deg) | Height | Median of its 8 neighbours | d = height − median | Spread of the neighbours (MAD) | From the Apollo 17 site | |---|---|---|---|---|---| | 20.4170°N, 30.5420°E (row 20266, col 15637 of the 60°N–60°S mosaic) | −1529 m | −1894 m | **+365 m** | 17.5 m | 9.47 km, azimuth 316.4° | The neighbours lie on a plane rising about 25 m per cell (a 23° slope); the cell stands 365 m above it, which would need flanks of 79° on every side. No lunar landform does that at a 59 m scale: it is an artefact of the DEM product, which merges LOLA altimetry with stereo heights from the SELENE Terrain Camera (Barker et al. 2016). In the catalog horizon (eye 2 m, 0.25° steps) it made a needle 1.61° high over three samples (azimuth 316.25–316.75°; 5.94° instead of 4.33° at 316.5°); from the EVA-2 pan camera (eye 1.5 m, 0.1° steps) 1.64° high and 0.7° wide (§5). It also stood as a 154 m post in the 3-D terrain patch. ## 2. The filter (`moonat.terrain.despike`) **Where:** in the DEM loading step. Every window that `moonat.terrain.dem` loads for a site (`window_around`, and the whole-file layers in `_whole_window`) is cleaned once, before any horizon, patch or tile is computed from it. `build_layers(..., despike=False)` and `window_around(..., despike=False)` give the raw product values; the changed cells of each window are listed in `Window.spikes`. **Definition** (per cell, in the product's own pixel grid, heights in metres above the 1737.4 km sphere): 1. N = the 8 neighbours of the cell (the 3 × 3 block without the centre); m = their median (the mean of the 4th and 5th smallest); MAD = the median of |N − m|; d = h − m. 2. **Shape test:** |d| > T = 2.09 × cell size. The tip of a cone whose flanks rise at angle θ stands 1.207 · cell · tan θ above the median of its 8 neighbours (4 edge neighbours one cell away, 4 diagonal ones 1.414 cells away; 1.207 = (1 + 1.414)/2). T is that height for θ = 60°: a flagged cell would need flanks steeper than 60° on every side. On any planar slope, however steep, the 8 neighbours come in symmetric pairs and m equals the centre height exactly, so a uniform slope is never touched. 3. **Outlier test:** |d| > 6 × MAD. A perfect cone has |d|/MAD = 5.83 whatever its slope and a rounded summit about 3, so summit-shaped relief fails this test too, while a spike, whose neighbours agree with each other, has a much larger ratio (20.8 for the Apollo 17 cell). A cell must pass both tests. 4. **Isolation guard**, so that a feature is either removed whole or left whole, never partly flattened: (a) a candidate is kept only if every neighbour that stands beyond T from the candidate's median, on the same side, is itself a kept candidate (repeated until nothing changes); (b) kept candidates are grouped into 8-connected clusters, and a cluster of more than 4 cells (a line, a trench, a blob) is left whole. So single cells, pairs, triples and 2 × 2 blocks are removed; nothing larger is touched. 5. Each kept candidate is replaced by m (one pass). Window borders, cells with a missing neighbour and missing cells are never changed. **Cell size** is the product's nominal pixel: the north-south size for the simple-cylindrical grids (the larger of the two, so the threshold is the more conservative one), the map scale for the polar stereographic grids. | Product (layer) | Cell | T (shape test) | |---|---|---| | LOLA LDEM_80S_20M (near, polar) | 20 m | 41.8 m | | LOLA LDEM_75S_30M (near, polar) | 30 m | 62.7 m | | SLDEM2015 512 px/deg (near, ±60°) | 59.2 m | 123.8 m | | LOLA LDEM_60S_60M (near, polar) | 60 m | 125.4 m | | LOLA LDEM_75S_240M (mid, polar, whole file) | 240 m | 501.8 m | | LOLA LDEM_64 (mid) | 473.8 m | 990.6 m | | LOLA LDEM_16 (far, whole file) | 1895.2 m | 3962.4 m | **Why these numbers (conservative by design):** - Lunar slopes at DEM baselines stay well below 60°, and a flagged cell would need more than 60° on all eight sides, not just on one wall. In the three relief windows of §3, 99.99 % of the cells have a 3 × 3 slope below 38° (Apollo 15), 35° (Apollo 17) and 46° (Shackleton, 20 m cells). In the two SLDEM2015 windows every cell except the spike and one trench (§6) stands within 0.66 T (Apollo 15) and 0.35 T (Apollo 17) of its neighbours' median; in the LOLA 20 m window 99.99 % of the cells are within 0.32 T. - The threshold scales with the cell, so the coarse products (where one cell may hold a whole central peak) get proportionally higher thresholds; in practice nothing in LDEM_64, LDEM_16 or LOLA 240 m reaches them (§4). - Two independent tests and the guard: a cell is changed only if it is impossible as terrain (shape), an outlier among its own neighbours (MAD) and isolated (guard). §7 shows what looser settings would add. ## 3. Proof: the known spike, and real relief **The known spike.** Within 30 km of Apollo 17 (the near band of its horizon) the filter changes exactly one cell, the one at 20.4170°N, 30.5420°E: −1529 m becomes −1894 m, the median of its neighbours (`tests/test_despike.py`, real-data test). Every other horizon azimuth and every other patch node is unchanged (figure below). ![The Apollo 17 spike: DEM profiles through the cell, and the North Massif skyline seen from the EVA-2 pan camera with the photos' skyline points](../figures/dem_spikes_apollo17.png) *Left: SLDEM2015 heights along the north-south and west-east lines through the cell, raw (orange) and despiked (blue): the cell is a 365 m post on a smooth 23° slope. Right: Moonat's skyline from the pan camera (LM + 19 m, eye 1.5 m, 0.1° steps), raw and despiked, with the skyline points of AS17-137-20870 and 20871 (camera fitted on the despiked horizon, as in [real_photos.md](real_photos.md)). The photos follow the despiked line. Between 301.5° and 303.3° Moonat's line is set by DEM ground 0.3 km from the camera, where 0.2° is 1 m of height; it hides the far notch the photo shows (a near-field limit of the DEM, terrain.md §7, not a spike).* **Real relief.** The three windows below hold some of the steepest relief near the catalog sites: Hadley Delta (13.6° high in the Apollo 15 horizon, 10.4 km away), Mons Hadley and Hadley Rille; the Taurus-Littrow massifs (North Massif 14.2° at 6.4 km, South Massif, Family Mountain, Sculptured Hills); and the rim and inner wall of Shackleton in LOLA 20 m. | Window, 30 km around the site | Product, T | Cells | Steeper than 20° | Above T | **Replaced** | Left whole | Kept by the MAD test | Horizon (C3) | Patch (C4) | |---|---|---|---|---|---|---|---|---|---| | Apollo 15: Hadley Delta, Mons Hadley, Hadley Rille | SLDEM2015, 124 m | 897 882 | 213 912 | 1 | **0** | 1 (a trench, §6) | 0 | identical | identical | | Apollo 17: North, South and East Massifs, Family Mountain, Sculptured Hills | SLDEM2015, 124 m | 858 889 | 142 201 | 1 | **1** (the spike) | 0 | 0 | 3 samples at 316.25–316.75° only | 4 nodes next to the spike only | | Shackleton rim (the catalog point on the connecting ridge, Gläser CR1 spot 1) | LOLA 20 m, 42 m | 7 069 306 | 1 328 945 | 48 | **32** | 0 | 16 | identical | 4 nodes, at most 30.8 m | ![The near-field windows of Apollo 15, Apollo 17 and the Shackleton rim, with the replaced and the left cells, and the distribution of |d|/T](../figures/dem_spikes_relief.png) *Top: hillshade of each 30 km window, replaced cells (red circles), candidates left whole by the guard (blue squares). Bottom: the distribution of |h − median of the 8 neighbours| / T over every cell (log scale). Real relief, steep massif walls included, stays far below T (red line); the dashed line is where a cone with 45° flanks would sit.* - **Apollo 15:** nothing is replaced. Apart from the cells of one trench (§6; up to 1.2 T, left whole), the largest value in the window is a pit cell in the Apennine highlands 24 km east-south-east (0.66 T: 82 m, in rough ground); every other cell, Hadley Delta, Mons Hadley and the rille walls included, stays within 0.37 T of its neighbours' median. - **Apollo 17:** the spike is the only cell above T among 0.86 million; the next largest is at 0.35 T (43 m). The steepest massif walls (99.99 % of slopes below 35°) are far from the threshold. - **Shackleton rim:** 32 of 7.07 million cells are replaced, 16 spikes and 16 pits, 42–77 m from their neighbours' median, 3.2–29.9 km from the site. None is on Shackleton's rim crest (rim radius about 10.5 km; the nearest replaced cells are 12.5 km from the crater centre, on the outer flank). Two are on its inner wall, 4.8 and 5.8 km from the centre: one cell 42 m below and one 50 m above a smooth 33–34° wall, a 20 m pit and a 20 m post that no real slope makes. Another 16 cells exceed T but sit in rough ground (their neighbours spread by more than |d|/6), so the outlier test keeps them. The horizon from the site, which sees the rim and the walls, is identical before and after, and so are the Gläser horizons (§5). ## 4. Scan of every catalog site `scripts/data/scan_dem_spikes.py` loads each site's layers exactly as `build_terrain.py` does (near SLDEM2015 or LOLA polar 20/30/60 m to 30 km, or 17.5 km for the sites placed by `search_polar_sites.py`; mid LDEM_64 to 150 km or LOLA 240 m to 450 km; far LDEM_16), raw and despiked, and counts the cells in the band where each layer is used for that site. "Needles" are replaced cells whose removal moves the horizon at their own azimuth by more than 0.01°. Horizons are the C3 files (eye 2 m, 0.25° steps); patches are the C4 grids (±12 km, 385 × 385 nodes). **Whole-file layers:** LOLA LDEM_16 (16.6 million cells, T = 3962 m) and LOLA LDEM_75S_240M (14.5 million cells, T = 502 m): no cell changed, none left by the guard. **LDEM_64 windows** (mid band of 26 sites): none changed; the guard left one blob (Blue Ghost 1, below). **LOLA 30 m and 60 m** (IM-1, Chandrayaan-3): none. | Site | Near DEM | Replaced: near / mid / far | Left whole | Needles | Horizon: max change (azimuth) | Patch: max change (nodes > 0.5 m) | |---|---|---|---|---|---|---| | apollo11 | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | shackleton_rim | LOLA 20 m | 32 / 0 / 0 | | | 0 (identical) | 30.83 m (4) | | apollo12 | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | apollo14 | SLDEM2015 | 1 / 0 / 0 | | | 0 (identical) | 0 | | apollo15 | SLDEM2015 | 0 / 0 / 0 | 1 | | 0 (identical) | 0 | | apollo16 | SLDEM2015 | 5 / 0 / 0 | | | 0 (identical) | 105.26 m (4) | | apollo17 | SLDEM2015 | 1 / 0 / 0 | | 1 | **1.61° (316.5°)** | 154.15 m (4) | | change4 | SLDEM2015 | 2 / 0 / 0 | | | 0 (identical) | 76.89 m (1) | | chandrayaan3 | LOLA 60 m | 0 / 0 / 0 | | | 0 (identical) | 0 | | im1 | LOLA 30 m | 0 / 0 / 0 | | | 0 (identical) | 0 | | malapert_massif | LOLA 20 m | 85 / 0 / 0 | 2 | | 0 (identical) | 26.33 m (8) | | degerlache_rim | LOLA 20 m | 12 / 0 / 0 | | | 0 (identical) | 2.79 m (2) | | south_pole | LOLA 20 m | 26 / 0 / 0 | | | 0 (identical) | 21.66 m (3) | | luna9 | SLDEM2015 | 2 / 0 / 0 | | | 0 (identical) | 69.31 m (4) | | luna13, luna16, luna17, luna20, luna21, luna24 | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | surveyor1, surveyor3, surveyor5, surveyor6 | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | surveyor7 | SLDEM2015 | 3 / 0 / 0 | | | 0 (identical) | 0 | | change3, change5, change6 | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | slim | SLDEM2015 | 1 / 0 / 0 | | | 0 (identical) | 0 | | blueghost1 | SLDEM2015 | 0 / 0 / 0 | 2 (LDEM_64) | | 0 (identical) | 0 | | im2 | LOLA 20 m | 75 / 0 / 0 | 5 | 2 | **0.08° (4.75°)** | 55.35 m (8) | | beresheet | SLDEM2015 | 0 / 0 / 0 | | | 0 (identical) | 0 | | art_cabeusb | LOLA 20 m | 2 / 0 / 0 | | | 0 (identical) | 1.11 m (1) | | art_haworth | LOLA 20 m | 51 / 0 / 0 | | | 0 (identical) | 59.43 m (12) | | art_malapert | LOLA 20 m | 36 / 0 / 0 | | | 0 (identical) | 65.86 m (11) | | art_mouton_plateau | LOLA 20 m | 35 / 0 / 0 | 5 | | 0 (identical) | 37.66 m (10) | | art_mouton | LOLA 20 m | 9 / 0 / 0 | | | 0 (identical) | 25.0 m (2) | | art_nobile1 | LOLA 20 m | 7 / 0 / 0 | | | 0 (identical) | 28.4 m (2) | | art_nobile2 | LOLA 20 m | 3 / 0 / 0 | | | 0 (identical) | 0.0005 m (0) | | art_degerlache2 | LOLA 20 m | 10 / 0 / 0 | | | 0 (identical) | 29.69 m (4) | | art_slater | LOLA 20 m | 19 / 0 / 0 | | | 0 (identical) | 27.22 m (10) | | starhab | LOLA 20 m | 92 / 0 / 0 | 1 | | 0 (identical) | 8.96 m (1) | (Counts are per site and the polar windows overlap: Malapert Massif, StarHab and the Artemis Malapert point share most of their cells, as do the Shackleton rim, the south pole and the de Gerlache points.) **Unique cells** (the polar windows overlap): SLDEM2015 15 cells replaced (10 spikes, 5 pits; |d| 132–493 m, i.e. 2.2–8.3 cells), 1 left; LOLA LDEM_80S_20M 309 cells replaced (154 spikes, 155 pits; |d| 42–77 m, 2.1–3.9 cells), 7 left; LDEM_64 2 candidates left (one blob). The full list, with place, heights, distance and azimuth from each site and the horizon change at each cell's azimuth, is in `docs/validation/dem_spikes.json`. **The 15 SLDEM2015 cells:** | Near site | Cell | Height | d | d / cell | From the site | Effect on the horizon | |---|---|---|---|---|---|---| | apollo14 | 4.5986°S, 17.5400°W | −1301 m | +135 m | +2.27 | 29.0 km, az 184.1° | none (−0.95° vs +2.38°) | | apollo16 | 8.7490°S, 15.4385°E | 347 m | +279 m | +4.71 | 7.0 km, az 344.8° | none (+2.59° vs +4.12°) | | apollo16 | 8.8408°S, 15.9307°E | 426 m | +143 m | +2.41 | 13.5 km, az 72.8° | none (+1.52° vs +1.58°) | | apollo16 | 8.8935°S, 16.1982°E | 783 m | +324 m | +5.47 | 21.1 km, az 83.5° | none in the C3 file, whose rays (one sample per cell) stepped past its top; a ray straight over it sees it 0.39° above the skyline (+1.74° vs +1.33°) | | apollo16 | 9.1982°S, 16.1924°E | 153 m | −180 m | −3.04 | 21.8 km, az 108.3° | none (a pit) | | apollo16 | 9.8896°S, 15.8291°E | 84 m | −330 m | −5.57 | 29.5 km, az 160.5° | none (a pit) | | **apollo17** | **20.4170°N, 30.5420°E** | **−1529 m** | **+365 m** | **+6.16** | **9.5 km, az 316.4°** | **needle 1.61°** | | change4 | 44.8037°S, 177.7432°E | −6153 m | −218 m | −3.68 | 20.1 km, az 9.6° | none (a pit) | | change4 | 45.3701°S, 178.0869°E | −6066 m | −146 m | −2.46 | 10.9 km, az 76.4° | none (a pit) | | luna9 | 7.3701°N, 64.5186°W | −1404 m | +200 m | +3.37 | 9.9 km, az 333.1° | none (−0.53° vs +8.41°) | | luna9 | 6.4131°N, 64.4600°W | −1497 m | +147 m | +2.48 | 20.4 km, az 187.6° | none (−0.78° vs +4.38°) | | surveyor7 | 40.1162°S, 11.8037°W | −1360 m | +160 m | +2.70 | 27.0 km, az 345.6° | none (−3.48° vs +3.77°) | | surveyor7 | 40.8467°S, 12.3818°W | 544 m | +204 m | +3.44 | 20.3 km, az 281.2° | none (+1.00° vs +5.39°) | | surveyor7 | 41.4990°S, 11.7471°W | 546 m | −132 m | −2.24 | 16.6 km, az 198.6° | none (a pit) | | slim | 12.5635°S, 25.5654°E | −2144 m | **+493 m** | +8.32 | 24.6 km, az 22.2° | none (−3.27° vs +7.24°) | (Elevations in brackets: the cell's top seen from the eye vs the raw horizon at its azimuth.) Inside the ±12 km patches, the cells near Apollo 16 (7.0 km), Luna 9 (9.9 km) and Chang'e 4 (10.9 km, a pit) stood as posts or a pit of 105 m, 69 m and 77 m at the nearest patch nodes. **Needles:** only two sites' horizons change by more than 0.01° anywhere: - **Apollo 17:** the spike above, 1.61° at azimuth 316.5° (3 samples). - **IM-2** (Mons Mouton plateau, LOLA 20 m): two cells 14.2 and 14.3 km north (azimuth 4.4° and 4.75°), 51.5 and 52 m above their neighbours, on the skyline; the horizon at 4.75° drops by 0.08° (−0.455° → −0.535°). They belong to a row of single-cell spikes 180–600 m apart along one line, which looks like one LOLA track with bad shots. Every other horizon is unchanged to the file's 0.0001° precision. The 309 LOLA 20 m cells sit below the skylines of their sites, and half of them are pits, which cannot raise a horizon. The site's own ground height (`ground_elev_m`) is unchanged everywhere. **Patches:** 18 patches change (a replaced cell inside ±12 km), by 1.1 m to 154 m at 1 to 12 nodes each (table); a 19th (art_nobile2) by 0.0005 m at one node, whose bilinear sample gives a replaced cell a weight of about 1e-5. ## 5. Rebuilt files and re-checks `uv run python scripts/data/build_terrain.py` (all sites, idempotent) was re-run with the filter. Before that, the same pipeline with `despike=False` reproduced the committed files byte for byte (apollo11, apollo17, beresheet, starhab, shackleton_rim, art_malapert), so every change below comes from the filter: - **Horizons (C3):** `apollo17.json`, three samples: 316.25° 5.03° → 4.30°, 316.5° 5.94° → 4.33°, 316.75° 4.68° → 4.44°. `im2.json`, one sample: 4.75° −0.455° → −0.535°. The other 40 files are byte-identical. - **Patches (C4):** 19 `.bin` files (the table in §4); their JSON metadata, `z_min_m` and `z_max_m` included, is unchanged. - **C5 tiles:** unchanged (no cell of LDEM_16 or LOLA 240 m is replaced). - `docs/validation/terrain_sites.json`: Apollo 17 mean 6.546° → 6.544°; Beresheet and StarHab rows added (they had been built one at a time). `docs/figures/horizon_apollo17.png` redrawn (the other key figures are byte-identical). - The terrain-everywhere comparison of live Moon Trek horizons with C3 ([terrain-everywhere.md](terrain-everywhere.md) §2) gave Apollo 17 a maximum error of 1.53°; that matches this needle (C3 was 1.61° too high there), and Moon Trek's LOLA-only grid does not have the cell, which is independent evidence that it is an SLDEM2015 artefact. Not re-run (it needs Moon Trek). ### Apollo 17 photos `uv run python scripts/validate_real_photos.py` was re-run in full. Its horizon cache key now includes the DEM cleaning version (`hz_____despike-1.json`), so every horizon was recomputed. | Frame (EVA-2 LM pan) | First run (raw SLDEM2015) | Now | |---|---|---| | AS17-137-20870, (Old) Family Mountain to the North Massif | RMS 0.133°, 2 points off by more than 1.5°, 95 % within 0.086° | **RMS 0.038°**, none, 95 % within 0.064° | | AS17-137-20871, North Massif | RMS 0.129°, 2 points off by more than 1.5°, 95 % within 0.078° | **RMS 0.037°**, none, 95 % within 0.054° | - The fitted cameras are the same (heading, pitch, roll to 0.001°): the trimmed fit had already ignored the needle. - The pan now has **16 frames at 0.017–0.06° RMS** (14 before); the other two are the up-Sun lens flare (20877) and a frame-edge point (20882), as before. - Everything else in `real_photos.json` is identical (the Station 2 horizon of the Earth frames is identical: the cell, 9.7 km north of Station 2, is hidden from there), except the focal length that the pan calibrates: the 16 clean frames give **61.43 mm** (14 frames gave 61.48 mm). With it, the Earth over the South Massif is +0.096°, +0.036°, +0.038° in elevation (was +0.084°, +0.021°, +0.023°); with the data sheet's 61.1 mm it is unchanged (+0.19°, +0.13°, +0.13°). [real_photos.md](real_photos.md) is updated. - Redrawn: `real_vs_moonat_AS17_LM_pan_360.png` and `real_vs_moonat_AS17-137-20870.png`; the other photo figures are byte-identical. ### Gläser et al. 2014 (connecting ridge) and Bussey et al. 2010 (Malapert) - **Gläser (`scripts/data/validate_illumination.py`, 18.5 years at 2 h steps):** `terrain_illumination.json` is identical: connecting-ridge spot 1 (eye 2 m) 86.0 % average illumination and 90.6 % of the time lit (published 88.1 % / 92 %), spot 3 (eye 10 m) 92.7 % / 95.8 % (published 92.5 % / 95.6 %), the old catalog point 71.8 %. The horizons at both spots, with and without the 100 m cutoff, are identical element by element before and after: no replaced cell is on their skylines. - **Bussey (`scripts/data/search_polar_sites.py --final`):** `polar_sites.json` is identical; the Artemis Malapert point keeps 75.9 % mean Sun visibility over 2027 (Bussey et al. 2010: 74 % at their point M1, 2.5 km away), and the other nine polar sites keep their C3 values. ## 6. What the filter leaves alone - **Larger features (the isolation guard leaves them whole):** - **Apollo 15:** a trench one or two cells wide and 4–5 cells long (about 60–120 m by 250 m) on the plain 1.3 km west of the LM, about 1 km east of Hadley Rille's rim, down to about 150 m below its surroundings. At that width it is probably an artefact too, but it is not isolated. It is a pit, 5.6° below the skyline, so it does not touch the horizon; it does show as a narrow slot in the Apollo 15 patch. A 5 × 5 median would remove it, but would also reach real narrow features. - **Blue Ghost 1:** a blob of 5 LDEM_64 cells, 0.9–1.2 km above the floor of Mare Crisium, 92 km west-north-west of the site (19.78°N, 58.86°E); LDEM_16 is flat there, so it is an artefact. It sits 1.5° below Blue Ghost 1's skyline (no effect) and no other site uses that part of LDEM_64. - **LOLA 20 m:** 7 cells in small clusters near Malapert, Mons Mouton and IM-2, 47–67 m from their neighbours' median; none sets a horizon (the closest is 0.03° below IM-2's skyline, 13.9 km away). - **Below the threshold:** single SLDEM2015 cells 70–124 m off their neighbours are kept, for example three cells of 102–112 m on the flat mare 16–27 km from Apollo 12 (d/cell 1.7–1.9). The 45° run of §7 removes them and no Apollo 12 horizon changes. - **Linear artefacts:** a straight trench two cells wide and about 160 m deep runs north-south 15 km south of Chang'e 5 in SLDEM2015; its cells stay below T, so it is not touched. It is a pit outside the ±12 km patch. - **Kept by the outlier test:** at the polar sites, cells above T in rough ground (16 in the Shackleton window). ## 7. Sensitivity: what looser settings would change The scan also ran two looser settings on every site (`sensitivity` in `dem_spikes.json`). Cells are counted over the whole near windows (corners beyond the near band included) and summed over the sites, so overlapping polar windows count a cell more than once. | Setting | Cells changed: SLDEM2015 / LOLA 20 m / LOLA 30 and 60 m | Horizons changed by more than 0.01° | |---|---|---| | **This filter:** 60° cone (T = 2.09 cells), K_MAD 6 | 22 / 604 / 0 | Apollo 17 1.61°, IM-2 0.08° | | 60° cone, K_MAD 4 | 23 / 760 / 1 | the same two | | 45° cone (T = 1.21 cells), K_MAD 6 | 43 / 1723 / 9 | Apollo 17 1.61°, Chang'e 6 0.10°, Artemis Slater 0.08°, Artemis Malapert 0.04° | A lower shape threshold nearly triples the LOLA 20 m changes and moves three more skylines by 0.04–0.10°, all through cells 71–124 m (SLDEM2015) or 24–42 m (LOLA 20 m) off their neighbours. Those cells are probably artefacts too, but at 45° a real, very steep cone would also qualify, so this filter stays at 60°. (With 45° the two IM-2 needles stay: more of their neighbours then count as part of the same anomaly, and the guard leaves the cluster whole.) The values 60° and K_MAD = 6 are a choice, not a derived result. ## 8. Known gaps - **The browser's live terrain for custom points** (C9 `terrainAt`, Moon Trek grids) does not run this filter. Its 118 m layer is LOLA only (no SLDEM2015, so no Apollo 17 spike), but its polar 20 m layer is a LOLA 20 m DEM like ours, so it probably holds the same 20 m artefacts; they move no catalog horizon, but can show in a custom point's 3-D patch. A port of `moonat.terrain.despike` to `web/js/terrain/` would close this (the web app is outside this change). - **Multi-cell artefacts** (§6) and **sub-threshold spikes** are left on purpose. - **Ray sampling:** the C3 rays take one sample per DEM cell, so a one-cell feature can fall between samples (the Apollo 16 cell in §4). With the spikes gone this matters only for real terrain, which is smooth at the scale of a cell. - **Not re-run:** the Moon Trek comparison of terrain-everywhere.md (needs the network), and the polar site search of `search_polar_sites.py` (its windows are now despiked too; only its final C3 check was re-run, identical). - **Cost:** the filter adds about 0.3 s per SLDEM2015 window, 1.6 s per LOLA 20 m window (9 million cells) and 3.5 s once for LDEM_16 when a process first loads it. ## 9. Second pass: compact pits and spikes (`despike-2`, 2026-11-18) The view's audit of steep patch cells (39 cells steeper than 45° in 9 patches) found the multi-cell artefacts this filter leaves whole: the Apollo 15 trench of §6 and LOLA 20 m pits and spikes 60–90 m deep or high and 40–130 m across. A second pass (`moonat.terrain.despike.find_compact`, run after this one by `clean`, VERSION `despike-2`) replaces a compact feature (inside a ring of at most 5 cells) deeper than 0.35 of its diameter by the ring's median. It changes one horizon (IM-2, 0.056° at az 5°), 17 patches and 18 far-ring files; North Ray and South Ray (real, the other 11 cells) are untouched; elongated track troughs stay, as the linear features of §6. Definition, numbers and figures: [view_leftovers.md](view_leftovers.md) §4.