21 lines
1.0 KiB
Python
21 lines
1.0 KiB
Python
"""Builds a test station folder: one day's export of a station with x, y emptied for chosen sensors, images linked.
|
|||
|
|
Usage: python3 -I blank_xy.py <station folder> <YYYYMMDD> <SENSOR,SENSOR> <new folder>"""
|
||
|
|
import csv
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
|
||
|
|
src, day, names, dst = sys.argv[1], sys.argv[2], set(sys.argv[3].split(",")), sys.argv[4]
|
||
|
|
os.makedirs(os.path.join(dst, "displacement"), exist_ok=True)
|
||
|
|
name = next(f for f in os.listdir(os.path.join(src, "displacement")) if day in f)
|
||
|
|
with open(os.path.join(src, "displacement", name), newline="") as f:
|
||
|
|
rows = list(csv.DictReader(f))
|
||
|
|
for r in rows:
|
||
|
|
if r["sensor_name"] in names:
|
||
|
|
r["x"] = r["y"] = ""
|
||
|
|
with open(os.path.join(dst, "displacement", name), "w", newline="") as f:
|
||
|
|
w = csv.DictWriter(f, fieldnames=list(rows[0]))
|
||
|
|
w.writeheader()
|
||
|
|
w.writerows(rows)
|
||
|
|
if not os.path.exists(os.path.join(dst, "images")):
|
||
|
|
os.symlink(os.path.abspath(os.path.join(src, "images")), os.path.join(dst, "images"))
|
||
|
|
print(os.path.join(dst, "displacement", name), len(rows), "rows")
|