Skip to main content

Chapter 5: Storm tracks from points

Chapter 5: Storm tracks from points

TipAt a glance
  • In this series: Part II, Paths. Until now, every point was used alone: a city, a star, an earthquake. The points of a storm belong together, and their order in time is important
  • You will build: A world map of 44 years of tropical cyclones, a map of their tracks around Indonesia, a picture of storms by day of the year and latitude, and all storms moved to the same starting point
  • You need: Chapter 0, for the environment, and section 5 of Chapter 1, for lines that work in every shell. About 250 MB of free space
  • Time to run: The commands took less than two minutes when tested, including 22 MB of downloads
  • Level: Intermediate; window functions in SQL are introduced step by step

A tropical cyclone is stored as a list of points, one every three hours. A row has only its own place and time. The path, the speed and the age of the storm come from comparing the rows, and a map of the points alone shows none of them.

SQL has a method for this: a window function gives a row the values of the rows before it. With it, a table of points becomes a table of tracks. This chapter does so for every known storm of 44 years, and then draws them in five different ways.

NoteLearning objectives

By the end of this chapter you will be able to:

  • join points into lines in the right order, one line for each storm;
  • recognise lines that cross the date line, and correct them in two ways;
  • use the values of earlier rows in a row, with lag, sum and over;
  • add up thousands of overlapping shapes into one raster;
  • move shapes to a common starting point to compare their form;
  • test whether the colours of a map keep the order of the data;
  • test a result against a published world record.

Before running this chapter, do section 1 of Chapter 0 and section 5 of Chapter 1. In a terminal, make a new empty folder and copy into it the files of sample-data/ch05. In this notebook, the next cell does that.

import sys
import time
from pathlib import Path

# The repository root, whether the notebook runs from en/, id/ or the root itself
ROOT = Path.cwd() if (Path.cwd() / "tutorial.yml").exists() else Path.cwd().parent
sys.path.insert(0, str(ROOT / "src"))
import oneline

T0 = time.perf_counter()
WORK = oneline.start("05")
print("working folder:", WORK.name, "| files copied there:", sorted(f.name for f in (ROOT / "sample-data/ch05").iterdir()))
working folder: ch05 | files copied there: ['brush.txt', 'season.csv', 'storm.txt', 'year.txt']

Warm-up

A few short commands first, in the form of Chapter 0. The file season.csv has all storm positions of the year 2023, a small part of the archive of section 1 (ledger L41). Each row has the name of the storm, the time, the wind kt in knots, and the position:

gdal vector make-point season.csv season.gpkg --x lon --y lat --dst-crs EPSG:4326 --overwrite

gdal vector grid maximum season.gpkg wind.tif --zfield kt --extent -180,-60,180,60 --size 1440,480 --radius 2 --overwrite

gdal raster color-map wind.tif wind.png --color-map brush.txt --overwrite

The storms of 2023 as bright bands on black, in two belts north and south of an empty equator. The hottest colours are in the east Pacific and the Atlantic, the west Pacific and the southern Indian Ocean.

make-point turns the rows into points, and --dst-crs sets the coordinate system: the numbers are longitude and latitude. grid maximum gives each cell the strongest wind within two degrees.

The picture seems to show the paths of the storms, but it has no lines. The points only lie close together. Select one storm, and look at its first rows:

gdal vector filter season.gpkg freddy.gpkg --where "name='FREDDY'" --overwrite

gdal vector info freddy.gpkg --limit 2 --format text
INFO: Open of `freddy.gpkg'
      using driver `GPKG' successful.

