qgis-tem-loader

qgis plugin for loading TEM geophysical inversion XYZ files as 3D objects
git clone git://src.adamsgaard.dk/qgis-tem-loader # fast
git clone https://src.adamsgaard.dk/qgis-tem-loader.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit f145156c365a6cb10397150ba2859752e75374d4
parent 97a85f59afdd58c8fdf3a94ebea8f14324c47ce6
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 15 May 2026 22:47:15 +0200

feat(parser): accept DOI masking options

Diffstat:
Mtem_loader/core.py | 14+++++++++++++-
Mtest/test_core.py | 21+++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/tem_loader/core.py b/tem_loader/core.py @@ -49,6 +49,16 @@ ABOVE_DOI_OPACITY = 100 BELOW_DOI_OPACITY = 10 +def validate_opacity(value): + try: + opacity = int(value) + except (TypeError, ValueError): + raise ValueError('opacity must be between 0 and 100') from None + if opacity < 0 or opacity > 100: + raise ValueError('opacity must be between 0 and 100') + return opacity + + def layer_opacity(depth_mid, doi): if doi is None: return ABOVE_DOI_OPACITY @@ -176,7 +186,9 @@ def count_valid_layers(row, res_cols, thick_cols): return count -def process_xyz(path): +def process_xyz(path, mask_below_doi=True, below_doi_opacity=BELOW_DOI_OPACITY): + validate_opacity(below_doi_opacity) + points = [] doi_points = [] layers = [] diff --git a/test/test_core.py b/test/test_core.py @@ -174,6 +174,27 @@ class ProcessXYZTests(unittest.TestCase): self.assertEqual(ABOVE_DOI_OPACITY, 100) self.assertEqual(BELOW_DOI_OPACITY, 10) + def test_process_xyz_accepts_default_masking_options(self): + path = FIXTURE_DIR / "profiler_temimager_4_0_4_6.xyz" + _, _, default_layers = process_xyz(path) + _, _, option_layers = process_xyz( + path, + mask_below_doi=True, + below_doi_opacity=BELOW_DOI_OPACITY, + ) + + self.assertEqual(len(option_layers), len(default_layers)) + self.assertEqual( + [row["Opacity"] for row in option_layers], + [row["Opacity"] for row in default_layers], + ) + + def test_process_xyz_rejects_invalid_below_doi_opacity(self): + path = FIXTURE_DIR / "profiler_temimager_4_0_4_6.xyz" + + with self.assertRaisesRegex(ValueError, "opacity must be between 0 and 100"): + process_xyz(path, below_doi_opacity=101) + 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)