ptr-editor 0.2.0__tar.gz → 0.3.0__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.
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/PKG-INFO +1 -1
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/pyproject.toml +12 -3
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/__init__.py +3 -0
- ptr_editor-0.3.0/src/attrs_xml/pandas.py +295 -0
- ptr_editor-0.3.0/src/juice_jsoc/__init__.py +19 -0
- ptr_editor-0.3.0/src/juice_jsoc/apl/__init__.py +42 -0
- ptr_editor-0.3.0/src/juice_jsoc/apl/elements.py +715 -0
- ptr_editor-0.3.0/src/juice_jsoc/apl/jsoc-apl-schema.json +195 -0
- ptr_editor-0.3.0/src/juice_jsoc/base.py +27 -0
- ptr_editor-0.3.0/src/juice_jsoc/diffing.py +171 -0
- ptr_editor-0.3.0/src/juice_jsoc/itl/__init__.py +46 -0
- ptr_editor-0.3.0/src/juice_jsoc/itl/elements.py +1100 -0
- ptr_editor-0.3.0/src/juice_jsoc/itl/jsoc-itl-schema.json +424 -0
- ptr_editor-0.3.0/src/juice_jsoc/opl/__init__.py +46 -0
- ptr_editor-0.3.0/src/juice_jsoc/opl/csv.py +202 -0
- ptr_editor-0.3.0/src/juice_jsoc/opl/elements.py +1147 -0
- ptr_editor-0.3.0/src/juice_jsoc/opl/jsoc-opl-schema.json +377 -0
- ptr_editor-0.3.0/src/juice_jsoc/schema.py +160 -0
- ptr_editor-0.3.0/src/juice_jsoc/utils.py +51 -0
- ptr_editor-0.3.0/src/juice_opl/__init__.py +39 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/io/simplified_converter2.py +5 -10
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/segments_collection_mixin.py +86 -22
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/.gitignore +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/LICENSE +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/README.md +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/README.md +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/base_element.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/converter_factory.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/decorators.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/decorators_utils.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/field_transformer.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/fields.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/inspect.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/protocols.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/sentinels.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/type_utils.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/core/validator_factory.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/elements_registry.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/formatting.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/globals.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/resolution/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/resolution/registry.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/resolution/strategies.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/converter.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/converters.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/custom_disambiguator.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/io.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/attrs_xml/xml/utils.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/README.md +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/commands/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/commands/validate.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/commands/version.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_cli/main.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_compare/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/accessors/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/accessors/accessor.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/accessors/attrs_dict_accessor.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_config/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_config/agm_config.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_config/agm_utils.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_config/html.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_validator/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/agm_validator/agm_config_validator.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/README.md +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/defaults.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/presets.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/service_config.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/context/services.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/core/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/core/codenames_gen.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/core/logging.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/core/ptr_element.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/core/tree_utils.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/data/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/data/snippets.txt +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/diff_report.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/matcher.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/text_diff_result.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/timeline_differ_simple.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/diffing/visualize.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/additional_elements.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/agm_config.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/array.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/attitude.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/blocks.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/directions.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/doc.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/metadata.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/offset.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/phase_angle.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/ref_typed_mixin.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/surface.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/timeline.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/units.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements/values.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/elements_extractor/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/extra/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/extra/add_block_comments.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/factory/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/factory/attitudes.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/factory/blocks.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/generators/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/generators/base.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/generators/generators.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/generators/processor.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/html.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/io/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/io/ptr_converter_setup.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/io/simplified_converter.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/io/xml_formatting.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/py.typed +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/services/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/services/quick_access.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/services/resolution_strategies.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/spice_accessors/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/spice_accessors/directions.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/spice_accessors/eval_directions.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/templates/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/templates/html.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/templates/register.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/templates/template.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/README.md +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/combinators.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/html.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/ptr_validators.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/result.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/ruleset_registry.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/runner.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/validation/validator.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/versioned_file_manager/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/versioned_file_manager/file_info.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/versioned_file_manager/html.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_editor/versioned_file_manager/manager.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_solver/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_solver/cached_solver.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_solver/ptr_solver.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/ptr_solver/solvable_mixin.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/__init__.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/config.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/interface.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/merging.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/opl.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/ops.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/plot.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/segment_mixin.py +0 -0
- {ptr_editor-0.2.0 → ptr_editor-0.3.0}/src/time_segments/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ptr-editor"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Utilities to edit PTR files."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Luca Penasa", email = "luca.penasa@inaf.it" },
|
|
@@ -117,7 +117,10 @@ include = [
|
|
|
117
117
|
"src/ptr_compare",
|
|
118
118
|
"src/ptr_solver",
|
|
119
119
|
"src/time_segments",
|
|
120
|
-
"src/ptr_cli"
|
|
120
|
+
"src/ptr_cli",
|
|
121
|
+
"src/juice_jsoc",
|
|
122
|
+
"src/juice_opl",
|
|
123
|
+
|
|
121
124
|
|
|
122
125
|
]
|
|
123
126
|
|
|
@@ -128,7 +131,10 @@ include = [
|
|
|
128
131
|
"src/ptr_compare",
|
|
129
132
|
"src/ptr_solver",
|
|
130
133
|
"src/time_segments",
|
|
131
|
-
"src/ptr_cli"
|
|
134
|
+
"src/ptr_cli",
|
|
135
|
+
"src/juice_jsoc",
|
|
136
|
+
"src/juice_opl",
|
|
137
|
+
|
|
132
138
|
]
|
|
133
139
|
|
|
134
140
|
[tool.hatch.build.targets.wheel.sources]
|
|
@@ -138,6 +144,9 @@ include = [
|
|
|
138
144
|
"src/ptr_solver" = "ptr_solver"
|
|
139
145
|
"src/time_segments" = "time_segments"
|
|
140
146
|
"src/ptr_cli" = "ptr_cli"
|
|
147
|
+
"src/juice_jsoc" = "juice_jsoc"
|
|
148
|
+
"src/juice_opl" = "juice_opl"
|
|
149
|
+
|
|
141
150
|
|
|
142
151
|
[build-system]
|
|
143
152
|
requires = ["hatchling"]
|
|
@@ -52,6 +52,7 @@ from attrs_xml.core import (
|
|
|
52
52
|
)
|
|
53
53
|
from attrs_xml.elements_registry import ElementsRegistry
|
|
54
54
|
from attrs_xml.globals import are_defaults_disabled, disable_defaults
|
|
55
|
+
from attrs_xml.pandas import attrs_flatten, attrs_to_dataframe
|
|
55
56
|
|
|
56
57
|
__all__ = [
|
|
57
58
|
"UNSET",
|
|
@@ -63,6 +64,8 @@ __all__ = [
|
|
|
63
64
|
"__version__",
|
|
64
65
|
"are_defaults_disabled",
|
|
65
66
|
"attr",
|
|
67
|
+
"attrs_flatten",
|
|
68
|
+
"attrs_to_dataframe",
|
|
66
69
|
"disable_defaults",
|
|
67
70
|
"element",
|
|
68
71
|
"element_define",
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"""Utilities for converting attrs objects to pandas DataFrames.
|
|
2
|
+
|
|
3
|
+
The main entry points are:
|
|
4
|
+
|
|
5
|
+
- :func:`attrs_flatten` – flatten a single attrs object (or dict/list/scalar)
|
|
6
|
+
into a flat ``{column: value}`` dict.
|
|
7
|
+
- :func:`attrs_to_dataframe` – convert a sequence of attrs objects into a
|
|
8
|
+
``pd.DataFrame`` with automatic column detection and optional filtering.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import TYPE_CHECKING, Any
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
import pandas as pd
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _resolve_dotpath(obj: Any, path: str) -> Any:
|
|
20
|
+
"""Resolve a dot-notation attribute path on *obj*.
|
|
21
|
+
|
|
22
|
+
Each segment is resolved with ``getattr``; if a segment is missing,
|
|
23
|
+
``None`` is returned. If the resolved value is callable it is called
|
|
24
|
+
with no arguments before being returned.
|
|
25
|
+
|
|
26
|
+
Examples::
|
|
27
|
+
|
|
28
|
+
_resolve_dotpath(seg, "attitude.mode") # → seg.attitude.mode
|
|
29
|
+
_resolve_dotpath(seg, "status") # → seg.status (or seg.status())
|
|
30
|
+
"""
|
|
31
|
+
value: Any = obj
|
|
32
|
+
for part in path.split("."):
|
|
33
|
+
value = getattr(value, part, None)
|
|
34
|
+
if value is None:
|
|
35
|
+
return None
|
|
36
|
+
return value() if callable(value) else value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _get_class_properties(cls: type) -> list[str]:
|
|
40
|
+
"""Return the names of all public ``@property`` members defined on *cls*.
|
|
41
|
+
|
|
42
|
+
Private names (leading ``_``) are excluded.
|
|
43
|
+
"""
|
|
44
|
+
import inspect
|
|
45
|
+
return [
|
|
46
|
+
name
|
|
47
|
+
for name, _ in inspect.getmembers(cls, predicate=lambda v: isinstance(v, property))
|
|
48
|
+
if not name.startswith("_")
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def attrs_flatten(
|
|
53
|
+
obj: Any,
|
|
54
|
+
*,
|
|
55
|
+
prefix: str = "",
|
|
56
|
+
sep: str = ".",
|
|
57
|
+
max_depth: int = 3,
|
|
58
|
+
include_properties: bool = False,
|
|
59
|
+
extra_fields: dict[str, Any] | None = None,
|
|
60
|
+
extra_attrs: list[str] | None = None,
|
|
61
|
+
_depth: int = 0,
|
|
62
|
+
) -> dict[str, Any]:
|
|
63
|
+
"""Flatten an attrs object (or dict / list / scalar) into a flat dict.
|
|
64
|
+
|
|
65
|
+
Rules:
|
|
66
|
+
|
|
67
|
+
- **attrs object**: each public field (no leading ``_``) is recursed into,
|
|
68
|
+
with ``sep`` inserted between the parent key and the field name, e.g.
|
|
69
|
+
field ``inner`` with sub-field ``x`` → key ``inner<sep>x``.
|
|
70
|
+
- **dict**: each key is recursed into using the same naming convention,
|
|
71
|
+
supporting arbitrary nesting, e.g. ``{"a": {"b": 1}}`` →
|
|
72
|
+
``{"params<sep>a<sep>b": 1}``.
|
|
73
|
+
- **list**: stored as a single cell value. Fan-out by index is not
|
|
74
|
+
performed because different rows may have different list lengths,
|
|
75
|
+
producing ragged columns that cause confusion in DataFrames.
|
|
76
|
+
- **scalar**: stored as-is.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
obj: The object to flatten. Can be an attrs instance, dict, list,
|
|
80
|
+
or any scalar.
|
|
81
|
+
prefix: Column name prefix accumulated during recursion. Leave as
|
|
82
|
+
``""`` for the root call.
|
|
83
|
+
sep: Separator inserted between key segments. Default is ``"."``.
|
|
84
|
+
max_depth: Maximum recursion depth. Objects deeper than this are
|
|
85
|
+
stored as-is. Default is ``3``.
|
|
86
|
+
extra_fields: Optional dict mapping column names to pre-computed values
|
|
87
|
+
(typically properties or computed fields). These are
|
|
88
|
+
added directly to the result at the top level.
|
|
89
|
+
include_properties: If ``True``, all public ``@property`` members of
|
|
90
|
+
the root object's class are automatically extracted
|
|
91
|
+
and added as columns. Properties already covered
|
|
92
|
+
by attrs fields, ``extra_fields``, or ``extra_attrs``
|
|
93
|
+
are skipped. Default is ``False``.
|
|
94
|
+
extra_attrs: Optional list of attribute paths (dot notation supported)
|
|
95
|
+
to extract from the root object. Each path is resolved
|
|
96
|
+
via successive ``getattr`` calls; if the final value is
|
|
97
|
+
callable it is called with no arguments. The column name
|
|
98
|
+
used is the path as given (e.g. ``"attitude.mode"`` →
|
|
99
|
+
column ``"attitude.mode"``). Paths that are already
|
|
100
|
+
present as flattened attrs fields are skipped.
|
|
101
|
+
_depth: Internal recursion counter – do not set manually.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
A flat ``{str: Any}`` dict ready to become a DataFrame row.
|
|
105
|
+
|
|
106
|
+
Examples:
|
|
107
|
+
>>> import attrs
|
|
108
|
+
>>> @attrs.define
|
|
109
|
+
... class Inner:
|
|
110
|
+
... x: float = 1.0
|
|
111
|
+
... y: float = 2.0
|
|
112
|
+
...
|
|
113
|
+
>>> @attrs.define
|
|
114
|
+
... class Outer:
|
|
115
|
+
... name: str = "a"
|
|
116
|
+
... inner: Inner = attrs.Factory(Inner)
|
|
117
|
+
... tags: list = attrs.Factory(list)
|
|
118
|
+
... meta: dict = attrs.Factory(dict)
|
|
119
|
+
...
|
|
120
|
+
>>> attrs_flatten(Outer(name="a", inner=Inner(x=3, y=4),
|
|
121
|
+
... tags=["x"], meta={"k": 1}))
|
|
122
|
+
{'name': 'a', 'inner.x': 3.0, 'inner.y': 4.0, 'tags': ['x'], 'meta.k': 1}
|
|
123
|
+
"""
|
|
124
|
+
import attrs as _attrs
|
|
125
|
+
|
|
126
|
+
result: dict[str, Any] = {}
|
|
127
|
+
|
|
128
|
+
if _depth > max_depth:
|
|
129
|
+
result[prefix] = obj
|
|
130
|
+
return result
|
|
131
|
+
|
|
132
|
+
if _attrs.has(type(obj)):
|
|
133
|
+
for f in _attrs.fields(type(obj)):
|
|
134
|
+
if f.name.startswith("_"):
|
|
135
|
+
continue
|
|
136
|
+
key = f"{prefix}{sep}{f.name}" if prefix else f.name
|
|
137
|
+
val = getattr(obj, f.name)
|
|
138
|
+
result.update(
|
|
139
|
+
attrs_flatten(val, prefix=key, sep=sep, max_depth=max_depth, _depth=_depth + 1)
|
|
140
|
+
)
|
|
141
|
+
elif isinstance(obj, dict):
|
|
142
|
+
if not obj:
|
|
143
|
+
# Empty dict: contribute no columns for this row; pandas will NaN-fill
|
|
144
|
+
# any nested keys that other rows produced from this same field.
|
|
145
|
+
pass
|
|
146
|
+
else:
|
|
147
|
+
for k, v in obj.items():
|
|
148
|
+
key = f"{prefix}{sep}{k}" if prefix else str(k)
|
|
149
|
+
result.update(
|
|
150
|
+
attrs_flatten(v, prefix=key, sep=sep, max_depth=max_depth, _depth=_depth + 1)
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
elif isinstance(obj, list):
|
|
154
|
+
result[prefix] = obj
|
|
155
|
+
|
|
156
|
+
else:
|
|
157
|
+
result[prefix] = obj
|
|
158
|
+
|
|
159
|
+
# Add extra fields at the top level only (when prefix is empty)
|
|
160
|
+
if _depth == 0:
|
|
161
|
+
import attrs as _attrs
|
|
162
|
+
|
|
163
|
+
# Build set of existing field names to avoid duplicates
|
|
164
|
+
existing_fields = set(result.keys())
|
|
165
|
+
|
|
166
|
+
# Also check for attrs fields if object is an attrs class
|
|
167
|
+
if _attrs.has(type(obj)):
|
|
168
|
+
existing_fields.update(f.name for f in _attrs.fields(type(obj)))
|
|
169
|
+
|
|
170
|
+
# Automatically add public @property members
|
|
171
|
+
if include_properties:
|
|
172
|
+
for prop_name in _get_class_properties(type(obj)):
|
|
173
|
+
if prop_name not in existing_fields:
|
|
174
|
+
try:
|
|
175
|
+
result[prop_name] = getattr(obj, prop_name)
|
|
176
|
+
except Exception:
|
|
177
|
+
result[prop_name] = None
|
|
178
|
+
existing_fields.add(prop_name)
|
|
179
|
+
|
|
180
|
+
# Add extra_fields, checking for duplicates
|
|
181
|
+
if extra_fields:
|
|
182
|
+
for field_name, value in extra_fields.items():
|
|
183
|
+
if field_name not in existing_fields:
|
|
184
|
+
result[field_name] = value
|
|
185
|
+
|
|
186
|
+
# Add extra_attrs (dot-notation supported), checking for duplicates
|
|
187
|
+
if extra_attrs:
|
|
188
|
+
for attr_path in extra_attrs:
|
|
189
|
+
if attr_path not in existing_fields:
|
|
190
|
+
result[attr_path] = _resolve_dotpath(obj, attr_path)
|
|
191
|
+
|
|
192
|
+
return result
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def attrs_to_dataframe(
|
|
196
|
+
objects: list[Any],
|
|
197
|
+
*,
|
|
198
|
+
sep: str = ".",
|
|
199
|
+
max_depth: int = 3,
|
|
200
|
+
include: list[str] | None = None,
|
|
201
|
+
exclude: list[str] | None = None,
|
|
202
|
+
include_properties: bool = True,
|
|
203
|
+
extra_fields: dict[str, Any] | None = None,
|
|
204
|
+
extra_attrs: list[str] | None = None,
|
|
205
|
+
) -> "pd.DataFrame":
|
|
206
|
+
"""Convert a sequence of attrs objects into a pandas DataFrame.
|
|
207
|
+
|
|
208
|
+
Each object is flattened with :func:`attrs_flatten` and becomes one row.
|
|
209
|
+
Column names are derived automatically: nested attrs objects and dicts
|
|
210
|
+
produce ``parent<sep>child`` column names (default separator is ``"."``).
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
objects: Sequence of attrs instances (or dicts/scalars) to convert.
|
|
214
|
+
sep: Separator inserted between key segments when building column names
|
|
215
|
+
from nested structures. Default is ``"."``.
|
|
216
|
+
max_depth: Maximum recursion depth for nested attrs objects / dicts.
|
|
217
|
+
Default is ``3``.
|
|
218
|
+
include: If given, only columns whose name is in this list are kept.
|
|
219
|
+
Use the full flattened name for nested columns
|
|
220
|
+
(e.g. ``"inner.x"`` with the default separator).
|
|
221
|
+
exclude: Field names (or flattened column names) to drop from every row.
|
|
222
|
+
include_properties: If ``True``, all public ``@property`` members of
|
|
223
|
+
each object's class are automatically extracted and
|
|
224
|
+
added as columns. Properties already covered by
|
|
225
|
+
attrs fields, ``extra_fields``, or ``extra_attrs``
|
|
226
|
+
are skipped. Default is ``False``.
|
|
227
|
+
extra_fields: Optional dict mapping column names to callables that
|
|
228
|
+
extract values from each object. The callables receive
|
|
229
|
+
the object and return the column value. Useful for
|
|
230
|
+
arbitrary computed fields. Names already present as
|
|
231
|
+
flattened attrs fields are skipped.
|
|
232
|
+
extra_attrs: Optional list of attribute paths (dot notation supported)
|
|
233
|
+
to extract from each object. Each path is resolved via
|
|
234
|
+
successive ``getattr`` calls
|
|
235
|
+
(e.g. ``"attitude.mode"`` → ``obj.attitude.mode``); if
|
|
236
|
+
the resolved value is callable it is called with no
|
|
237
|
+
arguments. The column is named after the path as given.
|
|
238
|
+
Paths already covered by attrs fields or ``extra_fields``
|
|
239
|
+
are skipped.
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
``pd.DataFrame`` with one row per object.
|
|
243
|
+
|
|
244
|
+
Examples:
|
|
245
|
+
>>> df = attrs_to_dataframe(plan.activities)
|
|
246
|
+
>>> df = attrs_to_dataframe(plan.activities, include=["id", "unit", "start"])
|
|
247
|
+
>>> df = attrs_to_dataframe(plan.activities, exclude=["instrument_area"])
|
|
248
|
+
>>> df = attrs_to_dataframe(plan.activities, sep="__", max_depth=2)
|
|
249
|
+
>>> df = attrs_to_dataframe(
|
|
250
|
+
... plan.activities,
|
|
251
|
+
... extra_fields={
|
|
252
|
+
... "duration": lambda x: x.end_time - x.start_time,
|
|
253
|
+
... "category": lambda x: getattr(x, "category", "default")
|
|
254
|
+
... }
|
|
255
|
+
... )
|
|
256
|
+
>>> df = attrs_to_dataframe(
|
|
257
|
+
... plan.activities,
|
|
258
|
+
... extra_attrs=["status", "attitude.mode", "computed_priority"]
|
|
259
|
+
... )
|
|
260
|
+
>>> df = attrs_to_dataframe(
|
|
261
|
+
... plan.activities,
|
|
262
|
+
... include_properties=True,
|
|
263
|
+
... )
|
|
264
|
+
"""
|
|
265
|
+
import pandas as pd
|
|
266
|
+
|
|
267
|
+
exclude_set: set[str] = set(exclude or [])
|
|
268
|
+
|
|
269
|
+
# Filter extra_attrs: exclude those that are already in extra_fields
|
|
270
|
+
extra_fields_set = set(extra_fields.keys()) if extra_fields else set()
|
|
271
|
+
filtered_extra_attrs = None
|
|
272
|
+
if extra_attrs:
|
|
273
|
+
filtered_extra_attrs = [
|
|
274
|
+
attr for attr in extra_attrs
|
|
275
|
+
if attr not in extra_fields_set
|
|
276
|
+
]
|
|
277
|
+
|
|
278
|
+
rows = []
|
|
279
|
+
for obj in objects:
|
|
280
|
+
# Compute extra field values for this object
|
|
281
|
+
computed_extra = {}
|
|
282
|
+
if extra_fields:
|
|
283
|
+
for field_name, extractor in extra_fields.items():
|
|
284
|
+
computed_extra[field_name] = extractor(obj)
|
|
285
|
+
|
|
286
|
+
row = attrs_flatten(obj, sep=sep, max_depth=max_depth, include_properties=include_properties, extra_fields=computed_extra, extra_attrs=filtered_extra_attrs)
|
|
287
|
+
|
|
288
|
+
if include is not None:
|
|
289
|
+
row = {k: v for k, v in row.items() if k in include}
|
|
290
|
+
if exclude_set:
|
|
291
|
+
row = {k: v for k, v in row.items() if k not in exclude_set}
|
|
292
|
+
|
|
293
|
+
rows.append(row)
|
|
294
|
+
|
|
295
|
+
return pd.DataFrame(rows)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""JUICE Science Operations JSON Planning (JSOC) package.
|
|
2
|
+
|
|
3
|
+
This package unifies the former stand-alone ``juice_opl`` and ``juice_apl``
|
|
4
|
+
packages under a single namespace::
|
|
5
|
+
|
|
6
|
+
from juice_jsoc import opl, apl
|
|
7
|
+
|
|
8
|
+
plan = opl.Timeline.from_json_file("opl.json")
|
|
9
|
+
apl_plan = apl.ActivityPlan.from_json_file("apl.json")
|
|
10
|
+
|
|
11
|
+
Backward-compatible imports from the original packages still work::
|
|
12
|
+
|
|
13
|
+
from juice_opl import Timeline # → juice_jsoc.opl.Timeline
|
|
14
|
+
from juice_apl import ActivityPlan # → juice_jsoc.apl.ActivityPlan
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from juice_jsoc import apl, itl, opl
|
|
18
|
+
|
|
19
|
+
__all__ = ["apl", "itl", "opl"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""juice_jsoc.apl – JUICE Science Operations Activity Plan (APL) sub-package.
|
|
2
|
+
|
|
3
|
+
Imports from here are identical to the former stand-alone ``juice_apl`` package::
|
|
4
|
+
|
|
5
|
+
from juice_jsoc.apl import ActivityPlan, Activity, Header
|
|
6
|
+
|
|
7
|
+
Or via the top-level namespace::
|
|
8
|
+
|
|
9
|
+
from juice_jsoc import apl
|
|
10
|
+
apl.ActivityPlan.from_json_file("apl.json")
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from juice_jsoc.diffing import make_apl_differ
|
|
14
|
+
|
|
15
|
+
from .elements import (
|
|
16
|
+
Activity,
|
|
17
|
+
ActivityPlan,
|
|
18
|
+
AplBaseItem,
|
|
19
|
+
AplConfiguration,
|
|
20
|
+
Header,
|
|
21
|
+
Uevt,
|
|
22
|
+
fetch_schema,
|
|
23
|
+
get_schema_cache_path,
|
|
24
|
+
structure_apl,
|
|
25
|
+
unstructure_apl,
|
|
26
|
+
validate_apl_json,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"Activity",
|
|
31
|
+
"ActivityPlan",
|
|
32
|
+
"AplBaseItem",
|
|
33
|
+
"AplConfiguration",
|
|
34
|
+
"Header",
|
|
35
|
+
"Uevt",
|
|
36
|
+
"fetch_schema",
|
|
37
|
+
"get_schema_cache_path",
|
|
38
|
+
"make_apl_differ",
|
|
39
|
+
"structure_apl",
|
|
40
|
+
"unstructure_apl",
|
|
41
|
+
"validate_apl_json",
|
|
42
|
+
]
|