示例#1
0
 def test_load_usgs_flows(self):
     "Test loadind USGS water data."
     #
     F02217900 = load_usgs_flows('02217900')
     data_192810 = [180, 180, 180, 180, 180, 180, 180, 180, 180, 180,
                    180, 180, 180, 180, 180, 180, 230, 300, 350, 300,
                    230, 200, 250, 270, 240, 200, 180, 180, 180, 180, 180]
     data_194912 = [276, 267, 267, 267, 262, 264, 269, 302, 291, 279,
                    310, 307, 304, 358, 425, 425, 371, 336, 336, 371,
                    336, 333, 336, 333, 317, 336, 410, 425, 384, 336, 330]
     assert(isinstance(F02217900, ts.TimeSeries))
     assert_equal(F02217900.start_date, ts.Date('D', '1928-10-01'))
     assert_equal(F02217900.end_date, ts.Date('D', '1949-12-31'))
     dates = F02217900.dates
     assert_equal(F02217900[(dates.year == 1928) & (dates.month == 10)],
                  data_192810)
     assert_equal(F02217900[(dates.year == 1949) & (dates.month == 12)],
                  data_194912)
     #
     F02217500 = load_usgs_flows('02217500')
     data_190110 = [ 570, 1000, 1200, 900, 650, 580, 540, 520, 510, 530,
                     499,  535,  535, 572, 535, 535, 499, 499, 499, 499,
                     499,  499,  499, 499, 499, 499, 464, 499, 499, 499, 499]
     assert(isinstance(F02217500, ts.TimeSeries))
     assert_equal(F02217500.start_date, ts.Date('D', '1901-10-01'))
     dates = F02217500.dates
     assert_equal(F02217500[(dates.year == 1901) & (dates.month == 10)],
                  data_190110)
示例#2
0
the following march.
To plot FDCs for each water year, use ``starting_month=4``.

"""

import numpy as np
import scikits.hydroclimpy as hydro
import scikits.hydroclimpy.enso as enso
import scikits.hydroclimpy.io.usgs as usgs
import scikits.hydroclimpy.plotlib as cpl
"""
Let's import the streamflow data for the North Oconee River in Athens, GA.
The corresponding USGS code of the gage is '02217770'.
"""

series = usgs.load_usgs_flows('02217770')
"""
Let's create a figure and add a subplot.
"""
fig = cpl.figure()
fsp = fig.add_subplot(111)
"""
Let's call the :func:`plot_fdc` function to plot the
corresponding flow duration curve.
By default, the curve is plotted on the current subplot. 
We can also select a particular subplot with the :keyword:`subplot` parameter.
We will use the additional parameters ``lw`` to specify the linewidth of the curve,
``ls`` for the linestyle, ``c`` for the color, and ``zorder`` for the priority order.
"""

cpl.plot_fdc(series, subplot=fsp, lw=2, ls='-', c='k', zorder=10)
   [13-Jan-1944 31-Dec-2007]
"""
print rainfall.freqstr
print rainfall.dates[[0,-1]]
"""

Importing the streamflow information
====================================

Let's import the streamflows recorded on the North Oconee River in Athens, GA.
We use the :func:`~scikits.hydroclimpy.io.usgs.load_usgs_flows` function, that requires
the identification code(s) of one or several USGS streamflow gages.
The corresponding code for the station of interest is '02217770'.
"""

flowdata = usgs.load_usgs_flows('02217770')

