| Title: | Download Archived Meteorological Data from Meteo-France |
|---|---|
| Description: | Download meteorological data from the 'Meteo-France' public API 'Données climatologiques' and 'SYNOP' open data archives. It provides functions to authenticate, list stations, retrieve station metadata, request data, download files, and import data directly into 'R'. |
| Authors: | Nicolas Moiroux [aut, cre] (ORCID: <https://orcid.org/0000-0001-6755-6167>) |
| Maintainer: | Nicolas Moiroux <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-04-03 11:44:49 UTC |
| Source: | https://github.com/Nmoiroux/mfclim |
Download the CSV file corresponding to a previously submitted data order . The function repeatedly queries the API until the file is ready and then downloads it to disk.
mfclim_download(token, id_cmde, filename = "data.csv", folder = tempdir())mfclim_download(token, id_cmde, filename = "data.csv", folder = tempdir())
token |
Character string. OAuth2 access token obtained with
|
id_cmde |
Numeric or character. Order ID returned by
|
filename |
Character string. Name of the output CSV file. |
folder |
Character string. Where to save the downloaded CSV file. Default to |
The function polls the API every 5 seconds until the file is
available. When the file is ready, it is downloaded and saved to
filename.
Character string. Path to the downloaded file.
mfclim_order()
## Not run: file <- mfclim_download(token, id_cmde = 123456, filename = "meteo.csv") ## End(Not run)## Not run: file <- mfclim_download(token, id_cmde = 123456, filename = "meteo.csv") ## End(Not run)
This is a wrapper function that retrieves data from the Climatological Data API for a given station and period. The function can either use an existing token or automatically request a new token using client credentials.
mfclim_get_data( token, client_auth, station, step, date_deb, date_fin, filename = "data.csv", folder = tempdir() )mfclim_get_data( token, client_auth, station, step, date_deb, date_fin, filename = "data.csv", folder = tempdir() )
token |
Character string. OAuth2 access token obtained with
|
client_auth |
Character string. Authentication string provided by the
Meteo-France API portal (optional if |
station |
Character string. Station identifier. |
step |
Character string. Time step of the requested data. |
date_deb |
Character string. Start date in ISO 8601 UTC format (see example). If |
date_fin |
Character string. End date in ISO 8601 UTC format. If |
filename |
Character string. Name of the downloaded CSV file. Default to |
folder |
Character string. Where to save the downloaded CSV file. Default to |
The function:
Obtains an access token if not provided
Submits a data order
Waits for the file to be generated
Downloads the CSV file
Reads the CSV file into R
A data.frame containing the climate data.
mfclim_get_token(),
mfclim_order(),
mfclim_download()
## Not run: data <- mfclim_get_data( client_auth = client_auth, station = "75114001", step = "1d", date_deb = "2020-01-01T00:00:00Z", date_fin = "2020-12-31T23:59:59Z" ) ## End(Not run)## Not run: data <- mfclim_get_data( client_auth = client_auth, station = "75114001", step = "1d", date_deb = "2020-01-01T00:00:00Z", date_fin = "2020-12-31T23:59:59Z" ) ## End(Not run)
Request an OAuth2 access token from the Meteo-France API using the client credentials authentication flow.
mfclim_get_token(client_auth)mfclim_get_token(client_auth)
client_auth |
Character string. Authentication identifier provided by the Meteo-France API portal (string following "Authorization: Basic"). |
Requires a valid account on the Meteo-France API portal https://portail-api.meteofrance.fr and
a (free) subscription to the 'Climatological data' API (https://portail-api.meteofrance.fr/web/en/api/DonneesPubliquesClimatologie).
The client_auth value must be obtained from your account on the Meteo-France API portal:
Go to 'My API' -> 'Climatological data' -> 'Generate Token' -> 'Curl'
Copy the string that appears after "Authorization: Basic" in the provided curl command (remove the trailing ").
A character string containing the access token used to authenticate subsequent API requests.
## Not run: token <- mfclim_get_token(client_auth) ## End(Not run)## Not run: token <- mfclim_get_token(client_auth) ## End(Not run)
Retrieve metadata and information for a given Meteo-France station using its station identifier.
mfclim_info_station(token, client_auth, station)mfclim_info_station(token, client_auth, station)
token |
Character string. OAuth2 access token obtained with
|
client_auth |
Character string. Authentication string provided by the
Meteo-France API portal. Used to automatically obtain a token if
|
station |
Character string. Station identifier (8-digit station code). |
If token is not provided, the function will automatically
request a new token using client_auth. The returned list structure
depends on the API response and may include station metadata, location,
altitude, opening and closing dates, and available parameters.
A list containing station metadata. Scalar elements are returned as vectors, and nested list elements are converted into data frames.
## Not run: info <- mfclim_info_station( client_auth = client_auth, station = "75114001" ) ## End(Not run)## Not run: info <- mfclim_info_station( client_auth = client_auth, station = "75114001" ) ## End(Not run)
Retrieve the list of available Meteo-France stations for a given French department and data frequency. The list can optionally be filtered by meteorological parameter.
mfclim_list_stations( token, client_auth, departement, step = c("1d", "1h", "6m"), parametre = NULL )mfclim_list_stations( token, client_auth, departement, step = c("1d", "1h", "6m"), parametre = NULL )
token |
Character string. OAuth2 access token obtained with
|
client_auth |
Character string. Authentication string provided by the
Meteo-France API portal. Used to automatically obtain a token if
|
departement |
Character or numeric. French department code. |
step |
Character string. Data frequency. One of:
|
parametre |
Character string. Optional meteorological parameter used
to filter stations. One of:
|
If token is not provided, the function will automatically
request a new token using client_auth.
A data.frame containing the list of stations and their metadata.
## Not run: stations <- mfclim_list_stations( client_auth = client_auth, departement = "75", step = "1d", parametre = "temperature" ) ## End(Not run)## Not run: stations <- mfclim_list_stations( client_auth = client_auth, departement = "75", step = "1d", parametre = "temperature" ) ## End(Not run)
Submit an asynchronous order for climatological data from a Meteo-France station. The function returns a order ID that must be used later to download the data file.
mfclim_order( token, station, step = c("1mo", "10d", "1d", "1h", "6m"), date_deb, date_fin )mfclim_order( token, station, step = c("1mo", "10d", "1d", "1h", "6m"), date_deb, date_fin )
token |
Character string. OAuth2 access token obtained with
|
station |
Character string. Station identifier (8-digit station code). |
step |
Character string. Time step of the ordered data. One of:
|
date_deb |
Character string. Start date of the requested period in
ISO 8601 UTC format (e.g. "2020-01-01T00:00:00Z"). If |
date_fin |
Character string. End date of the requested period in
ISO 8601 UTC format (e.g. "2020-12-31T23:59:59Z"). If |
The order is asynchronous: the data file is generated by the server and must be retrieved afterward using the order ID.
Numeric or character value corresponding to the order ID. This ID must be used to download the data file.
mfclim_download()
## Not run: id_cmd <- mfclim_order( token, station = "75114001", step = "1d", date_deb = "2020-01-01T00:00:00Z", date_fin = "2020-12-31T23:59:59Z" ) ## End(Not run)## Not run: id_cmd <- mfclim_order( token, station = "75114001", step = "1d", date_deb = "2020-01-01T00:00:00Z", date_fin = "2020-12-31T23:59:59Z" ) ## End(Not run)
Downloads SYNOP surface observation data from the Meteo-France open data portal for a given year, decompresses the archive, and return a data frame.
mfclim_synop(year, path = tempdir())mfclim_synop(year, path = tempdir())
year |
Numeric or character. Year of the data to download (YYYY), between 1996 and present year (included). |
path |
Path to folder where to save the archive. Default to |
SYNOP data come from observation messages exchanged through the World Meteorological Organization (WMO) Global Telecommunication System (GTS). These observations include measured atmospheric parameters such as temperature, humidity, wind direction and speed, atmospheric pressure, and precipitation amount, as well as observed variables such as present weather, cloud description, and visibility. Depending on instrumentation and local conditions, additional variables may be available (e.g., snow depth, ground state).
The dataset covers mainland France and overseas territories with a typical observation frequency of 3 hours. Available years cover 1996 to present.
Data description and documentation is available here (French): https://meteo.data.gouv.fr/datasets/686f8595b351c06a3a790867
Files are downloaded as .csv.gz, decompressed on the fly, and read.
Typical size of compressed files is <7MB for period 1996-2024 and <20MB for more recent years.
Missing values coded as "", "NA", or "mq" are converted to NA in the returned data frame.
A data.frame containing the downloaded data.
## Not run: mydata <- mfclim_synop(2020) ## End(Not run)## Not run: mydata <- mfclim_synop(2020) ## End(Not run)