Skip to content

Commit b0c5233

Browse files
MateusStanoclaude
andcommitted
MNT: polish event and flight-phase helper docstrings
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e76c31c commit b0c5233

5 files changed

Lines changed: 68 additions & 21 deletions

File tree

rocketpy/simulation/events/event.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
class Event:
28-
"""Event helper with trigger/callback execution and exact-time support.
28+
"""A rule that runs an action during a flight when a condition is met.
2929
3030
An ``Event`` is the main way RocketPy reacts to conditions during a
3131
flight. It pairs a ``trigger`` predicate with a ``callback`` action: at
@@ -147,11 +147,11 @@ def __init__( # pylint: disable=too-many-arguments
147147
slower with no gain in accuracy. Automatically forced to ``False``
148148
when ``sampling_rate`` is ``None``.
149149
changes_dynamics : bool, optional
150-
Set to ``True`` when the callback changes the simulation dynamics or
151-
any parameter affecting the ODE derivative. This includes mutating an
152-
attribute of any simulation object, and using the
153-
``set_derivative``, ``start_flight_phase``, or ``terminate_flight``
154-
commands. Defaults to ``False``.
150+
Set to ``True`` when the callback changes anything that affects the
151+
equations of motion. This includes changing an attribute of any
152+
simulation object, and using the ``set_derivative``,
153+
``start_flight_phase``, or ``terminate_flight`` commands. Defaults to
154+
``False``.
155155
name : str, optional
156156
Human-readable identifier used in logs and debugging. Defaults to
157157
``"Custom Event"``.
@@ -174,12 +174,11 @@ def __init__( # pylint: disable=too-many-arguments
174174
- 3: Controller events
175175
- 4: Custom / user-defined events (default)
176176
needs : list of str or None, optional
177-
Declares which expensive simulation values the event's trigger and
178-
callback actually access. Valid keys are ``'state_dot'``,
179-
``'pressure'``, and ``'state_history'``. The default``None`` is
180-
treated as an empty set and no expensive kwargs are computed.
181-
Supply a list with the keys this event accesses so the runtime
182-
computes them.
177+
Which of the slower-to-compute simulation values the event's trigger
178+
and callback actually use, so the rest are skipped. Valid keys are
179+
``'state_dot'``, ``'pressure'`` and ``'state_history'``. The default
180+
``None`` means none of them are computed. List the keys your event
181+
uses to have them provided in ``kwargs``.
183182
184183
See Also
185184
--------
@@ -306,6 +305,9 @@ def __call__(self, trigger_only=False, callback_only=False, reset=True, **kwargs
306305
If True, only execute the callback without evaluating the trigger
307306
condition. The exact time function and disable_on function are also
308307
called.
308+
reset : bool, optional
309+
If True (default), reset the event's queued commands (via
310+
``_reset_commands``) before evaluating the trigger.
309311
kwargs : dict
310312
Keyword arguments passed to the trigger and callback functions.
311313

rocketpy/simulation/events/event_builders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def apogee_event_exact_time_function(state, **_kwargs):
160160
----------
161161
state : array_like
162162
Interpolated flight state vector without time.
163-
**kwargs : dict
163+
**_kwargs : dict
164164
Event context (unused here).
165165
166166
Returns

rocketpy/simulation/helpers/event_calling.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@ def build_event_kwargs(
3030
3131
Parameters
3232
----------
33+
flight : Flight
34+
Flight instance whose rocket, environment and sensors are exposed.
35+
time : float
36+
Current simulation time.
37+
state : array_like
38+
Current flight state vector.
39+
step_size : float
40+
Size of the current integration step.
41+
phase : FlightPhase
42+
Active flight phase, providing the state derivative.
43+
rollback : bool, optional
44+
Whether this call happens during a rollback; shifts the state-history
45+
window by one extra step. Defaults to False.
3346
needs : frozenset of str, optional
3447
Union of ``Event.needs`` across all events that will consume the
3548
returned dict. Only keys present in ``needs`` are computed for the
3649
expensive values: ``state_dot``, ``pressure``, ``state_history``.
3750
Defaults to empty (compute nothing expensive).
51+
52+
Returns
53+
-------
54+
dict
55+
Keyword arguments consumed by event triggers and callbacks.
3856
"""
3957
kwargs = {
4058
"time": time,
@@ -72,10 +90,25 @@ def update_overshootable_event_kwargs(
7290
7391
Parameters
7492
----------
93+
flight : Flight
94+
Flight instance whose environment is used to recompute derived values.
95+
phase : FlightPhase
96+
Active flight phase, providing the state derivative.
97+
event_kwargs : dict
98+
Kwargs dict (from :func:`build_event_kwargs`) updated in place.
99+
interpolated_time : float
100+
Interpolated time of the overshootable node.
101+
interpolated_state : array_like
102+
Interpolated flight state at the node.
75103
needs : frozenset of str, optional
76104
Union of ``Event.needs`` across all overshootable events at this node.
77105
Expensive values are skipped when absent from ``needs``. Defaults to
78106
empty (compute nothing expensive).
107+
108+
Returns
109+
-------
110+
dict
111+
The updated ``event_kwargs``.
79112
"""
80113
event_kwargs["time"] = interpolated_time
81114
event_kwargs["state"] = interpolated_state

rocketpy/simulation/helpers/event_commands.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def apply_event_commands(
2828
Index of the current flight phase.
2929
node_index : int
3030
Index of the current time node.
31+
command_time : float
32+
Simulation time used to apply the commands when the event does not
33+
provide an exact time.
3134
3235
Returns
3336
-------
@@ -70,10 +73,6 @@ def apply_rollback_command(flight, time, state):
7073
----------
7174
flight : Flight
7275
Flight instance being updated.
73-
event_results : dict
74-
Result payload returned by the event system.
75-
phase : _FlightPhase
76-
Current flight phase.
7776
time : float
7877
Interpolated simulation time to restore.
7978
state : array_like
@@ -94,6 +93,8 @@ def apply_disable_commands(_, event_results, node_index, event, phase, time):
9493
9594
Parameters
9695
----------
96+
_ : Flight
97+
Flight instance (unused; accepted for a uniform command signature).
9798
event_results : dict
9899
Result payload returned by the event system.
99100
node_index : int
@@ -102,6 +103,8 @@ def apply_disable_commands(_, event_results, node_index, event, phase, time):
102103
Event currently being processed.
103104
phase : _FlightPhase
104105
Current flight phase.
106+
time : float
107+
Simulation time at which the events are disabled.
105108
106109
Returns
107110
-------
@@ -144,6 +147,8 @@ def apply_enable_commands(flight, event_results, node_index, event, phase, time)
144147
145148
Parameters
146149
----------
150+
flight : Flight
151+
Flight instance being updated.
147152
event_results : dict
148153
Result payload returned by the event system.
149154
node_index : int
@@ -152,6 +157,8 @@ def apply_enable_commands(flight, event_results, node_index, event, phase, time)
152157
Event currently being processed.
153158
phase : _FlightPhase
154159
Current flight phase.
160+
time : float
161+
Simulation time at which the events are enabled.
155162
156163
Returns
157164
-------
@@ -260,6 +267,8 @@ def apply_new_phase_or_derivative(
260267
Index of the current flight phase.
261268
node_index : int
262269
Index of the current time node.
270+
time : float
271+
Simulation time at which the new phase or derivative takes effect.
263272
264273
Returns
265274
-------
@@ -317,6 +326,8 @@ def apply_termination(flight, event_results, phase, phase_index, node_index, tim
317326
Index of the current flight phase.
318327
node_index : int
319328
Index of the current time node.
329+
time : float
330+
Simulation time at which the flight is terminated.
320331
321332
Returns
322333
-------
@@ -358,12 +369,10 @@ def apply_event_list_updates(flight, event_results, phase, time):
358369
Flight instance being updated.
359370
event_results : dict
360371
Result payload returned by the event system.
361-
node_index : int
362-
Index of the current time node.
363-
event : Event
364-
Event currently being processed.
365372
phase : _FlightPhase
366373
Current flight phase.
374+
time : float
375+
Simulation time at which the new events are scheduled.
367376
368377
Returns
369378
-------

rocketpy/simulation/helpers/flight_phase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def add_phase(
276276
name : str, optional
277277
A descriptive name to identify the phase in logs and
278278
debug output. Default is None.
279+
**kwargs
280+
Additional keyword arguments forwarded to the ``_FlightPhase``
281+
constructor (e.g. ``parachute``).
279282
280283
Returns
281284
-------

0 commit comments

Comments
 (0)