ptr-editor 0.4.0__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/PKG-INFO +1 -1
  2. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/pyproject.toml +1 -1
  3. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/converter.py +5 -2
  4. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/lxml_adapter.py +27 -3
  5. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/itl/elements.py +5 -1
  6. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/core/ptr_element.py +1 -1
  7. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/__init__.py +2 -0
  8. ptr_editor-0.4.1/src/ptr_editor/elements/offset_builder.py +377 -0
  9. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/timeline.py +29 -1
  10. ptr_editor-0.4.1/src/ptr_editor/spice_accessors/eval_offpointing.py +1109 -0
  11. ptr_editor-0.4.1/src/ptr_editor/spice_accessors/eval_slew.py +349 -0
  12. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_solver/cached_solver.py +16 -2
  13. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_solver/ptr_solver.py +54 -31
  14. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_solver/solvable_mixin.py +13 -2
  15. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/plot.py +15 -2
  16. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/.gitignore +0 -0
  17. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/LICENSE +0 -0
  18. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/README.md +0 -0
  19. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/README.md +0 -0
  20. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/__init__.py +0 -0
  21. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/__init__.py +0 -0
  22. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/base_element.py +0 -0
  23. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/converter_factory.py +0 -0
  24. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/decorators.py +0 -0
  25. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/decorators_utils.py +0 -0
  26. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/field_transformer.py +0 -0
  27. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/fields.py +0 -0
  28. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/inspect.py +0 -0
  29. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/protocols.py +0 -0
  30. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/sentinels.py +0 -0
  31. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/type_utils.py +0 -0
  32. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/core/validator_factory.py +0 -0
  33. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/elements_registry.py +0 -0
  34. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/formatting.py +0 -0
  35. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/globals.py +0 -0
  36. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/pandas.py +0 -0
  37. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/resolution/__init__.py +0 -0
  38. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/resolution/registry.py +0 -0
  39. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/resolution/strategies.py +0 -0
  40. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/__init__.py +0 -0
  41. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/converters.py +0 -0
  42. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/custom_disambiguator.py +0 -0
  43. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/io.py +0 -0
  44. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/attrs_xml/xml/utils.py +0 -0
  45. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/__init__.py +0 -0
  46. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/apl/__init__.py +0 -0
  47. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/apl/elements.py +0 -0
  48. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/apl/jsoc-apl-schema.json +0 -0
  49. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/base.py +0 -0
  50. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/diffing.py +0 -0
  51. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/itl/__init__.py +0 -0
  52. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/itl/jsoc-itl-schema.json +0 -0
  53. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/opl/__init__.py +0 -0
  54. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/opl/csv.py +0 -0
  55. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/opl/elements.py +0 -0
  56. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/opl/jsoc-opl-schema.json +0 -0
  57. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/schema.py +0 -0
  58. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_jsoc/utils.py +0 -0
  59. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/juice_opl/__init__.py +0 -0
  60. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/README.md +0 -0
  61. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/__init__.py +0 -0
  62. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/commands/__init__.py +0 -0
  63. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/commands/validate.py +0 -0
  64. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/commands/version.py +0 -0
  65. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_cli/main.py +0 -0
  66. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_compare/__init__.py +0 -0
  67. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/__init__.py +0 -0
  68. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/accessors/__init__.py +0 -0
  69. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/accessors/accessor.py +0 -0
  70. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/accessors/attrs_dict_accessor.py +0 -0
  71. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_config/__init__.py +0 -0
  72. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_config/agm_config.py +0 -0
  73. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_config/agm_utils.py +0 -0
  74. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_config/html.py +0 -0
  75. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_validator/__init__.py +0 -0
  76. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/agm_validator/agm_config_validator.py +0 -0
  77. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/README.md +0 -0
  78. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/__init__.py +0 -0
  79. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/defaults.py +0 -0
  80. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/presets.py +0 -0
  81. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/service_config.py +0 -0
  82. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/context/services.py +0 -0
  83. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/core/__init__.py +0 -0
  84. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/core/codenames_gen.py +0 -0
  85. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/core/logging.py +0 -0
  86. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/core/tree_utils.py +0 -0
  87. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/data/__init__.py +0 -0
  88. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/data/snippets.txt +0 -0
  89. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/__init__.py +0 -0
  90. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/diff_report.py +0 -0
  91. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/matcher.py +0 -0
  92. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/text_diff_result.py +0 -0
  93. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/timeline_differ_simple.py +0 -0
  94. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/diffing/visualize.py +0 -0
  95. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/additional_elements.py +0 -0
  96. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/agm_config.py +0 -0
  97. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/array.py +0 -0
  98. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/attitude.py +0 -0
  99. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/blocks.py +0 -0
  100. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/directions.py +0 -0
  101. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/doc.py +0 -0
  102. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/metadata.py +0 -0
  103. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/offset.py +0 -0
  104. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/phase_angle.py +0 -0
  105. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/ref_typed_mixin.py +0 -0
  106. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/surface.py +0 -0
  107. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/units.py +0 -0
  108. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements/values.py +0 -0
  109. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/elements_extractor/__init__.py +0 -0
  110. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/extra/__init__.py +0 -0
  111. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/extra/add_block_comments.py +0 -0
  112. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/factory/__init__.py +0 -0
  113. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/factory/attitudes.py +0 -0
  114. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/factory/blocks.py +0 -0
  115. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/generators/__init__.py +0 -0
  116. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/generators/base.py +0 -0
  117. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/generators/generators.py +0 -0
  118. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/generators/processor.py +0 -0
  119. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/html.py +0 -0
  120. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/io/__init__.py +0 -0
  121. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/io/ptr_converter_setup.py +0 -0
  122. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/io/simplified_converter.py +0 -0
  123. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/io/simplified_converter2.py +0 -0
  124. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/io/xml_formatting.py +0 -0
  125. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/py.typed +0 -0
  126. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/services/__init__.py +0 -0
  127. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/services/quick_access.py +0 -0
  128. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/services/resolution_strategies.py +0 -0
  129. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/spice_accessors/__init__.py +0 -0
  130. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/spice_accessors/directions.py +0 -0
  131. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/spice_accessors/eval_directions.py +0 -0
  132. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/templates/__init__.py +0 -0
  133. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/templates/html.py +0 -0
  134. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/templates/register.py +0 -0
  135. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/templates/template.py +0 -0
  136. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/README.md +0 -0
  137. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/__init__.py +0 -0
  138. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/combinators.py +0 -0
  139. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/html.py +0 -0
  140. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/ptr_validators.py +0 -0
  141. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/result.py +0 -0
  142. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/ruleset_registry.py +0 -0
  143. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/runner.py +0 -0
  144. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/validation/validator.py +0 -0
  145. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/versioned_file_manager/__init__.py +0 -0
  146. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/versioned_file_manager/file_info.py +0 -0
  147. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/versioned_file_manager/html.py +0 -0
  148. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_editor/versioned_file_manager/manager.py +0 -0
  149. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/ptr_solver/__init__.py +0 -0
  150. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/__init__.py +0 -0
  151. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/config.py +0 -0
  152. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/interface.py +0 -0
  153. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/merging.py +0 -0
  154. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/opl.py +0 -0
  155. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/ops.py +0 -0
  156. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/segment_mixin.py +0 -0
  157. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/segments_collection_mixin.py +0 -0
  158. {ptr_editor-0.4.0 → ptr_editor-0.4.1}/src/time_segments/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ptr-editor
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Utilities to edit PTR files.
5
5
  Project-URL: documentation, https://luca-penasa.github.io/ptr-editor
