Skip to main content
from ram_idopt.aircraft.cost.LCC import (
    load_parameters,
    calculate_annual_costs,
    calculate_metrics,
    run_simulation,
    run_comparison,
    create_comparison_charts,
    print_comparison_table,
    AnnualCosts,
)

load_parameters

load_parameters(param_file: str) -> Dict[str, Any]
Reads an Excel workbook and returns a flat parameter dictionary plus lookup-table arrays.
param_file
str
required
Path to the Excel workbook. Must contain sheets named Parameters, Lookup_Crews, and Lookup_Speed.
Returns Dict[str, Any] — all scalar parameters from the Parameters sheet, plus:
KeyTypeDescription
crews_lookup_xnp.ndarrayFlight hours breakpoints for crew count interpolation
crews_lookup_ynp.ndarrayCrew count values at each breakpoint
speed_lookup_xnp.ndarrayStage length breakpoints for speed interpolation
speed_lookup_ynp.ndarrayAircraft speed (knots) at each breakpoint

calculate_annual_costs

calculate_annual_costs(params: Dict[str, Any]) -> AnnualCosts
Core computation. Derives all 40+ cost components from the parameter dictionary.
params
Dict[str, Any]
required
Parameter dictionary returned by load_parameters.
Returns an AnnualCosts dataclass with every field populated except the optional life cycle fields (time_series, cumulative_costs, Life_Cycle_Total_Cost, Revenue_CASM, Fare_per_Pax_NM).

run_simulation

run_simulation(params: Dict[str, Any]) -> Tuple[np.ndarray, np.ndarray, AnnualCosts]
Runs the ODE integration over the service life.
params
Dict[str, Any]
required
Parameter dictionary returned by load_parameters.
Returns a 3-tuple:
PositionTypeDescription
[0]np.ndarray shape (n,)Time points from 0 to Life_Cycle_Time
[1]np.ndarray shape (10, n)State matrix — rows are the 10 cumulative cost channels
[2]AnnualCostsAnnual cost breakdown (same as calculate_annual_costs)
State row index mapping:
RowChannel
0Cumulative amortization
1Cumulative total costs
2Cumulative fixed costs
3Reserved
4Reserved
5Cumulative personnel costs
6Cumulative training costs
7Cumulative variable costs
8Total hours flown
9Cumulative landing fees

calculate_metrics

calculate_metrics(params: Dict[str, Any]) -> AnnualCosts
High-level function that runs the full pipeline — annual costs, simulation, and revenue metrics — and returns a single enriched AnnualCosts object.
params
Dict[str, Any]
required
Parameter dictionary returned by load_parameters.
Returns AnnualCosts with all optional fields populated:
FieldDescription
time_seriesTime array from ODE integration
cumulative_costsCumulative total cost array
Life_Cycle_Total_CostFinal cumulative cost (scalar)
Revenue_CASMCost per available seat-nautical mile
Fare_per_Pax_NMRequired fare per passenger-nautical mile

run_comparison

run_comparison(file_list: List[str]) -> Tuple[pd.DataFrame, Dict[str, AnnualCosts]]
Processes multiple Excel files and assembles a comparison matrix.
file_list
List[str]
required
List of paths to Excel workbooks. Each file is processed independently — errors are caught and printed without stopping the run.
Returns a 2-tuple:
PositionTypeDescription
[0]pd.DataFrameSummary table, one row per aircraft
[1]Dict[str, AnnualCosts]Full results keyed by aircraft display name
DataFrame columns: Aircraft, Revenue_CASM, Fare_per_Pax_NM, Total_Annual_Costs, Life_Cycle_Total_Cost, Annual_Fixed_Costs, Annual_Variable_Costs, Aircraft_Purchase_Price, Variable_Cost_per_Hour, Aircraft_Speed, Pilots_per_Aircraft, PAX_Seats
print_comparison_table(df: pd.DataFrame) -> None
Prints a formatted ASCII table to stdout, rows sorted by Revenue_CASM ascending.
df
pd.DataFrame
required
DataFrame returned by run_comparison.

create_comparison_charts

