Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [main, develop]
branches: [main]
pull_request:
branches: [main]

Expand All @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout code
Expand All @@ -23,25 +23,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
cache: pip
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run tests with coverage
run: |
pytest --cov=rocket_sim --cov-report=xml --cov-report=term-missing
run: pytest --cov=rocket_sim --cov-report=xml --cov-report=term-missing

- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
Expand All @@ -58,22 +52,21 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
cache: pip
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff black isort

- name: Check formatting with Black
run: black --check src tests

- name: Check import sorting with isort
run: isort --check-only src tests
pip install -e ".[dev]"

- name: Lint with Ruff
- name: Ruff lint
run: ruff check src tests

- name: Ruff format check
run: ruff format --check src tests

type-check:
name: Type Check
runs-on: ubuntu-latest
Expand All @@ -85,7 +78,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
cache: pip
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: |
Expand All @@ -107,7 +102,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: Install build tools
run: |
Expand Down
26 changes: 2 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@ repos:
- id: detect-private-key
- id: debug-statements

# Python code formatting
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
language_version: python3

# Import sorting
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]

# Linting with Ruff
# Lint + format with Ruff (replaces black, isort, flake8, pyupgrade, etc.)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

# Type checking with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
Expand All @@ -49,15 +36,6 @@ repos:
args: [--ignore-missing-imports]
exclude: tests/

# Check for security issues
- repo: https://github.com/PyCQA/bandit
rev: 1.7.7
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
exclude: tests/

# Configuration
ci:
autofix_commit_msg: |
Expand Down
29 changes: 15 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-01-24
## [Unreleased]

### Planned

- Multi-stage rocket support
- Atmospheric drag integrated into trajectory simulation
- 3D trajectory visualization
- Real-time simulation mode
- Export to various data formats (CSV, JSON)
- Orbital insertion calculations

## [0.1.0]

First public release on PyPI.

### Added

Expand Down Expand Up @@ -73,7 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- pytest test suite with fixtures
- Pre-commit hooks configuration
- GitHub Actions CI/CD
- Black, isort, ruff for code quality
- Ruff for linting and formatting
- mypy for type checking

### Technical Details
Expand All @@ -83,15 +96,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- NumPy for numerical operations
- Modern Python packaging with pyproject.toml
- src-layout package structure

## [Unreleased]

### Planned

- Multi-stage rocket support
- Atmospheric drag simulation
- 3D trajectory visualization
- Real-time simulation mode
- Rocket builder GUI
- Export to various data formats (CSV, JSON)
- Orbital insertion calculations
20 changes: 9 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ Feature suggestions are welcome! Please open an issue with:
```
8. **Ensure code quality**:
```bash
black src tests
isort src tests
ruff check src tests
ruff check --fix src tests
ruff format src tests
mypy src
```
9. **Commit** with a clear message:
Expand Down Expand Up @@ -108,20 +107,19 @@ pytest -k "test_gravity"

This project uses:

- **Black** for code formatting
- **isort** for import sorting
- **Ruff** for linting
- **Ruff** for linting and formatting (replaces black, isort, flake8, pyupgrade)
- **mypy** for type checking

All of these run automatically via pre-commit hooks, but you can also run them manually:

```bash
# Format code
black src tests
isort src tests
# Lint and auto-fix
ruff check --fix src tests

# Check for issues
ruff check src tests
# Format
ruff format src tests

