ArcGIS Developers

ArcGIS API for Python

Download the samples Try it live

Temperature forecast using time series data


Weather forecasting has been a significant area for application of advanced deep learning and machine learning methodologies over traditional methods to improve weather prediction. These new methods are appropriate for processing large chunks of data where massive quantity of historic weather datasets could be utilized for forecasting. This sample showcases two autoregressive methods: one using a deep learning and another using a machine learning framework to predict temperature of England.

Historic temperature data from various weather stations across England is collected from here. The data consists of daily temperature measurements ranging from February 2005 till September 2019 which are auto regressed to predict daily temperature for each of the identified stations for October 2019. The forecasted temperature obtained for the stations is then spatially interpolated using ArcGIS spatial interpolation tool to produce a temperature prediction surface for the entire country. Here is a schematic flow chart of the operation:


Some required libraries for this sample are NumPy for processing arrays, pandas for operating with DataFrame, ArcGIS for geoprocessing, scikit-learn=0.22.1 for machine learning, tensorflow=2.0.0 and keras=2.2.4 for deep learning.

Necessary Imports

In [3]:
%matplotlib inline
import matplotlib.pyplot as plt

import numpy as np
import pandas as pd
import math
from datetime import datetime as dt
from IPython.display import Image, HTML

from sklearn.svm import SVR
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error, r2_score

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Activation, Dropout
from tensorflow.keras.optimizers import Adam
import tensorflow.keras.backend as K

from arcgis.gis import GIS
from arcgis.features import SpatialDataFrame
from arcgis.features.analysis import interpolate_points

Connect to your GIS

In [5]:
gis = GIS('home')

Obtain and Visualize Data for Analysis

The primary data used for this sample is as follows:

Data 1— England Boundary

First the boundary of England shapefile is accessed. This will be used to interpolate temperature within this particular area.

In [6]:
# Access England Boundary
england_border = gis.content.get('0856d38fea9149a48227cdc2f1e4f4f6')
Feature Layer Collection by api_data_owner
Last Modified: December 17, 2019
0 comments, 22 views
In [7]:
# Get the feature layer
england_boundary_layer = england_border.layers[0]
In [77]:
# Plot England boundary
england_map ='England', zoomlevel=6)

Data 2 — England Weather Stations

There are several weather stations in England that record a variety of weather data. Here 29 weather stations are strategically selected such that they are well distributed across England and can be used to forecast temperature which will cover the entire country. These include stations located at prominent English cities such as London, Birmingham, Cardiff, Exeter, Nottingham, Plymouth and others, as shown in the map below.

In [8]:
# Access England Weather Stations
england_weather_stations = gis.content.get('fd3ecbd95b7148b8a7cbcc866cedd514')
Feature Layer Collection by api_data_owner
Last Modified: December 20, 2019
0 comments, 5 views
In [9]:
england_weather_stations_layer = england_weather_stations.layers[0]
In [78]:
# England weather stations
england_weather_stations_map ='England', zoomlevel=6)