Download presentation
Presentation is loading. Please wait.
1
Python Programming Challenge
Jeffery S. Horsburgh Hydroinformatics Fall 2016 This work was funded by National Science Foundation Grants EPS and EPS
2
Objectives Introduction to the Python programming language
Write and execute computer code to automate repetitive tasks Discover and access data from major data sources Retrieve and use data from common hydrologic data sources
3
Coding Challenge
4
Get the Data
5
Coding Challenge Choose a real-time streamflow gage from the USGS that you are interested in. It could be a nearby gage or one that is near and dear to your heart. To see an interactive map of gage locations, go to: Create a Python script that does the following: Download the most recent data from the USGS website Read the file Extract the most recent streamflow value from the file Print the most recent streamflow value and the date at which it occurred to the screen
6
Example Solution “The most recent streamflow value for USGS Gage was 109 cfs on :15.”
7
Step 1: Create a New PyCharm Project
Open PyCharm Select File New Project Name your project and select the interpreter
8
Step 2: Create a New Python Script
Right click on your project folder Select New Python File Name your script
9
Step 3: Write Some Pseudo Code
10
Step 4: Write Some Real Code
11
Some Hints Develop your solution as a script in PyCharm
The USGS website returns the data as a file, but you have to request it using a URL in your code. The Python module called “urllib2” (for Python 2.7) or “urllib3” for Python 3 is one option for downloading a file using a URL. The data are returned in a text file where each new line represents a new date/time and data value. Each new line is delineated with a new line character. Each element within a line is delimited by a tab character. Check out the Python “split” method for splitting a string based on a delimiter
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.