Skip to main content

A package to extract data from DMI Open Data into pandas dataframes

Project description

DMI Open Data API

Simple Python interface to the The Danish Meteorological Institute's (DMI) v2 Open Data API.

Forked from this repo to add support for more data sources as well as pandas output.

Currently the following APIs are supported:

  • climateDataAPI
  • forecastedr
  • metObsAPI

See API status here

Requirements

Installation

$ pip install dmi-open-data-pandas

Examples

Forecast API

from dmi_open_data import DMIOpenDataClient

# initialize client with API key stored in env variable
client = DMIOpenDataClient(env_var_name="DMI_FORECAST_EDR_API_KEY")

# get list of models available
models = client.get_models(as_df=True)

# get info about a specific model
model_info = client.get_models("harmonie_dini_sf")

# list parameters available for specific model
params = client.list_model_parameters("harmonie_dini_sf", as_df=True)

# get a forecast for wind speed and temperature
fc = client.get_forecast(
    latitude=55.767247, 
    longitude=12.464263,
    parameter=["temperature-0m", "wind-speed-10m"]
)

Observations and Climate Data API

from dmi_open_data import DMIOpenDataClient, Parameter, ClimateDataParameter
from datetime import datetime
import pandas as pd

# initialize client with API key stored in env variable
client = DMIOpenDataClient(env_var_name="DMI_API_KEY")

# get all stations
stations = client.get_stations()

# get station closest to a lat-lon
closest_station = client.get_closest_station(
    latitude=55.767247, 
    longitude=12.464263,
)

# Get available parameters
parameters = client.list_observation_parameters()

# Get temperature observations from DMI station in given time period
observations = client.get_observations(
    parameter=Parameter.TempDry,
    station_id=closest_station['properties']['stationId'],
    from_time=datetime(2021, 7, 20),
    to_time=datetime(2021, 7, 24),
    limit=1000
)

# you can also use the simple parameter string, and ask to return a pandas dataframe
observations = client.get_observations(
    parameter="temp_dry",
    station_id=closest_station['properties']['stationId'],
    from_time=datetime(2021, 7, 20),
    to_time=datetime(2021, 7, 24),
    as_df=True
)

# initialize climate data client
climate_data_client = DMIOpenDataClient(env_var_name='DMI_CLIMATE_DATA_API_KEY')

# get climate data, also using pandas Timestamps
climate_data = climate_data_client.get_climate_data(
    parameter=ClimateDataParameter.MeanTemp,
    station_id=closest_station['properties']['stationId'],
    from_time=pd.Timestamp("2023-01-01"),
    to_time=pd.Timestamp("2023-01-03"),
    time_resolution='day',
    as_df=True
)

Tests

Run tests (after installing pytest)

$ python -m pytest

Contributing

Please send an email to edu230991@gmail.com. We welcome contributions!

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dmi_open_data_pandas-0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmi_open_data_pandas-0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file dmi_open_data_pandas-0.1.tar.gz.

File metadata

  • Download URL: dmi_open_data_pandas-0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for dmi_open_data_pandas-0.1.tar.gz
Algorithm Hash digest
SHA256 2a6f917e0d657b2e90e5bd2a3513ee655a2ea0a46afd275f513a7dd36989df2e
MD5 b3037b7a2cd066de7330b98dd7029f55
BLAKE2b-256 79e209831e13a711688028f6b4f8ed02f347e097b8ef8a6112e8760e2dbf3b88

See more details on using hashes here.

File details

Details for the file dmi_open_data_pandas-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dmi_open_data_pandas-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5a508d9a0193efd16f16fca821f90901a01e4332aa641fdb62431d73bdef88a
MD5 3a52f484d14ebc1a03bfe0b9629b4e42
BLAKE2b-256 74acca5460a6872262b7220b92339225447a6b87c13d0d35cc6fe9f1db74c086

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page