49 lines
2.4 KiB
Python
49 lines
2.4 KiB
Python
"""Provisional, LENZSPITZE only: x / y of the advanced exports as absolute positions in the image, as on the other stations.
|
||||
|
|
|
|||
|
|
On LENZSPITZE, x / y are relative to the reference position of the pattern (medians ~0 px). This script rewrites in place
|
|||
|
|
data/LENZSPITZE/displacement/*.csv:
|
|||
|
|
x = x_pattern + DX + x_csv, y = y_pattern + DY + y_csv, where (x_pattern, y_pattern) is the centre of the pattern in
|
|||
|
|
data/LENZSPITZE/lentzpitze_patterns.json and (DX, DY) the offset between the frame of the JSON and the IRON images;
|
|||
|
|
pattern_type, empty in these exports, is filled from the JSON.
|
|||
|
|
The sensors missing from the JSON (1023, 8019): x / y emptied (position unknown); 8019 gets global_ref (it has reproj_err).
|
|||
|
|
A file whose pattern_type is already filled is left as it is (already converted). Pumping again restores the originals.
|
|||
|
|
|
|||
|
|
Usage: python3 extraction/lenzspitze_absolute.py
|
|||
|
|
"""
|
|||
|
|
import csv
|
|||
|
|
import glob
|
|||
|
|
import json
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
STATION = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data", "LENZSPITZE")
|
|||
|
|
# Measured on 2026-11-04: median (spot − pattern of the JSON) over 9 night images from 17.10 to 03.11, 25 to 34 matched
|
|||
|
|
# targets each, stable within 0.5 px. Includes the constant offset spot − (x, y) already seen on NORDEND (displacement-columns.md).
|
|||
|
|
DX, DY = 330.5, 15.8
|
|||
|
|
TYPE_WITHOUT_PATTERN = {"8019": "global_ref"} # reproj_err and inlier filled: reference of the compensation
|
|||
|
|
|
|||
|
|
patterns = {str(v["sensor_name"]): v for v in json.load(open(os.path.join(STATION, "lentzpitze_patterns.json"))).values()}
|
|||
|
|
|
|||
|
|
for path in sorted(glob.glob(os.path.join(STATION, "displacement", "*.csv"))):
|
|||
|
|
with open(path, newline="") as f:
|
|||
|
|
reader = csv.DictReader(f)
|
|||
|
|
fields, rows = reader.fieldnames, list(reader)
|
|||
|
|
if any(r["pattern_type"] for r in rows):
|
|||
|
|
print(f"{os.path.basename(path)}: already converted")
|
|||
|
|
continue
|
|||
|
|
for r in rows:
|
|||
|
|
s = r["sensor_name"].strip()
|
|||
|
|
m = patterns.get(s)
|
|||
|
|
if m is None:
|
|||
|
|
r["x"] = r["y"] = ""
|
|||
|
|
r["pattern_type"] = TYPE_WITHOUT_PATTERN.get(s, "")
|
|||
|
|
continue
|
|||
|
|
r["pattern_type"] = m["pattern_type"]
|
|||
|
|
if r["x"]:
|
|||
|
|
r["x"] = repr(m["x"] + DX + float(r["x"]))
|
|||
|
|
if r["y"]:
|
|||
|
|
r["y"] = repr(m["y"] + DY + float(r["y"]))
|
|||
|
|
with open(path, "w", newline="") as f:
|
|||
|
|
w = csv.DictWriter(f, fieldnames=fields)
|
|||
|
|
w.writeheader()
|
|||
|
|
w.writerows(rows)
|
|||
|
|
print(f"{os.path.basename(path)}: {len(rows)} rows converted")
|