Feb 10, 2009

Import USGS national real-time water data

The built-in real-time weather data in Mathematica 7.0 is wonderful. You may be interested in importing more related data.

USGS has web-interface for Daily Streamflow Conditions

Here is the simple steps from importing Gauge height and Discharge data

USGS 03353800 White Lick Creek at Mooresville, IN

(*import html as plain text *)

rawdata=Import[“http://waterdata.usgs.gov/nwis/uv?cb_00060=on&cb_00065=on&format=html&period=7&site_no=03353800”];

(* extract table information *)

rawdata=StringReplace[rawdata,","->""];
result=StringCases[rawdata,x:DatePattern[{"Month","/","Day","/","Year"," ","Hour",":","Minute"}]~~Whitespace~~y:NumberString~~Whitespace~~z:NumberString:>{x,ToExpression[y],ToExpression[z]}];

(*draw graph*)

DateListPlot[result[[All,1;;2]],PlotStyle->{Blue, PointSize[Medium]},PlotLabel->"Site: 03353800",Joined->True,Filling->Bottom,FrameLabel->{"Time","Gage Height (feet)"},DateFunction:>(DateList[{#,{"Month","/","Day","/","Year"," ","Hour",":","Minute"}}]&),DateTicksFormat->{"MonthShort","/","Day"," ","Hour",":","Minute"}]

By the way, the code is tested in Mathematica 6.0.

No comments: