View source: R/read_importprism.R
read_importprism | R Documentation |
Download and crop the latest weather rasters from Parameter-elevation Relationship on Independent Slopes Model (PRISM). Summarize by zone and save as CSV.
read_importprism(
vars = c("tmin", "tmax", "tdmean", "ppt"),
vars_ytd = c("ppt"),
date_beg = as.Date("1981-01-01"),
date_end = Sys.Date(),
bbox = sf::st_bbox(sf_zones),
dir_tif = sub("\\.[^.]*$", "", zonal_csv),
pfx_tif = "prism_daily_",
sf_zones,
fld_zones,
zonal_fun = "mean",
zonal_csv,
redo_zonal = F,
verbose = F
)
vars |
character vector of PRISM variables to download and crop. The
default is |
vars_ytd |
character vector of PRISM variables to be summed for the
year to date, which gets recorded as a new layer with the suffix |
date_beg |
defaults to the start of PRISM daily availability 1981-01-01. |
date_end |
defaults to today's date, but will be adjusted to the most recently available data, per update schedule. CAUTION: If you try to request the same date-variable in a given day, you will get an error from the PRISM service with a message like "You have tried to download the file PRISM_tdmean_stable_4kmD2_19810101_bil.zip more than twice in one day (Pacific local time). Note that repeated offenses may result in your IP address being blocked." |
bbox |
bounding box of the spatial extent to crop PRISM daily rasters,
which could be bigger than |
dir_tif |
directory path to store downloaded and cropped PRISM daily
rasters (as GeoTIFF) across years with file name of format
|
pfx_tif |
prefix for the PRISM daily raster files, appended by the month-day. Defaults to |
sf_zones |
spatial feature object ( |
fld_zones |
character vector of unique field name(s) in |
zonal_fun |
function to apply to the |
zonal_csv |
path to output of zonal statistics ( |
redo_zonal |
logical whether to recalculate the zonal statistics. Defaults to False. |
verbose |
logical whether to show informative messages on processing |
The Parameter-elevation Relationship on Independent Slopes Model (PRISM) is a combined dataset consisting of ground gauge station and RADAR products, at a 4km grid resolution covering the contiguous United States from 1981 to present.
The available variables (vars
) are:
tmin
: minimum temperature (ºC)
tmax
: maximum temperature (ºC)
tmean
: mean temperature (ºC; tmean = mean(tmin, tmax)
)
tdmean
: mean dew point temperature (ºC)
ppt
: total precipitation (mm; rain and snow)
vpdmin
: daily minimum vapor pressure deficit
vpdmax
: daily maximum vapor pressure deficit
The daily PRISM data is available over three stability levels, or 8 versions given by the update schedule:
stable
: data is considered final and will not change (before 6 months)
provisional
: data is considered final but may be updated (previous 6 months)
early
: data is preliminary and may be updated (this month)
The PRISM update schedule is downloaded and processed in a data frame to understand the latest date and variable available, along with version and date updated.
Any existing rasters in dir_tif
are fetched based on a common naming
structure for the raster file name (prism_daily_{month}-{day}.tif
) and
layer names ({date}_{variable}_v{version}-{date_updated}
) into a data
frame.
Based on intersecting above with the requested dates, any missing or more
recently updated variable-date PRISM rasters are downloaded and cropped to
the bounding box (bbox
) and written as GeoTIFFs (*.tif). Layers are renamed
to include extra information on {version}
(1-8) and {date_udpated}
.
Summary statistics (based on sf_zones
and zonal_fun
) are calculated on
the cropped PRISM daily rasters.
For more on Parameter-elevation Relationship on Independent Slopes Model (PRISM), see:
PRISM download methods information (FTP, web services)
data frame with the following columns:
{fld_zones}
column(s) specified from input sf_zones
{zonal_fun}
: value of input function (e.g. "mean"
) summarizing raster to zone
date
: date of PRISM daily raster
variable
: PRISM variable
version
: PRISM version
date_updated
: date of PRISM daily raster update
## Not run:
# setup output directory and table
dir_tif <- system.file("prism", package = "tbeptools")
zonal_csv <- system.file("prism/_zones.csv", package = "tbeptools")
# run function for Tampa Bay watersheds for first 3 days and 4 variables
d <- read_importprism(
vars = c("tdmean", "ppt"),
date_beg = as.Date("1981-01-01"),
date_end = as.Date("1981-01-02"),
dir_tif = dir_tif,
sf_zones = tbsegshed,
fld_zones = "bay_segment",
zonal_csv = zonal_csv)
# show raster files, layers and plot
tifs <- list.files(dir_tif, pattern = ".tif$", full.names = T)
basename(tifs)
r <- terra::rast(tifs[1])
r
names(r)
terra::plet(
r[[3]],
main = names(r)[3],
col = "Spectral",
tiles = "CartoDB.DarkMatter")
# show summary by zone
d
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.