Skip to content

Commit

Permalink
track_edit - a tool for clipping a track
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuethe committed Jun 18, 2024
1 parent 31ec8c1 commit 3f12cdd
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dist
.pytest_cache
*.egg-info
venv
*~
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rccalibrate = "calibrate:main"
rcdeadtime = "deadtime:main"
rcmultispg = "rcmultispg:main"
rcsanitize = "track_sanititze:main"
rctrkedit = "track_edit:main"
n42www = "n42www:main"
n42convert = "n42convert:main"
n42validate = "n42validate:main"
Expand Down
32 changes: 30 additions & 2 deletions src/rcfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ def _format_datetime(dt: datetime) -> str:


class RcTrack:
"Radiacode Track (.rctrk)"
"Radiacode Track (.rctrk) interface"

def __init__(self) -> None:
def __init__(self, filename: Optional[str] = None) -> None:
self._clear_data()
self._columns = ["DateTime", "Latitude", "Longitude", "Accuracy", "DoseRate", "CountRate", "Comment"]
self.filename = filename
if filename:
self.load_file(filename)

def _clear_data(self) -> None:
"Clear out the header, in preparation for loading"
Expand All @@ -53,6 +56,29 @@ def as_dict(self) -> Dict[str, Any]:
return rv

def from_dict(self, d: Dict[str, Any]) -> bool:
"""
Populate the in-memory representation from a dict:
{
"name": str,
"serialnumber": str,
"comment": str,
"flags": str,
"points": [
{
"datetime": datetime(),
"latitude": float(),
"longitude": float(),
"accuracy": float(),
"doserate": float(),
"countrate": float(),
"comment": str(),
},
...
]
}
"""

if sorted(d.keys()) != ["comment", "flags", "name", "points", "serialnumber"]:
raise ValueError

Expand All @@ -76,6 +102,7 @@ def _format_trackpoint(self, tp: TrackPoint):
return "\t".join([str(x) for x in fz])

def write_file(self, filename: str) -> None:
"Write the in-memory representation to filesystem"
with open(filename, "wt") as ofd:
print("Track: " + "\t".join([self.name, self.serialnumber, self.comment, self.flags]), file=ofd)
# Patch column names in output file.
Expand All @@ -84,6 +111,7 @@ def write_file(self, filename: str) -> None:
print(self._format_trackpoint(p), file=ofd)

def load_file(self, filename: str) -> None:
"Load a track from the filesystem"
with open(filename, "rt") as ifd:
self._clear_data()
nf = len(self._columns)
Expand Down
Loading

0 comments on commit 3f12cdd

Please sign in to comment.