The goal of the climate R package is to automatize downloading of meteorological and hydrological data from publicly available repositories:
The climate package consists of ten main functions - three for meteorological data, one for hydrological data and six auxiliary functions and datasets:
meteo_ogimet() - Downloading hourly and daily meteorological data from the SYNOP stations available in the ogimet.com collection. Any meteorological (aka SYNOP) station working under the World Meteorological Organizaton framework after year 2000 should be accessible.
meteo_imgw() - Downloading hourly, daily, and
monthly meteorological data from the SYNOP/CLIMATE/PRECIP stations
available in the dane.imgw.pl collection. It is a wrapper for
meteo_monthly()
, meteo_daily()
, and
meteo_hourly()
from the imgw
package.
meteo_noaa_hourly() - Downloading hourly NOAA Integrated Surface Hourly (ISH) meteorological data - Some stations have > 100 years long history of observations
sounding_wyoming() - Downloading measurements of the vertical profile of atmosphere (aka rawinsonde data)
hydro_annual()
, hydro_monthly()
, and
hydro_daily()
from the imgw
package.Examples shows aplication of climate package with additional use of tools that help with processing the data to increase legible of downloaded data.
Finding a 50 nearest meteorological stations in a given country:
library(climate)
= nearest_stations_ogimet(country ="United+Kingdom",
ns point = c(-4, 56),
no_of_stations = 50,
add_map = TRUE)
#> [1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=United+Kingdom&osum=no&fmt=html&ord=REV&ano=2022&mes=08&day=08&hora=06&ndays=1&Send=send"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb28ca92cd
head(ns)
#> wmo_id station_names lon lat alt distance
#> 28 03144 Strathallan -3.733348 56.31667 35 46.44794
#> 30 03155 Drumalbin -3.733348 55.61668 245 52.38975
#> 26 03134 Glasgow Bishopton -4.533344 55.90002 59 60.88179
#> 32 03166 Edinburgh Gogarbank -3.350007 55.93335 57 73.30942
#> 27 03136 Prestwick RNAS -4.583345 55.51668 26 84.99537
#> 31 03162 Eskdalemuir -3.200004 55.31667 242 118.04292
#> wmo_id station_names lon lat alt distance [km]
#> 29 03144 Strathallan -3.733348 56.31667 35 46.44794
#> 32 03155 Drumalbin -3.733348 55.61668 245 52.38975
#> 30 03148 Glen Ogle -4.316673 56.41667 564 58.71862
#> 27 03134 Glasgow Bishopton -4.533344 55.90002 59 60.88179
#> 35 03166 Edinburgh Gogarbank -3.350007 55.93335 57 73.30942
#> 28 03136 Prestwick RNAS -4.583345 55.51668 26 84.99537
Summary of stations available in Ogimet repository for a selected country:
library(climate)
= stations_ogimet(country = "Poland", add_map = TRUE)
PL #> [1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=Poland&osum=no&fmt=html&ord=REV&ano=2022&mes=08&day=08&hora=06&ndays=1&Send=send"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb58b23ccc
head(PL)
#> wmo_id station_names lon lat alt
#> 1 12001 Petrobaltic Beta 18.16667 55.46668 46
#> 2 12100 Kolobrzeg 15.58334 54.18334 3
#> 3 12105 Koszalin 16.15000 54.20000 32
#> 4 12115 Ustka 16.86668 54.58335 6
#> 5 12120 Leba 17.53334 54.75001 2
#> 6 12125 Lebork 17.75002 54.55001 17
Downlading hourly meteorological data Svalbard in a random year from Ogimet
# downloading data with NOAA service:
= meteo_noaa_hourly(station = "010080-99999",
df year = sample(2000:2020, 1))
#> [1] "https://www1.ncdc.noaa.gov/pub/data/noaa/2015/010080-99999-2015.gz"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb7fc42e7a
# downloading the same data with Ogimet.com (example for 2019):
# df <- meteo_ogimet(interval = "hourly", date = c("2019-01-01", "2019-12-31"),
# station = c("01008"))
date | lon | lat | alt | t2m | dpt2m | ws | wd | slp | visibility | |
---|---|---|---|---|---|---|---|---|---|---|
1 | 2015-01-01 00:00:00 | 15.467 | 78.25 | 29 | -2.6 | -5.4 | 4 | 110 | 986.9 | 55000 |
5 | 2015-01-01 03:00:00 | 15.467 | 78.25 | 29 | -3.9 | -5.3 | 4 | 120 | 986.7 | 30000 |
9 | 2015-01-01 06:00:00 | 15.467 | 78.25 | 29 | -2.9 | -5.1 | 3 | 100 | 985.7 | 40000 |
13 | 2015-01-01 09:00:00 | 15.467 | 78.25 | 29 | -3.1 | -5.4 | 1 | 120 | 985.7 | 30000 |
17 | 2015-01-01 12:00:00 | 15.467 | 78.25 | 29 | -2.6 | -4.7 | 2 | 260 | 985.1 | 30000 |
21 | 2015-01-01 15:00:00 | 15.467 | 78.25 | 29 | -3.1 | -4.9 | 1 | 190 | 984.2 | 30000 |
25 | 2015-01-01 18:00:00 | 15.467 | 78.25 | 29 | -3.7 | -4.9 | NA | NA | 983.0 | 30000 |
29 | 2015-01-01 21:00:00 | 15.467 | 78.25 | 29 | -3.1 | -4.3 | 5 | 100 | 982.2 | 30000 |
33 | 2015-01-02 00:00:00 | 15.467 | 78.25 | 29 | -5.0 | -7.0 | 6 | 120 | 981.1 | 40000 |
37 | 2015-01-02 03:00:00 | 15.467 | 78.25 | 29 | -3.0 | -6.8 | 5 | 150 | 980.2 | 40000 |
Downloading atmospheric (sounding) profile for Łeba, PL rawinsonde station:
library(climate)
data("profile_demo")
# same as:
# profile_demo <- sounding_wyoming(wmo_id = 12120,
# yy = 2000,
# mm = 3,
# dd = 23,
# hh = 0)
<- profile_demo[[1]]
df2 colnames(df2)[c(1, 3:4)] = c("PRESS", "TEMP", "DEWPT") # changing column names
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 |
Preparing an annual summary of air temperature and precipitation, processing with dplyr
library(climate)
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.0.5
#>
#> 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
= meteo_imgw(interval = "monthly", rank = "synop", year = 1991:2019, station = "ŁEBA")
df #> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/s_m_d_format.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb6badf50e
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/s_m_t_format.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb69b3a15c
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb1026d53b
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/1991_1995/1991_1995_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb65791cc5
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/1996_2000/1996_2000_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb618fb043
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2001/2001_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb7b0b5c42
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2002/2002_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb37f42951
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2003/2003_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb1f496a64
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2004/2004_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb49ed5a96
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2005/2005_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb215a967
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2006/2006_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb6b260250
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2007/2007_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb7846627c
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2008/2008_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb500ce81a
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2009/2009_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb78fffbed
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2010/2010_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb60185f4b
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2011/2011_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb61de9483
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2012/2012_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb72911d14
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2013/2013_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb58fccad4
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2014/2014_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb64db828b
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2015/2015_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18ebbafa09c
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2016/2016_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb4eab0df1
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2017/2017_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb11ffc5d4
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2018/2018_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb6315d37
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_meteorologiczne/miesieczne/synop/2019/2019_m_s.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb6061bfcf
# please note that sometimes 2 names are used for the same station in different years
= select(df, station:t2m_mean_mon, rr_monthly)
df2
= df2 %>%
monthly_summary 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))
= as.data.frame(t(monthly_summary[, c(5,2,3,4)]))
monthly_summary = round(monthly_summary, 1)
monthly_summary colnames(monthly_summary) = month.abb
Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
precip | 42.0 | 32.9 | 37.7 | 28.7 | 49.0 | 54.3 | 73.0 | 81.5 | 76.0 | 77.6 | 59.5 | 54.1 |
tmax | 7.5 | 8.9 | 14.5 | 22.1 | 26.2 | 28.5 | 29.6 | 29.0 | 24.5 | 18.8 | 12.2 | 8.7 |
tmin | -11.6 | -10.0 | -7.4 | -3.7 | -0.1 | 4.4 | 7.8 | 7.8 | 3.6 | -0.8 | -3.9 | -8.8 |
tavg | 0.1 | 0.5 | 2.7 | 6.9 | 11.3 | 14.9 | 17.5 | 17.5 | 13.9 | 9.2 | 4.7 | 1.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)
#> Warning: package 'tidyr' was built under R version 4.0.5
= hydro_imgw(interval = "monthly", year = 2001:2005, coords = TRUE)
h #> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb1496ca42
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/mies_info.txt"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb37b8bd9d
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2001/mies_2001.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb41a8aaff
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2002/mies_2002.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb7053b9a8
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2003/mies_2003.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb78184e10
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2004/mies_2004.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb61bd26c1
#> [1] "https://danepubliczne.imgw.pl/data/dane_pomiarowo_obserwacyjne/dane_hydrologiczne/miesieczne/2005/mies_2005.zip"
#> /var/folders/lw/3fnnk87n4q1dkl35s2_p24h80000gn/T//RtmpUdJonu/file18eb600a6fc7
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
= h %>%
h2 filter(idex == 3) %>%
select(id, station, X, Y, hyy, Q) %>%
group_by(hyy, id, station, X, Y) %>%
summarise(annual_mean_Q = round(mean(Q, na.rm = TRUE), 1)) %>%
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.
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 |
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.
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.
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")