ccsds_ndm.kvn_parser
KVN parser: type identification, document dispatch, and block location.
- Phase 1 implements:
identify_ndm_type— scan tokenised lines forCCSDS_*_VERSdispatch_document— split lines into header + Segment list(flat / segmented / CDM structural variants)
locate_blocks— given a list of KvLine objects and a targetdataclass, return the keyword-boundary spans for every instance of that class (DEFAULT locator only — no packed/covariance yet)
Functions
|
Split a tokenised KVN line list into a |
|
Scan tokenised KVN lines and return the matching |
|
Locate every instance of |
|
Locate every covariance matrix instance in lines. |
|
Locate every |
|
Locate every instance of |
|
Locate every |
|
Locate every |
Classes
|
A located sub-block within a list of KvnLines. |
|
Bucket indices for CDM document structure. |
|
Top-level representation of a dispatched KVN file. |
|
State machine states for document-level dispatch. |
|
One logical NDM segment as extracted by the document dispatcher. |
- class BlockSpan(start, end, lines)[source]
A located sub-block within a list of KvnLines.
- lines
The actual lines within [start, end).
- Type:
list[KvnLine]
- class KvnDocument(ndm_type, header=<factory>, segments=<factory>)[source]
Top-level representation of a dispatched KVN file.
- ndm_type
Enum member identifying the message type and xsdata class.
- Type:
_NdmDataType
- header
Lines that belong to the NDM header (
CCSDS_*_VERS,CREATION_DATE,ORIGINATOR, and top-levelCOMMENTlines).- Type:
list[KvnLine]
- segments
Ordered list of logical segments. One entry for flat types; one per
META_START/STOPblock (plus optional covariance segments) for segmented types.- Type:
list[Segment]
- class Segment(meta=<factory>, data=<factory>, covariance=<factory>)[source]
One logical NDM segment as extracted by the document dispatcher.
For segmented types (OEM, AEM, TDM) each
META_START/STOPblock produces oneSegment; aCOVARIANCE_START/STOPblock also produces aSegmentwith onlycovariancepopulated.For flat types (OPM, OMM, APM, RDM, CDM) there is exactly one
Segmentwith all non-header lines indata.
- dispatch_document(lines)[source]
Split a tokenised KVN line list into a
KvnDocument.Identifies the NDM type from the
CCSDS_*_VERSheader line and then routes to one of three structural variants:Segmented (OEM, AEM, TDM) — state machine over
META_START/STOP,DATA_START/STOP,COVARIANCE_START/STOPmarkers.Flat (OPM, OMM, APM, RDM) — no markers; all lines after the first
CCSDS_*_VERSline form one segment (meta lines are separated from data lines by the locator later).CDM — split on
OBJECT_1/OBJECT_2keyword occurrences;RELATIVE_METADATA_DATAsection handled as separate segment.
- Parameters:
lines (
list[KvnLine]) – Output oftokenize().- Returns:
- Return type:
- identify_ndm_type(lines)[source]
Scan tokenised KVN lines and return the matching
_NdmDataType.Searches for the first
KvLinewhose key starts with"CCSDS_"and delegates to_NdmDataType.find_ndm_type_by_class_id().- Parameters:
lines (
list[KvnLine]) – Output oftokenize().- Returns:
_NdmDataType- Raises:
ValueError – If no
CCSDS_*_VERSline is found.- Return type:
_NdmDataType
- locate_blocks(lines, cls)[source]
Locate every instance of
clswithinlinesusing the default keyword-set strategy (LOC_DEFAULT).The keyword set for
clsis derived from its dataclass field metadata ("name"entries that are ALL_UPPER strings). A new instance ofclsis considered to start whenever the anchor keyword (first declared uppercase field) is encountered, and to end just before the next occurrence of that same anchor keyword (or at end-of-list).This covers every flat
KEY = VALUEcontainer:NdmHeader,OpmMetadata,StateVectorType,ManeuverParametersType,SpacecraftParametersType,KeplerianElementsType, etc.Packed-data, covariance, and TDM-observation types are NOT handled here; they will be covered by their own locators in later phases.
- Parameters:
lines (
list[KvnLine]) – Source lines for one segment bucket (e.g.Segment.datafor flat types, orSegment.metafor metadata-only classes).cls (
type) – The dataclass whose instances are to be located.
- Returns:
list[BlockSpan]– Ordered list of located spans, one per detected instance.- Return type:
- locate_covariance(lines)[source]
Locate every covariance matrix instance in lines.
A covariance instance starts at an
EPOCHkeyword line and spans until the nextEPOCHline or end-of-list. Each instance typically contains theEPOCHline, an optionalCOV_REF_FRAMEline, and 6CovarianceRowLineobjects (21 lower-triangular values total). Used byOemCovarianceMatrixType.
- locate_packed_attitude(lines)[source]
Locate every
PackedDataLinein lines as oneBlockSpaneach.Identical to
locate_packed_state()in structure — each packed line is one attitude state record. Column interpretation (quaternion, Euler, spin, …) is determined later by the parser using segment metadata. Used byAttitudeStateTypein AEM data sections.
- locate_packed_lines(lines, cls)[source]
Locate every instance of
clsin lines using the anchor-keyword strategy, including non-KvLine rows within each span.Like
locate_blocks()but does not clip spans at the last matching keyword — packed text lines (trajectory / attitude / covariance rows stored as plain strings) that follow the KEY=VALUE header are kept inside the span. Used byOcmTrajStateType,OcmCovarianceMatrixType,AcmAttitudeStateType, andAcmCovarianceMatrixType.
- locate_packed_state(lines)[source]
Locate every
PackedDataLinein lines as oneBlockSpaneach.Each packed line represents a single epoch-led state vector record (
EPOCH X Y Z X_DOT Y_DOT Z_DOT [X_DDOT …]). Used byStateVectorAccTypein OEM data sections.