A Python library for accessing the Norwegian Meteorological Institute frost.met.no API
Project description
Frostrose
frostrose
is a Python library for easy access to the Norwegian Meteorological Institute's frost.met.no API. It simplifies the process of fetching weather data from various endpoints.
Installation
pip install frostrose
Usage
Setting up the Client
You can use the FrostClient
either by setting an environment variable FROST_CLIENT_ID
or by providing the client ID directly during instantiation.
Using an Environment Variable
Set the environment variable FROST_CLIENT_ID
with your API key:
export FROST_CLIENT_ID='your_api_key_here'
Then, in your Python code:
from frostrose import FrostClient
client = FrostClient()
Providing Client ID on Instantiation
Alternatively, you can provide the client ID directly:
from frostrose import FrostClient
client = FrostClient('your_api_key_here')
Working with Sources (Weather Stations)
Weather stations are referred to as "sources" in the frost.met.no API. frostrose
provides methods to find sources by name, near a specific longitude and latitude, or near another source.
Finding Sources by Name
from frostrose import Sources
sources = Sources(client)
sources.fetch_all_sources()
tynset_sources = sources.get_sources_with_name_icontains('tynset')
Finding Sources Near a Specific Location
nearby_sources = sources.get_sources_within_radius_of_lonlat(lon=5.1963, lat=59.2555, radius_km=50)
Finding Sources Near Another Source
nearby_sources_of_id = sources.get_sources_within_radius_of_source_id('SN47230', radius_km=50)
Finding Weather Elements
To find available weather elements:
from frostrose import Elements
elements = Elements(client)
elements_data = elements.get_elements()
Getting Observation Time Series
To get an observation time series for a specific weather element:
from frostrose import Observations
observations = Observations(client)
temperature = observations.get_data_for_source_element_for_period('SN9580', 'air_temperature', date_start='2023-01-01')
Converting to Pandas DataFrame
To convert the observation time series into a pandas DataFrame:
import pandas as pd
flat_data = temperature.to_flat_dict_list()
df = pd.DataFrame.from_records(flat_data)
License
Frostrose is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for frostrose-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd3247f2d7d0eba6a0614f2ea9d93fafd3cf8d7161f6da407152fc6dd2d6fabd |
|
MD5 | 4f9b28e45d1ac92928ca866e9e554835 |
|
BLAKE2b-256 | aad26c7d14c8e0f0fdf649bc6d0dd5a980630103402bb16729f8073e97d8dbf3 |