Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts - Snotel - add period of record download script #61

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions scripts/Snotel/get_snotelPoR_csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Download Snotel csv data from USDA for a site with end of day values in
# metric units for the full period of record. Modified from get_snotel_csv.sh
# Default state is Colorado, update as needed.
# Data includes: Depth, SWE, Density, Wind Speed, Air Temperature, Precipitation
#
# More information is in the header of the generated csv file.
#
# Arguments:
# 1: Snotel Site ID
#
# Outputs: CSV file
# Name: [downloaddate]_PoR_site[SiteID].csv
#
# Example:
# get_snotelPoR_csv.sh 112

set -e

if [ "$#" -ne 1 ]; then
echo 'Provide site number as the sole argument'
exit 1
fi


Help()
{
# Display Help
echo "Download SNOTEL period of record data for input site"
echo
echo "Syntax: get_snotelPoR_csv.sh siteID [-h]"
echo "options:"
echo "h Print this Help."
echo
}

# Get the options
while getopts ":h" option; do
case $option in
h) # display Help
Help
exit;;
esac
done

HOST="https://wcc.sc.egov.usda.gov/reportGenerator/view_csv/customMultiTimeSeriesGroupByStationReport,metric/daily/end_of_period/"
COLUMNS="/POR_BEGIN,POR_END/SNWD::value,WTEQ::value,SNDN::value,WSPDV::value,TOBS::value,PRCP::value"
STATE="${VARIABLE:-CO}"

echo "Downloading SNOTEL period of record data for site ${1}"
curl "${HOST}${1}:${STATE}:SNTL%7Cid=%22%22%7Cname/${COLUMNS}" > $(date +%Y%m%d)_PoR_site${1}.csv