Python directly read in USGS flow by given site number

Python packages are very powerful. Here is an example for hydrological data analysis. This small piece of code reads USGS flow by a given site number and store it as pandas DataFrame. You need to install “ulmo” first.

Original post is from here

import pandas as pd
import numpy as np
import ulmo

def importusgssite(siteno):
    sitename = {}
    sitename = ulmo.usgs.nwis.get_site_data(siteno, service="daily", period="all")
    sitename = pd.DataFrame(sitename['00060:00003']['values'])
    sitename['dates'] = pd.to_datetime(pd.Series(sitename['datetime']))
    sitename.set_index(['dates'],inplace=True)
    sitename[siteno] = sitename['value'].astype(float)
    sitename[str(siteno)+'qual'] = sitename['qualifiers']
    sitename = sitename.drop(['datetime','qualifiers','value'],axis=1)
    sitename = sitename.replace('-999999',np.NAN)
    sitename = sitename.dropna()
    #sitename['mon']=sitename.index.month
    return sitename

d = importusgssite('12472800');
d.plot(style='r', linewidth=1.0)

flowseries.png

Advertisements

Tecplot in cmd

It’s kinda weird to use command lines in Windows (maybe a lot of people do it, who knows) but the reason I’m using it is that in Windows based Matlab, the “system” function will just call cmd. So if I need to run something inside a Matlab loop, I should learn how to use cmd.

Here is the command line I used to open a data file and run a python script in Tecplot:

C:\ /WAIT tec360 -b -datafile C:\something.plt -p C:\some\python.py

“/WAIT” is to hold the program until it’s done
“-b” is batch mode, include this otherwise you will see the GUI
“-datafile” is reading file
“-p” is executing python script
Note that the python script must be put in the python path otherwise Tecplot won’t find it.

Delineate basins based on flow directions

1. Download the flow direction file (FDR) from here (Wu, et. al. 2012) then import it into ARCGIS.
Capture

2. Using “Basin” tool to identify the basins and then convert the generated raster to polygons.
Capture

3. Select the desired basin and output the polygon as a single file (Mekong Basin here).
Capture

4. Use “extract by mask” to extract the flow direction for the desired basin.
Capture

5. Export the flow direction as ascii