Code Description

BDLoG Class

Generate beaver dam locations and beaver dam heights along a stream network according to beaver dam capacities estimated by the Beaver Restoration Assessment Tool (BRAT). Information about BRAT is available at http://brat.joewheaton.org/home.

class bdws.BDLoG(brat, dem, fac, outDir, bratCap, stat=None)[source]
__init__(brat, dem, fac, outDir, bratCap, stat=None)[source]

Initialization of the Beaver Dam Location Generator class.

Parameters:
  • brat – Path to BRAT shapefile.
  • dem – Path to DEM for area of interest.
  • fac – Binary raster representing the stream network with a value of 1 (generally a thresholded flow accumulation).
  • outDir – Path to directory where output files will be generated.
  • bratCap – Proportion (0 - 1) of capacity for which to generate beaver dams.
  • stat – (Optional) Estimated pond volumes and prediction intervals as a function of reach slope and dam height (not yet implemented).
calculateDamsPerReach()[source]

Determine the number of beaver dams and beaver dam complexes to place on each BRAT reach.

Returns:None
close()[source]

Close all OGR and GDAL layers and datasets.

Returns:None
createDams()[source]

Place primary and secondary dams at a specific location on stream reaches.

Returns:None
createFields()[source]

Creates fields to be populated for the output dam location shapefile

Returns:None
generateDamLocationsFromBRAT()[source]

Generate dam locations on rasterized stream network.

Returns:None
getCellAddressOfPoint(x, y)[source]

Calculate the row and column of a coordinate pair (linear units) based on the input DEM. UTM projections suggested, will not work with degree units.

Parameters:
  • x – X coordinate (meters).
  • y – Y coordinate (meters).
Returns:

Numpy array with row and column address (array[row, col]).

getCoordinatesOfCellAddress(row, col)[source]

Calculate the coordinate pair at the center of a cell address based on the input DEM. UTM projections suggested, will not work with degree units.

Parameters:
  • row – Row index of raster.
  • col – Column index of raster.
Returns:

Numpy array with x and y coordinates (array[x, y]).

getStreamCellAddresses()[source]

List addresses of cells on the stream network.

Returns:Numpy array (2, n) with stream cell addresses (array[[row, col],[row, col],...]).
moveDamsToFAC()[source]

Set locations of generated dams to the nearest cell on the rasterized stream network. Only one dam can be present on each network cell.

Returns:None
run()[source]

Generate dam locations from BRAT and output as shapefile and raster.

Returns:None
setBratFields()[source]

Set values for fields derived from the input BRAT shapefile.

Returns:None
setDamFieldValues(feat, damType)[source]

Set attribute for dam type.

Parameters:
  • feat – OGR Feature of dam.
  • damType – String describing dam type (‘primary’ or ‘secondary’).
Returns:

Updated OGR Feature of dam.

setDamHeights(feat, low, mid, high)[source]

Set dam heights to be modeled for a dam.

Parameters:
  • feat – OGR Feature of dam.
  • low – Lower interval of dam height.
  • mid – Median dam height.
  • high – Upper interval of dam height.
Returns:

Updated OGR Feature of dam.

setVariables()[source]

Sets class variables for location generation.

Returns:None
sortByCapacity()[source]

Sort BRAT reaches by estimated dam capacity.

Returns:None
writeDamLocationRaster()[source]

Write dam locations to raster.

Returns:None

BDSWEA Class

Estimate the surface storage of beaver ponds at locations created from the BDLoG class.

class bdws.BDSWEA(dem, fdir, fac, id, outDir, modPoints)[source]
__init__(dem, fdir, fac, id, outDir, modPoints)[source]

Initialization of the Beaver Dam Surface Water Estimation Algorithm class.

Parameters:
  • dem – Path of DEM for area of interest.
  • fdir – Path to flow direction raster, should be concurrent with DEM.
  • fac – Path to binary raster representing the stream network with a value of 1 (generally a thresholded flow accumulation).
  • id – Path to raster of pond ID, calculated with BDLoG class.
  • outDir – Path where output files will be generated.
  • modPoints – Path to shapefile of modeled dam locations from BDLoG.
backwardHAND(startX, startY, startE, pondID)[source]

Recursively identify all cells draining to a dam location and the height of each cell above the dam.

Parameters:
  • startX – Column of dam location.
  • startY – Row of dam location.
  • startE – DEM elevation at dam location.
  • pondID – ID number of dam.
Returns:

None

calculateWaterDepth()[source]

Calculate the depth of each beaver pond cell for each modeled dam height.

Returns:None
close()[source]

Close all GDAL and OGR datasets.

Returns:None
createOutputArrays()[source]

Create arrays which will be written to rasters.

Returns:None
drainsToMe(index, fdir)[source]

Determine if a neighboring cell drains to a target cell.

Parameters:
  • index – Location of flow direction value in array.
  • fdir – Flow direction value.
Returns:

True if cell drains to center of 3x3, False if it does not

getDEM()[source]
Returns:Numpy array of DEM.
getDamId()[source]
Returns:Numpy array of original dam ID raster.
getFlowDirection()[source]
Returns:Numpy array of flow direction raster.
getHeightAbove()[source]
Returns:Numpy array of the height of cells above a beaver dam.
getPondID()[source]
Returns:Numpy array of the dam ID associated with each beaver pond.
heightAboveDams()[source]

For each cell draining to a beaver dam, calculate the height of cell above the dam location.

Returns:None
run()[source]

Run BDSWEA and save outputs.

Returns:None
saveOutputs()[source]

Save BDSWEA results to rasters.

