Skip to content

Commit

Permalink
ENH: completely private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Mar 31, 2024
1 parent fa8a892 commit 29bb5fa
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def set_inputs(self, inputs):
-------
self : Function
"""
self.__inputs__ = self._validate_inputs(inputs)
self.__inputs__ = self.__validate_inputs(inputs)
return self

def set_outputs(self, outputs):
Expand All @@ -162,7 +162,7 @@ def set_outputs(self, outputs):
-------
self : Function
"""
self.__outputs__ = self._validate_outputs(outputs)
self.__outputs__ = self.__validate_outputs(outputs)
return self

def set_source(self, source):
Expand Down Expand Up @@ -211,7 +211,7 @@ def set_source(self, source):
self : Function
Returns the Function instance.
"""
source = self._validate_source(source)
source = self.__validate_source(source)

# Handle callable source or number source
if callable(source):
Expand Down Expand Up @@ -247,15 +247,15 @@ def set_source(self, source):
self.x_initial, self.x_final = self.x_array[0], self.x_array[-1]
self.y_array = source[:, 1]
self.y_initial, self.y_final = self.y_array[0], self.y_array[-1]
self.get_value_opt = self._get_value_opt_1d
self.get_value_opt = self.__get_value_opt_1d
elif self.__dom_dim__ > 1:
self.x_array = source[:, 0]
self.x_initial, self.x_final = self.x_array[0], self.x_array[-1]
self.y_array = source[:, 1]
self.y_initial, self.y_final = self.y_array[0], self.y_array[-1]
self.z_array = source[:, 2]
self.z_initial, self.z_final = self.z_array[0], self.z_array[-1]
self.get_value_opt = self._get_value_opt_nd
self.get_value_opt = self.__get_value_opt_nd

self.source = source
self.set_interpolation(self.__interpolation__)
Expand Down Expand Up @@ -300,12 +300,12 @@ def set_interpolation(self, method="spline"):
self : Function
"""
if not callable(self.source):
self.__interpolation__ = self._validate_interpolation(method)
self._update_interpolation_coefficients(self.__interpolation__)
self._set_interpolation_func()
self.__interpolation__ = self.__validate_interpolation(method)
self.__update_interpolation_coefficients(self.__interpolation__)
self.__set_interpolation_func()
return self

def _update_interpolation_coefficients(self, method):
def __update_interpolation_coefficients(self, method):
"""Update interpolation coefficients for the given method."""
# Spline, akima and polynomial need data processing
# Shepard, and linear do not
Expand Down Expand Up @@ -339,11 +339,11 @@ def set_extrapolation(self, method="constant"):
The Function object.
"""
if not callable(self.source):
self.__extrapolation__ = self._validate_extrapolation(method)
self._set_extrapolation_func()
self.__extrapolation__ = self.__validate_extrapolation(method)
self.__set_extrapolation_func()
return self

def _set_interpolation_func(self):
def __set_interpolation_func(self):
"""Defines interpolation function used by the Function. Each
interpolation method has its own function with exception of shepard,
which has its interpolation/extrapolation function defined in
Expand Down Expand Up @@ -393,7 +393,7 @@ def spline_interpolation(x, x_min, x_max, x_data, y_data, coeffs):
elif interpolation == 4: # shepard does not use interpolation function
self._interpolation_func = None

def _set_extrapolation_func(self):
def __set_extrapolation_func(self):
"""Defines extrapolation function used by the Function. Each
extrapolation method has its own function. The function is stored in
the attribute _extrapolation_func."""
Expand Down Expand Up @@ -460,12 +460,12 @@ def set_get_value_opt(self):
if callable(self.source):
self.get_value_opt = self.source
elif self.__dom_dim__ == 1:
self.get_value_opt = self._get_value_opt_1d
self.get_value_opt = self.__get_value_opt_1d
elif self.__dom_dim__ > 1:
self.get_value_opt = self._get_value_opt_nd
self.get_value_opt = self.__get_value_opt_nd
return self

Check warning on line 466 in rocketpy/mathutils/function.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/mathutils/function.py#L460-L466

Added lines #L460 - L466 were not covered by tests

def _get_value_opt_1d(self, x):
def __get_value_opt_1d(self, x):
"""Evaluate the Function at a single point x. This method is used
when the Function is 1-D.
Expand All @@ -490,7 +490,7 @@ def _get_value_opt_1d(self, x):
y = self._extrapolation_func(x, x_min, x_max, x_data, y_data, coeffs)
return y

def _get_value_opt_nd(self, *args):
def __get_value_opt_nd(self, *args):
"""Evaluate the Function at a single point (x, y, z). This method is
used when the Function is N-D."""
# always use shepard for N-D functions
Expand Down Expand Up @@ -2883,7 +2883,7 @@ def savetxt(
np.savetxt(file, data_points, fmt=fmt, delimiter=delimiter, newline=newline)

# Input validators
def _validate_source(self, source):
def __validate_source(self, source):
"""Used to validate the source parameter for creating a Function object.
Parameters
Expand Down Expand Up @@ -2951,7 +2951,7 @@ def source_function(_):
# If source is a callable function
return source

def _validate_inputs(self, inputs):
def __validate_inputs(self, inputs):
"""Used to validate the inputs parameter for creating a Function object.
It sets a default value if it is not provided.
Expand Down Expand Up @@ -2990,7 +2990,7 @@ def _validate_inputs(self, inputs):
"the length of the domain dimension."
)

def _validate_outputs(self, outputs):
def __validate_outputs(self, outputs):
"""Used to validate the outputs parameter for creating a Function object.
It sets a default value if it is not provided.
Expand All @@ -3016,7 +3016,7 @@ def _validate_outputs(self, outputs):
)
return outputs

def _validate_interpolation(self, interpolation):
def __validate_interpolation(self, interpolation):
if self.__dom_dim__ == 1:
# possible interpolation values: linear, polynomial, akima and spline
if interpolation is None:
Expand Down Expand Up @@ -3044,7 +3044,7 @@ def _validate_interpolation(self, interpolation):
interpolation = "shepard"
return interpolation

def _validate_extrapolation(self, extrapolation):
def __validate_extrapolation(self, extrapolation):
if self.__dom_dim__ == 1:
if extrapolation is None:
extrapolation = "constant"
Expand Down

0 comments on commit 29bb5fa

Please sign in to comment.