Usage¶
The download_prism function allows you to download PRISM climate data for a specified time range and frequency.
Function Signature¶
def download_prism(start: str = None, end: Optional[str] = None, variable: str = None,
freq: Optional[str] = "daily", download_dir: Optional[str] = None,
unzip: Optional[bool] = True, remove_zip: Optional[bool] = True) -> None:
Parameters¶
start: The start date of the time range to download. Must be in the formatYYYYMMDD. Defaults toNone.end: The end date of the time range to download. Must be in the formatYYYYMMDD. IfNone, defaults to the latest available date for the specified variable.variable: The PRISM variable to download. Must be one of["ppt", "tmin", "tmax", "tmean", "tdmean", "vpdmin", "vpdmax"].freq: The frequency of the data to download. Must be one of["daily", "monthly", "annual"]. IfNone, defaults to"daily".download_dir: The directory to download the data to. IfNone, defaults todataunder current working directory. If the directory does not exist, it will be created.unzip: Whether to unzip the downloaded data. IfTrue, the data will be unzipped. IfFalse, the data will not be unzipped. Defaults toTrue.remove_zip: Whether to remove the downloaded zip file after unzipping. IfTrue, the zip file will be removed. IfFalse, the zip file will not be removed. Defaults toTrue.
Example Usage¶
Example 1: Download daily data for a single date¶
from prism import download_prism
download_prism(start="20100101", variable="ppt")
Example 2: Download daily data for a time range¶
download_prism(start="20100101", end="2010-01-31", variable="ppt")
Example 3: Download monthly data for a single date¶
download_prism(start="202305", variable="tmean", freq="monthly")
Example 4: Download annual data for a single year¶
download_prism(start="2023", variable="tmean", freq="annual")
Example 5: Download daily data for a time range and save to a specific directory¶
download_prism(start="20230501", variable="vpdmax", download_dir="path/to/download/directory")
Note¶
The function will only download data if it doesn’t already exist in the specified download directory.
The downloaded data will be saved in a subdirectory named after the variable within the specified download directory.
The function will raise a
ValueErrorif an invalid variable, frequency, or date range is provided.
Valid Variable Options¶
The following are the valid options for the variable parameter:
ppt: Precipitationtmin: Minimum temperaturetmax: Maximum temperaturetmean: Mean temperaturetdmean: Mean dew point temperaturevpdmin: Minimum vapor pressure deficitvpdmax: Maximum vapor pressure deficit
Valid Frequency Options¶
The following are the valid options for the freq parameter:
daily: Daily datamonthly: Monthly dataannual: Annual data
Date Range Considerations¶
For daily data, the start date must be provided in the
YYYYMMDDformat and must be on or after January 1, 1981. The end date, if provided, must also be in theYYYYMMDDformat and cannot be after yesterday’s date.For monthly data, the start date must be provided in the
YYYYMMformat and must be on or after January 1981. The end date, if provided, must also be in theYYYYMMformat and cannot be after the previous month.For annual data, the start date must be provided in the
YYYYformat and must be on or after 1981. The end date, if provided, must also be in theYYYYformat and cannot be after the previous year.If the end date is not provided, the function will download data for a single date specified by the start date.
The start date cannot be after the end date.
Output Format¶
The downloaded data will be saved in NetCDF format with the following naming convention:
Daily data:
daily_YYYYMMDD.ncMonthly data:
monthly_YYYYMM.ncAnnual data:
annual_YYYY.nc
The NetCDF files will contain the climate variable data reprojected to the EPSG:4326 coordinate reference system.