@@ -117,11 +117,6 @@ def tuple_handler(value):
117117 raise ValueError ("value must be a list or tuple of length 1 or 2." )
118118
119119
120- def _get_function_class ():
121- """Return ``Function`` using lazy import to avoid cyclic imports."""
122- return importlib .import_module ("rocketpy.mathutils.function" ).Function
123-
124-
125120def create_regular_grid_function (
126121 csv_source ,
127122 variable_names ,
@@ -147,44 +142,13 @@ def create_regular_grid_function(
147142 A ``Function`` configured with ``regular_grid`` interpolation when the
148143 CSV data forms a strict Cartesian grid, otherwise ``None``.
149144 """
150- function_class = _get_function_class ()
151-
152- data = np .loadtxt (csv_source , delimiter = "," , skiprows = 1 , dtype = float )
153-
154- data = np .atleast_2d (data )
155- expected_columns = len (variable_names ) + 1
156- if data .shape [1 ] != expected_columns :
157- return None
158-
159- coordinates = data [:, :- 1 ]
160- values = data [:, - 1 ]
145+ from rocketpy .mathutils .function import Function
161146
162- if np .unique (coordinates , axis = 0 ).shape [0 ] != coordinates .shape [0 ]:
163- return None
164-
165- axes = [np .unique (coordinates [:, i ]) for i in range (len (variable_names ))]
166- expected_size = int (np .prod ([axis .size for axis in axes ]))
167- if expected_size != coordinates .shape [0 ]:
168- return None
169-
170- sorting_keys = [coordinates [:, i ] for i in range (len (variable_names ) - 1 , - 1 , - 1 )]
171- sorted_indices = np .lexsort (tuple (sorting_keys ))
172- sorted_coordinates = coordinates [sorted_indices ]
173- sorted_values = values [sorted_indices ]
174-
175- expected_coordinates = np .column_stack (
176- [axis_values .ravel () for axis_values in np .meshgrid (* axes , indexing = "ij" )]
177- )
178- if not np .allclose (sorted_coordinates , expected_coordinates , rtol = 0 , atol = 1e-12 ):
179- return None
180-
181- grid_data = sorted_values .reshape (tuple (axis .size for axis in axes ))
182- return function_class (
183- (axes , grid_data ),
184- inputs = variable_names ,
185- outputs = [coeff_name ],
186- interpolation = "regular_grid" ,
187- extrapolation = extrapolation ,
147+ return Function .from_regular_grid_csv (
148+ csv_source ,
149+ variable_names ,
150+ coeff_name ,
151+ extrapolation ,
188152 )
189153
190154
@@ -195,7 +159,7 @@ def load_generic_surface_csv(file_path, coeff_name): # pylint: disable=too-many
195159 variables among: alpha, beta, mach, reynolds, pitch_rate, yaw_rate,
196160 roll_rate.
197161 """
198- function_class = _get_function_class ()
162+ from rocketpy . mathutils . function import Function
199163
200164 independent_vars = [
201165 "alpha" ,
@@ -247,7 +211,7 @@ def load_generic_surface_csv(file_path, coeff_name): # pylint: disable=too-many
247211 extrapolation = "natural" ,
248212 )
249213 if csv_func is None :
250- csv_func = function_class (
214+ csv_func = Function (
251215 file_path ,
252216 interpolation = "linear" ,
253217 extrapolation = "natural" ,
@@ -266,7 +230,7 @@ def wrapper(alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate):
266230 selected_args = [args_by_name [col ] for col in ordered_present_columns ]
267231 return csv_func (* selected_args )
268232
269- return function_class (
233+ return Function (
270234 wrapper ,
271235 independent_vars ,
272236 [coeff_name ],
@@ -281,7 +245,7 @@ def load_rocket_drag_csv(file_path, coeff_name): # pylint: disable=too-many-sta
281245 Supports either headerless two-column (mach, coefficient) tables or
282246 header-based multi-variable CSV tables.
283247 """
284- function_class = _get_function_class ()
248+ from rocketpy . mathutils . function import Function
285249
286250 independent_vars = [
287251 "alpha" ,
@@ -321,7 +285,7 @@ def _is_numeric(value):
321285 )
322286
323287 if is_headerless_two_column :
324- csv_func = function_class (
288+ csv_func = Function (
325289 file_path ,
326290 interpolation = "linear" ,
327291 extrapolation = "constant" ,
@@ -338,7 +302,7 @@ def mach_wrapper(
338302 ):
339303 return csv_func (mach )
340304
341- return function_class (
305+ return Function (
342306 mach_wrapper ,
343307 independent_vars ,
344308 [coeff_name ],
@@ -374,7 +338,7 @@ def mach_wrapper(
374338 extrapolation = "constant" ,
375339 )
376340 if csv_func is None :
377- csv_func = function_class (
341+ csv_func = Function (
378342 file_path ,
379343 interpolation = "linear" ,
380344 extrapolation = "constant" ,
@@ -393,7 +357,7 @@ def wrapper(alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate):
393357 selected_args = [args_by_name [col ] for col in ordered_present_columns ]
394358 return csv_func (* selected_args )
395359
396- return function_class (
360+ return Function (
397361 wrapper ,
398362 independent_vars ,
399363 [coeff_name ],
0 commit comments