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
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:
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):