-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Python class meta-programming for State construction (#244)
* feat: add StateTemplateType emitter in Python to create custom State types * test: add copy constructor tests * feat: add non-default copy-assignment operator * style: formatting * Update bindings/python/test/trajectory/test_state.py * Apply suggestions from code review Co-authored-by: Vishwa Shah <vishwa2710@gmail.com> * test: fix old naming in python test and address 1 MR comment --------- Co-authored-by: Vishwa Shah <vishwa2710@gmail.com>
- Loading branch information
1 parent
e93ad85
commit 2200a55
Showing
8 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
bindings/python/tools/python/ostk/astrodynamics/pytrajectory/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Apache License 2.0 |
38 changes: 38 additions & 0 deletions
38
bindings/python/tools/python/ostk/astrodynamics/pytrajectory/pystate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Apache License 2.0 | ||
|
||
|
||
# Python-only State functionality | ||
import numpy as np | ||
|
||
from ostk.physics.coordinate import Frame | ||
from ostk.physics.time import Instant | ||
|
||
from ostk.astrodynamics.trajectory import State, StateBuilder | ||
|
||
|
||
@staticmethod | ||
def custom_class_generator(frame: Frame, coordinates_subsets: list) -> type: | ||
""" | ||
Emit a custom class type for States. This is meta-programming syntactic sugar on top of the StateBuilder class. | ||
StateType = State.template(frame, coordinates_subsets) | ||
state = StateType(instant, coordinates) | ||
is equivalent to | ||
state_builder = StateBuilder(frame, coordinates_subsets) | ||
state = state_builder.build(instant, coordinates) | ||
""" | ||
|
||
class StateTemplateType(State): | ||
state_builder: StateBuilder = StateBuilder(frame, coordinates_subsets) | ||
|
||
def __init__(self, instant: Instant, coordinates: np.ndarray): | ||
super().__init__( | ||
StateTemplateType.state_builder.build(instant, coordinates) | ||
) | ||
|
||
return StateTemplateType | ||
|
||
|
||
State.template = custom_class_generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters