Source code for RCAIDE.Library.Mission.Common.Pre_Process.mass_properties_report

# RCAIDE/Library/Methods/Mission/Common/Pre_Process/mass_properties_report.py
# 
# ----------------------------------------------------------------------------------------------------------------------
#  Imports 
# ----------------------------------------------------------------------------------------------------------------------  
# RCAIDE imports 
import RCAIDE  

# python imports 
import os 
import sys
import pandas as pd 
# ----------------------------------------------------------------------------------------------------------------------
#  Helper Functions for Mass Properties Analysis
# ----------------------------------------------------------------------------------------------------------------------   



[docs] def write_mass_report(analyses): # ------------------------------------------------- # File name + location # ------------------------------------------------- excel_filename = os.path.join( os.path.dirname(os.path.abspath(sys.argv[0])), os.path.splitext(os.path.basename(sys.argv[0]))[0] + "_weight_breakdown.xlsx" ) # ------------------------------------------------- # Collect rows # ------------------------------------------------- rows = [] # Structural structural = analyses.vehicle.mass_properties.weight_breakdown.empty.get("structural", {}) for k, v in structural.items(): if k != "total": rows.append({"Section": "Structural", "Component": k.replace("_", " ").title(), "Weight (kg)": v}) if "total" in structural: rows.append({"Section": "Structural", "Component": "Total", "Weight (kg)": structural["total"]}) # Propulsion propulsion = analyses.vehicle.mass_properties.weight_breakdown.empty.get("propulsion", {}) for k, v in propulsion.items(): if k != "total": rows.append({"Section": "Propulsion", "Component": k.replace("_", " ").title(), "Weight (kg)": v}) if "total" in propulsion: rows.append({"Section": "Propulsion", "Component": "Total", "Weight (kg)": propulsion["total"]}) # Systems systems = analyses.vehicle.mass_properties.weight_breakdown.empty.get("systems", {}) for k, v in systems.items(): if k != "total": rows.append({"Section": "Systems", "Component": k.replace("_", " ").title(), "Weight (kg)": v}) if "total" in systems: rows.append({"Section": "Systems", "Component": "Total", "Weight (kg)": systems["total"]}) # Payload payload = analyses.vehicle.mass_properties.weight_breakdown.get("payload", {}) for k, v in payload.items(): if k != "total": rows.append({"Section": "Payload", "Component": k.replace("_", " ").title(), "Weight (kg)": v}) if "total" in payload: rows.append({"Section": "Payload", "Component": "Total", "Weight (kg)": payload["total"]}) # Operational Items ops = analyses.vehicle.mass_properties.weight_breakdown.get("operational_items", {}) for k, v in ops.items(): if k != "total": rows.append({"Section": "Operational Items", "Component": k.replace("_", " ").title(), "Weight (kg)": v}) if "total" in ops: rows.append({"Section": "Operational Items", "Component": "Total", "Weight (kg)": ops["total"]}) # ------------------------------------------------- # Summary # ------------------------------------------------- rows.extend([ {"Section": "Summary", "Component": "Operating Empty Weight", "Weight (kg)": analyses.vehicle.mass_properties.operating_empty}, {"Section": "Summary", "Component": "Payload Weight", "Weight (kg)": analyses.vehicle.mass_properties.payload}, {"Section": "Summary", "Component": "Fuel Weight", "Weight (kg)": analyses.vehicle.mass_properties.fuel}, {"Section": "Summary", "Component": "Zero Fuel Weight", "Weight (kg)": analyses.vehicle.mass_properties.weight_breakdown.get("zero_fuel_weight", 0)}, {"Section": "Summary", "Component": "Takeoff Weight", "Weight (kg)": analyses.vehicle.mass_properties.takeoff}, {"Section": "Summary", "Component": "Max Takeoff Weight", "Weight (kg)": analyses.vehicle.mass_properties.max_takeoff}, ]) # ------------------------------------------------- # Write Excel # ------------------------------------------------- df = pd.DataFrame(rows) with pd.ExcelWriter(excel_filename, engine="openpyxl") as writer: df.to_excel(writer, sheet_name="Weight Breakdown", index=False) print(f"Weight breakdown written to Excel:\n {excel_filename}") return excel_filename