Prism
Download data from the Oregon PRISM climate data project http://www.prism.oregonstate.edu/
Install / Use
/learn @ropensci/PrismREADME
prism
This package allows users to access and visualize data from the Oregon State PRISM project. Data are all in the form of gridded rasters for the continental US at 4 different temporal scales: daily, monthly, annual, and 30 year normals. Please see their webpage for a full description of the data products, or see their overview.
Installation
prism is available on CRAN:
install.packages("prism")
Or the development version can be installed from GitHub with devtools:
# install.packages("devtools")
library(devtools)
install_github("ropensci/prism")
Quickstart
The overall work flow in the prism package is (links go to details on this page):
- Set the download directory, i.e., the folder on
your computer that prism data will be saved to:
prism_set_dl_dir(). This is now referred to as the “prism archive”. - Download prism data to the archive:
get_prism_*(). Each folder, or variable, timestep, day/month/year is stored in a single folder in the archive and referred to as prism data (pd). - Interact with the prism
archive:
prism_archive_*(). Or interact with the prism data:pd_*().
The remainder of this README provides examples following this work flow.
prism data and parameters
Data are available in 4 different temporal scales as mentioned above. At each temporal scale, there are 11 different parameters/variables available. Keep in mind these are modeled parameters, not measured. Please see the full description for how they are calculated.
| Parameter name | Description | |:---------------|:-------------------------------------| | tmean | Mean temperature | | tmax | Maximum temperature | | tmin | Minimum temperature | | tdmean | Mean dew point temperature | | ppt | Total precipitation (rain and snow) | | vpdmin | Daily minimum vapor pressure deficit | | vpdmax | Daily maximum vapor pressure deficit | | solclear | Solar radiation (clear sky) | | solslope | Solar radiation (sloped) | | soltotal | Solar radiation (total) | | soltrans | Cloud transmittance |
Data availability
Normals (4km or 800m resolution) based on 1991-2020 average:
<span style="color:red; font-weight:bold;">Important</span> .bil files
are no longer available in .bil format. The get_prism_normals()
functions still work and will download the data in GeoTiff format.
But - the rest of the prism R package has not been updated to work
with GeoTiff, so none of the other functions will work with the 30-year
normal data, e.g.,
prism_archive_subset(temp_period = "monthly normals") will return
character(0) and plotting functions will not work.
| Variable | Annual | Monthly | Daily | |:-----------|:-------|:--------|:------| | tmean | X | X | X | | tmax | X | X | X | | tmin | X | X | X | | tdmean | X | X | X | | ppt | X | X | X | | vpdmin | X | X | X | | vpdmax | X | X | X | | solclear | 800m | 800m | | | solslope | 800m | 800m | | | soltotal | 800m | 800m | | | soltrans | 800m | 800m | |
Daily, monthly, and annual data:
| Variable | Annual (1895-present) | Monthly (1895-present) | Daily (1981-present) | |:-----------|:----------------------|:-----------------------|:---------------------| | tmean | X | X | X | | tmax | X | X | X | | tmin | X | X | X | | tdmean | X | X | X | | ppt | X | X | X | | vpdmin | X | X | X | | vpdmax | X | X | X | | solclear | | | | | solslope | | | | | soltotal | | | | | soltrans | | | |
Downloading data
Before downloading any data, set the directory that the prism data will be saved to:
library(prism)
#> Be sure to set the download folder using `prism_set_dl_dir()`.
prism_set_dl_dir("~/prismtmp")
This is now referred to as the “prism archive”. The prism_archive_*()
functions allow the user to search through the archive. The prism
archive contains “prism data”. The prism data are referred to by their
folder names, even though the “real” data are the .bil, .txt, and other
files that exist in the folder. The prism data (pd) can be accessed
using the pd_*() functions.
Download 30-year normal data
Normals are based on the latest 30-year period; currently 1991 - 2020. Normals can be downloaded in two resolutions, 4km and 800m, and a resolution must be specified. They can be downloaded for a given day, month, vector of days/months, or annual averages for all 30 years.
# Download March 14 30-year average precip. Note the year is ignored
get_prism_normals('ppt', '4km', day = as.Date('2025-03-14'))
# Download the January - June 30-year averages at 4km resolution
get_prism_normals(type="tmean", resolution = "4km", mon = 1:6, keepZip = FALSE)
# Download the 30-year annual average precip and annual average temperature
get_prism_normals("ppt", "4km", annual = TRUE, keepZip = FALSE)
get_prism_normals("tmean", "4km", annual = TRUE, keepZip = FALSE)
If the archive has not already been set, calling any of the
get_prism_*() functions will prompt the user to specify the directory.
prism data are downloaded as zip files and then unzipped. If the
keepZip argument is TRUE the zip file will remain on your machine,
otherwise it will be automatically deleted.
Download daily, monthly, and annual data
Let us download daily average temperatures from June 1 to June 14, 2013. We can also download January average temperature data from 1982 to 2014. Finally, we will download annual average precipitation for 2000 to 2015. Note that resolution must now be specified for all data downloads.
get_prism_dailys(
type = "tmean",
minDate = "2013-06-01",
maxDate = "2013-06-14",
resolution = "4km",
keepZip = FALSE
)
get_prism_monthlys(
type = "tmean",
years = 1982:2014,
mon = 1,
resolution = "4km",
keepZip = FALSE
)
get_prism_annual(
type = "ppt",
years = 2000:2015,
resolution = "4km",
keepZip = FALSE
)
Note that for daily data you need to give a well formed date string in the form of “YYYY-MM-DD”.
Interact with the archive and prism data
You can view all the prism data you have downloaded with a simple
command: prism_archive_ls(). This function gives a list of folder
names, i.e., prism data (pd). All the functions in the prism package
work off of one or more of these folder names (pd).
## Truncated to keep file list short
prism_archive_ls()
#> [1] "prism_ppt_us_25m_191004"
#> [2] "prism_ppt_us_25m_191401"
#> [3] "prism_ppt_us_25m_191402"
#> [4] "prism_ppt_us_25m_191403"
#> [5] "prism_ppt_us_25m_191404"
#> [6] "prism_ppt_us_25m_191405"
#> [7] "prism_ppt_us_25m_191406"
#> [8] "prism_ppt_us_25m_191407"
#> [9] "prism_ppt_us_25m_191408"
#> [10] "prism_ppt_us_25m_191409"
....
While prism functions use this folder format, other files may need an
absolute path (e.g. the raster package). The pd_to_file() function
conveniently returns the absolute path. Alternatively, you may want to
see what the normal name for the product is (not the file name), and we
can get that with the pd_get_name() function.
## Truncated to keep file list short
pd_to_file(prism_archive_ls()[1:10])
#> [1] "C:\\Users\\RAButler\\Documents\\prismtmp\\prism_ppt_us_25m_191004\\prism_ppt_us_25m_191004.bil"
#> [2] "C:\\Users\\RAButler\\Documents\\prismtmp\\prism_ppt_us_25m_191401\\prism_ppt_us_25m_191401.bil"
#> [3] "C:\\Users\\RAButler\\Documents\\prismtmp\\prism_ppt_us_25m_191402\\prism_ppt_us_25m_191402.bil"
#> [4] "C:\\Users\\RAButler\\Documents\\prismtmp\\prism_ppt_us_25m_191403\\prism_ppt_us_25m_191403.bil"
#> [5] "C:\\Users\\RAButler\\Documents\\prismtmp\\prism_ppt_us_25m_191404\\prism_ppt_us_25m_191404.bil"
....
pd_get_name(prism_archive_ls()[1:10])
#> [1] "Apr 1910 - 4km resolution - Precipitation"
#> [2] "Jan 1914 - 4km resolution - Precipitation"
#> [3] "Feb 1914 - 4km resolution - Precipitation"
#> [4] "Mar 1914 - 4km resolution - Precipitation"
#> [5] "Apr 1914 - 4km resolution - Precipitation"
....
Finally, prism_archive_subset() is a convenient way
