Skip to Content
cwa
Guides

Observations and stations

Current readings from nearby stations, and station lookup.

CWA stations report temperature, humidity, wind, rainfall and other readings every hour. cwa.observations finds the station nearest a location and returns its reading; cwa.stations looks up the stations themselves.

Nearby readings

import cwa

reading = cwa.observations.nearest("臺北市信義區")

if reading:
    print(reading.station.name, reading.distance_km, reading.observed_at)
    observation = reading.observation
    print(observation.temperature, observation.humidity, observation.wind.speed)

nearest() only uses stations that meet both conditions below, and returns None when none do:

ConditionDefaultParameter
Distance from the locationWithin 10 kmmax_distance_km
Observation timeWithin two hoursmax_age (a timedelta)

Mountain and island areas have fewer stations, so you may need to relax these. None removes a limit:

from datetime import timedelta

reading = cwa.observations.nearest(
    "花蓮縣秀林鄉", max_distance_km=30, max_age=timedelta(hours=3)
)

The nearest station may be in a neighboring township; reading.station is the station that actually reported.

Observation fields

reading.observation has these fields. Anything the station did not report is None:

FieldMeaning
temperatureAir temperature (°C)
humidityRelative humidity (%)
pressureStation pressure (hPa). This is the pressure at the station’s altitude, not the sea-level pressure on weather maps, so it is much lower at mountain stations
wind.speedWind speed (m/s)
wind.directionWind direction; see Wind direction below
precipitation.millimetresRainfall since midnight Taiwan time (mm)
precipitation.traceTrue when rain fell but too little to measure; millimetres is then None
conditionThe weather as text, such as 晴
observed_atObservation time

Wind direction

A wind direction is not always an angle. wind.direction.kind says which case applies:

kindMeaningdegrees
DirectionKind.DEGREESA normal direction0 to 360; 0 is a north wind, 90 an east wind
DirectionKind.CALMCalmNone
DirectionKind.VARIABLEVariableNone
DirectionKind.UNKNOWNNot reportedNone

A specific station

If you know a station ID, get its latest reading directly:

latest = cwa.observations.latest("466920")

It returns None when the station has no current reading, and raises NotFoundError when the ID does not exist.

Looking up stations

MethodUse
stations.nearest(location, limit=3)The stations closest to a location, with distances
stations.get("466920")A station by ID
stations.list(county=County.TAIPEI)The stations in a county; omit county for all of them
for item in cwa.stations.nearest("臺北市信義區", limit=3):
    print(item.station.id, item.station.name, item.distance_km)

Station fields:

FieldMeaning
idStation ID
nameStation name
coordinatesLatitude and longitude
county, townshipCounty and township, or None if unknown
elevation_mElevation (m)

The station list comes from the CWA’s current observation dataset, O-A0001-001, so it contains only stations that are currently reporting.

Rainfall, UV and staffed stations

FunctionContents
cwa.observations.rainfall()Latest rain gauge totals: today, 10 minutes, 1, 3, 6, 12 and 24 hours, 2 and 3 days (mm)
cwa.observations.uv()Today’s maximum UV index at each station
cwa.observations.staffed()Latest readings from staffed stations, with the same fields as Observation
rain = cwa.observations.rainfall("C0A9C0")
print(rain.observed_at, rain.past_hour, rain.past_24_hours)
print(cwa.observations.uv("466920").uv_index)

Each takes a station ID or a sequence of them; without an argument, every station is returned.