Introduction to the imgw package (EN)

Bartosz Czernecki, Arkadiusz Głogowski, Jakub Nowosad

2020-01-28

The main goal of the imgw package is to give convenient and programmable access to the Polish database of the archive meteorological and hydrological measurements.

It consists of tools that are:

Functions

The imgw package consists of nine main functions - four for meteorological data, four for hydrological data and one for sounding meteo:

  1. Meteorological data:
  1. Hydrological data:
  1. Rawinsonde data:

Most of the functions mentioned above have similar arguments allowing to choose:

Database

imgw also has a few additional databases:

#>                               fullname   abbr_eng
#> 1 Absolutna temperatura maksymalna [C]   tmax_abs
#> 2  Absolutna temperatura minimalna [C]   tmin_abs
#> 3                 Aktynometria [J/cm2]      irrad
#> 4      Charakterystyka tendencji [kod] press_tend
#> 5                      Chmury CH [kod] cl_CH_code
#> 6                    Chmury CH tekstem      cl_CH
#>                           fullname_eng
#> 1 Absolute maximum air temperature [C]
#> 2 Absolute minimum air temperature [C]
#> 3                   Irradiance [J/cm2]
#> 4                    Pressure tendency
#> 5              High cloud cover [code]
#> 6              High cloud cover [text]
#> # A tibble: 6 x 3
#>          id     X     Y
#>       <dbl> <dbl> <dbl>
#> 1 249190020  19.6  50.0
#> 2 249199999  19.3  49.9
#> 3 249190040  19.4  49.9
#> 4 249190050  19.8  49.9
#> 5 249190060  20.0  49.9
#> 6 249190070  19.2  49.9

Application

We will show how to use our package and prepare the data for spatial analysis with the additional help of the dplyr and tidyr packages. Firstly, we download ten years (2001-2010) of monthly hydrological observations for all stations available and automatically add their spatial coordinates.

#>              id       X        Y station riv_or_lake  hyy idhyy idex   H
#> 95158 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    1 214
#> 95159 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    2 228
#> 95160 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     1    3 250
#> 95161 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    1 215
#> 95162 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    2 225
#> 95163 150210180 21.8335 50.88641 ANNOPOL   Wisła (2) 2001     2    3 258
#>         Q  T mm
#> 95158 172 NA 11
#> 95159 207 NA 11
#> 95160 272 NA 11
#> 95161 174 NA 12
#> 95162 201 NA 12
#> 95163 297 NA 12

The idex variable represents id of the extremum, where 1 means minimum, 2 mean, and 3 maximum.1 Hydrologists often use the maximum value so we will filter the data and select only the station id, hydrological year (hyy), latitude X and longitude Y. Next, we will 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.

h2 = h %>%
  filter(idex == 3) %>%
  select(id, station, X, Y, hyy, Q) %>%
  group_by(hyy, id, station, X, Y) %>%
  summarise(srednie_roczne_Q = round(mean(Q, na.rm = TRUE),1)) %>% 
  spread(hyy, srednie_roczne_Q)
Examplary data frame of hydrological preprocesssing.
id station X Y 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
149180010 KRZYŻANOWICE 18.28780 49.99301 200.5 147.4 87.9 109.2 170.6 226.9 152.9 131.0 160.9 461.1
149180020 CHAŁUPKI 18.32752 49.92127 174.7 96.7 57.6 91.8 146.9 170.6 110.2 101.6 124.7 314.6
149180040 GOŁKOWICE 18.49640 49.92579 4.5 2.0 1.7 1.7 2.5 3.3 2.1 1.7 2.2 8.6
149180050 ZEBRZYDOWICE 18.61326 49.88025 13.5 7.9 3.8 5.0 10.4 6.5 5.8 2.8 4.5 23.6
149180060 CIESZYN 18.62972 49.74616 57.2 57.7 29.8 26.8 65.4 60.7 54.7 33.0 34.7 135.0
149180070 CIESZYN 18.63137 49.74629 NaN NaN NaN NaN NaN NaN 0.6 0.5 0.6 0.6

The result represent changing annual maximum average of water flow rate over the decade for all available stations in Poland. We can save it to:

library(sf)
library(tmap)
library(rnaturalearth)
library(rnaturalearthdata)
world = ne_countries(scale = "medium", returnclass = "sf")

h3 = h2 %>% 
  filter(!is.na(X)) %>% 
  st_as_sf(coords = c("X", "Y"))

tm_shape(h3) + 
  tm_symbols(size = as.character(c(2001:2010)),
             title.size = "Średni przepływ maksymalny") +
  tm_facets(free.scales = FALSE, ncol = 4) + 
  tm_shape(world) + 
  tm_borders(col = "black", lwd = 2) +
  tm_layout(legend.position = c(-1.25, 0.05),
            outer.margins = c(0, 0.05, 0, -0.25),
            panel.labels = as.character(c(2001:2010)))

  1. You can find more information about this in the hydro_abbrev dataset.