Introduction to the climate package

Bartosz Czernecki, Arkadiusz Głogowski, Jakub Nowosad

2024-12-20

The goal of the climate R package is to automatize downloading of meteorological and hydrological data from publicly available repositories:

Functions

The climate package consists of ten main functions - three for meteorological data, one for hydrological data and six auxiliary functions and datasets:

Meteorological data

Hydrological data

Auxiliary functions and datasets

Examples

Examples shows application of climate package with additional use of tools that help with processing the data to increase legible of downloaded data.

Example 1

Finding a 50 nearest meteorological stations for a given coordinates in a given country(ies):

library(climate)
ns = nearest_stations_ogimet(country = c("United Kingdom", "France"),
                             point = c(-3, 50),
                             no_of_stations = 50, 
                             add_map = TRUE)
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//Rtmphqzjft/file14b03b521250
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//Rtmphqzjft/file14b0930609d

if (is.data.frame(ns)) {
 knitr::kable(head(ns, 15))
}
wmo_id station_names lon lat alt distance
122 03894 Guernsey Airport -2.583345 49.41667 102 80.42783
116 03857 Isle Of Portland -2.450009 50.51668 52 84.66540
114 03844 Exeter Airport No2 -3.400008 50.73335 31 93.72323
113 03840 Dunkeswell Aerodrome -3.233338 50.85002 252 98.89712
115 03853 Yeovilton -2.633346 51.00000 23 119.50052
140 07020 La Hague -1.933352 49.71668 6 123.82404
123 03895 Jersey Airport -2.183337 49.20000 84 128.26450
112 03827 Plymouth -4.116669 50.35001 50 131.29669
124 03896 Saint Helier -2.100002 49.20000 54 135.10222
95 03710 Liscombe -3.600012 51.08333 348 138.94411
163 07117 Ploumanac’H -3.466676 48.81668 55 142.71600
164 07118 Lannion -3.466676 48.75001 88 149.69950
117 03862 Bournemouth Airport -1.833350 50.76668 12 156.62887
96 03716 St. Athan -3.433342 51.40001 50 164.42872
165 07120 Saint-Brieuc -2.850017 48.53334 138 165.41210

Example 2

Summary of stations available in Ogimet repository for a selected country:

library(climate)
PL = stations_ogimet(country = "Poland", add_map = TRUE)
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//Rtmphqzjft/file14b04217d91d


if (is.data.frame(PL)) {
    knitr::kable(head(PL))
}
wmo_id station_names lon lat alt
12001 Petrobaltic Beta 18.16667 55.46668 46
12100 Kolobrzeg 15.56668 54.16667 4
12105 Koszalin 16.15000 54.20000 33
12115 Ustka 16.85002 54.58335 3
12120 Leba 17.53334 54.75001 2
12125 Lebork 17.75002 54.55001 39

Example 3

Downlading hourly meteorological data from Svalbard (Norway) for year 2016 using NOAA service

# downloading data with NOAA service:
df = meteo_noaa_hourly(station = "010080-99999", year = 2016)

# You can also download the same (but more granular) data with Ogimet.com (example for year 2016):
# df = meteo_ogimet(interval = "hourly", 
#                   date = c("2016-01-01", "2016-12-31"),
#                   station = c("01008"))
knitr::kable(head(df))
date year month day hour lon lat alt t2m dpt2m ws wd slp visibility
1 2016-01-01 00:00:00 2016 1 1 0 15.467 78.25 29 5.0 -1.6 5 200 1007.5 65000
3 2016-01-01 01:00:00 2016 1 1 1 15.467 78.25 29 5.2 -1.7 3 180 1008.2 NA
5 2016-01-01 02:00:00 2016 1 1 2 15.467 78.25 29 4.6 -1.2 6 170 1008.5 NA
7 2016-01-01 03:00:00 2016 1 1 3 15.467 78.25 29 4.3 -0.9 5 190 1008.6 70001
9 2016-01-01 04:00:00 2016 1 1 4 15.467 78.25 29 3.7 -1.0 5 160 1008.8 NA
11 2016-01-01 05:00:00 2016 1 1 5 15.467 78.25 29 3.2 -1.0 4 150 1008.6 NA

Example 4

Downloading atmospheric vertical profile (sounding) for Łeba, PL station:

profile_demo <- sounding_wyoming(wmo_id = 12120,
                                 yy = 2000,
                                 mm = 3,
                                 dd = 23,
                                 hh = 0)
