get_eurocordex_stations_indices: Get locations of stations on the model grid defined in the...

Description Usage Arguments Value Examples

Description

We have a data.frame with station information and want to know, in which model grid cell boxes these stations are located.

Usage

1
2
get_eurocordex_stations_indices(file, stations, var_lon = "lon",
  var_lat = "lat", col_lon = "lon", col_lat = "lat")

Arguments

file

path (directory and name) of a netCDF file, in which den model grid is defined

stations

data.frame containing the stations information as columns station_name, lon, and lat

var_lon

character, optional: name of the longitude variable in file

var_lat

character, optional: name of the latitude variable in file

col_lon

character, optional: name of the longitude column in stations

col_lat

character, optional: name of the latitude column in stations

Value

data.frame containing the stations information as columns station_name, idx_lon, and idx_lat; if the stations are not on the model grid, idx_lon and idx_lat of the nearest grid cell are provided

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## EXAMPLE 1:
# construct data:
stations <- data.frame(c('abc', 'def', 'ghi', 'jkl'), 
                       c(10.31, 11.12, 9.2, 9.31), 
                       c(55.19, 54.77, 55.02, 53.2), 
                       c(44, 1, 5, 107), 
                       stringsAsFactors = FALSE)
names(stations) <- c('station_name', 'lon', 'lat', 'elev')

# we need to have some file with EURO-CORDEX data somewhere.
file = './tasmin_EUR-11_ICHEC-EC-EARTH_rcp26_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20060101-20101231.nc'

# call the function
idx_stations <- get_eurocordex_stations_indices(file, stations)

print(idx_stations)
#  station_name idx_lon idx_lat
# 1          abc     219     256
# 2          def     223     252
# 3          ghi     213     255
# 4          jkl     212     239


## EXAMPLE 2:
## If we have different column names in the stations data.frame
# construct data:
stations <- data.frame(c('abc', 'def', 'ghi', 'jkl'), 
                       c(10.31, 11.12, 9.2, 9.31), 
                       c(55.19, 54.77, 55.02, 53.2), 
                       c(44, 1, 5, 107), 
                       stringsAsFactors = FALSE)
names(stations) <- c('station_name', 'long', 'lati', 'elev')

# we need to have some file with EURO-CORDEX data somewhere.
file = './tasmin_EUR-11_ICHEC-EC-EARTH_rcp26_r12i1p1_CLMcom-CCLM4-8-17_v1_day_20060101-20101231.nc'

# call the function
idx_stations <- get_eurocordex_stations_indices(file, stations, col_lon = 'long', col_lat = 'lati')

print(idx_stations)
#  station_name idx_lon idx_lat
# 1          abc     219     256
# 2          def     223     252
# 3          ghi     213     255
# 4          jkl     212     239


# Used by `read_eurocordex_data`. Please look into that function's code for further usage examples.

neumannd/eurocordex2swatTools documentation built on May 14, 2019, 2:17 p.m.