November 7

Temperature Delta for Minnesota in 2017

The most traditional use case for weather data is displaying forecast details or current conditions for an end user. However, there are tons of other fun ways to integrate weather data into applications. Using our weather API, I’ll show you how to capture the greatest temperature delta on a monthly basis in Minnesota throughout 2017. Why am I doing this? Well, I simply wanted to know how large our temperature difference was on a monthly basis.

Temperature Delta by Month in 2017

Building the Query

The first component of this project will require us to build out a query that searches the entire state on each day for the highest and lowest temperature. We will need 2 separate queries: one to sort by the highest temperature recorded and one to sort by the lowest temperature recorded. Other than sorting, each request will be identical.

We will hit the observations/summary endpoint and use the search action (because we will search the entire state):

Next, we can add parameters such as date, state, and client credentials. With the date values, I’ll use variables since these change for each query:

I’m also going to utilize the fields parameter to limit the output:

The last parameter will be sorting. Within the observations/summary endpoint, we can see a couple temperature specific sorting parameters. I’ll need to sort by the mint ascending parameter for one query and maxt descending for the other query.

We have all the pieces for the API request now so we can concatenate them to make our queries:

To make this even simpler we can use the batch feature to combine these queries into a single query.* There are several parameters that are used by both queries such as state, date, fields, and client credentials so we can include those outside of the parameter. Within the parameter we will include the endpoints and sorting technique. Also, remember we’ll need to encode the value for the requests parameter. Here’s the full batch request:

* This will still count as 2 separate API hits in a single batch request.

Running the Script

Using NodeJS, we can run the script locally and output to a CSV file that will be used in a spreadsheet application. We need to use a request module that would be able to handle promises so I went with request-promise-native. Using async / await, we’re able to run the queries asynchronously in an attempt to stay below the Aeris account’s minute rate.

from: ,
to: ,
fields: ,
client_id: ,
client_secret: ,
await queryAPI(batchOptions)

async function queryAPI(urlOptions) {
const body = await request(urlOptions);
const json = JSON.parse(body);

function writeToCsv(json) {

let lowestMinResponse = json.response.responses[0].response[0];
let highestMaxResponse = json.response.responses[1].response[0];

let state =;
let date = lowestMinResponse.periods[0].summary.dateTimeISO.substr(0,10);

let lowTemp = lowestMinResponse.periods[0].summary.temp.minF;
let highTemp = highestMaxResponse.periods[0].summary.temp.maxF;



.then(() => {

Once the query is built by setting the date, it gets sent off to the function which will trigger the function. As the script initially loads, we write the column names and kick off the function. Simple enough, right? Once the script is complete, we have data that will help us derive the temperature delta by month.

Preparing the Temperature Delta for Graphing

Now that we have the data, we’re going to need some fancy spreadsheet skills to help paint the full picture. Microsoft Excel or Google Sheets should do the trick – I went with Google Sheets this time around. Using the Named Ranges feature, I created 12 separate data ranges based on the month:

named ranges



Next, I’ll create a separate table to identify the lowest and highest temperature for each month. Using the Named Ranges along with a simple  and  function within Sheets, I can easily return the expected values. Finally, we can add the Delta column by subtracting the high from the low:

MonthLowest TempHighest TempDelta

Graphing the Delta

The temperature delta will be relatively straightforward. First, let’s sort the delta by greatest number which puts the month of December in 1st place at 100. Go, December! In Sheets, select your data range and then Insert > Chart in the top menu. By default, Sheets is smart enough to select Column Chart for us so I’ll leave it at that. However, I will make some style changes to the chart to pretty it up. Here’s our final chart:

Temperature Delta by Month in 2017

Temperature Delta by Month in 2017

As you can see, us Minnesotans endure quite the range of temperatures in the colder months. No wonder we’re notorious for being snowbirds! Meanwhile, the summer months are clearly more consistent which keeps us sane.

Preparing the High’s and Low’s for Graphing

The Delta table is nice and all, but let’s take it one step further and create a table that will help us generate a bar chart for the highs and lows for each month. We can accomplish this with a stacked bar chart which will require 3 more columns in our table:

  1. One to represent negative lows.
  2. Another to represent positive lows.
  3. Finally, one to represent the difference between the high and low if the low is a positive value, otherwise this box will need to be high.

All of these can be achieved with the spreadsheets built-in IF statements.

  1. =IF(B2<0, B2, 0)
  2. =IF(B2>0, B2, 0)
  3. =IF(B2>0, C2B2, C2)

Why are we doing this? Good question! When we’re graphing the temperature difference we actually won’t be using any of the original values we pulled from the API. We’ll be using these new values to stack bars and hide others. Of course, this calculation could have been done in our script, but then we wouldn’t get to have as much fun in the spreadsheet. Here’s the final result:

MonthLow TempHigh TempNegative LowPositive LowHigh Unless Low is Positive

Graphing the High’s and Low’s

We’ll kick off our next chart by going to Insert > Chart from the top menu. Under the Chart type, select the stacked bar chart. Under data range select column A and then Add another range which will be columns D, E, and F. Here’s what we have so far:

Initial Chart

Initial Chart

Remember earlier when I mentioned we were going to hide some values? We want to hide the red bars in the chart above because the end of the bar will represent where the low will start when the low was positive. In the Chart Editor go to Customize > Series. Here we have the option to customize all series, or a specific series. Select the if low positive series and mark the color as none. While we’re here we can make sure the other two series have the same color so the chart flows. After some styling updates, here’s our final product:

Temperature Differences by Month 2017

Temperature Differences by Month 2017

Now we have a handy visualization for the temperature spread and temperature delta for each month! Welcome to Minnesota, where it’s brutally cold in the winter and oppressively hot in the summer. That’s good ol’ Minnesota for you.

Sign up for the weather API today and see what fun visualizations you can create!

Share this post:

Leave a Reply

Your email address will not be published.

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