STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
csv_to_eng.core Namespace Reference

Classes

Functions

Tuple[int, int, Dict[str, int]] _detect_column_indices (List[str] headers)
Tuple[Optional[str], Optional[str]] _detect_units_from_header (str header)
bool _is_comment_line (str line)
Optional[float] _parse_numeric (str value)
Tuple[EngineMetadata, CurvePoints] read_csv_curve (Union[str, Path] path, Optional[str] time_units=None, Optional[str] thrust_units=None)
CurvePoints normalize_curve (CurvePoints points, int time_decimals=3, int thrust_decimals=1)
None write_eng (Union[str, Path] path, EngineMetadata metadata, CurvePoints points, int time_decimals=3, int thrust_decimals=1, bool include_comment=True)
None convert (Union[str, Path] csv_path, Union[str, Path] eng_path, Optional[str] name=None, Optional[float] diameter_mm=None, Optional[float] length_mm=None, Optional[str] delays=None, Optional[float] prop_mass_kg=None, Optional[float] total_mass_kg=None, Optional[str] manufacturer=None, Optional[str] time_units=None, Optional[str] thrust_units=None, int time_decimals=3, int thrust_decimals=1)

Variables

float LBF_TO_N = 4.4482216152605
float MS_TO_S = 0.001
dict TIME_COLUMNS = {"time", "t", "seconds", "time_s", "time_ms"}
dict THRUST_COLUMNS = {"thrust", "f", "force", "thrust_n", "thrust_lbf"}
dict METADATA_COLUMNS
 CurvePoints = List[Tuple[float, float]]

Detailed Description

Core functionality for CSV to .eng conversion.

Function Documentation

◆ _detect_column_indices()

Tuple[int, int, Dict[str, int]] csv_to_eng.core._detect_column_indices ( List[str] headers)
protected
Detect time and thrust column indices from headers.

Returns:
    (time_idx, thrust_idx, metadata_col_indices)

Raises:
    ValueError: If time or thrust columns cannot be identified.

Definition at line 77 of file core.py.

Referenced by read_csv_curve().

◆ _detect_units_from_header()

Tuple[Optional[str], Optional[str]] csv_to_eng.core._detect_units_from_header ( str header)
protected
Detect units from column header suffix.

Returns:
    (time_unit, thrust_unit) - None if not detected

Definition at line 135 of file core.py.

Referenced by read_csv_curve().

◆ _is_comment_line()

bool csv_to_eng.core._is_comment_line ( str line)
protected
Check if a line is a comment.

Definition at line 159 of file core.py.

Referenced by read_csv_curve().

◆ _parse_numeric()

Optional[float] csv_to_eng.core._parse_numeric ( str value)
protected
Parse a string to float, returning None on failure.

Definition at line 165 of file core.py.

Referenced by read_csv_curve().

◆ convert()

None csv_to_eng.core.convert ( Union[str, Path] csv_path,
Union[str, Path] eng_path,
Optional[str] name = None,
Optional[float] diameter_mm = None,
Optional[float] length_mm = None,
Optional[str] delays = None,
Optional[float] prop_mass_kg = None,
Optional[float] total_mass_kg = None,
Optional[str] manufacturer = None,
Optional[str] time_units = None,
Optional[str] thrust_units = None,
int time_decimals = 3,
int thrust_decimals = 1 )
Convert a CSV thrust curve file to RASP .eng format.

This is the high-level convenience function that combines read, normalize,
and write operations.

Args:
    csv_path: Input CSV file path.
    eng_path: Output .eng file path.
    name: Engine name override.
    diameter_mm: Engine diameter in mm override.
    length_mm: Engine length in mm override.
    delays: Delay charges string override.
    prop_mass_kg: Propellant mass in kg override.
    total_mass_kg: Total loaded mass in kg override.
    manufacturer: Manufacturer name override.
    time_units: Force time units ("s" or "ms").
    thrust_units: Force thrust units ("N" or "lbf").
    time_decimals: Decimal places for time (default 3).
    thrust_decimals: Decimal places for thrust (default 1).

Definition at line 389 of file core.py.

