Advanced Machine Learning API for Exoplanet Detection and Classification
π Live API: https://api-server-772504622905.asia-southeast1.run.app
Features β’ Architecture β’ Installation β’ API Documentation β’ Deployment
- Overview
- Features
- Architecture
- Technology Stack
- Installation
- Configuration
- API Documentation
- Model Information
- Project Structure
- Development
- Testing
- Deployment
- Contributing
- License
StarShade Backend is a high-performance RESTful API service designed for exoplanet detection and classification using state-of-the-art machine learning models. The system processes astronomical data from multiple space telescope missions (Kepler, K2, TESS) and provides real-time predictions using ensemble learning techniques.
- π Multi-Mission Support: Processes data from Kepler, K2, TESS, and merged datasets
- π€ Advanced ML Models: Employs ensemble methods including Stacking, Voting, and Random Forest classifiers
- β‘ High Performance: Built with FastAPI for low-latency, high-throughput predictions
- π Batch Processing: Supports both single and batch prediction modes with CSV upload
- π³ Container-Ready: Fully Dockerized for seamless deployment
- π Production-Ready: CORS support, health checks, and environment-based configuration
- K2 Mission: Stacking Random Forest Classifier
- Kepler Mission: Soft Voting Classifier
- TESS Mission: Hard Voting Classifier
- Merged Dataset: Stacking Logistic Regression
- β Single prediction with confidence scores
- β Batch predictions via CSV upload
- β Dataset download endpoints
- β Probability distributions across classes
- β Comprehensive error handling and validation
- β CORS support for frontend integration
- β Health monitoring endpoints
βββββββββββββββββββ
β API Gateway β
ββββββββββ¬βββββββββ
β
ββββββΌβββββ
β FastAPI β
ββββββ¬βββββ
β
ββββββΌβββββββββββββββββββββββββββ
β Router Layer β
βββββββββββββ¬ββββββββββββββββββββ€
β β β
βββββΌββββ βββββΌβββββ ββββΌβββββ ββΌβββββ
β K2 β β Kepler β β TESS β βMergeβ
βββββ¬ββββ βββββ¬βββββ βββββ¬ββββ βββ¬ββββ
β β β β
βββββΌβββββββββββΌβββββββββββββΌββββββββββΌββββ
β ML Model Layer β
β (Stacking, Voting, Ensemble Methods) β
βββββββββββββββββββββββββββββββββββββββββββ
- Client Request β API endpoint with astronomical features
- Validation β Pydantic schema validation
- Preprocessing β Imputation β Scaling
- Prediction β Ensemble model inference
- Response β JSON with prediction, confidence, and probabilities
- FastAPI (v0.118.0) - Modern, fast web framework for building APIs
- Uvicorn - ASGI server for production deployment
- Pydantic (v2.11.10) - Data validation using Python type annotations
- scikit-learn (v1.7.2) - Core ML algorithms and preprocessing
- XGBoost - Gradient boosting framework
- LightGBM (v4.6.0) - High-performance gradient boosting
- imbalanced-learn (v0.14.0) - Handling imbalanced datasets
- TensorFlow/Keras (v3.11.3) - Deep learning capabilities
- NumPy (v2.3.3) - Numerical computing
- Pandas (v2.3.3) - Data manipulation and analysis
- SciPy (v1.16.2) - Scientific computing
- Matplotlib (v3.10.6) - Plotting and visualization
- Seaborn - Statistical data visualization
- Rich (v14.1.0) - Terminal formatting
- Docker - Containerization
- Python 3.11.3 - Runtime environment
- Python 3.11.3+
- pip (Python package manager)
- Docker (optional, for containerized deployment)
-
Clone the repository
git clone https://github.com/StarShade-1-0/starshade-backend.git cd starshade-backend -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the development server
./run.sh # Or manually: python -m uvicorn app.main:app --reload -
Access the API
- Local API: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Production API: https://api-server-772504622905.asia-southeast1.run.app
- Production Docs: https://api-server-772504622905.asia-southeast1.run.app/docs
-
Build the Docker image
docker build -t starshade-backend . -
Run the container
docker run -d -p 8080:8080 \ -e ENV=production \ -e ALLOW_ORIGINS="https://yourdomain.com" \ --name starshade-api \ starshade-backend -
Verify deployment
curl http://localhost:8080/health
| Variable | Description | Default | Required |
|---|---|---|---|
ENV |
Environment mode (dev, staging, production) |
dev |
No |
ALLOW_ORIGINS |
Comma-separated list of allowed CORS origins | * |
No |
Development:
export ENV=dev
export ALLOW_ORIGINS="http://localhost:3000,http://localhost:5173"Production:
export ENV=production
export ALLOW_ORIGINS="https://starshade.app,https://www.starshade.app"Check API status and environment configuration.
Response:
{
"status": "ok",
"env": "dev"
}Download raw datasets used for training the models.
Download K2 mission dataset (CSV)
Download Kepler mission dataset (CSV)
Download TESS mission dataset (CSV)
Download merged multi-mission dataset (CSV)
Single prediction using K2 mission features.
Request Body:
{
"pl_orbper": 3.5234,
"pl_tranmid": 2455123.456,
"pl_trandur": 2.345,
"pl_rade": 1.23,
"pl_radj": 0.109,
"pl_radjerr1": 0.005,
"pl_radjerr2": -0.005,
"pl_ratror": 0.0123,
"st_rad": 1.02,
"st_raderr1": 0.03,
"st_raderr2": -0.03,
"sy_dist": 123.45,
"sy_disterr1": 5.0,
"sy_disterr2": -5.0,
"sy_plx": 8.1,
"sy_plxerr1": 0.2,
"sy_plxerr2": -0.2
}Response:
{
"prediction": "CONFIRMED",
"confidence": 0.95,
"class_probabilities": {
"CONFIRMED": 0.95,
"FALSE POSITIVE": 0.03,
"CANDIDATE": 0.02
}
}Batch prediction via CSV file upload.
Request:
- Method: POST
- Content-Type: multipart/form-data
- Body: CSV file with feature columns
Response:
{
"total_predictions": 100,
"successful": 98,
"failed": 2,
"warnings": ["Row 5: More than 80% of values are missing"],
"errors": [],
"results": [
{
"row_number": 1,
"prediction": "CONFIRMED",
"confidence": 0.92,
"class_probabilities": {
"CONFIRMED": 0.92,
"FALSE POSITIVE": 0.05,
"CANDIDATE": 0.03
},
"error": null
}
]
}Single prediction for Kepler mission data.
Batch prediction for Kepler mission data.
Single prediction for TESS mission data.
Batch prediction for TESS mission data.
Single prediction using merged multi-mission features.
Batch prediction using merged multi-mission features.
All models use carefully selected astronomical features:
- Orbital Parameters:
pl_orbper(orbital period) - Transit Measurements:
pl_tranmid(mid-transit time),pl_trandur(transit duration) - Planetary Characteristics:
pl_rade(Earth radii),pl_radj(Jupiter radii),pl_ratror(planet-star radius ratio) - Stellar Properties:
st_rad(stellar radius) - System Metrics:
sy_dist(distance),sy_plx(parallax) - Error Margins: Various
err1anderr2parameters for uncertainty quantification
- Imputation: Missing values handled using
SimpleImputer - Scaling: Feature standardization with
StandardScaler - Encoding: Label encoding for categorical outputs
| Mission | Model Type | Algorithm | Use Case |
|---|---|---|---|
| K2 | Stacking | Random Forest meta-learner | High accuracy, interpretable |
| Kepler | Voting | Soft voting ensemble | Balanced predictions |
| TESS | Voting | Hard voting ensemble | Robust classification |
| Merged | Stacking | Logistic Regression meta-learner | Cross-mission generalization |
starshade-backend/
βββ app/
β βββ __init__.py
β βββ config.py # Environment configuration
β βββ main.py # FastAPI application entry point
β βββ routers/
β βββ __init__.py
β βββ k2/ # K2 mission endpoints
β β βββ __init__.py
β β βββ dataset.csv
β β βββ schemas.py
β β βββ stacking_rf/
β β βββ __init__.py
β β βββ model_impl.py
β β βββ schemas.py
β β βββ stacking_rf.pkl
β βββ kepler/ # Kepler mission endpoints
β β βββ __init__.py
β β βββ dataset.csv
β β βββ schemas.py
β β βββ voting_soft/
β β βββ ...
β βββ tess/ # TESS mission endpoints
β β βββ __init__.py
β β βββ dataset.csv
β β βββ schemas.py
β β βββ voting_hard/
β β βββ ...
β βββ merged/ # Merged dataset endpoints
β βββ __init__.py
β βββ dataset.csv
β βββ schemas.py
β βββ stacking_logreg/
β βββ ...
βββ Dockerfile # Container configuration
βββ requirements.txt # Python dependencies
βββ run.sh # Development server script
βββ README.md # Project documentation
This project follows PEP 8 guidelines. Key conventions:
- Use 4 spaces for indentation
- Maximum line length: 100 characters
- Use type hints where applicable
- Document functions with docstrings
- Create a new directory under
app/routers/{mission}/{model_name}/ - Implement
model_impl.pywithpredict()andbatch_predict()functions - Define response schemas in
schemas.py - Register router in
__init__.py - Update main router in
app/routers/{mission}/__init__.py
# Unit tests
pytest tests/
# Integration tests
pytest tests/integration/
# Coverage report
pytest --cov=app tests/The project includes configuration for GCP deployment on the dev/setup-gcp-deployment branch.
π Production Deployment: The API is currently deployed on GCP Cloud Run at:
- Base URL: https://api-server-772504622905.asia-southeast1.run.app
- Interactive Docs: https://api-server-772504622905.asia-southeast1.run.app/docs
- Health Check: https://api-server-772504622905.asia-southeast1.run.app/health
Cloud Run Deployment:
# Build and push to Container Registry
gcloud builds submit --tag gcr.io/PROJECT_ID/starshade-backend
# Deploy to Cloud Run
gcloud run deploy starshade-backend \
--image gcr.io/PROJECT_ID/starshade-backend \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars ENV=production,ALLOW_ORIGINS="https://yourdomain.com"# Build and tag
docker build -t starshade-backend .
docker tag starshade-backend:latest AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/starshade-backend:latest
# Push to ECR
aws ecr get-login-password --region REGION | docker login --username AWS --password-stdin AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com
docker push AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/starshade-backend:latest
# Deploy via ECS (configure task definition and service)apiVersion: apps/v1
kind: Deployment
metadata:
name: starshade-backend
spec:
replicas: 3
selector:
matchLabels:
app: starshade-backend
template:
metadata:
labels:
app: starshade-backend
spec:
containers:
- name: starshade-backend
image: starshade-backend:latest
ports:
- containerPort: 8080
env:
- name: ENV
value: "production"
- name: ALLOW_ORIGINS
value: "https://yourdomain.com"Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write clean, documented code
- Add tests for new features
- Update documentation as needed
- Follow existing code style
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License. See LICENSE file for details.
StarShade Team - StarShade-1-0
- NASA Exoplanet Archive for providing the astronomical datasets
- Kepler, K2, and TESS missions for groundbreaking exoplanet discoveries
- The open-source community for excellent ML libraries and tools
For issues, questions, or suggestions:
- π Bug Reports: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: support@starshade.app
Made with β€οΈ by the StarShade Team
β Star us on GitHub β it helps!
Production API β’ API Documentation β’ GitHub