create_comparison_charts(
    df: pd.DataFrame,
    full_results: Dict[str, AnnualCosts],
    output_dir: Path
) -> None
Saves three PNG files to output_dir.
df
pd.DataFrame
required
Summary DataFrame from run_comparison.
full_results
Dict[str, AnnualCosts]
required
Full results dict from run_comparison, used to access time series for the cumulative cost chart.
output_dir
Path
required
Directory where PNGs are written. Must already exist.
Output files:
FileContent
aircraft_comparison.pngSide-by-side horizontal bar charts: Revenue CASM (left) and Fare per Pax-NM (right), sorted ascending, coloured with the viridis gradient
cumulative_costs.pngLine plot of cumulative cost in millions USD over the service life, one line per aircraft
cost_breakdown_pies.pngGrid of pie charts — one per aircraft — showing the proportion of amortization, depreciation, insurance, personnel, training, facilities, fuel, maintenance, and other variable costs

extract_aircraft_name

extract_aircraft_name(filename: str) -> str
Parses a clean display name from an Excel filename.
filename
str
required
File path or name, e.g. Joby_S4_Cost_Model_1500hrs.xlsx.
Returns str — strips _Cost_Model_<hours>hrs, replaces underscores with spaces. Example: "Joby S4".

AnnualCosts dataclass

All monetary values are in USD. All rate values are per flight hour unless noted.

Derived flight parameters

FieldTypeDescription
Pilots_per_AircraftfloatNumber of pilots (crew count × pilots per crew)
Aircraft_SpeedfloatAverage cruise speed, knots
Flight_Time_HoursfloatHours per mission stage
Flights_per_HrfloatFrequency of flights per hour

Acquisition

FieldTypeDescription
Automation_CostfloatAutonomous systems premium (0 if crewed)
Aircraft_Purchase_PricefloatBaseline cost + automation cost
Resale_ValuefloatEstimated residual value

Annual fixed costs

FieldTypeDescription
Annual_AmortizationfloatAnnual loan repayment
Annual_DepreciationfloatStraight-line depreciation
Landing_Site_Annual_SupportfloatVertiport support fees
Hull_InsurancefloatHull damage insurance
Liability_InsurancefloatThird-party liability insurance
Maintenance_SoftwarefloatSoftware subscriptions
Miscellaneous_ServicefloatMiscellaneous service costs
Property_TaxfloatAnnual property tax
Hangar_and_Office_ExpensesfloatFacility and office lease
Pilots_SalariesfloatTotal pilot compensation
Staff_SalariesfloatTotal staff compensation
Personnel_BenefitsfloatBenefits on pilot salaries
Annual_Personnel_CostsfloatSum of all personnel costs
Annual_Training_CostfloatPilot and maintenance training
Annual_Fixed_CostsfloatSum of all fixed costs

Variable costs (per flight hour)

FieldTypeDescription
Maintenance_Hours_per_Flight_HourfloatMaintenance labour hours
Fuel_Burn_per_HourfloatGallons per flight hour
Fuel_Cost_per_HourfloatFuel cost per flight hour
Maintenance_Labor_per_HourfloatMaintenance labour cost
Schedule_Parts_per_HourfloatScheduled parts allowance
Midlife_Inspection_per_HourfloatMid-life inspection reserve
Propeller_Allowance_per_HourfloatPropeller maintenance reserve
Engine_Overhaul_per_HourfloatEngine overhaul amortised
Modernisation_per_HourfloatAvionics/systems upgrade reserve
Paint_per_HourfloatPaint maintenance reserve
Refurbishing_per_HourfloatInterior refurbishment reserve
Battery_per_HourfloatBattery pack replacement reserve
Miscellaneous_Trip_Expenses_per_HourfloatConsumables and trip costs
Landing_Fees_per_HourfloatLanding and handling fees
Total_Variable_Cost_per_HourfloatSum of all variable costs per hour
Annual_Variable_CostsfloatVariable costs × annual hours

Totals

FieldTypeDescription
Total_Annual_CostsfloatFixed + variable costs

Optional life cycle fields

Populated by calculate_metrics() and run_simulation().
FieldTypeDescription
time_seriesOptional[np.ndarray]Time points (years) from ODE
cumulative_costsOptional[np.ndarray]Cumulative total cost at each time point
Life_Cycle_Total_CostOptional[float]Total cost over service life
Revenue_CASMOptional[float]Cost per available seat-nm
Fare_per_Pax_NMOptional[float]Required fare per passenger-nm
PAX_SeatsOptional[float]Passenger seat count (copied from params)

Constants

NameValueDescription
mile_to_nm1.151Statute miles to nautical miles conversion