Flight Metrics Extraction of Starship IFT-2 and IFT-3 Using Artificial Intelligence with Python

April 21, 2024

Introduction

Recently, while following the launch of the Starchip IFT-3, I became interested in the performance and behavior of this spacecraft during its flight. Taking SpaceX's live broadcast data as a basis, I decided to create a program to extract the flight metrics of the spacecraft using Python. This project will allow displaying flight data.

Necessary Tools and Technologies

For this project, the following Python libraries were used:

  • csv: To store the collected data in .csv files for later analysis.
  • json: It is necessary to load a .json file containing information about the video and the regions to be analyzed.
  • progressbar: To display a progress bar of the video analysis.
  • cv2: It is used to extract frames from the video for data extraction.
  • easyocr: It is used for text extraction from images.

Video Data Extraction Process

The code can be found in its repository https://github.com/105-Code/spacex-launch-data.

To run the program, it is necessary to download the video to be analyzed and place it in the videos folder. The higher the video resolution, the better.

Within this videos folder, you have to modify the metadata.json file. This file is read by extractor.py to know about the videos, times, and regions of the video to be analyzed. The structure of the JSON object is as follows:

{
    // Video identifier, can be anything
    "id":"itf-3", 
    // Video path
    "path": "videos/IFT-3.webm",
    // Data collection every x number of frames
    "recolection_rate":15, 
    // Seconds of the video when takeoff starts
    "booster_start": 52, 
    // Seconds of the video when the booster lands
    "booster_end": 463,
    // Seconds of the video when the starship starts
    "starship_start": 220, 
    // Seconds of the video when the starchip lands
    "starship_end": 568, 
    // Video region in pixels where the starship engine data is located
    "starship_engine_pos": {
        "x": 1742,
        "y": 912,
        "width": 160,
        "height": 150
    },
    // Other regions...
}

Once the video is downloaded and the metadata.json file is configured, it is only necessary to run the program with python extractor.py.

The program will start processing the video and when it finishes, it will leave the data in the outputs folder.

Extracted Data

The extracted files are stored in the output folder and have the following structure:

time seconds altitude speed
00:00:03 5.5 0 13
00:00:03 6.0 0 17

Data explanation:

  • time: shows the time in hour:minutes:seconds format.
  • seconds: shows the capture time in seconds.
  • altitude: shows the altitude in kilometers.
  • speed: shows the speed in km/h.

You can find the extracted data in the repository in the history folder. They are divided by spacecraft and booster.

Charts

I had the opportunity to create some simple charts based on the extracted data.

Booster Acceleration

Booster acceleration

The first chart would show the acceleration the booster had during its flight. On the X-axis, we have the flight seconds, and on the Y-axis, the acceleration given in m/s.

Booster Speed and Altitude

Booster acceleration

The second chart would show the speed and altitude the booster had during its flight. On the X-axis, we have the kilometers of altitude reached, and on the Y-axis, the speed in km/h.

Conclusions

Through the Python, CSV, JSON, and OpenCV libraries, we were able to automate the collection of flight metrics during the launch.

By following this process, we were able to obtain precise data on altitude, speed, and other key flight parameters. These data, presented in CSV files and visualized in charts, provide us with a clear picture of the booster and starship's performance throughout their flight.

Furthermore, by sharing the code and results in the GitHub repository, I hope to inspire others to explore and analyze video data easily.

Ultimately, I hope to continue working on and refining video data extraction with Python. Since some failures have occurred in the collection process, I also wish to implement a function to detect the number of engines ignited.