Simple IMD Alerts

IMD (Indian Meteorological Department) has a district-level alert system. They give rain alerts for today and the next four days. They also have something called NowCast that shows the same alert level for now.

Alerts are basically four levels

  • No Warning - Green
  • Watch - Yellow
  • Alert - Orange
  • Warning - Red

Since it is district-level and not very specific, it might or may not be useful based on your use case. I find it useful when I am traveling.

IMD District Wise Warning Page

But there is no specific way to keep track of it or subscribe to it. You have to install their Android app or visit their website to get the details. Even there, there is no district-wise listing. All they have is a choropleth map showing you levels at the district level. I found it cumbersome, not so intuitive, and unnecessarily heavy for the information it provides.

IMD Distrcit Wise NowCast Warnings

What I want

I wanted a page showing the current and future warning levels given a location. So I got into exploring their maps. Their map is driven by a WMS layer, which serves the PNG tiles for bbox. So, if I craft my URL correctly, then I can just get one tile of the district that would give me warning levels. Since it's a standard GIS server, I can get SVG instead of PNG. SVG is easy to explore programmatically in future. Since I am getting only one tile, it's not heavy on the server, unlike loading their website and all the tiles.

IMD WMS Layer

Here are details of that layer for your exploration.

# WMS Layer for getting warning level

URL: https://reactjs.imd.gov.in/geoserver/imd/wms?env=day:Day1_Color
Layer: imd:Warnings_StateDistrict_Merged

# Note: You can add other parameters to URL part. 
# env is the most important.

# Different env parameters for different days
env=day:Day1_Color  - For today
env=day:Day2_Color  - For Tomorrow i.e today + 1
env=day:Day3_Color  - For today + 2
env=day:Day4_Color  - For today + 3
env=day:Day5_Color  - For today + 4

# if you don't pass env variable then it will return the value for **now**.

# For a web based WMS url to get a tile, 
# for a specific bbox will look like this. 
# I have added line breaks for ease of reading

https://reactjs.imd.gov.in/geoserver/imd/wms?service=WMS
&request=GetMap
&layers=imd%3AWarnings_StateDistrict_Merged
&styles=
&format=image%2Fsvg
&transparent=true
&version=1.1.1
&env=day%3ADay1_Color
&width=256
&height=256
&srs=EPSG%3A4326
&bbox=76.20981195447168,10.523111,76.21896604552832,10.532111

# I plan to play with
- width and height
- bbox
- format
- env

My plan

  1. Take lat and lon as URL parameters
  2. Create a bbox of one square KM with the above as the center
  3. Make a request to their map server to get one particular tile
  4. Change the parameters to get different day values
  5. Create a page that shows these images as tiles
  6. Also, have a JSON output in case in the future I want to plugin it to HomeAssistant or alert system

Since I was trying val.town, I wrote that script in Javascript and deployed it immediately. It's super easy and quick to iterate on val.town. I love how easy it is to build small apps.

My IMD Alert page for Thrissur.

It can produce an HTML web page and JSON. I have also added the code to GitHub gist as a backup. It supports the following URL parameters

  • lat = latitude, default is Bengaluru's
  • lon = longitude, default is Bengaluru's
  • format = html or json, default is html

Example pages

My IMD Alert page for Thrissur. NowCast turned orange as I was coding since it started raining. Imagine if I could subscribe to the warning level. I added timestamp to the screen just after this incident. It is useful if you want to send a screenshot to someone.

Future improvements

  1. Maybe cache everything except NowCast, further reducing the load on the upstream server. It's already very, very low. Saving also helps us to analyze data later.
  2. Currently, I am returning a small SVG and not the actual warning level value. I want to return textual values like green, yellow, orange, and red instead of image. I am not sure how to do that. One possible way is to extract the fill color from the SVG. The textual value will make it possible to plug into alerting systems, making it instantly more helpful. It will also make it a proper API.
  3. Provide a GEOJSON feed version ( format=geojson) of the API

You can read this blog using RSS Feed. But if you are the person who loves getting emails, then you can join my readers by signing up.

Join 2,236 other subscribers

3 Responses

  1. planemad says:

    Very nice Thej, a documented public API for this is very much needed.

    IMD also has this data on their WFS server[1] and which is used to render the map on their Nowcast page[2]. This endpoint could also be useful for fetching in an easy to parse format.

    [1] https://reactjs.imd.gov.in/geoserver/wfs?callback=getJson&service=WFS&version=1.1.0&request=GetFeature&typename=imd%3Adistrict_warnings_india&srsname=EPSG%3A4326&format_options=callback%3AgetJson&outputFormat=text%2Fjavascript&_=1726038102506
    [2] https://mausam.imd.gov.in/responsive/districtWiseWarningGIS.php

  1. September 14, 2024

    […] wrote a simple one-page web app to show IMD Warnings for any location. I blogged in detail about it. I have a couple of ideas to make it more useful. I will implement them in smaller […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.