77 thousand cities: how many distinct forecast points need processing

Separate cities, language pages and grid nodes. An independent example counts shared forecast reads while preserving the identity of each place.

A conceptual paper illustration of distinct places sharing a weather source.
A conceptual paper illustration of distinct places sharing a weather source.

A catalogue on the scale of 77 thousand cities invites a simple calculation: that many forecasts, multiplied by the number of languages and weather variables. It is easy to start choosing a server, planning a queue and estimating update time from that calculation. The problem is that its factors describe different things. A language page, a populated place and a position in a model grid do not have a one-to-one relationship.

Here, “77 thousand” sets the scale of the product problem. It does not report a full import performed for this article. We use “city” to mean a populated-place record in the catalogue. The experiment itself is much smaller: six fictional places, fourteen language URLs and three explicitly assigned positions in a teaching grid. They let us check which work can actually be shared while preserving each page’s identity.

Count the different objects first

For the reader, the main object is the selected place. It has its own name, administrative context, coordinates and local time. Switching from Ukrainian to English changes the presentation of that place. It must not silently select a different populated place.

A forecast source can organise its data differently. For example, ECMWF describes its open IFS data as forecasts interpolated onto a latitude/longitude grid. A city catalogue and the nodes of that grid have different roles. Obtaining a value requires a separate rule that connects the requested place to the model’s data.

In this exercise, those connections are already supplied. We do not choose the nearest node from coordinates, interpolate between nodes or account for terrain. That is the next domain decision. Today we check what happens after a mapping has been accepted.

What we count Identity in the exercise Why it needs separate accounting
City city_id Preserve the selected place and its relationships
Language URL City and locale Prepare a representation the reader can access
Grid position Grid, its revision, row and column Locate a particular source value
Read job Position and the full context of a forecast field Reuse only a compatible result

The number of URLs does not tell us the number of source values. Neither does the number of cities without an actual mapping table.

Six places must not become three cities

The teaching grid has three rows and four columns. It is an address space for the exercise, not a geographical map. A literal input table connects six fictional places to it:

City Example display name Available locales Position in grid v1
p01 Луг uk, ru, en, pl row 1, column 1
p02 Луг uk, en row 1, column 1
p03 Тиха Вода uk, ru, en row 1, column 2
p04 Low Hill en row 1, column 2
p05 Верхній Сад uk, pl row 2, column 0
p06 Новий Сад uk, ru row 2, column 0

The two places named Луг deliberately have different IDs. A matching name, and even the same forecast node, does not make them one place. They retain their own pages. Only a source value that satisfies the reuse conditions is shared.

The locale lists differ as well. p04 has only an English version, so “six cities times four languages” would produce 24 URLs instead of 14. The planner uses an explicit list rather than assuming that missing language pages should exist.

For the demonstration, a URL is built from the stable ID: /uk/places/p01. This is a teaching route, not a recommendation to change an existing site’s URLs. A name can change without changing that ID. A real product separately defines its slugs, redirects and language availability.

The same row and column do not necessarily mean the same data

The pair (1, 1) is meaningful only within a defined grid. In a grid with different geometry, the same index can refer to a different place. The teaching key therefore includes grid_id and grid_revision. Moving from v1 to v2 creates a different read identity even when the row and column numbers match.

The context of the forecast matters just as much. Temperature and relative humidity are different fields. Values at step 3 and step 6 are different requests. A new model run or a corrected source version must not receive a value under the old key either.

The exercise uses this key:

@dataclass(frozen=True, order=True)
class ReadKey:
    source: str
    model: str
    run: str
    source_revision: str
    grid_id: str
    grid_revision: str
    row: int
    column: int
    variable: str
    step: int

This is our own bounded contract. The names air_temperature_2m and relative_humidity_2m already specify the quantity and height. It does not cover arbitrary levels, ensemble members or temporal aggregates. Adding such data would require extending the identity, not merely returning another number.

dataclass with frozen=True restricts assignment to fields. Here the fields contain strings and integers, so the key can be used in a set. The decorator itself does not validate geography or establish data provenance. Source and grid versions in this exercise are trusted synthetic inputs; there is no mechanism for externally attesting them.

The read plan does not depend on the number of translations

The planner first validates all selected cities, bindings and fields. It then builds a set of jobs:

jobs = tuple(sorted({
    read_key(grid, scope, binding, field)
    for binding in ordered_bindings
    for field in ordered_fields
}))

A Python set stores distinct elements. In this example, equality of every ReadKey field means that the same read is needed. Sorting provides a stable order for checking the result; it does not determine city priority or a variable’s importance.

Locales are absent from this loop. They are needed after the values have been obtained, when the result is distributed to pages. Adding a Ukrainian version for p04 therefore increases the URL count from 14 to 15 while leaving the source-work plan unchanged.

This reuse requires the field’s meaning to remain the same. Translating the label “temperature” does not change its numerical basis. If a separate product or user applies a different correction, time interval or source, we must determine again at which layer the result is still shared. Language independence does not justify mixing different calculation rules.

What the execution showed

The experiment requests two fields at one synthetic forecast step. Its reader function takes six predefined numbers from an in-memory dictionary. It neither calls a weather service nor downloads a file.

Way of counting jobs For our fixture
Separately for each language URL 14 × 2 = 28
Separately for each city 6 × 2 = 12
By distinct read keys 3 × 2 = 6
Actual reader-function calls in one pass 6
Network requests 0

One field leaves three keys. Two fields leave six. All 14 representations receive their required values and keep their own IDs and locales. A missing value, None, also remains missing: sharing does not turn it into zero.

Twelve and twenty-eight in the table are arithmetic plans for a naive traversal. Six is also the observed number of calls to our reader. This is not a speedup measurement. A single HTTP request can deliver many values; one binary block may need decoding for several nodes. The physical download plan and the logical value plan must be measured separately.

Errors to catch before reading

The planner rejects a repeated city_id, two bindings for one city, a missing binding or a reference to an unknown city. It does not pick the “last record” in a list. A data-preparation error therefore cannot disappear behind a successful dictionary result.

Indices must be integers within the teaching grid. Column zero is valid. A negative, excessive or unknown index, or the Boolean True instead of a number, is not. The grid revision, supported locales and absence of repeated field/step pairs are checked separately.

All these checks finish before the reader is invoked. If the reader itself fails on the second job, the function does not return a collection of pages. The first call has already happened, however: this is not a transactional rollback of an external system. In the exercise, it only read a local number.

Sharing lasts for one execution of resolve. A subsequent separate call reads all six values again. We did not build a durable cache, coordination between processes or a protocol for updating public pages.

Scope and limits of the local check

The local check used the Python standard library.

Twenty-five test methods ran locally under Python 3.12.14. They checked the exact keys, all 14 URLs, the values of each representation, changes of language and name, different grid and source revisions and runs, missing data, and refusals. Expected URLs and values are written separately from the function that produces them.

This execution includes no full catalogue, GRIB decoder or load-test environment. The relationship “six cities to three nodes” was assigned by hand; it cannot be extrapolated to 77 thousand cities. A real workload requires actual bindings, an accepted geometric policy and a chosen set of fields and forecast horizons.

The useful result of this first step is separate counters with the relationships preserved. We can first see how many places the product serves, how many representations it prepares and how many distinct source values it needs. The next question then becomes specific: is each place correctly bound to its node, and which cases require a different spatial rule?

  1. Weather One weather field for thousands of cities: batch reading and decoding
  2. Weather A city between grid nodes: choosing a forecast point
  3. Weather A town is more than its name: identity in a geographic catalogue

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article