"""
Here also we can check the frequency and range of dates of the series:

   >>> print flowdata.freqstr
   D
   >>> print flowdata.dates[[0,-1]]
   [10-Aug-2002 14-Sep-2008]


Adjusting the series
====================


The rainfall and streamflows series do not have the same length.
import numpy as np
import numpy.ma as ma
import scikits.hydroclimpy as hydro

import scikits.hydroclimpy.io.coaps as coaps
import scikits.hydroclimpy.io.usgs as usgs

import matplotlib.pyplot as pyplot
import scikits.hydroclimpy.plotlib as cpl

weatherdata = coaps.load_coaps_stationdata(90435).fill_missing_dates()
rainfall = weatherdata["rain"]
flowdata = usgs.load_usgs_flows("02217770").fill_missing_dates()

rainfall = hydro.adjust_endpoints(rainfall, start_date=flowdata.dates[0])
flowdata = hydro.adjust_endpoints(flowdata, end_date=rainfall.dates[-1])

fig = cpl.hydrograph(rainfall, flowdata, figsize=(12, 6))

fig.hyeto.set_ylabel("Rainfall (mm)", fontweight="bold")
fig.hydro.set_ylabel("Flows (cfs)", fontweight="bold")
fig.suptitle("Hydrograph for the North Oconee River at Athens, GA", fontweight="bold", fontsize=12)
import numpy as np
import scikits.hydroclimpy as hydro
import scikits.hydroclimpy.enso as enso
import scikits.hydroclimpy.io.usgs as usgs
import scikits.hydroclimpy.plotlib as cpl

ONI = enso.load_oni()
series = usgs.load_usgs_flows('02217770').fill_missing_dates()
series = enso.set_ensoindicator(series, ONI)

fig = cpl.figure()
fsp = fig.add_subplot(111)
cpl.plot_fdc(series, plot_enso=True, marker='o', markersize=6, ax=fsp)
cpl.plot_fdc(series, plot_enso=True, starting_month=4, ax=fsp)
fsp.legend()
fsp.set_ylabel("Flows (cfs)", fontweight='bold')
fig.suptitle("Flow duration curve for the North Oconee River at Athens, GA",
             fontweight="bold", fontsize=12)

           (-81.87, 31.22, '02228000', 'Satilla River at Atkinson, GA'),
           (-82.56, 30.68, '02314500', 'Suwannee River at US 441, Fargo, GA')]
USGS_SW = [(-84.34, 31.31, '02353000', 'Flint River at Newton, GA'),
           (-84.55, 31.38, '02353500', 'Ichawaynochaway Creek at Milford, GA'),
           (-84.58, 30.91, '02356000', 'Flint River at Bainbridge, GA'),
           (-84.74, 31.04, '02357000', 'Spring Creek near Iron City, GA')]
ndtype = np.dtype([('lon', float), ('lat', float), ('site_no', '|S8'),
                   ('desc', '|S40')])
USGS_SE = np.array(USGS_SE, dtype=ndtype)
USGS_SW = np.array(USGS_SW, dtype=ndtype)


end_date = climpy.Date('D', '2009-02-28')
USGS_data = {}
for site_no in itertools.chain(USGS_SE['site_no'], USGS_SW['site_no']):
    data = usgs.load_usgs_flows(site_no).fill_missing_dates()
    USGS_data[site_no] = data.adjust_endpoints(end_date=end_date)

table_template = []
csc = "*"
separator = csc.join(['-'*10, '-'*41, '-'*12, '-'*6, '-'*6, '-'*9])
for region in (USGS_SW, USGS_SE):
    table_template.append("%s%s%s" % (csc, separator, csc))
    for (site_no, desc) in zip(region['site_no'], region['desc']):
        data = USGS_data[site_no]
        start_date = data.dates[0].strfmt("%m/%d/%Y")
        mdata = extras.accept_atmost_missing(data.convert('M'), 0.1)
        nbtotal = len(mdata)
        nbvalid = mdata.any(-1).filled(False).sum()
        row = csc.join([" %8s " % site_no, "%40s " % desc,
                        " %10s " % start_date,
import numpy as np
import scikits.hydroclimpy as hydro
import scikits.hydroclimpy.enso as enso
import scikits.hydroclimpy.io.usgs as usgs
import scikits.hydroclimpy.plotlib as cpl


series = usgs.load_usgs_flows('02217770')

fig = cpl.figure()
fsp = fig.add_subplot(111)

cpl.plot_fdc(series, ax=fsp, lw=2, ls='-', c='k', zorder=10)
cpl.plot_fdc(series, ax=fsp, starting_month=4)
fsp.set_ylabel("Flows (cfs)", fontweight='bold')
fig.suptitle("Flow duration curve for the North Oconee River at Athens, GA",
             fontweight="bold", fontsize=12)
import numpy as np
import scikits.hydroclimpy as hydro
import scikits.hydroclimpy.enso as enso
import scikits.hydroclimpy.io.usgs as usgs
import scikits.hydroclimpy.plotlib as cpl

ONI = enso.load_oni()
series = usgs.load_usgs_flows('02217770').fill_missing_dates()
series = enso.set_ensoindicator(series, ONI)

fig = cpl.figure()
fsp = fig.add_subplot(111)
cpl.plot_fdc(series, plot_enso=True, marker='o', markersize=6, ax=fsp)
cpl.plot_fdc(series, plot_enso=True, starting_month=4, ax=fsp)
fsp.legend()
fsp.set_ylabel("Flows (cfs)", fontweight='bold')
fig.suptitle("Flow duration curve for the North Oconee River at Athens, GA",
             fontweight="bold",
             fontsize=12)
示例#9
0
   [13-Jan-1944 31-Dec-2007]
"""
print rainfall.freqstr
print rainfall.dates[[0, -1]]
"""

Importing the streamflow information
====================================

Let's import the streamflows recorded on the North Oconee River in Athens, GA.
We use the :func:`~scikits.hydroclimpy.io.usgs.load_usgs_flows` function, that requires
the identification code(s) of one or several USGS streamflow gages.
The corresponding code for the station of interest is '02217770'.
"""

flowdata = usgs.load_usgs_flows('02217770')
"""
Here also we can check the frequency and range of dates of the series:

   >>> print flowdata.freqstr
   D
   >>> print flowdata.dates[[0,-1]]
   [10-Aug-2002 14-Sep-2008]


Adjusting the series
====================


The rainfall and streamflows series do not have the same length.
Let's select the overlapping region of the two series.