commit 9e3241ac3615a3d7c84301ce1e9c25636907f133
parent 6008a24d70e72128a989445aadd729c1556636e8
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 15 May 2026 18:04:59 +0200
test(core): add tests for layer_opacity helper and SCI no-DOI fallback
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/test/test_core.py b/test/test_core.py
@@ -9,7 +9,10 @@ from unittest.mock import Mock, patch
import xml.etree.ElementTree as ET
from tem_loader.core import (
+ ABOVE_DOI_OPACITY,
+ BELOW_DOI_OPACITY,
detect_source_epsg,
+ layer_opacity,
process_xyz,
resistivity_color,
write_csv,
@@ -167,6 +170,51 @@ class ProcessXYZTests(unittest.TestCase):
self.assertAlmostEqual(layers[0]["Resistivity"], 0.2732)
self.assertEqual(layers[0]["Color"], resistivity_color(0.2732))
+ def test_opacity_constants(self):
+ self.assertEqual(ABOVE_DOI_OPACITY, 100)
+ self.assertEqual(BELOW_DOI_OPACITY, 10)
+
+ def test_layer_opacity_returns_above_when_doi_is_none(self):
+ self.assertEqual(layer_opacity(50.0, None), ABOVE_DOI_OPACITY)
+ self.assertEqual(layer_opacity(0.0, None), ABOVE_DOI_OPACITY)
+ self.assertEqual(layer_opacity(999.0, None), ABOVE_DOI_OPACITY)
+
+ def test_layer_opacity_returns_above_when_depth_at_doi(self):
+ self.assertEqual(layer_opacity(10.0, 10.0), ABOVE_DOI_OPACITY)
+ self.assertEqual(layer_opacity(0.0, 50.0), ABOVE_DOI_OPACITY)
+
+ def test_layer_opacity_returns_below_when_depth_exceeds_doi(self):
+ self.assertEqual(layer_opacity(11.0, 10.0), BELOW_DOI_OPACITY)
+ self.assertEqual(layer_opacity(200.0, 50.0), BELOW_DOI_OPACITY)
+
+ def test_fixture_layers_have_correct_opacity(self):
+ # TEMImage fixture has DOI, so opacity depends on depth vs DOI.
+ # Each sounding has its own DOI; we verify the first sounding's layers.
+ path = FIXTURE_DIR / "profiler_temimager_4_0_4_6.xyz"
+ points, doi_points, layers = process_xyz(path)
+ self.assertTrue(all("Opacity" in row for row in layers))
+ # Every layer's opacity is one of the two valid values
+ self.assertTrue(
+ all(row["Opacity"] in (ABOVE_DOI_OPACITY, BELOW_DOI_OPACITY) for row in layers)
+ )
+ # The first sounding's DOI and layer count
+ first_doi = doi_points[0]["DOI"]
+ first_n = points[0]["NumLayers"]
+ first_layers = layers[:first_n]
+ for layer in first_layers:
+ expected = ABOVE_DOI_OPACITY if layer["DepthBottom"] <= first_doi else BELOW_DOI_OPACITY
+ self.assertEqual(
+ layer["Opacity"],
+ expected,
+ f"Layer {layer['Layer']} depth {layer['DepthBottom']} vs DOI {first_doi}",
+ )
+
+ def test_sci_fixture_layers_all_above_opacity(self):
+ # SCI format has no DOI, so all layers get ABOVE_DOI_OPACITY
+ path = FIXTURE_DIR / "sci_workbench_2026_1.xyz"
+ _, _, layers = process_xyz(path)
+ self.assertTrue(all(row["Opacity"] == ABOVE_DOI_OPACITY for row in layers))
+
def test_resistivity_color_buckets(self):
self.assertEqual(resistivity_color(-5), "#000091")
self.assertEqual(resistivity_color(0.5), "#000091")