weather
frequenz.client.weather ¤
Weather API Client for Python.
Classes¤
frequenz.client.weather.Client ¤
Bases: BaseApiClient[WeatherForecastServiceStub]
Weather forecast client.
Source code in frequenz/client/weather/_client.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
Attributes¤
channel
property
¤
The underlying gRPC channel used to communicate with the server.
Warning
This channel is provided as a last resort for advanced users. It is not recommended to use this property directly unless you know what you are doing and you don't care about being tied to a specific gRPC library.
RAISES | DESCRIPTION |
---|---|
ClientNotConnected
|
If the client is not connected to the server. |
channel_defaults
property
¤
The default options for the gRPC channel.
stub
property
¤
The gRPC stub for the API.
RETURNS | DESCRIPTION |
---|---|
WeatherForecastServiceAsyncStub
|
The async gRPC stub for the Weather Forecast Service. |
RAISES | DESCRIPTION |
---|---|
ClientNotConnected
|
If the client is not connected to the server. |
Functions¤
__aexit__
async
¤
__aexit__(
_exc_type: type[BaseException] | None,
_exc_val: BaseException | None,
_exc_tb: Any | None,
) -> bool | None
Exit a context manager.
Source code in frequenz/client/base/client.py
__init__ ¤
__init__(
server_url: str,
*,
connect: bool = True,
channel_defaults: ChannelOptions = ChannelOptions()
) -> None
Initialize the client.
PARAMETER | DESCRIPTION |
---|---|
server_url
|
The URL of the server to connect to.
TYPE:
|
connect
|
Whether to connect to the server as soon as a client instance is
created. If
TYPE:
|
channel_defaults
|
Default options for the gRPC channel.
TYPE:
|
Source code in frequenz/client/weather/_client.py
connect ¤
connect(
server_url: str | None = None,
*,
auth_key: str | None | EllipsisType = ...,
sign_secret: str | None | EllipsisType = ...
) -> None
Connect to the server, possibly using a new URL.
If the client is already connected and the URL is the same as the previous URL, this method does nothing. If you want to force a reconnection, you can call disconnect() first.
PARAMETER | DESCRIPTION |
---|---|
server_url
|
The URL of the server to connect to. If not provided, the previously used URL is used.
TYPE:
|
auth_key
|
The API key to use when connecting to the service. If an Ellipsis is provided, the previously used auth_key is used.
TYPE:
|
sign_secret
|
The secret to use when creating message HMAC. If an Ellipsis is provided,
TYPE:
|
Source code in frequenz/client/base/client.py
disconnect
async
¤
Disconnect from the server.
If the client is not connected, this method does nothing.
hist_forecast_iterator ¤
hist_forecast_iterator(
locations: list[Location],
features: list[ForecastFeature],
start: datetime,
end: datetime,
) -> HistoricalForecastIterator
Stream historical weather forecast data.
PARAMETER | DESCRIPTION |
---|---|
locations
|
locations to stream data for. |
features
|
features to stream data for.
TYPE:
|
start
|
start of the time range to stream data for.
TYPE:
|
end
|
end of the time range to stream data for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
HistoricalForecastIterator
|
A channel receiver for weather forecast data. |
Source code in frequenz/client/weather/_client.py
stream_live_forecast
async
¤
stream_live_forecast(
locations: list[Location],
features: list[ForecastFeature],
) -> Receiver[Forecasts]
Stream live weather forecast data.
PARAMETER | DESCRIPTION |
---|---|
locations
|
locations to stream data for. |
features
|
features to stream data for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Receiver[Forecasts]
|
A channel receiver for weather forecast data. |
Source code in frequenz/client/weather/_client.py
frequenz.client.weather.ForecastFeature ¤
Bases: Enum
Weather forecast features available through the API.
Source code in frequenz/client/weather/_types.py
Attributes¤
SURFACE_NET_SOLAR_RADIATION
class-attribute
instance-attribute
¤
Surface net solar radiation.
SURFACE_SOLAR_RADIATION_DOWNWARDS
class-attribute
instance-attribute
¤
Surface solar radiation downwards.
TEMPERATURE_2_METRE
class-attribute
instance-attribute
¤
Temperature at 2m above the earth's surface.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified forecast feature.
U_WIND_COMPONENT_100_METRE
class-attribute
instance-attribute
¤
Eastward wind component at 100m altitude.
U_WIND_COMPONENT_10_METRE
class-attribute
instance-attribute
¤
Eastward wind component at 10m altitude.
V_WIND_COMPONENT_100_METRE
class-attribute
instance-attribute
¤
Northward wind component at 100m altitude.
V_WIND_COMPONENT_10_METRE
class-attribute
instance-attribute
¤
Northward wind component at 10m altitude.
Functions¤
from_pb
classmethod
¤
from_pb(forecast_feature: ValueType) -> ForecastFeature
Convert a protobuf ForecastFeature value to ForecastFeature enum.
PARAMETER | DESCRIPTION |
---|---|
forecast_feature
|
protobuf forecast feature to convert.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ForecastFeature
|
Enum value corresponding to the protobuf message. |
Source code in frequenz/client/weather/_types.py
frequenz.client.weather.Forecasts
dataclass
¤
Weather forecast data.
Source code in frequenz/client/weather/_types.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
Functions¤
flatten ¤
flatten() -> list[ForecastData]
Flatten forecast data into a list of ForecastData tuples.
RETURNS | DESCRIPTION |
---|---|
list[ForecastData]
|
List of ForecastData tuples containing the flattened forecast data. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the forecasts data is missing or invalid. |
Source code in frequenz/client/weather/_types.py
from_pb
classmethod
¤
from_pb(
forecasts: ReceiveLiveWeatherForecastResponse,
) -> Forecasts
Convert a protobuf Forecast message to Forecast object.
PARAMETER | DESCRIPTION |
---|---|
forecasts
|
protobuf message with live forecast data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Forecasts
|
Forecast object corresponding to the protobuf message. |
Source code in frequenz/client/weather/_types.py
to_ndarray_vlf ¤
to_ndarray_vlf(
validity_times: list[datetime] | None = None,
locations: list[Location] | None = None,
features: list[ForecastFeature] | None = None,
) -> ndarray[tuple[Any, Any, Any], dtype[float64]]
Convert a Forecast object to numpy array and use NaN to mark irrelevant data.
If any of the filters are None, all values for that parameter will be returned.
PARAMETER | DESCRIPTION |
---|---|
validity_times
|
The validity times to filter by. |
locations
|
The locations to filter by. |
features
|
The features to filter by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray[tuple[Any, Any, Any], dtype[float64]]
|
Numpy array of shape (num_validity_times, num_locations, num_features) |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the forecasts data is missing or invalid. |
RuntimeError
|
If there is an error processing the forecast data. |
Source code in frequenz/client/weather/_types.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
to_resampled_ndarray ¤
to_resampled_ndarray(
validity_times: list[datetime],
locations: list[Location] | None = None,
features: list[ForecastFeature] | None = None,
solar_offset_sec: int = 1800,
) -> ndarray[tuple[Any, Any, Any], dtype[float64]]
Convert the forecast to a numpy array and resample to the specified validity_times.
PARAMETER | DESCRIPTION |
---|---|
validity_times
|
The validity times to resample to. |
locations
|
The locations to filter by. |
features
|
The features to filter by.
TYPE:
|
solar_offset_sec
|
Time offset in seconds to shift solar forecasts
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray[tuple[Any, Any, Any], dtype[float64]]
|
Numpy array of shape (num_validity_times, num_locations, num_features) |
Source code in frequenz/client/weather/_types.py
upsample_vlf ¤
upsample_vlf(
array: ndarray[tuple[Any, Any, Any], dtype[float64]],
validity_times: list[datetime],
target_times: list[datetime],
features: list[ForecastFeature],
solar_offset_sec: int = 1800,
) -> ndarray[tuple[Any, Any, Any], dtype[float64]]
Upsample the forecast array to requested timestamps.
PARAMETER | DESCRIPTION |
---|---|
array
|
3D array from to_ndarray_vlf (time, location, feature) |
validity_times
|
List of original timestamps |
target_times
|
List of desired timestamps to interpolate to |
features
|
List of forecast features
TYPE:
|
solar_offset_sec
|
Time offset in seconds to shift solar forecasts
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray[tuple[Any, Any, Any], dtype[float64]]
|
Resampled 3D array with same structure interpolated to target timestamps |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If input dimensions don't match or timestamps aren't monotonic |
Source code in frequenz/client/weather/_types.py
frequenz.client.weather.Location
dataclass
¤
Location data.
ATTRIBUTE | DESCRIPTION |
---|---|
latitude |
latitude of the location.
TYPE:
|
longitude |
longitude of the location.
TYPE:
|
country_code |
ISO 3166-1 alpha-2 country code of the location.
TYPE:
|
Source code in frequenz/client/weather/_types.py
Functions¤
from_pb
classmethod
¤
from_pb(location: Location) -> Location
Convert a protobuf Location message to Location object.
PARAMETER | DESCRIPTION |
---|---|
location
|
protobuf location to convert.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Location
|
Location object corresponding to the protobuf message. |
Source code in frequenz/client/weather/_types.py
to_pb ¤
Convert a Location object to protobuf Location message.
RETURNS | DESCRIPTION |
---|---|
Location
|
Protobuf message corresponding to the Location object. |