The Zambretti Algorithm for Weather Forecasting ESP example illustrates how SAS Event Stream Processing can be used to perform various functions, including:
Performing calculations using the ESP Expression Language
Eliminating outliers
Detecting trends
Splitting and rejoining an events stream
Zambretti Algorithm Overview
The Zambretti algorithm is based on an instrument developed by Negretti and Zambra in the mid-1800s to forecast local weather. The partners had already developed a very accurate barometer and realized that by applying principles of weather forecasting to their barometer readings they could also develop an instrument to forecast the weather.
The output of the instrument (or algorithm) is one of 26 forecast statements and can be as much as 94% accurate in the Northern Hemisphere.
The forecast is determined based on four parameters:
Value of the pressure at sea level
Whether the pressure is falling, rising, or steady
Pressure meets range requirements
Wind direction
Pressure at Sea Level
Barometric or atmospheric pressure is affected by altitude and temperature. The pressure measured on a barometer is the station pressure, which does not consider altitude and temperature. Therefore, all pressure values reported must be converted to the pressure at sea level using the following formula. This provides a common metric for all locations.
The ESP Expression Language provides the functionality to include calculations like this to be included in ESP models. You can use the expression language in ESP Compute windows. The following is the expression language equivalent to the above formula:
pressure * pow(1 - (0.0065 * elevationM) / (tempC + (0.0065 * elevationM) + 273.15),-5.257 ))
Pressure Trends
The most significant factor in any weather forecast is whether the atmospheric pressure is falling, rising, or steady. A falling barometer is indicated by a drop of 1.6 millibars within a three-hour period. If the pressure rises 1.6 millibars within three hours, it is a rising barometer. If the pressure neither rises nor falls it is steady.
In ESP, we can detect trends using Pattern windows. There is a pattern window for rising, falling, and steady trend detection. Therefore, the event stream is split into three parallel channels, one for each trend type.
The pattern stores the value of the pressure at sea level for an event, and then determines if subsequent events have a change of 1.6 millibars within three hours.
The first event of interest (EOI), e1, simply stores the value of pressure at sea level. e1 is the same for all three pattern windows.
p0==pressureSeaLevel
The second EOI (e2) of the window looks for a drop of 1.6 millibars, a rise of 1.6 millibars, or no change. The following is an example of e2 for a falling barometer.
p0>pressureSeaLevel + 1.6
The pattern logic says if the first EOI (e1) is followed by the second (e2) within 10800 seconds, output a record:
fby{10800 seconds}(e1,e2)
Pressure Ranges
The pressure values must also fall in specified ranges, meaning some values (outliers) are thrown out. This is accomplished in ESP using Filter windows. There is a filter window for rising, falling, and steady range requirements.
The following table shows the requirements for each type of pressure trend:
Pressure at Sea Level Range
Trend Requirement
Falling
Between 985 mbar and 1050 mbar
Drop of 1.6 mbar in 3 hours
Steady
Between 960 mbar and 1033 mbar
No drop or rise of 1.6 mbar in 3 hours
Rising
Between 947 mbar and 1030 mbar
Rise of 1.6 mbar in 3 hours
Algorithms
To determine the forecast value (Z), we use the appropriate calculation and lookup table based on the trend. A separate calculation and lookup table exists for falling, rising, and steady pressure trends.
The output schema of a pattern window allows for calculated fields. Therefore, the Z factor is part of the output schema of the appropriate pattern window.
Pressure Falling
If the pressure is falling, we use the following formula:
Z = 127 – 0.12p
Since the pressure range for a falling barometer is between 985 and 1050, Z will be between 0 and 9. The following lookup table is used:
Z
Forecast
1
Settled Fine
2
Fine Weather
3
Fine, Becoming Less Settled
4
Fairly Fine, Showery Later
5
Showery, Becoming More Unsettled
6
Unsettled, Rain Later
7
Rain at Times, Worse Later
8
Rain at Times, Becoming Very Unsettled
9
Very Unsettled, Rain
Pressure Steady
If the pressure is steady, we use a different formula:
Z = 144 – 0.13p
The pressure range for steady pressure is between 960 and 1033, giving us a Z factor between 10 and 19. For steady pressures, the following lookup table is used:
Z
Forecast
10
Settled Fine
11
Fine Weather
12
Fine, Possibly Showers
13
Fairly Fine, Showers Likely
14
Showery, Bright Intervals
15
Changeable, Some Rain
16
Unsettled, Rain at Times
17
Rain at Frequent Intervals
18
Very Unsettled, Rain
19
Stormy, Much Rain
Pressure Rising
Rising barometers use a third calculation:
Z = 185 – 0.16p
Z will fall between 20 and 32, because the pressure range is between 947 and 1030. We use this lookup table for rising barometers:
Z
Forecast
20
Settled Fine
21
Fine Weather
22
Becoming Fine
23
Fairly Fine, Improving
24
Fairly Fine, Possibly Showers Early
25
Showery Early, Improving
26
Changeable, Mending
27
Rather Unsettled, Clearing Later
28
Unsettled, Probably Improving
29
Unsettled, Short Fine Intervals
30
Very Unsettled, Finer at Times
31
Stormy, Possibly Improving
32
Stormy, Much Rain
Wind Direction
The direction of the wind and the season have a minor effect on the forecast. If the wind is from the south, we add 2 to the Z factor. If from the west or east, we add 1. A wind from the north has no effect.
The effect wind direction has on Z is calculated using the ESP Expression Language in a Compute window. The following code is used to calculate wind effect:
if (windDir >= 135) and (windDir <= 225) then return 2 else if (windDir >= 315) or (windDir <=45) then return 0 else return 1
Summary
The Zambretti Algorithm for Weather Forecasting ESP example utilizes several of the features of ESP in a fun sort of way. There is more information and code you can execute on the GitHub page for this project. Enjoy!
... View more