Skip to Content
cwa
Guides

Warnings

Query active weather warnings and check whether they affect a place.

cwa.alerts.active() returns the weather warnings in effect, such as heavy rain advisories, low temperature advisories and typhoon warnings. Get all of them, or only those affecting a place.

import cwa

for alert in cwa.alerts.active("臺北市信義區"):
    print(alert.title, alert.effective_at, alert.expires_at)

Filtering

WriteTo get
active()Every active warning in Taiwan
active("臺北市信義區")Warnings affecting this township
active(County.TAIPEI)Warnings affecting this county
active(Coordinates(...))Warnings covering this point; needs cwa[geo]
active(..., alert_type=AlertType.RAIN)Only one kind of warning

AlertType is one of RAIN (heavy rain), FOG (dense fog), WIND (strong wind on land), COLD (low temperature), HEAT (high temperature), TYPHOON, THUNDERSTORM or OTHER.

Warning fields

FieldMeaning
typeThe kind of warning, an AlertType
titleThe title, such as 豪雨特報
textThe full text published by the CWA, or None
effective_at, expires_atWhen it takes effect and expires
areasThe published affected areas, each with a label, county and township
polygonsThe coverage polygons published with typhoon warnings, as coordinates; empty for other warnings

Does it affect a place?

CWA warnings describe their coverage in varying detail: some list townships, some only counties, and some say things like “mountain areas”. That is why alert.affects(place) returns one of three results rather than True or False:

ResultMeaningSuggested handling
Match.YESDefinitely affects the placeShow the warning
Match.NODefinitely does notSkip it
Match.UNKNOWNNot enough detail to tell, for example only the county is listed, or the area is described as “mountain areas”Treat it as possibly affecting the place, and show alert.areas so users can judge
from cwa import Match

for alert in cwa.alerts.active("臺北市信義區"):
    match alert.affects("臺北市信義區"):
        case Match.YES:
            print("Affects this township:", alert.title)
        case Match.UNKNOWN:
            areas = ", ".join(area.label for area in alert.areas)
            print("May affect this township:", alert.title, areas)

When you query by place, active() drops only Match.NO warnings and keeps Match.UNKNOWN ones, so an important warning is never missed.

To check a point, use alert.contains(coordinates), which also returns a Match. It needs cwa[geo] because polygon matching uses Shapely; alert.geometry gives the Shapely polygons too. Without it, both raise MissingDependencyError.

Completeness

Warnings come from several datasets. If one of them is out of date or incomplete, complete is False:

alerts = cwa.alerts.active("臺北市信義區")
if not alerts.complete:
    print("Warning data may be incomplete; try again later")

In that case, finding no warnings does not mean there are none. Check that complete is True before showing “no active warnings”; if it is False, query again later or tell users the data may be incomplete.

Township-level warnings

cwa.alerts.hazards() reads the township-level rain, cold, heat, wind and fog warnings, including issued warnings that take effect later. The location argument works as in active(), and alert_type keeps one kind:

from cwa import AlertType

for alert in cwa.alerts.hazards("臺北市信義區", alert_type=AlertType.RAIN):
    print(alert.title, alert.effective_at, alert.expires_at)