6
6
  Project-URL: homepage, https://luca-penasa.github.io/ptr-editor
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ptr-editor"
3
- version = "0.4.0"
3
+ version = "0.4.1"
4
4
  description = "Utilities to edit PTR files."
5
5
  authors = [
6
6
  { name = "Luca Penasa", email = "luca.penasa@inaf.it" },
@@ -553,9 +553,12 @@ def make_structure_hook_factory(converter: Converter):
553
553
  if forbidden_errors:
554
554
  exc = forbidden_errors[0]
555
555
  log.warning(
556
- f"Unexpected keys encountered during structuring. Extra keys: {exc.extra_fields}. Those won't be preserved when saving the timeline",
556
+ f"Unexpected keys encountered during structuring of {cls.__name__!r}."
557
+ f" Extra keys: {exc.extra_fields}. Those won't be preserved when saving the timeline."
558
+ f" This is typically caused by a malformed XML file where a tag-mismatch cascade"
559
+ f" re-parents child elements onto the wrong ancestor."
557
560
  )
558
- log.debug(f"Original value: {val}")
561
+ log.debug(f"Original value for {cls.__name__}: {val}")
559
562
  log.exception(eg)
560
563
  # remove the extra keys and retry
561
564
  cleaned_val = {
@@ -152,12 +152,36 @@ def parse_xml(xml: str, preprocess: bool = True) -> dict[str, Any]:
152
152
 
153
153
  if parser.error_log:
154
154
  log.warning(
155
- f"XML parsing encountered {len(parser.error_log)} recoverable errors"
155
+ f"XML parsing encountered {len(parser.error_log)} recoverable error(s) "
156
+ f"in {'file: ' + xml if os.path.isfile(xml) else 'inline XML'}. "
157
+ f"The file is malformed and lxml repaired it automatically, but data may be lost."
156
158
  )
157
159
  for error in parser.error_log:
158
- log.debug(
159
- f" Line {error.line}, Column {error.column}: {error.message}"
160
+ log.warning(
161
+ f" XML recovery: line {error.line}, col {error.column}: {error.message}"
160
162
  )
163
+ # Warn about the most dangerous consequence: a tag-mismatch cascade can
164
+ # close <timeline> prematurely, causing blocks after the bad tag to be
165
+ # re-parented to an ancestor element and silently dropped.
166
+ timeline_elems = tree.findall(".//timeline")
167
+ if timeline_elems:
168
+ timeline = timeline_elems[0]
169
+ blocks_in_timeline = len(timeline.findall("block"))
170
+ # Blocks outside timeline that landed on ancestor elements
171
+ orphan_blocks = [
172
+ elem for elem in tree.iter()
173
+ if elem.tag != "timeline" and any(c.tag == "block" for c in elem)
174
+ ]
175
+ if orphan_blocks:
176
+ total_orphans = sum(
177
+ sum(1 for c in elem if c.tag == "block") for elem in orphan_blocks
178
+ )
179
+ log.warning(
180
+ f" XML recovery side-effect: {total_orphans} <block> element(s) "
181
+ f"were re-parented outside <timeline> due to the tag-mismatch cascade. "
182
+ f"Only {blocks_in_timeline} block(s) remain inside <timeline>. "
183
+ f"The orphaned blocks will be dropped when saving."
184
+ )
161
185
 
162
186
  root_dict = _lxml_element_to_dict(tree, force_list_func=is_element_a_list)
163
187
  return {tree.tag: root_dict}
@@ -127,7 +127,11 @@ class RelativeTime(ItlBaseItem):
127
127
  """Get absolute time if calculated."""
128
128
  if self.event_abs_time is not None:
129
129
  return self.event_abs_time + self.delta_time
130
- return None
130
+ msg = (
131
+ "Absolute time not known for this RelativeTime"
132
+ " instance. Cannot compute an abs time."
133
+ )
134
+ raise ValueError(msg)
131
135
 
132
136
  @abs_time.setter
133
137
  def abs_time(self, value: pd.Timestamp | None) -> None:
@@ -273,7 +273,7 @@ class PtrElement(BaseElement):
273
273
 
274
274
  ptr = get_elements_registry()
275
275
 
276
- return ptr.from_xml(xml, disable_defaults=disable_defaults, cls=cls)
276
+ return ptr.from_xml(xml, disable_defaults=disable_defaults)
277
277
 
278
278
  def _repr_html_(self) -> str:
279
279
  """Return syntax-highlighted HTML representation for Jupyter notebooks."""
@@ -85,6 +85,7 @@ from .offset import (
85
85
  RasterOffsetAngles,
86
86
  ScanOffsetAngles,
87
87
  )
88
+ from .offset_builder import MeridianStareBuilder
88
89
 
89
90
  # Phase angle elements
90
91
  from .phase_angle import (
@@ -178,6 +179,7 @@ __all__ = [
178
179
  # Offsets
179
180
  "CustomOffsetAngles",
180
181
  "FixedOffsetAngles",
182
+ "MeridianStareBuilder",
181
183
  "OffsetAngles",
182
184
  "RasterOffsetAngles",
183
185
  "ScanOffsetAngles",
@@ -0,0 +1,377 @@
1
+ """Builder for stare-and-slew CustomOffsetAngles patterns.
2
+
3
+ Simplifies construction of :class:`~ptr_editor.elements.offset.CustomOffsetAngles`
4
+ for meridian-scan observation patterns: a sequence of stares at fixed Y-offset
5
+ positions connected by constant-velocity slews.
6
+
7
+ Knot structure
8
+ --------------
9
+ For each stare position ``y_i`` followed by a transition to ``y_{i+1}``:
10
+
11
+ 1. **Dwell** — two knots at ``y_i``, rate = 0, duration = ``dwell_time``.
12
+ The Hermite polynomial is flat (zero displacement, zero velocity).
13
+
14
+ 2. **Pre-slew ramp** — one knot still at ``y_i``, rate = ``v``,
15
+ duration = ``trans_time``.
16
+ Because both endpoint Y values are identical the **net displacement is
17
+ exactly zero** regardless of the intermediate profile. The spacecraft
18
+ builds scan velocity while nominally holding the dwell angle; a small
19
+ transient dip of magnitude ≈ ``v · trans_time · 4/27`` is present but
20
+ is typically within pointing tolerance.
21
+
22
+ 3. **Constant-velocity slew** — one knot at
23
+ ``y_slew_end = y_i + v · slew_time``, rate = ``v``,
24
+ duration = ``slew_time``.
25
+ Both endpoint rates equal ``Δy / Δt`` so the Hermite polynomial
26
+ is exactly linear (pure constant-velocity motion).
27
+
28
+ 4. **Post-decel ramp** — one knot at ``y_{i+1}``, rate = 0,
29
+ duration = ``trans_time``.
30
+ Smooth ease-out that lands exactly on the next dwell position.
31
+ ``delta_decel = y_{i+1} − y_slew_end`` can be small positive (slew stops
32
+ just short of target) or slightly negative (mild overshoot corrected
33
+ during ramp).
34
+
35
+ Example — reproducing the MAJ_G-RS-SEG_TGT_RASTER_001 pattern::
36
+
37
+ builder = MeridianStareBuilder(
38
+ stare_y_angles=[-4.87, -3.57, -2.30, -1.06, +0.155, +1.35, +2.52],
39
+ dwell_time=90.0,
40
+ slew_velocity=0.0055, # deg/sec
41
+ slew_time=225.0, # sec → covers 0.0055 × 225 = 1.2375 deg
42
+ trans_time=60.0,
43
+ start_time="2033-11-27T10:01:30",
44
+ )
45
+ offset_angles = builder.build()
46
+
47
+ See Also
48
+ --------
49
+ :class:`~ptr_editor.elements.offset.CustomOffsetAngles`
50
+ """
51
+
52
+ from __future__ import annotations
53
+
54
+ from dataclasses import dataclass, field
55
+ from typing import TYPE_CHECKING
56
+
57
+ import numpy as np
58
+ import pandas as pd
59
+
60
+ from attrs_xml.core.sentinels import UNSET
61
+
62
+ from ptr_editor.elements.array import AnglesVector, AngularVelocityVector, TimesVector
63
+ from ptr_editor.elements.offset import CustomOffsetAngles
64
+
65
+ if TYPE_CHECKING:
66
+ pass
67
+
68
+
69
+ # ---------------------------------------------------------------------------
70
+ # Public builder
71
+ # ---------------------------------------------------------------------------
72
+
73
+
74
+ @dataclass
75
+ class MeridianStareBuilder:
76
+ """Build :class:`~ptr_editor.elements.offset.CustomOffsetAngles` for a
77
+ stare-and-slew pattern along the Y offset axis.
78
+
79
+ Parameters
80
+ ----------
81
+ stare_y_angles:
82
+ Y-offset dwell angles in **degrees**, one per stare position.
83
+ At least two values are required.
84
+ dwell_time:
85
+ Duration of each stare in **seconds**.
86
+ slew_velocity:
87
+ Magnitude of the constant-velocity scan in **deg/sec** (positive).
88
+ The sign is inferred from the direction between consecutive stares.
89
+ slew_time:
90
+ Duration of the constant-velocity phase in **seconds**.
91
+ During this phase the spacecraft moves exactly
92
+ ``slew_velocity × slew_time`` degrees.
93
+ trans_time:
94
+ Duration of each acceleration/deceleration ramp in **seconds**.
95
+ Default: 60 s.
96
+ x_angle:
97
+ Constant X-offset angle in **degrees** applied throughout.
98
+ Default: 0.
99
+ start_time:
100
+ Start time of the first stare. Accepts any value accepted by
101
+ ``pd.Timestamp``. If *None* the
102
+ :attr:`CustomOffsetAngles.start_time` will be left as ``UNSET``
103
+ and must be assigned before the object is used.
104
+
105
+ Notes
106
+ -----
107
+ The net displacement during each pre-slew ramp is *always* zero because
108
+ the Hermite polynomial shares the same Y value at both endpoints. The
109
+ post-decel ramp may have a small positive or negative residual
110
+ (``delta_decel``) depending on how ``slew_velocity × slew_time``
111
+ compares with the actual step spacing:
112
+
113
+ * ``delta_decel > 0`` — slew stops slightly short, ramp covers remainder.
114
+ * ``delta_decel < 0`` — slew mildly overshoots, ramp corrects back.
115
+ Inspect :meth:`transition_info` to check magnitudes.
116
+ """
117
+
118
+ stare_y_angles: list[float]
119
+ dwell_time: float
120
+ slew_velocity: float
121
+ slew_time: float
122
+ trans_time: float = 60.0
123
+ x_angle: float = 0.0
124
+ start_time: pd.Timestamp | str | None = None
125
+
126
+ # ------------------------------------------------------------------
127
+ # Derived helpers
128
+ # ------------------------------------------------------------------
129
+
130
+ @property
131
+ def n_stares(self) -> int:
132
+ """Number of stare positions."""
133
+ return len(self.stare_y_angles)
134
+
135
+ @property
136
+ def total_duration(self) -> float:
137
+ """Total duration of the generated offset profile in **seconds**.
138
+
139
+ Equals the sum of all delta-times produced by :meth:`build`.
140
+ """
141
+ n = self.n_stares
142
+ if n == 0:
143
+ return 0.0
144
+ # Each complete "stare+transition" block (all but last):
145
+ # dwell (1×) + trans + slew + trans = dwell + 2×trans + slew
146
+ # Plus the final dwell which only contributes 1 dwell_time.
147
+ n_transitions = n - 1
148
+ return (
149
+ n * self.dwell_time
150
+ + n_transitions * (2 * self.trans_time + self.slew_time)
151
+ )
152
+
153
+ # ------------------------------------------------------------------
154
+ # Transition introspection
155
+ # ------------------------------------------------------------------
156
+
157
+ def transition_info(self) -> list[dict]:
158
+ """Return a list of dicts describing each stare-to-stare transition.
159
+
160
+ Each dict contains:
161
+
162
+ * ``i`` — transition index (0-based)
163
+ * ``y_from`` — current dwell Y angle (deg)
164
+ * ``y_to`` — next dwell Y angle (deg)
165
+ * ``step`` — total Y displacement (deg)
166
+ * ``v_slew`` — signed constant-velocity scan speed (deg/sec)
167
+ * ``slew_covers`` — distance covered during constant-velocity phase (deg)
168
+ * ``y_slew_end`` — Y angle at end of constant-velocity slew (deg)
169
+ * ``delta_decel`` — post-decel displacement ``y_to − y_slew_end`` (deg)
170
+ * ``overshoot`` — True when the slew goes slightly past ``y_to``
171
+ """
172
+ info = []
173
+ for i in range(self.n_stares - 1):
174
+ y_from = self.stare_y_angles[i]
175
+ y_to = self.stare_y_angles[i + 1]
176
+ step = y_to - y_from
177
+ v = float(np.sign(step)) * abs(self.slew_velocity)
178
+ slew_covers = v * self.slew_time
179
+ y_slew_end = y_from + slew_covers
180
+ delta_decel = y_to - y_slew_end
181
+ info.append(
182
+ {
183
+ "i": i,
184
+ "y_from": y_from,
185
+ "y_to": y_to,
186
+ "step": step,
187
+ "v_slew": v,
188
+ "slew_covers": slew_covers,
189
+ "y_slew_end": y_slew_end,
190
+ "delta_decel": delta_decel,
191
+ "overshoot": delta_decel * step < 0,
192
+ }
193
+ )
194
+ return info
195
+
196
+ def summary(self) -> str:
197
+ """Return a human-readable summary of the scan pattern."""
198
+ lines = [
199
+ f"MeridianStareBuilder — {self.n_stares} stares",
200
+ f" dwell_time : {self.dwell_time:.1f} s",
201
+ f" slew_velocity: {self.slew_velocity:.5f} deg/s",
202
+ f" slew_time : {self.slew_time:.1f} s → "
203
+ f"{self.slew_velocity * self.slew_time:.4f} deg at const. v",
204
+ f" trans_time : {self.trans_time:.1f} s "
205
+ f"(pre-accel dip ≈ {self.slew_velocity * self.trans_time * 4 / 27:.4f} deg)",
206
+ f" x_angle : {self.x_angle:.4f} deg",
207
+ f" total duration: {self.total_duration:.1f} s "
208
+ f"({self.total_duration / 60:.2f} min)",
209
+ "",
210
+ " Transitions:",
211
+ ]
212
+ for t in self.transition_info():
213
+ flag = " ⚠ overshoot" if t["overshoot"] else ""
214
+ lines.append(
215
+ f" [{t['i']}] {t['y_from']:+.4f} → {t['y_to']:+.4f} deg"
216
+ f" (Δ={t['step']:+.4f}, slew {t['slew_covers']:+.4f},"
217
+ f" decel {t['delta_decel']:+.4f}){flag}"
218
+ )
219
+ return "\n".join(lines)
220
+
221
+ # ------------------------------------------------------------------
222
+ # Core builder
223
+ # ------------------------------------------------------------------
224
+
225
+ def build(self) -> CustomOffsetAngles:
226
+ """Construct and return the :class:`~ptr_editor.elements.offset.CustomOffsetAngles`.
227
+
228
+ The resulting knot sequence covers the full stare-and-slew pattern
229
+ starting from the first stare and ending at the last dwell position.
230
+
231
+ Raises
232
+ ------
233
+ ValueError
234
+ If fewer than 2 stare positions are provided or if
235
+ ``slew_velocity`` is zero.
236
+ """
237
+ if self.n_stares < 2:
238
+ msg = (
239
+ "MeridianStareBuilder requires at least 2 stare positions; "
240
+ f"got {self.n_stares}."
241
+ )
242
+ raise ValueError(msg)
243
+ if self.slew_velocity == 0.0:
244
+ msg = "slew_velocity must be non-zero."
245
+ raise ValueError(msg)
246
+
247
+ dts: list[float] = []
248
+ xs: list[float] = []
249
+ ys: list[float] = []
250
+ vxs: list[float] = []
251
+ vys: list[float] = []
252
+
253
+ def _add(dt: float, y: float, vy: float) -> None:
254
+ dts.append(dt)
255
+ xs.append(self.x_angle)
256
+ ys.append(y)
257
+ vxs.append(0.0)
258
+ vys.append(vy)
259
+
260
+ # First stare: two dwell knots
261
+ # dt=0 → first knot is exactly at start_time
262
+ # dt=dwell_time → end of first dwell (flat Hermite segment)
263
+ _add(0.0, self.stare_y_angles[0], 0.0)
264
+ _add(self.dwell_time, self.stare_y_angles[0], 0.0)
265
+
266
+ for i in range(self.n_stares - 1):
267
+ y_curr = self.stare_y_angles[i]
268
+ y_next = self.stare_y_angles[i + 1]
269
+
270
+ # Signed constant scan velocity for this leg
271
+ v = float(np.sign(y_next - y_curr)) * abs(self.slew_velocity)
272
+ y_slew_end = y_curr + v * self.slew_time
273
+
274
+ # (a) Pre-slew ramp — same y as dwell, velocity builds 0 → v
275
+ # Net Y displacement = 0 (identical endpoint values guarantee this).
276
+ _add(self.trans_time, y_curr, v)
277
+
278
+ # (b) Constant-velocity slew — rates at both ends equal v = Δy/Δt
279
+ # so the Hermite polynomial is exactly linear.
280
+ _add(self.slew_time, y_slew_end, v)
281
+
282
+ # (c) Post-decel ramp — smooth ease-out landing at y_next
283
+ # This knot also serves as the dwell-start of the next stare.
284
+ _add(self.trans_time, y_next, 0.0)
285
+
286
+ # (d) Dwell end for non-final stares
287
+ if i < self.n_stares - 2:
288
+ _add(self.dwell_time, y_next, 0.0)
289
+
290
+ # Final stare dwell-end knot
291
+ _add(self.dwell_time, self.stare_y_angles[-1], 0.0)
292
+
293
+ # Resolve start_time
294
+ if self.start_time is None:
295
+ resolved_start = UNSET
296
+ else:
297
+ resolved_start = pd.Timestamp(self.start_time)
298
+
299
+ return CustomOffsetAngles(
300
+ start_time=resolved_start,
301
+ delta_times=TimesVector(values=np.array(dts), units="sec"),
302
+ x_angles=AnglesVector(values=np.array(xs), units="deg"),
303
+ x_rates=AngularVelocityVector(values=np.array(vxs), units="deg/sec"),
304
+ y_angles=AnglesVector(values=np.array(ys), units="deg"),
305
+ y_rates=AngularVelocityVector(values=np.array(vys), units="deg/sec"),
306
+ )
307
+
308
+ # ------------------------------------------------------------------
309
+ # Convenience constructors
310
+ # ------------------------------------------------------------------
311
+
312
+ @classmethod
313
+ def from_even_spacing(
314
+ cls,
315
+ n_stares: int,
316
+ y_start: float,
317
+ y_spacing: float,
318
+ dwell_time: float,
319
+ slew_velocity: float,
320
+ trans_time: float = 60.0,
321
+ x_angle: float = 0.0,
322
+ start_time: pd.Timestamp | str | None = None,
323
+ slew_time_fraction: float = 0.9,
324
+ ) -> "MeridianStareBuilder":
325
+ """Create a builder for a uniformly-spaced meridian scan.
326
+
327
+ Parameters
328
+ ----------
329
+ n_stares:
330
+ Number of stare positions.
331
+ y_start:
332
+ Y angle of the first stare in **degrees**.
333
+ y_spacing:
334
+ Step between consecutive stares in **degrees** (may be negative
335
+ for a descending scan).
336
+ dwell_time:
337
+ Stare duration in **seconds**.
338
+ slew_velocity:
339
+ Desired scan speed in **deg/sec** (positive; sign inferred from
340
+ ``y_spacing``).
341
+ trans_time:
342
+ Ramp duration in **seconds**. Default: 60 s.
343
+ x_angle:
344
+ Constant X offset in **degrees**. Default: 0.
345
+ start_time:
346
+ Optional start time.
347
+ slew_time_fraction:
348
+ Fraction of the available travel distance covered at constant
349
+ velocity. The constant-velocity phase covers
350
+ ``|y_spacing| × slew_time_fraction`` degrees, which gives
351
+ ``slew_time = |y_spacing| × slew_time_fraction / slew_velocity``.
352
+ Must be in ``(0, 1]``. Default: 0.9 (10 % reserved for
353
+ post-decel ramp).
354
+
355
+ Returns
356
+ -------
357
+ MeridianStareBuilder
358
+ """
359
+ if not (0 < slew_time_fraction <= 1.0):
360
+ msg = "slew_time_fraction must be in (0, 1]."
361
+ raise ValueError(msg)
362
+
363
+ stare_y_angles = [
364
+ y_start + i * y_spacing for i in range(n_stares)
365
+ ]
366
+ slew_distance = abs(y_spacing) * slew_time_fraction
367
+ slew_time = slew_distance / slew_velocity
368
+
369
+ return cls(
370
+ stare_y_angles=stare_y_angles,
371
+ dwell_time=dwell_time,
372
+ slew_velocity=slew_velocity,
373
+ slew_time=slew_time,
374
+ trans_time=trans_time,
375
+ x_angle=x_angle,
376
+ start_time=start_time,
377
+ )
@@ -1219,7 +1219,35 @@ class Timeline(PtrElement, PtrSolvableMixin, SegmentsCollectionMixin[BLOCKS]):
1219
1219
  # Priority columns are already handled by tabletize_block
1220
1220
  return pd.DataFrame(data).reset_index(drop=True)
1221
1221
 
1222
- def plot(self, hover_cols=["id", "designer", "start", "end"], **kwargs):
1222
+ def plot(self, hover_cols=["id", "designer", "start", "end", 'attitude.target' ], **kwargs):
1223
+ """Plot the timeline as an interactive Gantt chart.
1224
+
1225
+ Defaults to coloring and grouping rows by ``designer``. Height is
1226
+ auto-scaled to the number of unique designers so crowded timelines
1227
+ don't look squashed. Any keyword accepted by
1228
+ :func:`time_segments.plot.plot` or ``plotly.express.timeline`` can be
1229
+ passed to override these defaults.
1230
+
1231
+ Args:
1232
+ hover_cols: Columns shown in the hover tooltip.
1233
+ **kwargs: Forwarded to :func:`time_segments.plot.plot`. Common
1234
+ overrides: ``color``, ``y``, ``height``, ``title``.
1235
+ """
1223
1236
  from time_segments.plot import plot
1224
1237
 
1238
+ tab = self.as_pandas()
1239
+
1240
+ # Default y / color to "attitude.target" — the natural PTR grouping axis.
1241
+ # Fall back to a single "timeline" row when no attitude.target column exists.
1242
+ if "attitude.target" in tab.columns:
1243
+ kwargs.setdefault("color", "attitude.target")
1244
+ if 'designer' in tab.columns:
1245
+ kwargs.setdefault("y", "designer")
1246
+ n_lanes = max(tab["designer"].nunique(), 1)
1247
+ else:
1248
+ n_lanes = 1
1249
+
1250
+ # Auto-scale height: 80 px per lane, 120 px minimum header/padding.
1251
+ kwargs.setdefault("height", max(300, 120 + 40 * n_lanes))
1252
+
1225
1253
  return plot(self, hover_cols=hover_cols, **kwargs)