|
33 | 33 | } |
34 | 34 |
|
35 | 35 | _SOURCE_DEPTH_FIELDS: Tuple[str, ...] = ( |
| 36 | + # Likely-first: true source depth when present |
36 | 37 | "SourceDepth", |
37 | | - "SourceWaterDepth", |
| 38 | + # Next prefer datum elevation over water depth; surface elevation after |
38 | 39 | "SourceDatumElevation", |
39 | 40 | "SourceSurfaceElevation", |
| 41 | + # Least likely candidate |
| 42 | + "SourceWaterDepth", |
40 | 43 | ) |
41 | 44 |
|
42 | 45 | _RECEIVER_DEPTH_FIELDS: Tuple[str, ...] = ( |
43 | | - "GroupWaterDepth", |
| 46 | + # Prefer receiver group elevation first |
44 | 47 | "RecGroupElevation", |
45 | 48 | "RecDatumElevation", |
| 49 | + # Least likely candidate |
| 50 | + "GroupWaterDepth", |
46 | 51 | ) |
47 | 52 |
|
48 | 53 | _DEPTH_SENTINELS = {0, 2147483647, -2147483648, 32767, -32768} |
@@ -151,6 +156,15 @@ def get_header( |
151 | 156 |
|
152 | 157 |
|
153 | 158 | def _depth_score(values: Iterable[float]) -> Tuple[int, float]: |
| 159 | + """ |
| 160 | + Compute a simple quality score for a sequence of depth-like values. |
| 161 | +
|
| 162 | + The score returns a tuple of ``(count, span)`` where ``count`` is the |
| 163 | + number of non-sentinel entries and ``span`` is the range of the data. This |
| 164 | + is retained for backwards compatibility but is no longer used to choose the |
| 165 | + preferred header field. Header selection now follows a fixed priority order |
| 166 | + and simply checks for the presence of valid (non-zero, non-sentinel) data. |
| 167 | + """ |
154 | 168 | cleaned: List[float] = [] |
155 | 169 | for val in values: |
156 | 170 | fval = float(val) |
@@ -227,21 +241,27 @@ def detect_depth_keys( |
227 | 241 | if not headers: |
228 | 242 | return source_key, receiver_key |
229 | 243 |
|
230 | | - best_source_score = (0, 0.0) |
| 244 | + def _has_valid(values: Iterable[float]) -> bool: |
| 245 | + """Return True when any non-sentinel, non-zero value is present.""" |
| 246 | + for v in values: |
| 247 | + fval = float(v) |
| 248 | + if fval in _DEPTH_SENTINELS: |
| 249 | + continue |
| 250 | + if fval != 0.0: |
| 251 | + return True |
| 252 | + return False |
| 253 | + |
231 | 254 | for candidate in _SOURCE_DEPTH_FIELDS: |
232 | 255 | vals = get_header(headers, candidate) |
233 | | - score = _depth_score(vals) |
234 | | - if score > best_source_score: |
235 | | - best_source_score = score |
| 256 | + if _has_valid(vals): |
236 | 257 | source_key = candidate |
| 258 | + break |
237 | 259 |
|
238 | | - best_receiver_score = (0, 0.0) |
239 | 260 | for candidate in _RECEIVER_DEPTH_FIELDS: |
240 | 261 | vals = get_header(headers, candidate) |
241 | | - score = _depth_score(vals) |
242 | | - if score > best_receiver_score: |
243 | | - best_receiver_score = score |
| 262 | + if _has_valid(vals): |
244 | 263 | receiver_key = candidate |
| 264 | + break |
245 | 265 |
|
246 | 266 | return source_key, receiver_key |
247 | 267 |
|
|
0 commit comments