# Forecasts (https://nolantw.github.io/cwa/en/reference/forecast/)

## `forecast.county`

```python
def county(county: None = None) -> tuple[CountyForecast, ...]
def county(county: CountyInput) -> CountyForecast
def county(county: Sequence[CountyInput]) -> Mapping[County, CountyForecast]
```

Return the 36-hour county forecast in 12-hour periods.

```python
from cwa import forecast

result = forecast.county("臺北市")
```

```python
client.forecast.county(county: None = None) -> tuple[CountyForecast, ...]
client.forecast.county(county: CountyInput) -> CountyForecast
client.forecast.county(county: Sequence[CountyInput]) -> Mapping[County, CountyForecast]
await async_client.forecast.county(county: None = None) -> tuple[CountyForecast, ...]
await async_client.forecast.county(county: CountyInput) -> CountyForecast
await async_client.forecast.county(county: Sequence[CountyInput]) -> Mapping[County, CountyForecast]
```

## `forecast.get`

```python
def get(location: TownshipInput, *, days: int = 7) -> Forecast
def get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
def get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
```

Get forecasts for a township, county, or sequence of locations.

**Parameters**

- `location` — Township name or object, county, or sequence of locations.
- `days` — Number of Taiwan calendar dates, from 1 to 7.
- `errors` — Pass collect for a batch to keep its successes and failures.

**Returns**

One forecast or a collection. With errors=collect, returns a BatchResult.

**Raises**

- `ValueError` — The number of days is outside the supported range.
- `BatchError` — At least one batch item failed and errors is raise.

```python
from cwa import forecast

result = forecast.get("臺北市信義區", days=3)
```

```python
client.forecast.get(location: TownshipInput, *, days: int = 7) -> Forecast
client.forecast.get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
client.forecast.get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
await async_client.forecast.get(location: TownshipInput, *, days: int = 7) -> Forecast
await async_client.forecast.get(location: BatchScope, *, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
await async_client.forecast.get(location: BatchScope, *, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
```

## `forecast.get_all`

```python
def get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
def get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
```

Get forecasts for all catalog townships.

```python
client.forecast.get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
client.forecast.get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
await async_client.forecast.get_all(*, days: int = 7, errors: Literal['raise'] = 'raise') -> ForecastCollection
await async_client.forecast.get_all(*, days: int = 7, errors: Literal['collect']) -> BatchResult[Township, Forecast]
```

## `forecast.CountyForecast`

```python
county: CountyName
periods: Annotated[tuple[CountyPeriod, ...], ordered(start)]
```

The 36-hour forecast for one county, in three 12-hour periods.

## `forecast.CountyPeriod`

```python
start: Time
end: Time
condition: Text
condition_code: Text
precipitation_probability: Number
min_temperature: Number
max_temperature: Number
comfort: Text
```

One 12-hour period. Temperatures are in °C, probability in %.

## `DayForecast`

```python
date: date
temperature: TemperatureRange
precipitation: PrecipitationForecast
wind: WindForecast
condition: WeatherCondition | None
periods: tuple[ForecastPeriod, ...]
sources: tuple[Source, ...]
```

Available forecast values overlapping one Taiwan calendar date.

## `Forecast`

```python
location: Township
as_of: datetime
sources: tuple[Source, ...]
periods: tuple[ForecastPeriod, ...]
days: tuple[DayForecast, ...]
today: DayForecast | None
tomorrow: DayForecast | None
temperature: NumericSeries
```

Immutable township forecast with Taiwan calendar and source-time views.

### `Forecast.on`

```python
def on(day: date) -> DayForecast | None
```

Return an available Taiwan calendar day.

### `Forecast.at`

```python
def at(instant: datetime) -> ForecastAtTime | None
```

Return only values valid at an instant; naive times are Taiwan time.

### `Forecast.between`

```python
def between(start: datetime, end: datetime) -> Forecast
```

Return a half-open window; naive times are Taiwan time.

### `Forecast.to_polars`

```python
def to_polars() -> pl.DataFrame
```

Export one row per available township calendar date.

### `Forecast.to_pandas`

```python
def to_pandas() -> pd.DataFrame
```

Export the daily schema using nullable Arrow-backed Pandas columns.

### `Forecast.to_arrow`

```python
def to_arrow() -> pa.Table
```

Export the daily schema as a PyArrow table.

## `ForecastAtTime`

```python
time: datetime
periods: tuple[ForecastPeriod, ...]
```

Published values valid at an instant.

## `ForecastCollection`

```python
class ForecastCollection
```

Read-only forecasts indexed by township.

### `ForecastCollection.to_polars`

```python
def to_polars() -> pl.DataFrame
```

Export one row per township and available calendar date.

### `ForecastCollection.to_pandas`

```python
def to_pandas() -> pd.DataFrame
```

Export the daily schema using nullable Arrow-backed Pandas columns.

### `ForecastCollection.to_arrow`

```python
def to_arrow() -> pa.Table
```

Export the daily schema as a PyArrow table.

## `ForecastPeriod`

```python
element: str
sample: ForecastSample[_Value]
```

An individual published forecast element, its value and validity.

## `ForecastSample`

```python
value: T | None
start: datetime
end: datetime | None
source: Source
```

A value at an instant or over a half-open validity interval.

### `ForecastSample.overlaps`

```python
def overlaps(start: datetime, end: datetime) -> bool
```

Whether this sample intersects the requested half-open window.

### `ForecastSample.contains`

```python
def contains(instant: datetime) -> bool
```

Whether this sample is valid at the given instant.

## `LowerBound`

```python
value: float
```

A published value known only to be at least ``value``, such as ``>= 11``.

## `NumericSeries`

```python
samples: tuple[ForecastSample[float], ...]
```

Samples of one numeric forecast element.

### `NumericSeries.min`

```python
def min() -> float | None
```

Return the smallest available sample.

### `NumericSeries.max`

```python
def max() -> float | None
```

Return the largest available sample.

### `NumericSeries.mean`

```python
def mean() -> float | None
```

Return the unweighted mean of available samples.

## `PrecipitationForecast`

```python
max_probability: int | None
```

Maximum published period probability in percent.

## `TemperatureRange`

```python
min: float | None
max: float | None
sampled_min: float | None
sampled_max: float | None
```

Published extrema in °C, with separate extrema of hourly samples.

## `WeatherCondition`

```python
description: str
code: str | None
```

CWA's weather description and optional category code.

## `WindForecast`

```python
max_speed: float | None
max_speed_is_lower_bound: bool
```

Maximum published wind speed in metres per second.

When max_speed_is_lower_bound is True, at least one period was published
as a lower bound and the maximum is at least max_speed.