Layer name: season
Geometry: Point
Feature Count: 305
Extent: (31.300000, -24.100000) - (118.900000, -10.900000)
Layer SRS WKT:
GEOGCRS["WGS 84",
    ENSEMBLE["World Geodetic System 1984 ensemble",
        MEMBER["World Geodetic System 1984 (Transit)"],
        MEMBER["World Geodetic System 1984 (G730)"],
        MEMBER["World Geodetic System 1984 (G873)"],
        MEMBER["World Geodetic System 1984 (G1150)"],
        MEMBER["World Geodetic System 1984 (G1674)"],
        MEMBER["World Geodetic System 1984 (G1762)"],
        MEMBER["World Geodetic System 1984 (G2139)"],
        MEMBER["World Geodetic System 1984 (G2296)"],
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ENSEMBLEACCURACY[2.0]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["Horizontal component of 3D system."],
        AREA["World."],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
FID Column = fid
Geometry Column = geometry
NAME: String (0.0)
SID: String (0.0)
utc: String (0.0)
kt: String (0.0)
lon: String (0.0)
lat: String (0.0)
OGRFeature(season):550
  NAME (String) = FREDDY
  SID (String) = 2023036S12117
  utc (String) = 2023-02-04 12:00:00
  kt (String) = 25
  lon (String) = 116.6
  lat (String) = -12.3
  POINT (116.6 -12.3)

OGRFeature(season):551
  NAME (String) = FREDDY
  SID (String) = 2023036S12117
  utc (String) = 2023-02-04 15:00:00
  kt (String) = 25
  lon (String) = 117
  lat (String) = -12.2
  POINT (117.0 -12.2)

Look before moving on. Each row has a place and a time, and nothing in it tells you which row comes next. That is the subject of this chapter. (Freddy appears again in section 9, because it set a record.)

1. Every storm since 1980

IBTrACS is an archive kept by NOAA. It merges the records of weather services around the world, and may be used and passed on without restriction (ledger L41). The points since 1980 are a shapefile in a zip of 20 MB. The first line reads it from the web and keeps what this chapter needs:

ogr2ogr -overwrite storms.gpkg "/vsizip//vsicurl/https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r01/access/shapefile/IBTrACS.since1980.list.v04r01.points.zip" -dialect SQLite -sql "select sid, name, basin, iso_time utc, usa_wind kt, geometry geom from 'IBTrACS.since1980.list.v04r01.points' where track_type='main' and iso_time<'2024'" -nln fix

ogr2ogr -update -overwrite storms.gpkg /vsizip//vsicurl/https://naciscdn.org/naturalearth/50m/physical/ne_50m_land.zip -nln land -nlt PROMOTE_TO_MULTI

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select count(*) positions, count(distinct sid) storms, min(utc) first, max(utc) last, max(kt) strongest from fix"
positions,storms,first,last,strongest
292572,4643,1980-01-01 00:00:00,2023-12-31 21:00:00,185
Part Meaning
sid the identifier of a storm. Names are used again in later years, so they do not identify a storm
usa_wind kt the highest sustained wind in knots, as given by the US agencies, averaged over one minute (ledger L42). One knot is 1.852 km/h
track_type='main' leaves out short side tracks, and recent storms whose record is still provisional (ledger L42)
iso_time<'2024' 44 full years. The newer ones are still being checked
'IBTrACS.since1980...' the layer name has dots in it, so it needs quotes. SQLite accepts single ones, so the double ones are free for the shell

Why one agency for the wind? Most services average the wind over ten minutes, and the numbers cannot simply be converted into each other (ledger L42). One column with one method is better than a mixture. It has gaps, though:

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select sid, name, utc, kt, round(st_x(geom),1) east, round(st_y(geom),1) north from fix where name='SEROJA' order by utc limit 10"
SID,NAME,utc,kt,east,north
2021093S11122,SEROJA,2021-04-02 12:00:00,,122.1,-11.1
2021093S11122,SEROJA,2021-04-02 15:00:00,,122.2,-11.1
2021093S11122,SEROJA,2021-04-02 18:00:00,,122.2,-11
2021093S11122,SEROJA,2021-04-02 21:00:00,,122.3,-10.9
2021093S11122,SEROJA,2021-04-03 00:00:00,,122.4,-10.7
2021093S11122,SEROJA,2021-04-03 03:00:00,,122.7,-10.6
2021093S11122,SEROJA,2021-04-03 06:00:00,25,123.1,-10.6
2021093S11122,SEROJA,2021-04-03 09:00:00,28,123.5,-10.6
2021093S11122,SEROJA,2021-04-03 12:00:00,30,123.7,-10.7
2021093S11122,SEROJA,2021-04-03 15:00:00,30,123.8,-10.7

This is Seroja, which formed near Timor in April 2021. The first positions have no wind, then there is one every three hours. Most agencies report every six hours, and the archive calculates the positions between them (ledger L42).

Look before moving on. A single row does not show where the storm came from. Row 8 has a meaning only together with row 7.

2. One line for each storm

makeline joins points into a line, and group by sid makes one line for each storm. The points must arrive in the order of time, so an inner query sorts them first:

ogr2ogr -update -overwrite storms.gpkg storms.gpkg -sql "select sid, max(name) name, min(utc) born, max(kt) kt, makeline(geom) geom from (select * from fix order by sid, utc) group by sid having count(*)>1" -nln raw -nlt LINESTRING

gdal pipeline read storms.gpkg ! sql "select 1 v, geom from land union all select 6, geom from raw" ! rasterize --attribute-name v --init 0 --ot Byte --size "3600,1300" --extent "-180,-60,180,70" ! edit --nodata none ! color-map --color-map storm.txt ! materialize ! resize --size "1800,650" -r average ! write broken.png --overwrite

World map with pale yellow storm tracks. Hundreds of straight horizontal lines run across the whole map from the left edge to the right edge, over Africa, Asia and America.

having count(*)>1 removes a few storms with a single position, which cannot make a line.

Look before moving on. The tracks are there, and so are hundreds of straight lines across the whole map. A storm that crosses 180 degrees has a point at 179 and the next one at -179. The true step is two degrees long, and the line goes the 358 degrees in the other direction.

To find the steps where this happens, a row needs the value of the row before it. This is lag:

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select count(*) jumps, count(distinct sid) storms from (select sid, st_x(geom)-lag(st_x(geom)) over (partition by sid order by utc) step from fix) where abs(step)>180"
jumps,storms
411,359

Read it from the inside out:

  • lag(st_x(geom)) is the longitude of the previous row;
  • over (...) defines what “previous” means. partition by sid treats every storm separately, and order by utc sorts by time;
  • so step is the change of longitude in three hours. No storm moves 180 degrees in that time, so a larger step is an error at the date line.

3. Cut the lines, or continue the longitude

There are two good corrections, for two purposes.

Cut the lines at 180 degrees when the result goes to other people or to a web map. -wrapdateline did it for the constellations of Chapter 3, and it works here too:

ogr2ogr -overwrite tracks.geojson storms.gpkg raw -s_srs EPSG:4326 -t_srs EPSG:4326 -wrapdateline -datelineoffset 50 -nln tracks -nlt PROMOTE_TO_MULTI -lco COORDINATE_PRECISION=2

Continue the longitude past 180 when you want to go on calculating: 179, 181, 183. Such a storm has no break at all. The next line starts each storm somewhere between 25 and 385 degrees, and then adds up the true steps:

ogr2ogr -update -overwrite storms.gpkg storms.gpkg -sql "select sid, name, utc, kt, makepoint(sum(dx) over (partition by sid order by utc), y) geom from (select *, st_y(geom) y, coalesce(mod(st_x(geom)-lag(st_x(geom)) over (partition by sid order by utc)+540,360)-180, mod(st_x(geom)+335,360)+25) dx from fix)" -nln pos -nlt POINT -a_srs EPSG:4326

ogr2ogr -update -overwrite storms.gpkg storms.gpkg -sql "select sid, max(name) name, min(utc) born, max(kt) kt, makeline(geom) geom from (select * from pos order by sid, utc) group by sid having count(*)>1" -nln track -nlt LINESTRING
Part Meaning
mod(step+540,360)-180 brings any step into the range from -180 to 180. A step of -358 becomes 2
coalesce(a, b) takes b if a is empty. The first row of a storm has no previous row, so it takes its own longitude, counted from 25
sum(dx) over (...) a running total: the start plus all steps so far. With order by, a window reaches from the first row to the current one

Why 25? The left and right edges of the map will be at this longitude, which goes through Africa, where very few storms pass. The Pacific stays in one piece.

Is it right? Both corrections should give the same length of track, and both should be much shorter than the version with the errors:

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select (select round(sum(st_length(geom))) from raw) broken_degrees, (select round(sum(st_length(geom))) from track) unrolled_degrees"

ogr2ogr -f CSV /vsistdout/ tracks.geojson -dialect SQLite -sql "select round(sum(st_length(geometry))) cut_degrees, sum(st_numgeometries(geometry)>1) storms_cut from tracks"
broken_degrees,unrolled_degrees
299504,152578
cut_degrees,storms_cut
152571,359

Look before moving on. About half of the length in the first map was an error. The two corrections agree, apart from the rounding of the coordinates in the GeoJSON, and the number of storms that were cut is the number that lag found.

4. Every step with its own wind

One line for each storm has one colour. To show how the wind of a storm increases and decreases, make a line for every step, from the previous point to this one, with the wind at its end:

ogr2ogr -update -overwrite storms.gpkg storms.gpkg -sql "select sid, name, utc, kt, makeline(before, geom) geom from (select *, lag(geom) over (partition by sid order by utc) before from pos) where before is not null" -nln step -nlt LINESTRING -a_srs EPSG:4326

gdal pipeline read storms.gpkg ! sql "select 1 v, geom from land union all select 1, st_translate(geom,360,0,0) from land union all select * from (select case when kt is null or kt<34 then 2 when kt<64 then 3 when kt<96 then 4 when kt<137 then 5 else 6 end v, geom from step order by 1)" ! rasterize --attribute-name v --init 0 --ot Byte --size "3600,1200" --extent "25,-55,385,65" ! edit --nodata none ! color-map --color-map storm.txt ! materialize ! resize --size "1800,600" -r average ! write world.png --overwrite

World map centred on the Pacific with nearly 300,000 short coloured lines. A dense orange and pale yellow cloud lies east of the Philippines, others off Mexico and in the North Atlantic. South of the equator a belt runs from Madagascar past Australia into the Pacific. The equator itself is an empty strip, and so is most of the sea around South America.

lag works for geometries as well: before is the previous point. The land is drawn twice, the second time moved by 360 degrees, because this map runs from 25 to 385.

The colours follow the Saffir-Simpson scale that the archive uses (ledger L42):

Colour Wind in knots Name
dark blue-grey under 34, or not given depression
blue 34 to 63 tropical storm
pink 64 to 95 categories 1 and 2
orange 96 to 136 categories 3 and 4
pale yellow 137 and more category 5

Why not red for the strongest? Wind is a quantity, so the colours have an order, and people recognise an order by lightness better than by hue (ledger L49). On a dark map the strongest storms must therefore be the lightest. Red is darker than yellow, and a red line would be hard to see against the dark background. GDAL can make the test. This line turns the picture into shades of grey, with weights for red, green and blue that are close to how bright they look:

gdal pipeline calc -i X=world.png --calc "0.2126*X[1]+0.7152*X[2]+0.0722*X[3]" --ot Byte ! write grey.png --overwrite

The same world map in shades of grey. The brightest areas are still the sea east of the Philippines and the sea off Mexico, and the weak parts of the tracks are dark.

The strong parts are still the bright ones. A map that passes this test also works in a black and white print, and for readers who cannot distinguish red from green.

Look before moving on. Two things in this picture come from the records and not from the weather.

  • In the far north of the Pacific, many tracks stop in a straight line. That line is the 180th meridian. The documentation warns of large differences there, because the responsible agency changes (ledger L43).
  • A few tracks end in a perfectly horizontal piece. They are in the data: some reports kept the same latitude to the end (ledger L43).

A third thing comes from the weather. Along the equator there is an empty strip, and Indonesia lies in it.

5. Storm tracks around Indonesia

Get the outline of Indonesia, as in Chapter 1, and draw the same steps at a larger scale:

ogr2ogr -update -overwrite storms.gpkg /vsizip//vsicurl/https://naciscdn.org/naturalearth/50m/cultural/ne_50m_admin_0_countries.zip -nln idn -nlt PROMOTE_TO_MULTI -sql "select name country from ne_50m_admin_0_countries where name='Indonesia'"

gdal pipeline read storms.gpkg ! sql "select 1 v, geom from land union all select 7, geom from idn union all select * from (select case when kt is null or kt<34 then 2 when kt<64 then 3 when kt<96 then 4 when kt<137 then 5 else 6 end v, st_buffer(geom, case when kt>=34 then 0.05 else 0.025 end) geom from step where st_maxx(geom)>90 and st_minx(geom)<145 and st_maxy(geom)>-20 and st_miny(geom)<14 order by 1)" ! rasterize --attribute-name v --init 0 --ot Byte --size "4950,3060" --extent "90,-20,145,14" ! edit --nodata none ! color-map --color-map storm.txt ! materialize ! resize --size "1650,1020" -r average ! write indonesia.png --overwrite

Indonesia in light grey on a dark map, with storm tracks above and below it. A dense weave of blue, pink, orange and pale yellow lines fills the upper right, over the Philippines, and the lower part, off Australia. Between them the tracks leave a wide empty band in which the islands lie. One short line reaches Singapore.

Look before moving on. Very few storms reach the islands. A cyclone needs the rotation of the Earth to start spinning, through the Coriolis force, and close to the equator that force is too small. The Hong Kong Observatory gives 5 degrees as the limit within which cyclones hardly form (ledger L44).

There are exceptions. Which storms came nearest to the equator?

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select name, date(utc) day, round(min(abs(st_y(geom))),1) degrees_from_equator, kt, round(st_x(geom)) east from pos where kt>=34 group by sid order by 3 limit 5"
NAME,day,degrees_from_equator,kt,east
UNNAMED,2004-11-28,0.7,35,69
VAMEI,2001-12-26,1.5,35,106
PEIPAH,2014-04-04,2.6,35,145
PALI,2016-01-14,2.7,35,188
BOPHA,2012-11-29,3.5,50,148

The second one is Vamei, the single line near Singapore in the picture. It was on record as the first to form so close to the equator (ledger L44). The unnamed storm in the first row came later, in the Indian Ocean.

This query uses a special feature of SQLite. With min() and a group by, the other columns, here utc, kt and the longitude, come from the row with the minimum. Most other databases do not accept such a query.

And which storms came within about one degree of Indonesian land, at storm strength?

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select name, date(utc) day, kt, round(min(st_distance(p.geom,i.geom))*111.2) km_to_land, round(st_x(p.geom),1) east, round(st_y(p.geom),1) north from pos p, idn i where kt>=34 and st_x(p.geom) between 93 and 143 and st_distance(p.geom,i.geom)<1 group by sid order by day"
NAME,day,kt,km_to_land,east,north
ESTHER,1983-12-20,40,0,127.9,-8.2
KAY,1987-04-08,35,25,138.6,-8.6
MARIAN,1991-04-11,35,83,124.8,-10.8
VIVIENNE,1994-04-07,35,32,122.9,-11.2
CHLOE,1995-04-05,35,73,121.1,-10.8
UNNAMED,2001-11-21,35,45,128.8,-6.7
VAMEI,2001-12-27,35,33,102.7,1.7
BONNIE,2002-04-11,45,0,120.8,-10.1
INIGO,2003-04-01,35,0,120.3,-10.1
KIRRILY,2009-04-27,40,0,134.3,-6.6
ERROL,2011-04-17,35,0,124.6,-10
LILI,2019-05-08,35,76,128.8,-8.1
SEROJA,2021-04-04,40,3,123.3,-10.3
ILSA,2023-04-07,35,89,130.5,-9.1

Look before moving on. Fourteen in 44 years, and ten of them in April. All but Vamei came to the south-east, between Sumba and Papua. Each row shows the moment when the storm was nearest. The distances are rough: they are calculated from degrees, and to a simplified coast.

The list is also too short. Cempaka, off the south coast of Java in November 2017, is missing. The archive has its track, but the column used here has no wind for it at all, so kt>=34 removes it without a message. A condition on a column with gaps also removes the rows with a gap. A storm can also cause great damage with its rain from far away, and this list contains nothing about rain.

6. How many storms pass here?

Where many lines lie on top of each other, a map of lines becomes unreadable. Count them instead. Every storm gets a wide band along its path, one degree to each side, and GDAL counts how many bands cover each place:

gdal_rasterize -q -add -burn 1 -init 0 -ot Float32 -te 25 -55 385 65 -tr 0.25 0.25 -sql "select st_buffer(geom,1,6) geom from track where kt>=34" storms.gpkg brush.tif

gdal pipeline read brush.tif ! edit --nodata none ! materialize ! resize --size "1800,600" -r cubicspline ! color-map --color-map brush.txt ! write brush_map.tif --overwrite

gdal_rasterize -q -b 1 -b 2 -b 3 -burn 130 -burn 145 -burn 165 -sql "select st_boundary(geom) geom from land union all select st_boundary(st_translate(geom,360,0,0)) from land" storms.gpkg brush_map.tif

gdal_translate -q -of PNG brush_map.tif brush.png

A density map on a dark background, centred on the Pacific. The brightest spot lies off the west coast of Mexico, and a larger bright area stretches from the South China Sea past the Philippines into the Pacific. The belts of the Southern Hemisphere are fainter, and the equator is dark.

gdal_rasterize -add is the command of Chapter 4, now with areas instead of points. In brush.txt, too, lightness rises evenly with the number, so that equal steps in the number look like equal steps in the picture (ledger L49). A storm whose track makes a loop still counts once, because its buffer is one shape. The number in a cell is therefore the number of storms whose centre passed within one degree, in 44 years, among those that reached storm strength at some time.

edit --nodata none ! materialize stands in front of resize for a reason. The zeros in the raster are marked as “no data”, and resize would not blend with them. The edges would then be square blocks (ledger L45).

Read the raster at single places, here Manila, Kupang and Jakarta:

gdallocationinfo -valonly -geoloc brush.tif 120.98 14.60

gdallocationinfo -valonly -geoloc brush.tif 123.60 -10.17

gdallocationinfo -valonly -geoloc brush.tif 106.80 -6.20
54
11
0

Look before moving on. More than one a year for Manila, one every four years for Kupang, and none for Jakarta. The highest number of the whole map is neither in Asia nor in the Caribbean. It lies off the west coast of Mexico, at about 16 degrees north and 108 degrees west, with 145 storms.

7. Storms by day of the year

Chapter 4 had time on the x axis. Here the x axis is the day of the year, so all 44 years are drawn on top of each other. The y axis is latitude:

gdal_rasterize -q -add -burn 1 -init 0 -ot Float32 -te 0 -45 366 55 -tr 3 1 -sql "select makepoint(julianday(utc)-julianday(date(utc,'start of year')), st_y(geom)) geom from pos where kt>=34" storms.gpkg year.tif

gdal pipeline read year.tif ! edit --nodata none ! materialize ! resize --size "1464,800" -r cubicspline ! color-map --color-map year.txt ! write year_map.tif --overwrite

gdal_rasterize -q -b 1 -b 2 -b 3 -burn 90 -burn 105 -burn 130 -sql "with recursive m(d) as (select '2023-01-01' union all select date(d,'+1 month') from m where d<'2023-12-01') select makeline(makepoint(0,0),makepoint(366,0)) geom union all select makeline(makepoint(julianday(d)-julianday('2023-01-01'),-45), makepoint(julianday(d)-julianday('2023-01-01'),55)) from m" storms.gpkg year_map.tif

gdal_translate -q -of PNG year_map.tif year.png

The months run from left to right and latitude from bottom to top, with a line at the equator. Above the equator a bright arch rises from May, is brightest from August to October, and falls towards December. Below the equator a second bright area runs from December to April. A dark strip along the equator separates them.

The grid is three days wide and one degree high, and a point is added for every three hours of every storm. The third line draws the equator and the first of each month into the finished picture.

Look before moving on. The two hemispheres have their seasons at different times. The northern season starts in May, is at its height in August and September, and the southern one runs from December to April. The northern part never ends completely. And the dark strip along the equator is there again, in a picture that has no map in it.

8. All storms from one point

Every storm starts in a different place, which makes their forms hard to compare. So move them. st_translate moves each track by its own first point, and all 3,807 storms start at the same place, in the middle of the picture:

gdal pipeline read storms.gpkg ! sql "select case when st_y(st_startpoint(geom))>0 then 6 else 3 end v, st_translate(geom, -st_x(st_startpoint(geom)), -st_y(st_startpoint(geom)), 0) geom from track where kt>=34" ! edit --crs none ! rasterize --attribute-name v --init 0 --ot Byte --size "3600,2000" --extent "-90,-45,90,55" ! edit --nodata none ! color-map --color-map storm.txt ! materialize ! resize --size "1800,1000" -r average ! write birth.png --overwrite

Thousands of curves start from one point in the middle. The yellow ones, of the Northern Hemisphere, go left and upwards, and many bend over to the right. The blue ones, of the Southern Hemisphere, go down, to the left and to the right.

Look before moving on. Yellow storms started north of the equator, and blue ones south of it. Both first go left, towards the west. Then both turn away from the equator, up or down, and many turn round towards the east. There are no coasts, no countries and no dates in this picture, only the form of the movement, and the form is nearly the same for a typhoon and for an Atlantic hurricane.

How many storms follow that rule?

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select case when y0>0 then 'north' else 'south' end hemisphere, count(*) storms, round(100.0*avg(abs(y1)>abs(y0))) percent_end_further_from_equator, round(100.0*avg(x1<x0)) percent_end_further_west, sum(crossed) crossed_the_equator from (select st_x(st_startpoint(geom)) x0, st_y(st_startpoint(geom)) y0, st_x(st_endpoint(geom)) x1, st_y(st_endpoint(geom)) y1, st_miny(geom)<0 and st_maxy(geom)>0 crossed from track where kt>=34) group by 1"
hemisphere,storms,percent_end_further_from_equator,percent_end_further_west,crossed_the_equator
north,2700,95,70,0
south,1107,97,53,0

Nearly all end further from the equator than they began, and not one of them crossed it. The turn to the east is less of a rule: most northern storms, and about half of the southern ones, still end further west than they began.

9. The longest distance and the longest life

Tracks can be measured. The last 1 in st_length(..., 1) gives the length in metres on the ellipsoid. The World Meteorological Organization (WMO) counts only the time at storm strength, so this line keeps each storm from its first to its last position with 34 knots or more:

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select name, date(a) first_day, round(julianday(b)-julianday(a),1) days, round(st_length(makeline(geom),1)/1000) km from (select * from (select *, min(case when kt>=34 then utc end) over (partition by sid) a, max(case when kt>=34 then utc end) over (partition by sid) b from pos) where utc>=a and utc<=b order by sid, utc) group by sid order by km desc limit 5"
NAME,first_day,days,km
JOHN,1994-08-11,29.5,13214
FREDDY,2023-02-06,34.8,12726
ALBERTO,2000-08-04,20.3,12084
IVAN,2004-09-03,20.6,11961
MITCH,1998-10-22,18,11762

over (partition by sid) without order by uses the whole storm. Every row gets the first and the last time at which its storm was strong, and the where around it uses them.

Is it right? In 2024 a committee of the WMO confirmed both records (ledger L46):

This chapter WMO
John, 1994, the longest distance 13,214 km in 29.5 days 13,159 km in 29.75 days
Freddy, 2023, the longest life 12,726 km in 34.8 days 12,785 km in 36.0 days

The distances agree to within half a percent. The days differ a little more. WMO accepted only observations at storm strength, while this line also keeps the weaker periods in between, and the committee worked with the records of several agencies. The order is the same: John travelled further, and Freddy lasted longer.

10. One file for each ocean

A line for everyday work. A colleague needs one ocean, and not the world. partition splits a layer by the values of a column, and makes the folders itself:

gdal vector pipeline read storms.gpkg --input-layer fix ! partition basins --field basin --format GPKG --overwrite

ogr2ogr -f CSV /vsistdout/ storms.gpkg -sql "select basin, count(*) positions, count(distinct sid) storms from fix group by basin order by 2 desc"
basins
BASIN,positions,storms
WP,98443,1417
SI,62102,833
EP,47148,1084
NA,39560,711
SP,30449,510
NI,14751,440
SA,119,3

The result is a file for each value, such as basins/fix/basin=SI/part_0000000001.gpkg for the South Indian Ocean. This way of naming folders is called hive. With --scheme flat all files go into one folder.

The storms in the last column add up to more than the total of section 1. A storm that moves into another ocean has positions in both.

Try it yourself

  • One year. Draw the map of section 4 for a single year, with where utc>='2021' and utc<'2022' after from step.
  • Colours by ocean. Colour the picture of section 8 by ocean. The layer fix has the column basin, and the lines of section 3 can copy it.
  • A narrower band. Change the 1 in st_buffer(geom,1,6) to 0.5 and read the value for Manila again. Is the number half as large?
  • The storms of now. Replace since1980 by ACTIVE in both places of the first line, and leave out the where.

Checkpoint

The cell below stops with an error if the results are not what this chapter expects.

import csv
import io

def rows(sql, dataset="storms.gpkg"):
    """The rows of a query, as dictionaries."""
    return list(csv.DictReader(io.StringIO(oneline.run(f'ogr2ogr -f CSV /vsistdout/ {dataset} -sql "{sql}"'))))

n = int(rows("select count(*) n from fix")[0]["n"])
assert 285_000 < n < 300_000, "section 1 should find about 292,000 positions"

longest = float(rows("select max(st_length(geom)) m from step")[0]["m"])
assert longest < 10, "no storm should move more than 10 degrees in one step"

# The tracks must be as long as the sum of their steps: the points were joined in the right order
a, b = (float(rows(f"select sum(st_length(geom)) m from {t}")[0]["m"]) for t in ("track", "step"))
assert abs(a - b) < 0.01, "tracks and steps should have the same total length"

from osgeo import gdal
gdal.UseExceptions()
year = gdal.Open("year.tif").ReadAsArray()
assert year.sum() > 100_000 and year[:, :].argmax() // year.shape[1] < 55, "the busiest cell should be north of the equator"

pictures = ("broken.png", "world.png", "grey.png", "indonesia.png", "brush.png", "year.png", "birth.png")
assert all((WORK / f).stat().st_size > 10_000 for f in pictures)
print(f"checkpoint passed: {n:,} positions; longest step {longest:.1f} degrees; tracks and steps differ by {abs(a - b):.6f} degrees")
print(f"time since the first cell: {time.perf_counter() - T0:.0f} s")
checkpoint passed: 292,572 positions; longest step 6.8 degrees; tracks and steps differ by 0.000000 degrees
time since the first cell: 110 s

Troubleshooting

Symptom Cause Fix
incomplete input order by inside the brackets of makeline(...). GDAL 3.12.3 cuts the query off there (ledger L47) Sort in an inner query, as in section 2
Lines that go back and forth The points were joined in the wrong order The inner query needs order by sid, utc
Horizontal lines across the map Steps over 180 degrees Section 3
A storm is missing Its wind is empty, and kt>=34 leaves out empty values where kt>=34 or kt is null
The first line stops with an error The connection to the server was lost Download the zip with a browser, and write /vsizip/ and its file name in place of the address
Square blocks at the edge of a smooth map resize treats zeros as no data edit --nodata none ! materialize before resize (ledger L45)

What comes next

In this chapter, each row used the values of the row before it, and points became paths. In Chapter 6: Graphs and maps from a bus timetable the points are bus stops, the time comes from the timetable, and one picture shows a whole day of traffic.

Storm data: NOAA’s International Best Track Archive for Climate Stewardship (IBTrACS) data, accessed on 3 December 2026, doi:10.25921/82ty-9e16, and Knapp and others (2010), doi:10.1175/2009BAMS2755.1. Land and countries: Natural Earth, in the public domain.