There are approximately 70,000 wildfire emergencies globally each year, leading to billions of dollars in damages not to mention human casualties, displacement from homes, and destruction of precious natural land. Specific weather conditions and factors affect the spread and severity of a new or existing fire, especially drought that’s common in dry climates. Wind, humidity, and temperature are also major factors in wildfire events. Tracking these weather data factors and forecasts is the key to being aware of likely disaster breakouts, as well as how best to combat and prevent them.
Early detection is especially important when dealing with wildfires; they can occur with little to no warning, and spread rapidly. Knowing when conditions are ripe for wildfires and tracking the spread of them by following weather trends can save lives. In this post, we’ll walk through how to use the Tomorrow.io weather API to get early notification of dangerous conditions and get alerts for ongoing or current wildfires.
Tracking Wildfires and Potential Fires with Tomorrow.io
The Tomorrow.io API can be used to track fire alerts so that businesses and individuals can prepare and evacuate if necessary. With the API, you can get two pieces of data important in tracking fires:
- Fire Index: The Fire Weather Index (FWI) is an integer value from 1-100 that indicates the intensity of fire potential within a region.
- Active Fires Alerts: This value provides a percentage of probability a fire will occur or a fire has been observed.
Both values provide unique information. For example, an active fire alert could indicate that a fire was observed in a region and anyone close to the current location should evacuate depending on the severity of the fire. The Fire Index value could be used to track weather conditions that could lead to a fire. It can act as a warning for people and businesses in the area that could be impacted. Both values can be used separately or in combination to provide information about surrounding weather conditions to either you or your users.
Retrieving Fire Index Values for Each Hour of the Day
The timelines endpoint returns all core weather codes back to you using a simple GET request. With this endpoint, you can use your local region or any region around the globe to return weather conditions every hour, day, week or other time interval. Using the timelines endpoint, you can generate information for a weather tracking application and follow trends based on your own input parameters.
For example, suppose that you want to track the Fire Index rating along with temperature and humidity in your city. High temperatures, low humidity, and a high Fire Index value could indicate that a potential fire could happen in the near future. You can also track this data days in advance and use it to follow trends based on previous years. If the right weather conditions occur the same week every July, for example, then you could warn people to prepare for potential fires this particular week.
The following code returns humidity, temperature, and Fire Index values every hour for the next 24 hours:
void GetTimelineData() { string getTimelineURL = "https://api.tomorrow.io/v4/timelines"; string apikey = "YOUR API KEYS"; string location = "607f3e4188a6a60007947b82"; //locationId string units = "imperial"; string[] timesteps = {"1h"}; string timezone = "America/New_York"; // configure the time frame from now to 1 day out string now = DateTime.UtcNow.ToString(); string startTime = DateTime.UtcNow.AddMinutes(0).ToString("o", CultureInfo.InvariantCulture); string endTime = DateTime.UtcNow.AddDays(1).ToString("o", CultureInfo.InvariantCulture); // list the fields string[] fields = { "temperature", "humidity", "fireIndex" }; string getTimelineParameters = "apikey=" + apikey + "&location=" + location + "&fields=" + fields[0] + "&fields=" + fields[1] + "&fields=" + fields[2] + "&units=" + units + "×teps=" + timesteps[0] + "&timezone=" + timezone + "&startTime=" + startTime + "&endTime=" + endTime; string fullUrl = "https://api.tomorrow.io/v4/timelines?" + getTimelineParameters; var apiResult = CallApi(fullUrl); JObject result = JObject.Parse(apiResult.Result); } private static async Task CallApi(string fullUrl) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; HttpClient client = new HttpClient(); var response = client.GetStringAsync(fullUrl); return await response; }
The GetTimelineData() method sets up the GET request, and the CallApi() method performs the call to the API. The first one is the meat of the API request. GetTimelineData() sets up parameters to send to the request specifying that we want temperature, humidity and fireIndex from the API. The request is set up as a GET request using a URL and query string parameters. For every API call, you must send your API keys, and the rest of the parameters in the GetTimelineData() method are specific to the timeline endpoint. You can see the list of parameters both required and optional in the documentation for the endpoint.
You get a location ID by adding a location in the form of an address in your account dashboard. You can also use latitude and longitude points instead of a location ID, but for simplicity we use the location ID copied from the account dashboard. The JSON response will have a data set for every hour, since we configure the request for hourly data. You should get a JSON object similar to the following:
In the above example, each data set represents an hour with the registered humidity, temperature and fireIndex values. This location has high(er) humidity, average temperatures, and a very low Fire Index value. From this example, you can assume that a fire is very unlikely based on weather conditions.
Retrieving Fire Alerts
Retrieving Fire Index values is useful for analyzing future events and determining trends, but it does not tell you when a fire is currently active. You could assume if the fireIndex value is very high (e.g., 90 or more) that a fire could be active, but it does not tell you with accuracy that one is currently an issue.
The Tomorrow.io API has an events endpoint that you can leverage based on specific insight categories. You can identify specific natural disasters using our events endpoint including fires. In this example, we’ll poll the API for fire alerts, but you can get alerts from this endpoint for fog, floods, thunderstorms, tornadoes and numerous other natural events. A list of insights can be found in the API documentation. The insight documentation for fire alerts can be found here.
Tomorrow.io insights makes querying events much easier. The following code queries the events endpoint using the “fires” parameter, which tells the API to respond with fire alerts:
string getTimelineURL = "https://api.tomorrow.io/v4/events"; string apikey = "YOUR API KEY"; string location = "607f3e4188a6a60007947b82"; //locationId string insights = "insights=fires"; string fullUrl = getTimelineURL + "?apikey=" + apikey + "&location=" + location + "&" + insights; var apiResult = CallApi(fullUrl); JObject result = JObject.Parse(apiResult.Result); private static async Task CallApi(string fullUrl) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; HttpClient client = new HttpClient(); var response = client.GetStringAsync(fullUrl); return await response; }
Running this code, you receive alerts based on the location you define in the request. If your location has no fire alerts, you receive an empty data set. With this code, you can send alerts to clients, post them to a website, or use it to manage weather applications.
Note that in both these code snippets, we create a separate method for calling the API. This gives you the ability to reuse the same code for each GET request to the API. Notice that it’s used in the call to the timelines endpoint and the current call to events. The reusable method makes it easier to write your code when the API call just needs a single GET URL string.
Fires are one of the most dangerous weather events that affects livelihoods, businesses, homes, wildfire, and your local economy. With the Tomorrow.io API, you can build applications and alerts that let your neighbors know when a fire is close to their location or collect data to build fire trends. You can also get alerts, insights, and weather conditions based on time and location to stay ahead of natural disasters and severe weather changes to keep you and your neighbors safe.
See how fire alerts – or any other weather condition – work for you by signing up for a free account today!