- Blog/
Using Nushell and polars on weather data from open-meteo to find windy days
·301 words·2 mins
I windsurf and needed a way to get wind forecasts.
And recently a new feature was added to Nushell that makes it easy to consume the data from the Open-Meteo API.
First we find the data we need here: DMI Weather Model API | Open-Meteo.com
From that page we get the following url to the API:
https://api.open-meteo.com/v1/forecast?latitude=55.934&longitude=12.5048&hourly=wind_speed_10m,wind_direction_10m&wind_speed_unit=ms&timezone=auto&forecast_days=10&models=dmi_seamless
We can easily inspect this from Nushell like so:
http get https://api.open-meteo.com/v1/forecast?latitude=55.934&longitude=12.5048&hourly=wind_speed_10m,wind_direction_10m&wind_speed_unit=ms&timezone=auto&forecast_days=10&models=dmi_seamless
Let us save these data in a variable:
let wind = http get https://api.open-meteo.com/v1/forecast?latitude=55.934&longitude=12.5048&hourly=wind_speed_10m,wind_direction_10m&wind_speed_unit=ms&timezone=auto&forecast_days=10&models=dmi_seamless
This we now turn into a dataframe based on the colums:
let dfwind = $wind | get hourly | polars into-df --as-columns
Finally, let us make the datetime relative to now:
let final = $dfwind | polars with-column ($dfwind | polars get time | polars as-datetime "%Y-%m-%dT%H:%M" ) --name datetime
We can then turn this dataframe back into stadard nu:
let nuwind = $final | polars into-nu
And then it is easy to find any datetimes with enough wind:
$nuwind | where wind_speed_10m > 5
Seems like I will have to wait a week to go wind-🏄:
╭───┬──────────────────┬────────────────┬────────────────────┬───────────╮
│ # │ time │ wind_speed_10m │ wind_direction_10m │ datetime │
├───┼──────────────────┼────────────────┼────────────────────┼───────────┤
│ 0 │ 2024-08-07T09:00 │ 5.22 │ 144 │ in a week │
│ 1 │ 2024-08-07T10:00 │ 5.75 │ 149 │ in a week │
│ 2 │ 2024-08-07T11:00 │ 6.08 │ 153 │ in a week │
│ 3 │ 2024-08-07T12:00 │ 6.45 │ 156 │ in a week │
│ 4 │ 2024-08-07T13:00 │ 6.61 │ 160 │ in a week │
│ 5 │ 2024-08-07T14:00 │ 6.48 │ 163 │ in a week │
│ 6 │ 2024-08-07T15:00 │ 5.77 │ 166 │ in a week │
╰───┴──────────────────┴────────────────┴────────────────────┴───────────╯
Note: The above polars flag --as-colums
assume you have the latest Nushell and latest polars plugin.