Returns:None
setConstants()[source]

Set constant variables.

Returns:None
setVars(dem, fdir, fac, id, shp)[source]

Set class variables.

Parameters:
  • dem – Path to DEM.
  • fdir – Path to flow direction raster.
  • fac – Path to binary raster representing the stream network with a value of 1 (generally a thresholded flow accumulation).
  • id – Path to dam ID raster.
  • shp – Path to shapefile of dam locations.
Returns:

None

summarizePondStatistics()[source]

Caclulate area and volume of each pond for each dam height scenario and write results to the input shapefile.

Returns:None
writeArrayToRaster(file, array, lowernd, uppernd)[source]

Save numpy array as a GeoTiff raster concurrent with the input DEM.

Parameters:
  • file – Path to save file.
  • array – Numpy array of data.
  • lowernd – Lowest data value.
  • uppernd – Highest data value.
Returns:

None

writeHead()[source]

Calculate water surface elevation of cells inundated by modeld beaver ponds or represented by the rasterized stream network and save as GeoTiff.

Returns:None
writeModflowFiles()[source]

Save files to be used with BDflopy for MODFLOW parameterization.

Returns:None
writeSurfaceWSE()[source]

Update DEM to reflect water surface elevation of modeled beaver ponds and save as GeoTiff.

Returns:None

BDflopy Class

Use MODFLOW-2005 to estimate the change in groundwater storage resulting from the construction of beaver dams.

class bdflopy.BDflopy(modflowexe, indir, modeldir, outdir, demfilename)[source]
__init__(modflowexe, indir, modeldir, outdir, demfilename)[source]

Initialize BDflopy class.

Parameters:
  • modflowexe – Path to MODFLOW executable file.
  • indir – Path to directory of raster inputs for BDSWEA.
  • modeldir – Path to directory of outputs from BDSWEA.
  • outdir – Path to directory where output files will be genearted.
  • demfilename – Name of DEM file in the input directory (e.g. ‘dem.tif’).
calculateHeadDifference(frac=1.0, fconv=1.0)[source]

Calculate the head difference between MODFLOW runs.

Parameters:
  • frac – Fraction of the soil that can hold water (e.g. field capacity, porosity). For calculating volumetric groundwater changes. Represented as numpy array concurrent with the input DEM. Default array is a single value of 1.0.
  • fconv – Factor to convert frac to a proportion. Default = 1.0.
Returns:

None

close()[source]

Close GDAL datasets.

Returns:None
createDatasets(filelist)[source]

Create GDAL raster datasets.

Parameters:filelist – List of paths where raster datasets will be created.
Returns:List of GDAL datasets
createIboundData()[source]

Create ibound arrays for MODFLOW parameterization.

Returns:None
createModflowDatasets()[source]

Create GDAL raster datasets for MODFLOW inputs and outputs.

Returns:None
createStartingHeadData()[source]

Calculate starting head arrays.

Returns:None
loadBdsweaData()[source]

Load data from BDSWEA.

Returns:None
loadData(filelist)[source]

Read data from input rasters as numpy arrays.

Parameters:filelist – List of raster files to read as numpy arrays.
Returns:List of numpy arrays
loadSoilData(data)[source]

Load/create data for hydraulic conductivity and fraction of soil that holds water. This function is called internally.

Parameters:data – Float, numpy.ndarray, or file path to raster.
Returns:Numpy array
run(hksat, vksat, kconv=1.0, frac=1.0, fconv=1.0)[source]

Run MODFLOW to calculate water surface elevation changes from beaver dam construction.

Parameters:
  • hksat – Horizontal saturated hydraulic conductivity value(s). Single value, numpy array, or name of raster from input directory. Numpy arrays and rasters must be concurrent with input DEM.
  • vksat – Vertical saturated hydraulic conductivity value(s). Single value, numpy array, or name of raster from input directory. Numpy arrays and rasters must be concurrent with input DEM.
  • kconv – Factor to convert khsat and kvsat to meters per second. Default = 1.0.
  • frac – Fraction of the soil (0-1) that can hold water (e.g. field capacity, porosity). Single value, numpy array, or name of raster from input directory. Numpy arrays and rasters must be concurrent with input DEM. Default = 1.0.
  • fconv – Factor to convert frac to a proportion. Default = 1.0.
Returns:

None

runModflow()[source]

Run MODFLOW for baseline, low dam height, median dam height, and high dam height scenarios.

Returns:None
saveResultsToRaster()[source]

Read modeled head values and write to GDAL rasters.

Returns:None
setHeadPaths()[source]

Set file names for head data to be read and written.

Returns:None
setIBoundPaths()[source]

Set file names for output ibound rasters.

Returns:None
setLpfVariables(hksat, vksat, kconv)[source]

Set variables required for MODFLOW LPF package. This function is called internally.

Parameters:
  • khsat – Horizontal hydraulic conductivity.
  • kvsat – Vertical hydraulic conductivity.
  • kconv – Factor to convert hksat and vksat to meters per second.
Returns:

None

setPaths()[source]

Set file paths for input and output data.

Returns:None
setPondDepthPaths()[source]

Set file paths for pond depth rasters created by BDSWEA.

Returns:None
setVariables(demfilename)[source]

Set class variables.

Parameters:demfilename – Name of DEM raster file.
Returns:None
setWsePaths()[source]

Set file paths for water surface elevation rasters created by BDSWEA.

Returns:None
writeModflowInput()[source]

Add MODFLOW packages and write input files for baseline, low dam height, median dam height, and high dam height scenarios.

Returns:None