Introduction to the climate package

Bartosz Czernecki, Arkadiusz Głogowski, Jakub Nowosad

2020-06-02

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 aplication 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 in a given country:

Example 2

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

Example 3

Downlading hourly meteorological data Svalbard in 2019 from Ogimet

Examplary data frame of meteorological data.
date lon lat alt t2m dpt2m ws wd slp visibility
1 2019-01-01 00:00:00 15.467 78.25 29 -14.5 -19.8 7 330 1004.5 60000
3 2019-01-01 01:00:00 15.467 78.25 29 -15.0 -20.6 9 320 1004.9 NA
5 2019-01-01 02:00:00 15.467 78.25 29 -15.1 -20.5 5 320 1005.4 NA
7 2019-01-01 03:00:00 15.467 78.25 29 -15.0 -20.1 5 320 1005.7 50000
10 2019-01-01 04:00:00 15.467 78.25 29 -15.2 -20.3 8 320 1006.2 NA
12 2019-01-01 05:00:00 15.467 78.25 29 -15.2 -20.1 9 330 1006.6 NA
14 2019-01-01 06:00:00 15.467 78.25 29 -15.5 -20.1 6 330 1007.3 50000
16 2019-01-01 07:00:00 15.467 78.25 29 -15.6 -21.3 6 340 1007.8 NA
18 2019-01-01 08:00:00 15.467 78.25 29 -15.7 -22.4 6 350 1008.6 NA
20 2019-01-01 09:00:00 15.467 78.25 29 -15.9 -22.6 5 360 1009.4 55000

Example 4

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

Examplary 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, processing with dplyr

library(climate)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df = meteo_imgw(interval = 'monthly', rank='synop', year = 1991:2019, 
                station = c("POZNAŃ", "POZNAŃ-ŁAWICA")) 
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/s_m_d_format.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8fb3b63e
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/s_m_t_format.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f85f81a87f
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8395d5ad5
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/1991_1995/1991_1995_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f81ff6735f
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/1996_2000/1996_2000_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f852c46f9b
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2001/2001_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f872ab4365
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2002/2002_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f87602a7a3
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2003/2003_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f81442962f
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2004/2004_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f826aa43ac
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2005/2005_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8507cabd8
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2006/2006_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f835730152
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2007/2007_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f82124a73f
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2008/2008_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8446bc5c1
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2009/2009_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f83c98e119
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2010/2010_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f871ca1a2b
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2011/2011_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f881a160a
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2012/2012_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f816f9d583
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2013/2013_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f86a195d48
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2014/2014_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f82927dfb4
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2015/2015_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8d1a3e08
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2016/2016_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8242b6b31
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2017/2017_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f812e0f9c6
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2018/2018_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f86c61b771
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2019/2019_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f82244e796
#> Warning in substr(all_data$`Nazwa stacji`, 1, nchar(station)) == station: longer
#> object length is not a multiple of shorter object length
# sometimes 2 names are used for the same station in different years

df2 = select(df, station:t2m_mean_mon, rr_monthly)

monthly_summary = df2 %>% 
  group_by(mm) %>% 
  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
Examplary data frame of meteorological preprocessing.
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
precip 37.7 29.2 45.0 29.5 54.5 57.7 83.4 55.7 45.1 35.6 34.3 41.2
tmax 9.2 11.1 17.0 24.1 27.6 31.5 32.1 32.3 26.4 21.2 14.0 10.8
tmin -13.8 -11.9 -7.5 -3.4 1.1 5.8 7.7 7.1 2.5 -3.5 -5.7 -11.2
tavg -0.5 0.4 3.6 9.5 14.0 17.4 18.9 19.1 14.1 8.8 4.3 0.7

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:2005, coords = TRUE)
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f822eeb83d
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/mies_info.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f86681beb5
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2001/mies_2001.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8500f91a6
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2002/mies_2002.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f810f3aa60
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2003/mies_2003.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f81877f8db
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2004/mies_2004.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f8719cd71e
#> [1] "https://dane.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2005/mies_2005.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmphZHKCQ/file13f83f6910aa
head(h)
#>              id       X        Y station riv_or_lake  hyy idhyy idex   H   Q  T
#> 47027 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    1 214 172 NA
#> 47028 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    2 228 207 NA
#> 47029 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    3 250 272 NA
#> 47030 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    1 215 174 NA
#> 47031 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    2 225 201 NA
#> 47032 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    3 258 297 NA
#>       mm
#> 47027 11
#> 47028 11
#> 47029 11
#> 47030 12
#> 47031 12
#> 47032 12
Examplary data frame of hydrological preprocesssing.
id station X Y 2001 2002 2003 2004 2005
149180010 KRZYŻANOWICE 18.28780 49.99301 200.5 147.4 87.9 109.2 170.6
149180020 CHAŁUPKI 18.32752 49.92127 174.7 96.7 57.6 91.8 146.9
149180040 GOŁKOWICE 18.49640 49.92579 4.5 2.0 1.7 1.7 2.5
149180050 ZEBRZYDOWICE 18.61326 49.88025 13.5 7.9 3.8 5.0 10.4
149180060 CIESZYN 18.62972 49.74616 57.2 57.7 29.8 26.8 65.4
149180070 CIESZYN 18.63137 49.74629 NaN NaN NaN 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 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")