-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
m.cdo.download: Add a new addon for downloading NCEI (previouly NCDC)…
… Climate Data Online (CDO) (#963) * m.cdo.download: Add a new addon for downloading NCEI (previouly NCDC) Climate Data Online * Change PRCP examples to PRCP,AVG * Change PRCP examples to PRCP,AVG * Add a vector creation example * Add a vector figure * Add spaces in awk script
- Loading branch information
Showing
4 changed files
with
591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
MODULE_TOPDIR = ../.. | ||
|
||
PGM = m.cdo.download | ||
|
||
include $(MODULE_TOPDIR)/include/Make/Script.make | ||
|
||
default: script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<h2>DESCRIPTION</h2> | ||
|
||
<em>m.cdo.download</em> downloads data from | ||
<a href="https://www.ncei.noaa.gov/cdo-web/webservices/v2">NCEI's Climate Data | ||
Online (CDO)</a> using their v2 API. | ||
|
||
<h2>NOTES</h2> | ||
|
||
This module uses <a href="https://www.ncei.noaa.gov/cdo-web/api/v2/">the CDO | ||
Web Services v2 API</a> to download CDO data. | ||
|
||
<h2>EXAMPLES</h2> | ||
|
||
<p>List available datasets: | ||
<div class="code"><pre> | ||
m.cdo.download fetch=datasets | ||
</pre></div> | ||
|
||
<p>List available dataset IDs without column names: | ||
<div class="code"><pre> | ||
m.cdo.download -c fetch=datasets fields=id | ||
</pre></div> | ||
|
||
<p>List available stations within (47.5204,-122.2047)-(47.6139,-122.1065): | ||
<div class="code"><pre> | ||
m.cdo.download fetch=stations extent=47.5204,-122.2047,47.6139,-122.1065 | ||
</pre></div> | ||
|
||
<p>List available "precipitation" and "average temperature" | ||
data types: | ||
<div class="code"><pre> | ||
m.cdo.download fetch=datatypes field=id,mindate,maxdate,name | | ||
grep -i "|precipitation\||average temperature" | ||
</pre></div> | ||
|
||
<p>List 10 available stations with PRCP and TAVG data starting 2023-01-01: | ||
<div class="code"><pre> | ||
m.cdo.download fetch=stations datatypeid=PRCP,TAVG startdate=2023-01-01 limit=10 | ||
</pre></div> | ||
|
||
<p>Fetch daily PRCP and TAVG data for a station with mindate ≤ 2023-01-01 and | ||
save it into a file: | ||
<div class="code"><pre> | ||
# find dataset IDs for data types PRCP and TAVG; let's use GHCND (Daily Summary) | ||
m.cdo.download fetch=datasets datatypeid=PRCP,TAVG | ||
|
||
# find the first station ID with mindate ≤ 2023-01-01 | ||
stationid=$(m.cdo.download -c fetch=stations datatypeid=PRCP,TAVG \ | ||
startdate=2023-01-01 fields=id limit=1) | ||
|
||
# fetch actual data and save it to data.txt | ||
m.cdo.download fetch=data datasetid=GHCND datatypeid=PRCP,TAVG \ | ||
stationid=$stationid startdate=2023-01-01 enddate=2023-10-15 \ | ||
output=data.txt | ||
</pre></div> | ||
|
||
<p>Create a point vector map with all stations: | ||
<div class="code"><pre> | ||
# from a latlong location | ||
|
||
# download metadata for all stations | ||
m.cdo.download stations output=cdo_stations.txt | ||
|
||
# import cdo_stations.txt | ||
xy=$(awk -F'|' '{ | ||
if (NR == 1) { | ||
for (i = 1; i <= NF; i++) | ||
if ($i == "latitude") | ||
latind = i | ||
else if ($i == "quot;longitude"quot;) | ||
lonind = i | ||
printf "x=%s y=%s", lonind, latind | ||
exit | ||
} | ||
}' cdo_stations.txt) | ||
v.in.ascii input=cdo_stations.txt output=cdo_stations skip=1 $xy | ||
|
||
# rename columns | ||
old_cols=$(db.columns table=cdo_stations exclude=cat) | ||
new_cols=$(head -1 cdo_stations.txt | sed 's/|/ /g') | ||
|
||
for old_new in $(echo $old_cols $new_cols | | ||
awk '{ | ||
n = NF / 2 | ||
for (i = 1; i <= n; i++) | ||
printf "%s,%s\n", $i, $(i + n) | ||
}'); do | ||
v.db.renamecolumn map=cdo_stations column=$old_new | ||
done | ||
</pre></div> | ||
|
||
<img src="m_cdo_download_cdo_stations.png" alt="CDO stations"> | ||
|
||
<h2>SEE ALSO</h2> | ||
|
||
<em> | ||
<a href="m.tnm.download.html">m.tnm.download</a> | ||
</em> | ||
|
||
<h2>AUTHOR</h2> | ||
|
||
<a href="mailto:grass4u@gmail com">Huidae Cho</a>, New Mexico State University |
Oops, something went wrong.