Skip to content

Commit 68ff563

Browse files
committed
Merge branch 'enh/multi-variable-drag-fix' of https://github.com/RocketPy-Team/RocketPy into enh/multi-variable-drag-fix
2 parents 5707b85 + a80b41b commit 68ff563

2 files changed

Lines changed: 1 addition & 69 deletions

File tree

rocketpy/rocket/aero_surface/generic_surface.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -407,71 +407,6 @@ def __load_csv(self, file_path, coeff_name):
407407
columns can appear in any order. The last column must contain the
408408
coefficient values.
409409
"""
410-
411-
try:
412-
with open(file_path, mode="r") as file:
413-
reader = csv.reader(file)
414-
header = next(reader)
415-
except (FileNotFoundError, IOError) as e:
416-
raise ValueError(f"Error reading {coeff_name} CSV file: {e}") from e
417-
except StopIteration as e:
418-
raise ValueError(f"Invalid or empty CSV file for {coeff_name}.") from e
419-
420-
if not header:
421-
raise ValueError(f"Invalid or empty CSV file for {coeff_name}.")
422-
423-
# TODO make header strings flexible (e.g. 'alpha', 'Alpha', 'ALPHA')
424-
independent_vars = [
425-
"alpha",
426-
"beta",
427-
"mach",
428-
"reynolds",
429-
"pitch_rate",
430-
"yaw_rate",
431-
"roll_rate",
432-
]
433-
header = [column.strip() for column in header]
434-
present_columns = [col for col in independent_vars if col in header]
435-
436-
invalid_columns = [col for col in header[:-1] if col not in independent_vars]
437-
if invalid_columns:
438-
raise ValueError(
439-
f"Invalid independent variable(s) in {coeff_name} CSV: "
440-
f"{invalid_columns}. Valid options are: {independent_vars}."
441-
)
442-
443-
# Check that the last column is not an independent variable
444-
if header[-1] in independent_vars:
445-
raise ValueError(
446-
f"Last column in {coeff_name} CSV must be the coefficient"
447-
" value, not an independent variable."
448-
)
449-
450-
# Ensure that at least one independent variable is present
451-
if not present_columns:
452-
raise ValueError(f"No independent variables found in {coeff_name} CSV.")
453-
454-
# Build ordered variable names as they appear in the CSV header.
455-
# This guarantees argument order consistency with Function(file_path),
456-
# which interprets columns positionally.
457-
ordered_present_columns = [
458-
col for col in header[:-1] if col in independent_vars
459-
]
460-
461-
# Initialize the CSV-based function
462-
csv_func = create_regular_grid_function(
463-
file_path,
464-
ordered_present_columns,
465-
coeff_name,
466-
extrapolation="natural",
467-
)
468-
if csv_func is None:
469-
csv_func = Function(
470-
file_path,
471-
interpolation="linear",
472-
extrapolation="natural",
473-
)
474-
475410
# Generate a lambda that applies only the relevant arguments to csv_func
476411
def wrapper(alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate):
477412
args_by_name = {

rocketpy/tools.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ def create_regular_grid_function(
143143
"""
144144
from rocketpy.mathutils.function import Function
145145

146-
try:
147-
data = np.loadtxt(csv_source, delimiter=",", skiprows=1, dtype=float)
148-
except (OSError, ValueError):
149-
return None
146+
data = np.loadtxt(csv_source, delimiter=",", skiprows=1, dtype=float)
150147

151148
data = np.atleast_2d(data)
152149
expected_columns = len(variable_names) + 1

0 commit comments

Comments
 (0)