Radar: API Reference#

class yr_weather.Radar(headers: dict | None = {}, use_cache: bool | None = True)#

Bases: BaseClient

A client for interacting with the Yr Radar API.

get_available_radars() RadarOptions#

Get a dict of available typed of radars.

This function retrieves all types of radars, as well as which areas they are available in. The dict also includes available types of content (image or animation).

Returns:

A TypedDict with available radars and additional info.

Return type:

RadarOptions

get_radar(area: str, radar_type: str, content: Literal['image', 'animation'] | None = 'image', time: str | None = None) Response#

Get a radar image (png) or animation (gif).

For more information about what arguments are valid, please see: https://api.met.no/weatherapi/radar/2.0/documentation

Parameters:
  • area (RadarArea) – A string of one the of the possible values for area, based on valid Radar Yr API literals.

  • radar_type (RadarType) – A string of one of the possible values for type, based on valid Radar Yr API literals.

  • content (Optional[RadarContentType]) – Either the string “image” or “animation”, based on the desired result from the API.

  • time (Optional[str]) – An optional string containing the time when the image was taken, provided in ISO 8601 format.

Returns:

A Response class, enabling for further saving or managing of the data received from the open stream.

Return type:

requests.Response

Examples

Example 1: Basic usage:

import yr_weather

radar = yr_weather.Radar()

result = radar.get_radar("central_norway", "5level_reflectivity", "image")

with open("image.png", "wb") as f:
    for chunk in result:
        f.write(chunk)

Example 2. Getting a radar image from a few hours back:

import yr_weather
from datetime import datetime

radar = yr_weather.Radar()

# Replace with your time
time_now = datetime(2023, 1, 20, 12, 00, 00)
time_str = time_now.isoformat(timespec="seconds") + "Z"

result = radar.get_radar("central_norway", "5level_reflectivity", "image", time_str)

if result.status_code != 404:
    with open("image.png", "wb") as f:
        for chunk in result:
            f.write(chunk)
else:
    print("Couldn't get this radar image/animation!")
get_status() RadarStatus#

Get the operational status of all radars.

Returns:

A TypedDict with statuses of radars.

Return type:

RadarStatus