References normalize_curve(), read_csv_curve(), and write_eng().

◆ normalize_curve()

CurvePoints csv_to_eng.core.normalize_curve ( CurvePoints points,
int time_decimals = 3,
int thrust_decimals = 1 )
Normalize thrust curve data.

Operations:
1. Sort by time (ascending)
2. Remove duplicate time entries (keep last value for each time)
3. Ensure curve starts at t=0 (insert if missing)
4. Ensure curve ends with thrust=0 at burnout (append if needed)
5. Round values to specified decimal places

Args:
    points: List of (time_s, thrust_N) tuples.
    time_decimals: Decimal places for time (default 3).
    thrust_decimals: Decimal places for thrust (default 1).

Returns:
    Normalized list of (time_s, thrust_N) tuples.

Definition at line 295 of file core.py.

Referenced by convert().

◆ read_csv_curve()

Tuple[EngineMetadata, CurvePoints] csv_to_eng.core.read_csv_curve ( Union[str, Path] path,
Optional[str] time_units = None,
Optional[str] thrust_units = None )
Read a CSV file containing thrust curve data.

Args:
    path: Path to the CSV file.
    time_units: Force time units ("s" or "ms"). Auto-detected if None.
    thrust_units: Force thrust units ("N" or "lbf"). Auto-detected if None.

Returns:
    Tuple of (EngineMetadata, list of (time_s, thrust_N) tuples)

Raises:
    FileNotFoundError: If file doesn't exist.
    ValueError: If CSV format is invalid.

Definition at line 173 of file core.py.

References _detect_column_indices(), _detect_units_from_header(), _is_comment_line(), _parse_numeric(), and max.

Referenced by convert().

◆ write_eng()

None csv_to_eng.core.write_eng ( Union[str, Path] path,
EngineMetadata metadata,
CurvePoints points,
int time_decimals = 3,
int thrust_decimals = 1,
bool include_comment = True )
Write thrust curve data to a RASP .eng file.

Args:
    path: Output file path.
    metadata: Engine metadata for header line.
    points: List of (time_s, thrust_N) tuples.
    time_decimals: Decimal places for time output (default 3).
    thrust_decimals: Decimal places for thrust output (default 1).
    include_comment: Include generator comment at top (default True).

Definition at line 349 of file core.py.

Referenced by convert().

Variable Documentation

◆ CurvePoints

csv_to_eng.core.CurvePoints = List[Tuple[float, float]]

Definition at line 74 of file core.py.

◆ LBF_TO_N

float csv_to_eng.core.LBF_TO_N = 4.4482216152605

Definition at line 14 of file core.py.

◆ METADATA_COLUMNS

dict csv_to_eng.core.METADATA_COLUMNS
Initial value:
1= {
2 "engine_name": "name",
3 "name": "name",
4 "motor_name": "name",
5 "diameter_mm": "diameter_mm",
6 "diameter": "diameter_mm",
7 "diam": "diameter_mm",
8 "length_mm": "length_mm",
9 "length": "length_mm",
10 "len": "length_mm",
11 "prop_mass_kg": "prop_mass_kg",
12 "propellant_mass": "prop_mass_kg",
13 "prop_mass": "prop_mass_kg",
14 "total_mass_kg": "total_mass_kg",
15 "total_mass": "total_mass_kg",
16 "mass": "total_mass_kg",
17 "manufacturer": "manufacturer",
18 "mfr": "manufacturer",
19 "mfg": "manufacturer",
20 "delays": "delays",
21 "delay": "delays",
22}

Definition at line 22 of file core.py.

◆ MS_TO_S

float csv_to_eng.core.MS_TO_S = 0.001

Definition at line 15 of file core.py.

◆ THRUST_COLUMNS

dict csv_to_eng.core.THRUST_COLUMNS = {"thrust", "f", "force", "thrust_n", "thrust_lbf"}

Definition at line 19 of file core.py.

◆ TIME_COLUMNS

dict csv_to_eng.core.TIME_COLUMNS = {"time", "t", "seconds", "time_s", "time_ms"}

Definition at line 18 of file core.py.