# Type check
mypy src
```

Expand Down
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
# Rocket Simulator

[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
[![PyPI](https://img.shields.io/pypi/v/rocket-sim.svg)](https://pypi.org/project/rocket-sim/)
[![Python](https://img.shields.io/pypi/pyversions/rocket-sim.svg)](https://pypi.org/project/rocket-sim/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Tests](https://img.shields.io/badge/tests-passing-brightgreen.svg)]()
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![CI](https://github.com/rramboer/rocket-sim/actions/workflows/ci.yml/badge.svg)](https://github.com/rramboer/rocket-sim/actions/workflows/ci.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

A physics-based rocket trajectory simulation library for Python. Simulate rocket launches with realistic gravitational physics, visualize trajectories, and compare real-world rockets.
A small, educational physics-based rocket trajectory simulation library for Python. Simulate vertical rocket launches with altitude-dependent gravity, visualize trajectories, and compare real-world rockets.

![Rocket Trajectory Simulation](docs/images/rocket_comparison.png)

## Features

- **Realistic Physics** - Altitude-dependent gravity using Newton's inverse-square law
- **Pre-configured Rockets** - 13 real-world rockets including Saturn V, Falcon 9, Starship, and more
- **Custom Rockets** - Create and simulate your own rocket designs
- **Beautiful Visualizations** - Publication-quality plots with multiple styling options
- **CLI & Library** - Use as a command-line tool or import as a Python library
- **Type-Safe** - Full type hints for excellent IDE support
- **Well-Tested** - Comprehensive test suite with pytest
- **Altitude-dependent gravity** using Newton's inverse-square law
- **13 pre-configured rockets** including Saturn V, Falcon 9, Starship, and more
- **Custom rockets** — create and simulate your own designs
- **Multiple celestial bodies** — Earth, Moon, and Mars, or roll your own
- **Plots** with multiple matplotlib styles (trajectory, velocity, dashboard, comparison)
- **CLI & library** — use as a command-line tool or import as a Python library
- **Type-safe** — full type hints throughout the public API
- **Well-tested** — pytest suite covering physics and simulation logic

### Modelling caveats

This is a deliberately simplified educational model:

- Motion is **1-D vertical only** (no pitch-over, no horizontal velocity, no orbital insertion).
- **Mass is constant** during flight; propellant burn is not modelled.
- **No atmospheric drag** is applied to trajectories. (`Physics.atmospheric_density` and `Physics.drag_force` are exposed as standalone utilities for users doing their own analyses.)

For a realistic 6-DOF aerospace simulation, see tools like RocketPy.

## Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/yourusername/rocket-sim.git
cd rocket-sim
pip install rocket-sim
```

# Install in development mode
pip install -e .
Or, for development:

# Or install with development dependencies
```bash
git clone https://github.com/rramboer/rocket-sim.git
cd rocket-sim
pip install -e ".[dev]"
```

Expand Down Expand Up @@ -130,9 +141,11 @@ plotter.plot_dashboard(result, filename="dashboard.png")
| Long March 5 | 867,000 | 10,600,000 | 480 | 1.25 |
| Vega | 137,000 | 2,310,000 | 110 | 1.72 |
| Electron | 12,550 | 240,000 | 150 | 1.95 |
| New Shepard | 75,000 | 490,000 | 110 | 0.67 |
| New Shepard | 75,000 | 490,000 | 110 | 0.67 |
| Vulcan Centaur | 546,700 | 11,340,000 | 180 | 2.11 |

† New Shepard's listed first-stage thrust gives T/W < 1 at the masses shown, so the simulator reports immediate landing. The numbers reflect public BE-3 specs; treat the result as a sanity-check signal, not a flight prediction.

## Physics Model

The simulation uses realistic physics including:
Expand All @@ -149,7 +162,7 @@ The simulation uses realistic physics including:
v_esc = √(2GM / (R + h))
```

- **Atmospheric Density** (optional): Exponential atmosphere model
- **Atmospheric Density** (utility, *not* applied to trajectories): Exponential atmosphere model exposed via `Physics.atmospheric_density(...)`
```
ρ(h) = ρ₀ × exp(-h / H)
```
Expand Down Expand Up @@ -188,7 +201,7 @@ rocket-sim/

```bash
# Clone and install with dev dependencies
git clone https://github.com/yourusername/rocket-sim.git
git clone https://github.com/rramboer/rocket-sim.git
cd rocket-sim
pip install -e ".[dev]"

Expand All @@ -212,12 +225,9 @@ pytest tests/test_physics.py
### Code Quality

```bash
# Format code
black src tests
isort src tests

# Lint
ruff check src tests
# Lint and format (Ruff handles both)
ruff check --fix src tests
ruff format src tests

# Type checking
mypy src
Expand Down
Loading
Loading