Skip to content

astrobytes-edu/manim-astro

Repository files navigation

🌟 manim-astro

PyPI version Documentation Status Tests Coverage License: MIT

Astronomical animations for Manim - Create stunning, scientifically accurate visualizations of astronomical phenomena.

Demo Animation

✨ Features

  • 🌟 Physically accurate stellar models with proper color-temperature relations
  • 🌌 Galaxy simulations with realistic morphologies
  • πŸͺ Orbital mechanics using real gravitational physics
  • πŸ“Š Astronomical diagrams (HR, Hubble, CMDs)
  • πŸ”­ Observation planning tools and projections
  • 🌈 Spectroscopy animations with real line physics
  • πŸš€ Cosmological simulations with proper scaling

πŸš€ Quick Start

Installation

pip install manim-astro

For development:

git clone https://github.com/yourusername/manim-astro.git
cd manim-astro
pip install -e ".[dev,docs]"

Basic Usage

from manim import *
from manim_astro import Star, HRDiagram

class StellarScene(Scene):
    def construct(self):
        # Create a main sequence star
        sun = Star(mass=1.0)
        self.add(sun)
        
        # Create an HR diagram
        hr_diagram = HRDiagram()
        hr_diagram.plot_main_sequence()
        self.play(Create(hr_diagram))

πŸ“š Documentation

Full documentation available at manim-astro.readthedocs.io

πŸŽ“ Educational Examples

Main Sequence Stars

# Demonstrate mass-luminosity relation
star_sequence = StarSequence(masses=[0.5, 1.0, 2.0, 5.0])
star_sequence.show_scaling_relations()

Galaxy Evolution

# Animate galaxy collision
galaxy1 = SpiralGalaxy(mass=1e12)
galaxy2 = SpiralGalaxy(mass=5e11)
collision = GalaxyCollision(galaxy1, galaxy2)

🀝 Contributing

We welcome contributions! Please see our Contributing Guide.

πŸ“„ License

This project is licensed under the MIT License - see LICENSE file.

πŸ™ Acknowledgments

  • Manim Community for the amazing animation framework
  • ASTR596 course at [Your University]
  • Astronomical data from ESA Gaia, SDSS, and NASA

πŸ“– Citation

If you use manim-astro in your research or teaching, please cite:

@software{manim_astro,
  author = {Your Name},
  title = {manim-astro: Astronomical Animations for Manim},
  year = {2024},
  url = {https://github.com/yourusername/manim-astro}
}

### **CONTRIBUTING.md**
```markdown
# Contributing to manim-astro

Thank you for your interest in contributing to manim-astro! 

## πŸš€ Getting Started

1. Fork the repository
2. Clone your fork:
   ```bash
   git clone https://github.com/yourusername/manim-astro.git
   cd manim-astro
  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  2. Install in development mode:

    pip install -e ".[dev,docs]"
    pre-commit install

πŸ”§ Development Workflow

  1. Create a new branch:

    git checkout -b feature/your-feature-name
  2. Make your changes and ensure:

    • All tests pass: pytest
    • Code is formatted: black src/ tests/
    • Imports are sorted: isort src/ tests/
    • Type hints are correct: mypy src/
  3. Write tests for new features

  4. Update documentation if needed

  5. Commit with descriptive messages:

    git commit -m "feat: add binary star system class"
  6. Push and create a pull request

πŸ“ Code Style

  • Follow PEP 8
  • Use Black for formatting
  • Add type hints for all functions
  • Document with NumPy-style docstrings

πŸ§ͺ Testing

Run tests with:

pytest                          # All tests
pytest tests/unit/test_star.py  # Specific file
pytest -v --cov=manim_astro    # With coverage

πŸ“š Documentation

Build docs locally:

cd docs
make html
open _build/html/index.html

🌟 Areas for Contribution

  • New celestial objects: Nebulae, clusters, etc.
  • Physical processes: Accretion, jets, shocks
  • Observational tools: Telescope simulations
  • Educational animations: Tutorials and demos
  • Performance optimizations: Speed improvements
  • Documentation: Tutorials, examples, API docs

πŸ“„ Pull Request Process

  1. Ensure all tests pass
  2. Update CHANGELOG.md
  3. Update documentation
  4. Request review from maintainers

🀝 Code of Conduct

Please read our Code of Conduct.

❓ Questions?

Open an issue or join our Discord: [link]


### **tests/conftest.py** - Pytest Configuration
```python
"""
Pytest configuration and fixtures for manim-astro tests.
"""

import pytest
import numpy as np
from manim import *
import tempfile
import shutil
from pathlib import Path

# Configure Manim for testing
config.verbosity = "WARNING"
config.preview = False
config.progress_bar = "none"
config.background_color = BLACK

@pytest.fixture
def temp_media_dir():
    """Create temporary directory for test media files."""
    temp_dir = tempfile.mkdtemp()
    original_media_dir = config.media_dir
    config.media_dir = temp_dir
    
    yield Path(temp_dir)
    
    # Cleanup
    config.media_dir = original_media_dir
    shutil.rmtree(temp_dir)

@pytest.fixture
def test_scene():
    """Create a test scene for animations."""
    class TestScene(Scene):
        def construct(self):
            pass
    
    return TestScene()

@pytest.fixture
def sample_star_data():
    """Sample stellar parameters for testing."""
    return {
        'sun': {'mass': 1.0, 'radius': 1.0, 'temperature': 5772},
        'sirius': {'mass': 2.06, 'radius': 1.71, 'temperature': 9940},
        'proxima': {'mass': 0.12, 'radius': 0.15, 'temperature': 3042},
        'betelgeuse': {'mass': 20, 'radius': 1000, 'temperature': 3500},
    }

@pytest.fixture
def sample_galaxy_data():
    """Sample galaxy parameters for testing."""
    return {
        'milky_way': {
            'mass': 1.5e12,  # M_sun
            'radius': 50000,  # pc
            'type': 'spiral'
        },
        'andromeda': {
            'mass': 1.2e12,
            'radius': 60000,
            'type': 'spiral'
        }
    }

GitHub Actions Workflow - .github/workflows/tests.yml

name: Tests

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

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: ['3.8', '3.9', '3.10', '3.11']

    steps:
    - uses: actions/checkout@v3
    
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    
    - name: Install system dependencies (Ubuntu)
      if: runner.os == 'Linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y ffmpeg libcairo2-dev
    
    - name: Install system dependencies (macOS)
      if: runner.os == 'macOS'
      run: |
        brew install ffmpeg cairo
    
    - name: Install Python dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e ".[dev]"
    
    - name: Lint with flake8
      run: |
        flake8 src/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics
    
    - name: Check formatting with black
      run: |
        black --check src/ tests/
    
    - name: Sort imports with isort
      run: |
        isort --check-only src/ tests/
    
    - name: Type check with mypy
      run: |
        mypy src/
    
    - name: Test with pytest
      run: |
        pytest --cov=manim_astro --cov-report=xml --cov-report=term
    
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v3
      with:
        file: ./coverage.xml
        flags: unittests
        name: codecov-umbrella

πŸš€ Getting Started Commands

# 1. Create the repository structure
mkdir manim-astro
cd manim-astro

# 2. Initialize git
git init
git remote add origin https://github.com/yourusername/manim-astro.git

# 3. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# 4. Create the directory structure
mkdir -p src/manim_astro/{celestial,coordinates,physics,spectroscopy,diagrams,data,utils,animations}
mkdir -p tests/{unit,integration,fixtures}
mkdir -p docs/{api,tutorials,gallery,_static}
mkdir -p examples/{basic,intermediate,advanced}
mkdir -p scripts
mkdir -p media/{images,videos,logos}
mkdir -p .github/workflows

# 5. Create all the configuration files
# Copy the content from above into respective files

# 6. Install in development mode
pip install -e ".[dev,docs]"

# 7. Initialize pre-commit
pre-commit install

# 8. Run initial tests
pytest

# 9. Build documentation
cd docs
sphinx-quickstart
make html

# 10. Initial commit
git add .
git commit -m "feat: initial manim-astro package structure"
git push -u origin main

πŸ“‹ Development Checklist

  • Set up repository structure
  • Configure packaging (pyproject.toml)
  • Set up testing framework
  • Configure CI/CD (GitHub Actions)
  • Set up documentation (Sphinx)
  • Create initial Star class
  • Write comprehensive tests
  • Add example animations
  • Configure pre-commit hooks
  • Set up code coverage
  • Create contribution guidelines
  • Add issue templates
  • Configure automated releases
  • Set up ReadTheDocs
  • Create project logo
  • Write comprehensive README

### πŸ“ Complete Directory Structure

manim-astro/
β”‚
β”œβ”€β”€ πŸ“„ README.md                    # Main project documentation
β”œβ”€β”€ πŸ“„ LICENSE                      # MIT License
β”œβ”€β”€ πŸ“„ CONTRIBUTING.md              # Contribution guidelines
β”œβ”€β”€ πŸ“„ CHANGELOG.md                 # Version history
β”œβ”€β”€ πŸ“„ CODE_OF_CONDUCT.md          # Community guidelines
β”œβ”€β”€ πŸ“„ pyproject.toml              # Modern Python packaging config
β”œβ”€β”€ πŸ“„ setup.cfg                   # Additional setup configuration
β”œβ”€β”€ πŸ“„ MANIFEST.in                 # Include non-Python files
β”œβ”€β”€ πŸ“„ .gitignore                  # Git ignore patterns
β”œβ”€β”€ πŸ“„ .gitattributes              # Git attributes
β”‚
β”œβ”€β”€ πŸ“‚ .github/                    # GitHub specific files
β”‚   β”œβ”€β”€ πŸ“‚ workflows/              # GitHub Actions CI/CD
β”‚   β”‚   β”œβ”€β”€ tests.yml              # Run tests on push/PR
β”‚   β”‚   β”œβ”€β”€ docs.yml               # Build and deploy docs
β”‚   β”‚   β”œβ”€β”€ release.yml            # Automated releases
β”‚   β”‚   └── lint.yml               # Code quality checks
β”‚   β”œβ”€β”€ πŸ“‚ ISSUE_TEMPLATE/         # Issue templates
β”‚   β”‚   β”œβ”€β”€ bug_report.md
β”‚   β”‚   β”œβ”€β”€ feature_request.md
β”‚   β”‚   └── documentation.md
β”‚   └── πŸ“„ PULL_REQUEST_TEMPLATE.md
β”‚
β”œβ”€β”€ πŸ“‚ src/                        # Source code (src layout)
β”‚   └── πŸ“‚ manim_astro/
β”‚       β”œβ”€β”€ πŸ“„ __init__.py         # Package initialization
β”‚       β”œβ”€β”€ πŸ“„ __version__.py      # Version information
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ celestial/          # Celestial objects
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ star.py            # Star class
β”‚       β”‚   β”œβ”€β”€ planet.py          # Planet classes
β”‚       β”‚   β”œβ”€β”€ galaxy.py          # Galaxy classes
β”‚       β”‚   β”œβ”€β”€ binary.py          # Binary systems
β”‚       β”‚   └── exotics.py         # Pulsars, black holes, etc.
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ coordinates/        # Coordinate systems
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ celestial.py       # RA/Dec, Alt/Az
β”‚       β”‚   β”œβ”€β”€ projections.py     # Sky projections
β”‚       β”‚   └── transformations.py # Coordinate transforms
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ physics/            # Physical processes
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ radiation.py       # Radiation processes
β”‚       β”‚   β”œβ”€β”€ dynamics.py        # Orbital mechanics
β”‚       β”‚   β”œβ”€β”€ relativity.py      # GR effects
β”‚       β”‚   └── cosmology.py       # Cosmological models
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ spectroscopy/       # Spectral analysis
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ spectrum.py        # Spectrum classes
β”‚       β”‚   β”œβ”€β”€ lines.py           # Spectral lines
β”‚       β”‚   └── photometry.py      # Photometric tools
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ diagrams/           # Astronomical diagrams
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ hr_diagram.py      # HR diagram
β”‚       β”‚   β”œβ”€β”€ hubble.py          # Hubble diagram
β”‚       β”‚   └── color_magnitude.py # CMD
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ data/               # Package data
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ constants.py       # Physical constants
β”‚       β”‚   β”œβ”€β”€ catalogs/          # Star catalogs
β”‚       β”‚   β”œβ”€β”€ filters/           # Filter curves
β”‚       β”‚   └── colormaps/         # Custom colormaps
β”‚       β”‚
β”‚       β”œβ”€β”€ πŸ“‚ utils/              # Utilities
β”‚       β”‚   β”œβ”€β”€ __init__.py
β”‚       β”‚   β”œβ”€β”€ units.py           # Unit conversions
β”‚       β”‚   β”œβ”€β”€ validators.py      # Input validation
β”‚       β”‚   β”œβ”€β”€ data_loader.py     # Load FITS, etc.
β”‚       β”‚   └── colors.py          # Color utilities
β”‚       β”‚
β”‚       └── πŸ“‚ animations/         # Pre-built animations
β”‚           β”œβ”€β”€ __init__.py
β”‚           β”œβ”€β”€ stellar_evolution.py
β”‚           β”œβ”€β”€ galaxy_collision.py
β”‚           └── cosmological_evolution.py
β”‚
β”œβ”€β”€ πŸ“‚ tests/                      # Test suite
β”‚   β”œβ”€β”€ πŸ“„ __init__.py
β”‚   β”œβ”€β”€ πŸ“„ conftest.py            # Pytest configuration
β”‚   β”œβ”€β”€ πŸ“‚ unit/                  # Unit tests
β”‚   β”‚   β”œβ”€β”€ test_star.py
β”‚   β”‚   β”œβ”€β”€ test_coordinates.py
β”‚   β”‚   └── test_physics.py
β”‚   β”œβ”€β”€ πŸ“‚ integration/           # Integration tests
β”‚   β”‚   └── test_animations.py
β”‚   └── πŸ“‚ fixtures/              # Test data
β”‚       └── sample_data.py
β”‚
β”œβ”€β”€ πŸ“‚ examples/                   # Example animations
β”‚   β”œβ”€β”€ πŸ“„ README.md
β”‚   β”œβ”€β”€ πŸ“‚ basic/                 # Basic examples
β”‚   β”‚   β”œβ”€β”€ 01_creating_stars.py
β”‚   β”‚   β”œβ”€β”€ 02_hr_diagram.py
β”‚   β”‚   └── 03_orbits.py
β”‚   β”œβ”€β”€ πŸ“‚ intermediate/          # Intermediate examples
β”‚   β”‚   β”œβ”€β”€ stellar_evolution.py
β”‚   β”‚   β”œβ”€β”€ binary_systems.py
β”‚   β”‚   └── galaxy_rotation.py
β”‚   └── πŸ“‚ advanced/              # Advanced examples
β”‚       β”œβ”€β”€ nbody_simulation.py
β”‚       β”œβ”€β”€ cosmological_sim.py
β”‚       └── gravitational_lensing.py
β”‚
β”œβ”€β”€ πŸ“‚ docs/                      # Documentation
β”‚   β”œβ”€β”€ πŸ“„ conf.py               # Sphinx configuration
β”‚   β”œβ”€β”€ πŸ“„ index.rst             # Documentation home
β”‚   β”œβ”€β”€ πŸ“„ installation.rst      # Installation guide
β”‚   β”œβ”€β”€ πŸ“„ quickstart.rst        # Quick start guide
β”‚   β”œβ”€β”€ πŸ“„ requirements.txt      # Docs dependencies
β”‚   β”œβ”€β”€ πŸ“‚ api/                  # API reference
β”‚   β”‚   └── modules.rst
β”‚   β”œβ”€β”€ πŸ“‚ tutorials/            # Tutorials
β”‚   β”‚   β”œβ”€β”€ index.rst
β”‚   β”‚   β”œβ”€β”€ stellar.rst
β”‚   β”‚   └── cosmology.rst
β”‚   β”œβ”€β”€ πŸ“‚ gallery/              # Example gallery
β”‚   β”‚   └── index.rst
β”‚   └── πŸ“‚ _static/              # Static files
β”‚       β”œβ”€β”€ css/
β”‚       └── images/
β”‚
β”œβ”€β”€ πŸ“‚ scripts/                   # Utility scripts
β”‚   β”œβ”€β”€ generate_catalog.py      # Generate star catalogs
β”‚   β”œβ”€β”€ validate_physics.py      # Validate physics
β”‚   └── benchmark.py             # Performance benchmarks
β”‚
└── πŸ“‚ media/                     # Media files
    β”œβ”€β”€ πŸ“‚ images/               # README images
    β”œβ”€β”€ πŸ“‚ videos/               # Demo videos
    └── πŸ“‚ logos/                # Project logos

About

Astronomy & Astrophysics plug-in for Manim.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors