Skip to content

Commit 42fb8b1

Browse files
committed
DOC: improve doc strings for Function.reset method
1 parent 61a5a12 commit 42fb8b1

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

rocketpy/Function.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -528,27 +528,45 @@ def reset(
528528
interpolation=None,
529529
extrapolation=None,
530530
):
531-
"""This method resets the Function object to its initial state, with the
532-
possibility of resetting all of its initialization arguments besides the
533-
source.
531+
"""This method allows the user to reset the inputs, outputs, interpolation
532+
and extrapolation settings of a Function object, all at once, without
533+
having to call each of the corresponding methods.
534534
535535
Parameters
536536
----------
537537
inputs : string, sequence of strings, optional
538538
List of input variable names. If None, the original inputs are kept.
539+
See Function.setInputs for more information.
539540
outputs : string, sequence of strings, optional
540541
List of output variable names. If None, the original outputs are kept.
542+
See Function.setOutputs for more information.
541543
interpolation : string, optional
542544
Interpolation method to be used if source type is ndarray.
543-
For 1-D functions, linear, polynomial, akima and spline is
544-
supported. For N-D functions, only shepard is supported.
545-
If None, the original interpolation method is kept.
545+
See Function.setInterpolation for more information.
546546
extrapolation : string, optional
547547
Extrapolation method to be used if source type is ndarray.
548-
Options are 'natural', which keeps interpolation, 'constant',
549-
which returns the value of the function at the edge of the interval,
550-
and 'zero', which returns zero for all points outside of source
551-
range. If None, the original extrapolation method is kept.
548+
See Function.setExtrapolation for more information.
549+
550+
Examples
551+
--------
552+
A simple use case is to reset the inputs and outputs of a Function object
553+
that has been defined by algebraic manipulation of other Function objects.
554+
555+
>>> from rocketpy import Function
556+
>>> v = Function(lambda t: t**2, inputs='t', outputs='v')
557+
>>> mass = 10 # Mass
558+
>>> kinetic_energy = mass * v**2 / 2
559+
>>> v.getInputs(), v.getOutputs()
560+
(['t'], ['v'])
561+
>>> kinetic_energy.getInputs(), kinetic_energy.getOutputs()
562+
(['x'], ['Scalar'])
563+
>>> kinetic_energy.reset(inputs='t', outputs='Kinetic Energy')
564+
>>> kinetic_energy.getInputs(), kinetic_energy.getOutputs()
565+
(['t'], ['Kinetic Energy'])
566+
567+
Returns
568+
-------
569+
self : Function
552570
"""
553571
if inputs is not None:
554572
self.setInputs(inputs)
@@ -559,6 +577,8 @@ def reset(
559577
if extrapolation is not None and extrapolation != self.__extrapolation__:
560578
self.setExtrapolation(extrapolation)
561579

580+
return self
581+
562582
# Define all get methods
563583
def getInputs(self):
564584
"Return tuple of inputs of the function."

0 commit comments

Comments
 (0)