# smooth DEM elevations in segment interiors so that they decrease in downstream direction
sfr.smooth_interior_elevations()

# read in the DIS file (this is needed for some of the methods below;
# e.g. model top elevations are added to the stream profiles by default)
sfr.read_dis2(mfdis='Forsy.DIS', mfnam='ForsySFRMaker.nam')

# plot profiles of streambed elevations in comparison to model top and DEM minimum
sfr.plot_stream_profiles(add_profiles={'Minimum DEM elevation': 'landsurface'})

# enforce only one SFR conductance for each model cell 
# (other reaches in cell assigned near-zero conductance)
sfr.consolidate_conductance()

# adjust model grid so that all SFR reaches are in layer 1
# outputs a new DIS file for model
sfr.reset_model_top_2streambed(outdisfile='Forsy_adjusted_to_streambed.dis')

# run suite of diagnostics to test for common problems with SFR package
sfr.run_diagnostics()

# create shapefile for visualizing SFR package
sfr.write_shapefile(outshp='Forsy.shp', prj='ForsyGrd.prj')

# write updated tables
sfr.write_tables(basename='Forsy')

# write an SFR package file
sfr.write_sfr_package(basename='Forsy')
# In cells with multiple SFR reaches (at confluences), put all conductance in the dominant reach
# (to avoid circular routing)
sfr.consolidate_conductance()

# Put all SFR reaches in layer 1, and adjust layer bottoms in SFR cells accordingly,
# so that no streambed bottoms are below the bottom of layer 1, and
# so that there are no cell thicknesses less than 1
# Note: This produces a new MODFLOW DIS file with the suffix "_adjusted to streambed.dis"
# (unless another suffix is specified)
sfr.reset_model_top_2streambed(minimum_thickness=1)

# write out a shapefile of the SFR dataset
sfr.write_shapefile('SFR_postproc.shp')

# run some diagnostics to look for common problems
sfr.run_diagnostics(model_domain=mf_domain, sfr_linework_shapefile='SFRlines.shp')

# write out updated Mat1 and Mat2 tables
sfr.write_tables(basename='ozark_pp_')

# write the SFR package file
sfr.write_sfr_package(basename='ozark')

# the development branch of flopy now includes an SFR module, with a checker
# run the flopy suite of diagnostics as well
import flopy
m = flopy.modflow.Modflow(model_ws='ozarkgwmod/3-Input/A-calibration/')
dis = flopy.modflow.ModflowDis.load('ozarkgwmod/3-Input/A-calibration/ozark_adjusted_to_streambed.dis', m)
sfr = flopy.modflow.ModflowSfr2.load('ozark.sfr', m)
sfr.check(f='flopy_SFR_check')