ccsds_ndm.kvn_tokenizer
KVN tokenizer: convert raw KVN text into a list of classified line objects.
- This module provides:
KvnLineand its subclasses for representing each line formattokenize()to convert raw KVN source intoKvnLineobjects
Functions
|
Convert a raw KVN string into an ordered list of |
Classes
A whitespace-only (or completely empty) line. |
|
|
A |
|
A space-separated row of plain numbers inside a covariance block. |
|
A standard |
|
Abstract base class for a single tokenised KVN line. |
|
A space-separated data row whose first token is an epoch. |
|
A block-delimiter keyword. |
|
A TDM observation line: |
- class CommentLine(text='')[source]
A
COMMENTline.The comment text is stored in
textwith leading/trailing whitespace stripped. Both the plain (COMMENT text) and equals (COMMENT = text) variants are normalised to plain on construction;to_stralways writes the plain form.- Parameters:
text (str)
- class CovarianceRowLine(tokens=<factory>)[source]
A space-separated row of plain numbers inside a covariance block.
OEM covariance matrix rows contain only numeric tokens with no epoch and no key. Each row represents one row of the lower-triangular matrix:
v11,v21 v22,v31 v32 v33, …- tokens
The numeric tokens on this row.
- Type:
list[str]
- class KvLine(key='', value='', unit='')[source]
A standard
KEY = value [unit]line.
- class KvnLine[source]
Abstract base class for a single tokenised KVN line.
Subclasses represent each distinct line format found in KVN files. Every subclass implements
to_str()to render itself back to a canonical KVN string, making round-trip writing straightforward: build a list ofKvnLineinstances, callto_str()on each, and join with newlines.- abstractmethod to_str(**kwargs)[source]
Render this line to a KVN string (no trailing newline).
Subclasses accept keyword arguments relevant to their own format. Unknown kwargs are silently ignored, so callers can pass a common set (e.g.
key_width=24) to all line types without special-casing.- Return type:
- class PackedDataLine(epoch='', tokens=<factory>)[source]
A space-separated data row whose first token is an epoch.
Used for OEM state vectors and AEM attitude states, where an entire record is encoded on a single line with no explicit keys:
EPOCH x y z x_dot y_dot z_dot- tokens
All whitespace-separated tokens on the line (epoch + numeric values).
- Type:
list[str]
- class SectionMarkerLine(key='')[source]
A block-delimiter keyword.
Examples:
META_START,META_STOP,DATA_START,DATA_STOP,COVARIANCE_START,COVARIANCE_STOP.- Parameters:
key (str)
- class TdmObsLine(key='', epoch='', value='', unit='')[source]
A TDM observation line:
KEY = EPOCH value.TDM data lines carry an epoch and a numeric value in the value field, separated by whitespace, rather than a single scalar.
- tokenize(kvn_source)[source]
Convert a raw KVN string into an ordered list of
KvnLineobjects.Each input line is classified and parsed into the appropriate subclass. The rules applied in order are:
Strip surrounding whitespace. Empty result →
BlankLine.Line is in
_SECTION_MARKERS→SectionMarkerLine.Line starts with
"COMMENT"→CommentLine. A leading"="after"COMMENT"is stripped (handles theCOMMENT = textvariant).Line contains
"=":Split on the first
"="into key and rest.Extract a trailing
[unit]from rest if present.Split remaining rest on whitespace. Two tokens where the first looks like an epoch →
TdmObsLine. Otherwise →KvLine.
No
"="— split on whitespace:First token looks like an epoch →
PackedDataLine.Otherwise →
CovarianceRowLine.
Blank lines that appear before the first
CCSDS_header line are dropped so that files with a leading blank or BOM are handled cleanly.