Grid.Demo.mp4
With recent events causing Jamaica's power grid to fail for long periods, particularly caused by the worsening weather patterns. My aim was to develop a full-stack, intelligent power grid monitoring and auxiliary decision-making platform. By integrating a power grid simulation framework with machine learning-based anomaly detection and load prediction. The system enables early warning of potential grid failures (line overloads, voltage violations) and generates standardized anomaly analysis reports.
- Frontend: A Single Page Application built with
Vite + React + TypeScript, responsible for spatial topology visualization and time-series data rendering. - API: An asynchronous RESTful API built with
FastAPI. FastAPI was chosen for its asynchronous nature which performs well for high-frequency time-series data streams. - Simulation & Algorithm: The core physics engine utilizes
Grid2Opcombined with a two machine learning models, predicting the value of the highest load in the next 30 mins (~6 steps in Grid2op) and anomaly detection. - Database:
PostgreSQL + TimeScaleDBfor historical time-series data persistence;Open-Meteo APIfor real-world meteorological boundary conditions.
| Component | Tech Stack |
|---|---|
| Simulation | Grid2Op (l2rpn_neurips_2020_track1_small) |
| Backend | FastAPI + Uvicorn |
| Frontend | React + TypeScript + Leaflet |
| Database | PostgreSQL + TimeScaleDB |
| Reports | WeasyPrint + Jinja2 |
-
Grid Simulation : Using Grid2Op to simulate a realistic power grid.
-
Real-Time Grid Topology : Using the user's location and their countries substation data gathered from
earth-osmto recreate the country's ten closest substations to the user to generate a grid topology onreact-leaflet, as well as creating a ring-based grid system if the country's data is not found. -
Anomaly Detection & Highest Load Prediction : Based on features including highest load, the power production for both renewable and non-renewable generators, load drop, rolling mean and standard deviation, the difference between the power generated vs the power used and the active/reactive power consumption. These features were generated from Grid2Op to train a
LGBMClassifierto predict anomalies within the grid and aLGBMRegressorto predict the highest load in the system in the next 30 mins (~6 steps in Grid2Op). -
Top 5 Load Time Series Chart : A time series plot of the top five highest loads in the grid using
recharts. -
Report Generation : Generates a report based on the most recent anomalies.
The dataset held high imbalance, as such a precision-recall curve was the best method to visulalize the performance of the model. The model had strong performance having an average precision of 0.97.
The model held strong performance in the range of 0.65 rho to 0.90 rho, and began underestimating at >0.90 due to the rarity of these cases from the simulated data. The model made predominant usage of max_rho for predicting the target_rho, but also made use of power production and consumption. The rolling variables had much smaller influence on the prediction. There was only a 1.14% error when predicting, and only ~3.3% of the variation remains unexplained.
https://colab.research.google.com/drive/1GGFtfbIZ2igx6gKjMGZXHP8VJ-__kYIm?usp=sharing
Clone the project
git clone https://github.com/ty-dotcom/Grid-Monitoring-System.gitDownload and setup PostgreSQL and TimeScaleDB
https://www.postgresql.org https://timescaledb.org
- Copy backend/.env.example to backend/.env:
cp backend/.env.example backend/.env-
Edit your backend/.env and add your PostgreSQL credentials.
-
Ensure grid_db database exists and TimeScaleDB is installed, afterwhich run
SELECT create_hypertable('grid_metrics', 'time', chunk_time_interval => INTERVAL '5 mins');Using separate terminals/IDE
Go to the frontend directory
cd Grid-Monitoring-System/frontendInstall dependencies
npm installGo to the backend directory
cd Grid-Monitoring-System/backendInstall python requirements
pip install -r requirements-dev.txtOtherwise run python code using an IDE. Start the Backend server (Using Command Line).
python main.pyStart the Client server
npm run start