Professional magnetic field analysis platform for research and industrial applications
Author: Manas Pandey | Developed with Claude AI assistance
Current State: Core functionality implemented, requires comprehensive testing and production hardening.
MagTrace provides magnetic field data analysis capabilities using machine learning for anomaly detection and pattern recognition. The platform processes magnetometer sensor data (B_x, B_y, B_z components) with interactive visualization and automated classification.
git clone https://github.com/manasp21/MagTrace.git
cd MagTrace
python3 run.pyAccess Points:
- Main Application: http://localhost:8000/app/
- API Documentation: http://localhost:8000/api/
- Health Check: http://localhost:8000/health/
- Project Management - Organize magnetic field analysis projects
- CSV Data Upload - Process magnetometer readings with automatic parsing
- Interactive Visualization - D3.js charts with zoom, pan, and brush selection
- Data Labeling - Manual annotation of magnetic field anomalies and patterns
- Machine Learning Training - Scikit-learn Random Forest classification
- Real-time Progress - Live training monitoring with progress indicators
- RESTful API - Complete API for programmatic access
timestamp_pc,b_x,b_y,b_z,lat,lon,altitude,thetax,thetay,thetaz,sensor_id
24:40.0,7746.664,9395.448,14682.022,26.5123251,80.2238068,2018,0,0,0,S963350075783Required Columns: timestamp_pc, b_x, b_y, b_z
Optional Columns: lat, lon, altitude, sensor_id, thetax, thetay, thetaz
1. Security
- ❌ No authentication system - Single-user development setup only
- ❌ No input validation - Limited CSV format checking
- ❌ No rate limiting - API endpoints unprotected
- ❌ Insecure file uploads - Basic validation only
- ❌ Debug mode enabled - Not production-ready
2. Scalability Issues
- ❌ SQLite database - Single-user, no concurrent access
- ❌ File upload limits - ~100MB maximum, no chunking
- ❌ Memory limitations - Large datasets (>50k points) cause performance issues
- ❌ No background processing - Training blocks server threads
- ❌ Single-threaded ML - No distributed computing support
3. Data Management
- ❌ No data validation - Limited error handling for malformed CSV
- ❌ No backup system - Manual database backup required
- ❌ No data retention - Unlimited storage consumption
- ❌ No audit logging - No tracking of data access or modifications
4. Reliability
- ❌ No error recovery - Failed operations require manual cleanup
- ❌ No monitoring - No health checks or alerting
- ❌ Development server - Django development server not production-ready
- ❌ No load balancing - Single point of failure
CRITICAL: This system requires extensive testing before any production deployment.
- Small datasets (< 1,000 points) - Response time < 2 seconds
- Medium datasets (1,000-10,000 points) - Memory usage < 2GB
- Large datasets (> 10,000 points) - Verify decimation works correctly
- Concurrent users - Test multiple simultaneous uploads
- Memory stress - Monitor for memory leaks during extended use
- End-to-end workflow - Project → Upload → Label → Train → Predict
- API endpoints - All CRUD operations for each model
- Error handling - Invalid data, network failures, timeouts
- Browser compatibility - Chrome, Firefox, Safari, Edge
- Data integrity - Verify annotations persist correctly
- Input validation - SQL injection, XSS, file upload attacks
- CSRF protection - Verify all state-changing operations protected
- File upload security - Malicious file upload attempts
- API security - Authentication bypass attempts
- CSV format variations - Different timestamp formats, missing columns
- Magnetic field ranges - Extreme values, negative numbers, scientific notation
- GPS coordinates - Invalid lat/lon values, missing location data
- Large file handling - Files approaching 100MB limit
Minimum Test Dataset Collection:
- Small datasets (10-100 points) - Quick validation
- Medium datasets (1,000-5,000 points) - Performance testing
- Large datasets (10,000+ points) - Stress testing
- Anomaly datasets - Clear patterns for ML validation
- Edge case datasets - Missing values, extreme ranges, malformed data
Sample data provided: example/data_1.csv (46 points) - Insufficient for comprehensive testing.
- Framework: Django 4.2 + Django REST Framework
- Database: SQLite (development) / PostgreSQL (production required)
- ML Framework: Scikit-learn 1.3.2 (TensorFlow optional, often fails)
- File Processing: Pandas for CSV parsing and data manipulation
- UI: HTML5 + Vanilla JavaScript + CSS
- Visualization: D3.js for interactive magnetic field charts
- AJAX: Fetch API for backend communication
backend/
├── magtrace_api/ # Main API application
│ ├── models.py # Database models (Project, Dataset, Annotation)
│ ├── views.py # API endpoints and business logic
│ ├── simple_training_service.py # ML training orchestration
│ └── serializers.py # API data serialization
├── templates/magtrace.html # Single-page application interface
├── static/js/magtrace.js # Frontend application logic
└── manage.py # Django management commands
Infrastructure:
- Web Server - Nginx/Apache with WSGI (Gunicorn/uWSGI)
- Database - PostgreSQL with connection pooling
- Caching - Redis for session storage and API caching
- File Storage - S3/MinIO for uploaded datasets (not local filesystem)
- Monitoring - Application performance monitoring (APM)
Security Hardening:
- Authentication - User management system with role-based access
- HTTPS - SSL certificate and secure headers
- Input Validation - Comprehensive data sanitization
- Rate Limiting - API request throttling
- File Upload Security - Virus scanning, type validation
Scalability:
- Background Jobs - Celery + Redis for ML training
- Load Balancing - Multiple application instances
- Database Scaling - Read replicas, connection pooling
- CDN - Static file delivery optimization
Operational:
- Backup Strategy - Automated database and file backups
- Logging - Structured application and access logs
- Monitoring - Health checks, error tracking, alerting
- Deployment Pipeline - CI/CD with automated testing
- Python 3.8+ (3.10+ recommended)
- 8GB+ RAM (for large dataset processing)
- Modern web browser
1. Quick Start (Recommended)
python3 run.py # Automated setup with virtual environment2. Manual Setup
cd backend
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Use lightweight requirements (TensorFlow often fails)
pip install -r requirements-lite.txt
python manage.py migrate
python manage.py runserver# Health check
curl http://localhost:8000/health/
# Comprehensive workflow test
python3 test_workflow.pyCore Endpoints:
POST /api/projects/- Create magnetic field analysis projectPOST /api/datasets/upload/- Upload CSV magnetometer dataGET /api/datasets/{id}/data/- Retrieve processed data with decimationPOST /api/annotations/- Create labeled data regionsPOST /api/training/start/- Begin ML model trainingGET /api/training/status/{session_id}/- Monitor training progress
Full API Documentation: docs/source/api_reference.rst
- Training sessions may hang with very large datasets (>20k points)
- Browser performance degrades with >50 annotations on single chart
- CSV parsing fails silently with some timestamp formats
- Memory leaks in long-running training sessions
- No graceful failure handling for interrupted operations
- Database locks occur with rapid successive API calls
- File upload corrupts with network interruptions
- Training progress not recoverable after server restart
- Authentication system - User registration, login, permissions
- Production database - PostgreSQL migration and optimization
- Security hardening - Input validation, rate limiting, HTTPS
- Error handling - Graceful failures and recovery mechanisms
- Unit testing - Comprehensive test suite beyond integration tests
- Background processing - Celery task queue for ML training
- File chunking - Large dataset upload support (>100MB)
- Data validation - Robust CSV format checking and sanitization
- Performance optimization - Database query optimization, caching
- Model export/import - Save/load trained models
- Batch processing - Multiple dataset analysis
- Advanced ML algorithms - Deep learning options
- Real-time data streaming - Live magnetometer data processing
Complete Documentation: GitHub Pages
Key Resources:
- Installation Guide - Setup and troubleshooting
- Quick Start Tutorial - 10-minute walkthrough
- API Reference - Complete endpoint documentation
- Troubleshooting Guide - Common issues and solutions
- Testing Results - Validation and performance data
Development Environment:
# Fork repository, then:
git clone https://github.com/YOUR_USERNAME/MagTrace.git
cd MagTrace/backend
source venv/bin/activate
pip install -r requirements-lite.txt
# Run tests
python3 test_workflow.py
python manage.py testCode Standards:
- Follow Django best practices for backend development
- Use vanilla JavaScript (no framework dependencies) for frontend
- Include docstrings for all new functions and classes
- Add integration tests for new API endpoints
Author: Manas Pandey
Development Assistance: Claude AI (Anthropic)
License: [Specify license]
This software is in active development and not ready for production use without significant additional work.
For Production Deployment:
- Complete comprehensive testing with your specific datasets
- Implement authentication and security hardening
- Migrate to production-grade database and infrastructure
- Add monitoring, logging, and backup systems
- Conduct security audit and penetration testing
Use in controlled environments only until production readiness checklist is completed.