KWB-R / wasserportal

R Package with Functions for Scraping Data of Wasserportal Berlin (https://wasserportal.berlin.de)
https://kwb-r.github.io/wasserportal/
MIT License
0 stars 0 forks source link

Wasserportal Berlin: examples failing #7

Closed mrustl closed 3 years ago

mrustl commented 3 years ago

See: https://kwb-r.github.io/kwb.read/reference/read_wasserportal.html

remotes::install_github("kwb-r/kwb.read@dev")

# Get a list of available water quality stations and variables
stations <- kwb.read::get_wasserportal_stations()
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
variables <- kwb.read::get_wasserportal_variables()

# Read the timeseries (multiple variables for one station)
water_quality <- kwb.read::read_wasserportal(
  station = stations$MPS_Charlottenburg,
  variables = c(variables["Sauerstoffgehalt"], variables["Leitfaehigkeit"]),
  from_date = "2019-03-01", include_raw_time = TRUE
)
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
#> Warning: The function hsSubstSpecChars() is deprecated.
#> Please use substSpecialChars() instead.
#> Reading 'Sauerstoffgehalt' for station 153 (MPS_Charlottenburg) ... ok. (0.59s) 
#> Error in timestamps[first_indices]: invalid subscript type 'list'

# Look at the first few records
head(water_quality)
#> Error in head(water_quality): object 'water_quality' not found

# Check the metadata
kwb.utils::getAttribute(water_quality, "metadata")
#> Error in kwb.utils::getAttribute(water_quality, "metadata"): object 'water_quality' not found

# Set missing values to NA
water_quality[water_quality == -777] <- NA
#> Error in water_quality[water_quality == -777] <- NA: object 'water_quality' not found

# Look at the first few records again
head(water_quality)
#> Error in head(water_quality): object 'water_quality' not found

### How was the original timestamp interpreted?

# Determine the days at which summer time starts and ends, respectively
switches <- kwb.datetime::date_range_CEST(2019)

# Reformat to dd.mm.yyyy
switches <- kwb.datetime::reformatTimestamp(switches, "%Y-%m-%d", "%d.%m.%Y")

# Define a pattern to look for timestamps "around" the switches
pattern <- paste(switches, "0[1-4]", collapse = "|")

# Look at the data for these timestamps
water_quality[grepl(pattern, water_quality$timestamp_raw), ]
#> Error in eval(expr, envir, enclos): object 'water_quality' not found

# The original timestamps (timestamps_raw) are not all plausible, e.g. 
# "31.03.2019 03:00" appears twice! See the Details in ?read_wasserportal()
# how this is treated.
hsonne commented 3 years ago

Should be fixed with KWB-R/kwb.read#3