Skip to content

Commit 6842347

Browse files
committed
add week5 exercise
1 parent c1e1379 commit 6842347

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

week5_exercise.ipynb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@
7777
"\n",
7878
"`func([1, 2, 3, 4, 5], 2)` return `' 1 2 3 4 5'`"
7979
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"### 7. The USGS Water Data service provides retrival of streamflow data at the USGS stream gages. The download url follows the pattern below. Write a Python program 1) generate the url for a given list of gage numbers; 2) read this url and download the data to csv file (do not use numpy or pandas); 3) based on the downloaded data calculate the monthly stasticstics including maximum, minimum and average of the streamflow data and save it to another csv file. The data need to be formatted to 2 decimal digits. 4) calculate the average annual runoff of each gage (expressed in acre-feet) \n",
86+
"\n",
87+
"\n",
88+
"url: https://waterdata.usgs.gov/nwis/dv?&cb_00060=on&format=rdb&site_no=06803495&referred_module=sw&period=&begin_date=2019-02-11&end_date=2020-02-11\n",
89+
"\n",
90+
"where `&site_no=06803495` define which gages are included in this data retrieval; for multiple gages, simply repeat it, e.g. `&site_no=06803495&site_no=06803486`;\n",
91+
"\n",
92+
"the datas are specified by `&period=&begin_date=2018-02-11&end_date=2020-02-11`\n",
93+
"\n",
94+
"You could test your program using the gages `['06803495', '06803486']` for the period between `2000-10-1` and `2019-9-30`\n",
95+
"\n",
96+
"Hint 1: using the str.format() method to construct the url.\n",
97+
"\n",
98+
"Hint 2: use the `urllib.request.urlopen()` to download the url:\n",
99+
"```python\n",
100+
" import urllib.request.urlopen\n",
101+
" f = urllib.request.urlopen(a_url)\n",
102+
" lines = f.readlines()\n",
103+
"```\n",
104+
"\n",
105+
"Hint 3: skip the lines starts with `#` in the downloaded data.\n",
106+
"\n",
107+
"Hint 4: print some of the downloaded lines and identify the elements in each line.\n",
108+
"\n",
109+
"Hint 5: using the str.format() or f-string method to write `csv` file.\n",
110+
"\n",
111+
"Hint 6: the monthly stasticstics refer to the time series of monthly stasticstics.\n",
112+
"\n",
113+
"Hint 7: for the average annual runoff, you need to calculate the total runoff for each year and then calculate average of these annual runoff."
114+
]
80115
}
81116
],
82117
"metadata": {

0 commit comments

Comments
 (0)