Write the homogenisation program of a regional climate service: unit and daily-mean reduction, break detection against non-urban neighbours, monthly adjustments and adjusted trends for climate station temperature series, scored on further district networks with known truth.
harbor run -t reactive-labs/station-homogenisationharbor download reactive-labs/station-homogenisationYou are a data analyst in the Climate Data Unit of the Havelin Regional Climate Service (HRCS). The unit has to deliver homogenised monthly temperature series and station trends for the 30 districts of the Climate Atlas 2025. Today is Monday 10 March 2025, and Ingrid Solberg, Head of the Climate Data Unit, wrote to the unit this morning:
I need one program that takes a district network export (the ARCH-FMT 3.2 folder the archive team produces: manifest, station files, station history) and returns, for every target station of the district, the homogenised monthly series, the breaks it found and the adjusted trend. Arne's team will export the remaining 24 districts over the next weeks and we will run the program on each export as it arrives without touching it. Please also send the trends and breaks for the six districts exported last week, D01 to D06.
In /app/inputs:
request/: Ingrid's emailnetworks/D01 ... networks/D06: the six district network exports, each with manifest.csv,
station_history.csv and stations/<station_id>.csvdocs/: the archive's export format note ARCH-FMT-3.2, the unit's homogenisation procedure SOP-CLIM-07 rev C and
technical note TN-11 rev 2 on the daily-mean formulasprevious_analyst/: Per Aasland's script homog_v1.py and his working notes/app/output/analyze.py, run as
python3 /app/output/analyze.py <network_dir> <out.json>
<network_dir> is one district network export in the same format as those in /app/inputs/networks
(read-only; its folder name is the network id). The program writes <out.json>:
{"network_id": "D07",
"stations": {"<station_id>": {"trend_degC_per_decade": 0.153,
"breaks": ["1957-04", "1988-11"],
"adjusted": [-4.21, -5.02, null, ...]},
...}}
with one entry under stations for every station whose role in the manifest is target:
| key | meaning |
|---|---|
trend_degC_per_decade |
the station's adjusted trend: least-squares slope of the calendar-year means of its homogenised monthly series over the whole analysis period (ANALYSIS_PERIOD in the manifest), with every year complete (months without a usable value estimated from the network), in degC per decade |
breaks |
the inhomogeneities found in the station's series within the analysis period, each as YYYY-MM, the first month measured under the new conditions |
adjusted |
the homogenised monthly mean temperature in degC, as 24-hour means, adjusted to the station's present site and instruments (its latest homogeneous period), one value per month from January of the first to December of the last year of the analysis period, null for months in which the station has no usable value |
Further keys are ignored. The program may load files that you put next to it in /app/output (find them
relative to __file__); /app/inputs is not available when it runs. It runs on one CPU core with 3 GB of
memory and no network, with Python 3.12, numpy, scipy and pandas, and must finish each network within 60 seconds
(a batch of 24 networks within 14 minutes).
/app/output/results.csv with the header network_id,station_id,trend_degC_per_decade,breaks and one row for
each target station of D01 to D06; breaks lists the YYYY-MM dates separated by ; (empty if none).
The program is run on further district network exports from the same archive, for which the true homogeneous series of every target station is known. Per target station:
| quantity | full credit | no credit |
|---|---|---|
trend T |
error up to 0.020 degC/decade | error of 0.040 or more |
series S |
RMSE of adjusted against the true series up to 0.20 degC |
RMSE of 0.35 degC or more |
The RMSE is taken over the months in which the station has a usable value; a null in such a month counts as an
error of 0.5 degC, and values in other months are ignored. Credit falls linearly between the two columns. The
station scores 0.40 * T * (0.5 + 0.5 * S) + 0.35 * S * (0.5 + 0.5 * T).
Breaks are scored per network over all its target stations: a reported date matches a true break of the same
station when at most 12 months with a usable value lie between them, each true break matches at most one date,
and the F1 score of matched dates against true breaks earns full credit at 0.85 or more and none at 0.35 or less
(linear between). Dates within 12 such months of a change that SOP-CLIM-07 section 4.4 does not count as a
break, or outside the analysis period, are neither credited nor penalised. The network scores the mean of its station scores plus
0.25 * B * (0.5 * mean T + 0.5 * mean S), where B is the breaks credit and the means are over its target
stations.
A network for which the program fails, runs out of time or writes no readable JSON object scores zero, and a station
that is missing or has no finite trend scores zero. The rows of results.csv are scored per network in hand as
0.75 * mean T + 0.25 * B * mean T. The final score is 0.8 times the mean over the further networks
plus 0.2 times the mean over the six networks in hand.