# NOT RUN {
# read an EPW file from EnergyPlus website
path_base <- "https://energyplus.net/weather-download"
path_region <- "north_and_central_america_wmo_region_4/USA/CA"
path_file <- "USA_CA_San.Francisco.Intl.AP.724940_TMY3/USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw"
path_epw <- file.path(path_base, path_region, path_file)
epw <- read_epw(path_epw)
# read an EPW file distributed with EnergyPlus
if (is_avail_eplus(8.8)) {
epw_path <- file.path(
eplus_config(8.8)$dir,
"WeatherData",
"USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw"
)
epw <- read_epw(path_epw)
}
# get file path
epw$path()
# get basic info
epw$city
epw$state_province
epw$country
epw$data_source
epw$wmo_number
epw$latitude
epw$longitude
epw$time_zone
epw$elevation
epw$time_step
epw$start_day_of_week
# set basic info
# NOTE: Use with caution. May mess up your weather data
epw$city <- "Chongqing"
epw$city
epw$state_province <- "Chongqing"
epw$state_province
epw$country <- "China"
epw$country
epw$data_source <- "TMY"
epw$data_source
epw$wmo_number <- "724944"
epw$wmo_number
epw$latitude <- 20.0
epw$latitude
epw$longitude <- -120.0
epw$longitude
epw$time_zone <- 8
epw$time_zone
epw$elevation <- 100
epw$elevation
epw$time_step <- 2
epw$time_step
epw$start_day_of_week <- "Monday"
epw$start_day_of_week
# get weather data
str(epw$get_data())
# get weather data but change the year to 2018
# the year column is not changed by default, only the returned datetime column
str(epw$get_data(year = 2018)$datetime)
str(epw$get_data(year = 2018)$year)
# you can force to update the year column
str(epw$get_data(year = 2018, update = TRUE)$year)
# get weather data with units
str(epw$get_data(unit = TRUE))
# with units specified, you can easily perform unit conversion using units
# package
t_dry_bulb <- epw$get_data(unit = TRUE)$dry_bulb_temperature
units(t_dry_bulb) <- with(units::ud_units, "kelvin")
str(t_dry_bulb)
# change the time zone of datetime column in the returned weather data
attributes(epw$get_data()$datetime)
attributes(epw$get_data(tz = "America/Chicago")$datetime)
# change the weather data
# NOTE: This feature is experimental. There is no validation when replacing.
epw$set_data(epw$get_data())
# save the weather file
epw$save(file.path(tempdir(), "weather.epw"))
# }
Run the code above in your browser using DataLab