Exemple #1
0
# extracted files

gagepath  = '{}/gagedata'.format(directory)     # all HUC8 NWIS flow data path

# time series start and end

start = datetime.datetime(1980, 1, 1)      # start date for timeseries
end   = datetime.datetime(2010, 1, 1)      # end date for timeseries

# create an instance of the NWIS extractor

nwisextractor = NWISExtractor(NWIS)

# extract the locations of the gage stations in the HUC8 (Patuxent watershed) 
# into a new shapefile 

nwisextractor.extract_HUC8(HUC8, directory)

# and download all the daily flow and water quality data across the period 
# for the gages in the gage shapefile

if not os.path.isdir(gagepath):
    nwisextractor.download_all(start, end, output = gagepath)

# alternatively, download the daily flow and water quality data for one gage
# given the USGS NWIS Site ID number (Hunting Creek)

gageid    = '01594670'
gagedata  = 'hunting_station'
nwisextractor.download_gagedata(gageid, start, end, output = gagedata)
Exemple #2
0
    print('Please ensure that the file {} exists\n'.format(flowfile))
    raise

# create an instance of the NWISExtractor to use to download the gage data

extractor = NWISExtractor(NWIS)

# download the metadata for all NWIS gages (will be skipped if it exists)

extractor.download_metadata()

# download all the data for the gage, including measured values of stage,
# discharge, channel width, and channel area and save it to "gageid" file
# (will be skipped if it already exists)

extractor.download_gagedata(gageid, start, end, output=gageidpath)

# need to know the reach length; so find the location of the gage, then find
# the flowline in the shapefile and use the record info to get the length

# first use the NWIS metadata file to get the latitude and longitude of the gage

reader = Reader('{}/USGS_Streamgages-NHD_Locations.shp'.format(NWIS))

# find the record index for the NWIS gage ids

i = [f[0] for f in reader.fields].index('SITE_NO') - 1

# find the index of the gage

j = [r[i] for r in reader.records()].index(gageid)
Exemple #3
0
# into a new shapefile 

nwisextractor.extract_HUC8(HUC8, directory)

# and download all the daily flow and water quality data across the period 
# for the gages in the gage shapefile

if not os.path.isdir(gagepath):
    nwisextractor.download_all(start, end, output = gagepath)

# alternatively, download the daily flow and water quality data for one gage
# given the USGS NWIS Site ID number (Hunting Creek)

gageid    = '01594670'
gagedata  = 'hunting_station'
nwisextractor.download_gagedata(gageid, start, end, output = gagedata)

# the output directory will contain images with flow-duration curves and 
# daily flow hydrographs. the statements below show how to access the data 
# from the downloaded files. let's open up the data files from the patuxent 
# directory that was made above.

print('fetching flow data from the Patuxent watershed')

# make a list of all the data files just downloaded

datafiles = [f for f in os.listdir(gagepath) if f[-3:] != 'png']

# iterate through the list, get/print some data for each gage

print('Data for downloaded stations:')
Exemple #4
0
def extract():
    """Create an extract function to call from at runtime and to turn off
    the extraction steps when they are done."""

    # create an instance of the NWIS extractor

    nwisextractor = NWISExtractor(NWIS)

    # download and decompress the source metadata files

    nwisextractor.download_metadata()

    # extract all the gage stations and metadata into a shapefile for the HUC8

    nwisextractor.extract_HUC8(HUC8, output)

    # tell the extractor to use the metadata file above to find gage data

    nwisextractor.set_metadata(gagefile)

    # create an instance of the NHDPlus extractor

    nhdplusextractor = NHDPlusExtractor(drainid, VPU, NHDPlus)

    # download and decompress the source data for the Mid Atlantic Region

    nhdplusextractor.download_data()

    # extract the HUC8 data for the Patuxent watershed

    nhdplusextractor.extract_HUC8(HUC8, output)

    # create an instance of the NHDPlusDelineator to use to build the Watershed

    delineator = NHDPlusDelineator(VAAfile,
                                   flowfile,
                                   catchfile,
                                   elevfile,
                                   gagefile=gagefile)

    # delineate the watershed (extract the flowlines, catchments and other data)

    delineator.delineate_gage_watershed(gage, output=gagepath)

    # download the daily flow and water quality data for the gage

    nwisextractor.download_gagedata(gage, estart, eend, output=gagedata)

    # open the NWIS flow data for the Hunting Creek gage station

    with open(gagedata, 'rb') as f:
        station = pickle.load(f)

    # get the time series of daily flow values for the gage

    flow = station.make_timeseries(estart, eend)

    # add land use data from 1988 to the delineator

    delineator.add_basin_landuse(1988, landuse)

    # build the watershed

    delineator.build_gage_watershed(gage, watershed, masslinkplot=masslink)