Python to CUAHSI WaterML & WaterOneFlow web service, Pt. 2

In my previous post, I described how to access a CUAHSI HIS WaterML time series data stream regardless of whether it originates in a direct WaterOneFlow web service GetValues request, or a locally stored WaterML file. I also created a simple plot from this time series. I’ve now taken the code described in that post and made it more modularized for re-use and to demonstrate how CUAHSI HIS data access may be made a bit simpler in Python. In particular, I generalized the ElementTree find and findall functions to deal with namespaces more easily; also, I created a class to store the data and some basic attributes for a WaterML time series.

I spent far more time than I anticipated on the first post, so I’ll be brief here. I’ve added metadata to the plot (title from site information, and y-axis label from variable information), extracted directly from the WaterML data stream. When extracting information about variables, I discovered that the NWISIID service doesn’t provide a number of metadata elements that are included in the NWISDV service. One of these is the units of the observation variable. This is an important omission. But for my purposes here, I just have to add a test to see if the units element exists; that test may serve as an example for handling missing elements.

The complete code file is available here. This code can be imported into your code or interactive Python session; or you can run it from the command line to see the __init__ test block in action, in which case a figure png file will be created, but you may also get some warning messages.

Here are the updated figures, with metadata. Everything on these plots was generated dynamically from data obtained live from the WOF web service. The first plot is for Big Rock Creek:

Discharge at Big Rock Creek

Discharge at Big Rock Creek

And the second plot is for the Mississippi mainstem at St. Francisville (I extended the Miss. time series to 1990, to make it more interesting):

Nitrate concentration in the Missississippi mainstem

Nitrate concentration in the Missississippi mainstem

Advertisements
This entry was posted in Python and tagged , , , . Bookmark the permalink.

One Response to Python to CUAHSI WaterML & WaterOneFlow web service, Pt. 2

  1. Pingback: Python to CUAHSI WaterML & WaterOneFlow web service, Pt. 1 « Mi estero

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s