df2 = profile_demo[[1]] 
colnames(df2)[c(1, 3:4)] = c("PRESS", "TEMP", "DEWPT") # changing column names
Exemplary data frame of sounding preprocessing
PRESS HGHT TEMP DEWPT RELH MIXR DRCT SKNT THTA THTE THTV
1013 6 4.2 3.8 97 4.98 270 8 276.3 290.0 277.2
1009 37 2.4 2.3 99 4.50 285 12 274.9 287.2 275.6
1000 107 2.2 1.9 98 4.41 295 17 275.4 287.5 276.1
976 303 0.8 -1.3 86 3.58 298 23 275.9 285.8 276.5
970 352 1.0 -6.0 60 2.53 299 25 276.6 283.8 277.0
959 444 1.0 -0.6 89 3.83 300 27 277.4 288.2 278.1
925 733 -1.1 -1.1 100 3.83 290 27 278.2 288.9 278.8
913 837 -1.5 -1.5 100 3.76 285 27 278.8 289.4 279.4
877 1157 -2.9 -2.9 100 3.54 288 29 280.6 290.6 281.2
850 1404 -4.1 -4.1 100 3.33 290 31 281.8 291.4 282.4

Example 5

Preparing an annual summary of air temperature and precipitation using dplyr syntax for 10-years period (1991-2000)

library(climate)
df = meteo_imgw(interval = "monthly", rank = "synop", year = 1991:2000, station = "ŁEBA") 
# please note that sometimes 2 names are used for the same station in different years
suppressMessages(library(dplyr))
df2 = dplyr::select(df, station:t2m_mean_mon, rr_monthly)

monthly_summary = df2 %>% 
  dplyr::group_by(mm) %>% 
  dplyr::summarise(tmax = mean(tmax_abs, na.rm = TRUE), 
                   tmin = mean(tmin_abs, na.rm = TRUE),
                   tavg = mean(t2m_mean_mon, na.rm = TRUE), 
                   precip = sum(rr_monthly) / n_distinct(yy))            

monthly_summary = as.data.frame(t(monthly_summary[, c(5, 2, 3, 4)])) 
monthly_summary = round(monthly_summary, 1)
colnames(monthly_summary) = month.abb
Exemplary data frame of meteorological preprocessing.
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
precip 39.0 34.6 41.0 32.1 50.5 57.5 52.7 78.5 68.9 83.8 47.9 52.0
tmax 8.1 9.1 13.6 22.6 25.6 29.6 29.6 28.5 22.7 18.4 11.6 8.8
tmin -11.6 -9.6 -6.3 -4.1 0.0 4.5 6.4 6.7 3.0 -1.6 -6.0 -10.4
tavg 0.5 0.7 2.7 6.8 10.6 14.4 16.9 17.0 13.2 8.8 3.7 0.9

Example 6

Calculate the mean maximum value of the flow on the stations in each year with dplyr’s summarise(), and spread data by year using tidyr’s spread() to get the annual means of maximum flow in the consecutive columns.

library(climate)
library(dplyr)
library(tidyr)
h = hydro_imgw(interval = "monthly", year = 2001:2002, coords = TRUE)
knitr::kable(head(h))
id X Y station riv_or_lake hyy idhyy idex H Q T mm
18723 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 1 1 214 172 NA 11
18724 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 1 2 228 207 NA 11
18725 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 1 3 250 272 NA 11
18726 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 2 1 215 174 NA 12
18727 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 2 2 225 201 NA 12
18728 150210180 21.8335 50.88641 ANNOPOL Wisła (2) 2001 2 3 258 297 NA 12
h2 = h %>%
  dplyr::filter(idex == 3) %>%
  dplyr::select(id, station, X, Y, hyy, Q) %>%
  dplyr::group_by(hyy, id, station, X, Y) %>%
  dplyr::summarise(annual_mean_Q = round(mean(Q, na.rm = TRUE), 1)) %>% 
  tidyr::pivot_wider(names_from = hyy, values_from = annual_mean_Q)
#> `summarise()` has grouped output by 'hyy', 'id', 'station', 'X'. You can
#> override using the `.groups` argument.

knitr::kable(head(h2))
id station X Y 2001 2002
149180010 KRZYŻANOWICE 18.28780 49.99301 200.5 147.4
149180020 CHAŁUPKI 18.32752 49.92127 174.7 96.7
149180040 GOŁKOWICE 18.49640 49.92579 4.5 2.0
149180050 ZEBRZYDOWICE 18.61326 49.88025 13.5 7.9
149180060 CIESZYN 18.62972 49.74616 57.2 57.7
149180070 CIESZYN 18.63137 49.74629 NaN NaN

Acknowledgment

Ogimet.com, University of Wyoming, and Institute of Meteorology and Water Management - National Research Institute (IMGW-PIB), National Oceanic & Atmospheric Administration (NOAA) - Earth System Research Laboratories - Global Monitoring Laboratory, Global Monitoring Division and Integrated Surface Hourly (NOAA ISH) are the sources of the data.

Contribution

Contributions to this package are welcome. The preferred method of contribution is through a GitHub pull request. Feel also free to contact us by creating an issue.

Citation

To cite the climate package in publications, please use this paper:

Czernecki, B.; Głogowski, A.; Nowosad, J. Climate: An R Package to Access Free In-Situ Meteorological and Hydrological Datasets for Environmental Assessment. Sustainability 2020, 12, 394. https://doi.org/10.3390/su12010394

LaTeX version can be obtained with:

library(climate)
citation("climate")