output = 'HSPF_data' if not os.path.isdir(output): os.mkdir(output) # HUC8 NHDPlus info VPU = '02' # NHDPlus Vector Processing Unit HUC8 = '02060006' # 8-digit HUC # path for the output files HUC8output = '{}/{}'.format(output, HUC8) # path for a plot of the output plotfile = '{}/watershed'.format(HUC8output) # create an instance of the NHDPlus extractor nhdplusextractor = NHDPlusExtractor(NHDPlus) # download and decompress the source data. worth noting--if you point the # extractor to the source files, it will skip the (lengthy) download. nhdplusextractor.download_decompress(VPU,decompress=True) # extract the HUC8 data for the Patuxent watershed. same thing here--if any of # these files already exist the extraction step will be skipped. nhdplusextractor.extract_HUC8(VPU, HUC8, HUC8output, plotfile = plotfile)
def main(): # make sure the metadata are set before starting the download print('') print('preparing to delineate the subbasins for HUC {}\n'.format(HUC8)) print('if you have already downloaded the NHDPlus, NWIS, and NID source ' + 'data make sure you set the directory paths, or all the data will ' + 'be downloaded again.\n') print('press "y" to continue or "n" to abort...\n') s = 'n' while s != 'y': s = input() if s == 'n': exit() # source data directory structure (ideally a data drive or server) NHDPlus = '{}/NHDPlus'.format(source) NWIS = '{}/NWIS'.format(source) NID = '{}/NID'.format(source) # download and extract the data using the PyHSPF data extractors (if needed) # these steps can/will be skipped if they are not needed nhdplusextractor = NHDPlusExtractor(destination=NHDPlus) nwisextractor = NWISExtractor(NWIS) nidextractor = NIDExtractor(NID) # extract or set the path to the source NHDPlus data nhdplusextractor.download_decompress(VPU, decompress=True) # extract the hydrography data for the HUC8 to the output directory nhdplusextractor.extract_HUC8(VPU, HUC8, output) # paths to the NHDPlus data files created above by the nhdplusextractor bfile = '{}/boundary'.format(output) # watershed boundary cfile = '{}/catchments'.format(output) # individual catchments ffile = '{}/flowlines'.format(output) # individual flowlines VAAs = '{}/flowlineVAAs'.format(output) # value-added attributes efile = '{}/elevations'.format(output) # elevation geotiff # extract the NWIS gages to a shapefile in the HUC8 directory nwisextractor.extract_HUC8(HUC8, output) # path to the gage shapefile created above gfile = '{}/gagestations'.format(output, HUC8) # extract the NID dams to a shapefile in the new HUC8 directory dfile = '{}/dams'.format(output, HUC8) nidextractor.extract_shapefile(bfile, dfile) # use the locations of the gages and dams, the NHDPlus data files, and # PyHSPF's HUC8Delineator to delineate subbasins subject to the criteria # into a new file in the HUC8 output directory delineator = HUC8Delineator(HUC8, VAAs, ffile, cfile, efile, gfile, dfile) # delineate the watershed using the NHDPlus data and delineator delineator.delineate(output, drainmax=drainmax, parallel=parallel)