ccsds_ndm.kvn_handlers
Handler category sentinels and TypeHandler namedtuple for the KVN registry.
Each xsdata type is identified by its class name (str) and mapped to a
TypeHandler namedtuple that classifies its locator, parser, and writer.
Types absent from a schema registry implicitly use DEFAULT_HANDLER.
There is one registry dict per NDM schema version (e.g. ndmxml2.REGISTRY
for ndmxml 2.0). The string class name can be resolved to the actual class
at runtime via the schema’s __init__.py imports.
Handler categories
Locators (locate)
Classify a span of KvnLines as belonging to one instance of a type.
LOC_DEFAULTKeyword-set matching via
get_ccsds_kw_list. A new instance starts when a keyword belonging to this type’s keyword set appears, and ends at the first repetition of that keyword or at a block boundary. Works for every flat KEY = VALUE container (NdmHeader, OpmMetadata, StateVectorType, ManeuverParametersType, SpacecraftParametersType, …).LOC_PACKED_STATEEpoch-led packed lines (
EPOCH X Y Z X_DOT Y_DOT Z_DOT [X_DDOT …]). Each logical record is one text line; a new instance starts on the next non-comment line. Used byStateVectorAccType(OEM data rows).LOC_PACKED_ATTITUDEEpoch-led packed lines whose column count and semantics depend on
ATTITUDE_TYPEfrom the enclosing segment’s metadata. Used byAttitudeStateType(AEM data rows).LOC_COVARIANCEStarts on an
EPOCHkeyword line, followed by an optionalCOV_REF_FRAMEkeyword line, then 6 lower-triangular numeric rows (21 values total). Used byOemCovarianceMatrixType.LOC_TDM_OBSEach observation is
KEY = EPOCH VALUEon one line inside DATA_START / DATA_STOP markers. Used byTrackingDataObservationType.LOC_PACKED_LINESMixed block: KEY=VALUE header fields followed by a packed
list[str](trajLine/attLine/covLine). One instance starts when the anchor keyword (first declared uppercase field) appears; ends before the next occurrence of that same anchor. Used byOcmTrajStateType,OcmCovarianceMatrixType,AcmAttitudeStateType,AcmCovarianceMatrixType.
Parsers (parse)
Convert located KvnLines into an xsdata object.
PARSE_DEFAULTSplits each line into
[keyword, value, unit]and feeds the result tobuild_ndm_objectfromkvn_utils. Sub-containers are handled by recursing through the registry. Works for all KEY = VALUE types.PARSE_PACKED_STATESplits one packed line on whitespace → positional columns for EPOCH, X, Y, Z, X_DOT, Y_DOT, Z_DOT (+ optional X_DDOT, Y_DDOT, Z_DDOT) →
StateVectorAccType.PARSE_PACKED_ATTITUDESplits one packed line on whitespace; derives the column template from
ctx['meta'].attitude_type(andeuler_rot_seqwhere needed), then populates the appropriate sub-object insideAttitudeStateType: one of quaternion_state, quaternion_derivative, quaternion_euler_rate, euler_angle, euler_angle_rate, spin, spin_nutation.PARSE_COVARIANCEReads the EPOCH (and optional COV_REF_FRAME) keyword lines, then the 6 lower-triangular numeric rows →
OemCovarianceMatrixType.PARSE_TDM_OBSSplits the
KEY = EPOCH VALUEline into keyword, epoch, value →TrackingDataObservationType.PARSE_ROTATION_ANGLEThe keyword is NOT fixed — it comes from the
anglediscriminator attribute (X_ANGLE / Y_ANGLE / Z_ANGLE). Reads up to 3 such lines →RotationAngleType.PARSE_ROTATION_RATEAnalogous to
PARSE_ROTATION_ANGLEfor theratediscriminator (X_RATE / Y_RATE / Z_RATE) →RotationRateType.PARSE_PACKED_LINESReads KEY=VALUE header fields via the default parser, then stores each remaining packed text line verbatim into the embedded
list[str]field. Used byOcmTrajStateType,OcmCovarianceMatrixType,AcmAttitudeStateType,AcmCovarianceMatrixType.
Writers (write)
Serialise an xsdata object to a list of KvnLines.
WRITE_DEFAULTIterates dataclass fields in declaration order:
str/int/float/Enumleaf → oneKvnLine(keyword from field metadata"name", value, unit from theunitsattribute on the value object if present).list[str](COMMENT) → oneCommentLineper entry.sub-container → recurse via registry.
Works for all KEY = VALUE containers.
WRITE_PACKED_STATEEmits one line per
StateVectorAccType:EPOCH X Y Z X_DOT Y_DOT Z_DOT [X_DDOT Y_DDOT Z_DDOT].WRITE_PACKED_ATTITUDEEmits one line per
AttitudeStateType; column order derived from the populated sub-object andctx['meta'].attitude_type.WRITE_COVARIANCEEmits
EPOCH(and optionalCOV_REF_FRAME) keyword lines then the 6 lower-triangular numeric rows.WRITE_TDM_OBSEmits
KEY = EPOCH VALUEfor eachTrackingDataObservationType.WRITE_ROTATION_ANGLEEmits up to 3 lines, keyword from
rotation.angle(X_ANGLE / Y_ANGLE / Z_ANGLE) →RotationAngleType.WRITE_ROTATION_RATEAnalogous to
WRITE_ROTATION_ANGLEfor theratediscriminator (X_RATE / Y_RATE / Z_RATE) →RotationRateType.WRITE_PACKED_LINESEmits the KEY=VALUE header fields first, then one text line per entry in the embedded packed
list[str]field (trajLine/attLine/covLine). Used byOcmTrajStateType,OcmCovarianceMatrixType,AcmAttitudeStateType, andAcmCovarianceMatrixType.
Document-level dispatch (structural, not per-type)
DISPATCH_FLATOPM, OMM, APM, RDM — single segment, no META_START/STOP markers. Partition lines into header / metadata / data buckets by keyword-set membership, then call the registry for each bucket.
DISPATCH_SEGMENTEDOEM, AEM, TDM — one or more segments delimited by META_START / META_STOP / DATA_START / DATA_STOP (plus COVARIANCE_START / COVARIANCE_STOP for OEM). A state machine yields
(meta_lines, data_lines[, cov_lines])per segment before calling the registry.DISPATCH_CDMCDM — split on OBJECT_1 / OBJECT_2 keywords; handle the RELATIVE_METADATA_DATA section separately.
Classes
|
Structural type for schema-specific KVN registries (ndmxml1, ndmxml2, …). |
|
Handler classification for one xsdata type. |
- class SchemaRegistry(*args, **kwargs)[source]
Structural type for schema-specific KVN registries (ndmxml1, ndmxml2, …).
- class TypeHandler(locate, parse, write)[source]
Handler classification for one xsdata type.
Each field holds a sentinel string from the constants above. All three slots must be explicitly filled. Types not present in a schema registry implicitly use
DEFAULT_HANDLER.Fields
- locate:
Which locator strategy to use.
- parse:
Which parser strategy to use.
- write:
Which writer strategy to use.
Create new instance of TypeHandler(locate, parse, write)