Skip to content

Commit

Permalink
Merge pull request #16 from jtgilbert/windows-dev
Browse files Browse the repository at this point in the history
updates for updated shapely and skimage
  • Loading branch information
jtgilbert authored Apr 21, 2022
2 parents 06835a1 + 56901db commit e448b9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
32 changes: 15 additions & 17 deletions classVBET.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, **kwargs):
]
self.md = open(metatxt, 'w+')
self.md.writelines(L)
self.md.writelines('\n VBET-2 version {}'.format(self.version))
self.md.writelines('\nVBET-2 version {}\n'.format(self.version))
self.md.writelines('\nStarted: {} \n'.format(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))

# either use selected drainage area field, or pull drainage area from raster
Expand Down Expand Up @@ -159,14 +159,13 @@ def clean_network(self):
# get rid of perfectly straight segments
sin = []
for i in self.network.index:
seg_geom = self.network.loc[i, 'geometry']
x_coord1 = seg_geom.boundary[0].xy[0][0]
y_coord1 = seg_geom.boundary[0].xy[1][0]
x_coord2 = seg_geom.boundary[1].xy[0][0]
y_coord2 = seg_geom.boundary[1].xy[1][0]

dist = ((x_coord1 - x_coord2) ** 2 + (y_coord1 - y_coord2) ** 2) ** 0.5
sin_val = seg_geom.length / dist
seg_geom = self.network.loc[i].geometry
pts = []
for pt in seg_geom.boundary.geoms:
pts.append([pt.xy[0][0], pt.xy[1][0]])
line = LineString(pts)

sin_val = seg_geom.length / line.length
sin.append(sin_val)
self.network['sinuos'] = sin

Expand Down Expand Up @@ -347,7 +346,7 @@ def fill_raster_holes(self, array, thresh, ndval):
binary[j, i] = 1

b = mo.remove_small_holes(binary, thresh, 1)
c = mo.binary_closing(b, selem=np.ones((7, 7)))
c = mo.binary_closing(b, footprint=np.ones((7, 7)))
d = mo.remove_small_holes(c, thresh, 1)

out_array = np.full(d.shape, ndval, dtype=np.float32)
Expand Down Expand Up @@ -398,7 +397,6 @@ def raster_to_shp(self, array, raster_like):
geoms = list(results)
if len(geoms) == 0:
return 0
#raise Exception('No raster cells to convert to shapefile, try changing model parameters')

else:
df = gpd.GeoDataFrame.from_features(geoms)
Expand Down Expand Up @@ -444,13 +442,13 @@ def valley_bottom(self):
for i in tqdm(self.network.index):
seg = self.network.loc[i]
da = seg['Drain_Area']
geom = seg['geometry']
seg_geom = seg.geometry

# print('segment ', i+1, ' of ', len(self.network.index))

ept1 = (geom.boundary[0].xy[0][0], geom.boundary[0].xy[1][0])
ept2 = (geom.boundary[1].xy[0][0], geom.boundary[1].xy[1][0])
line = LineString([ept1, ept2])
pts = []
for pt in seg_geom.boundary.geoms:
pts.append([pt.xy[0][0], pt.xy[1][0]])
line = LineString(pts)

if da >= self.lg_da:
buf = line.buffer(self.lg_buf, cap_style=1)
Expand Down Expand Up @@ -497,7 +495,7 @@ def valley_bottom(self):
thresh = avlen * self.lg_buf * 0.005

# detrend segment dem
detr = self.detrend(dem, geom) # might want to change this offset
detr = self.detrend(dem, seg_geom) # might want to change this offset

if da >= self.lg_da:
depth = self.reclassify(detr, ndval, self.lg_depth)
Expand Down
12 changes: 6 additions & 6 deletions run_VBET.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
class RunVBET:
def __init__(self):
self.params = {
'network': '/home/jordan/Documents/Riverscapes/scratch/10190004_network.shp',
'dem': '/home/jordan/Documents/Riverscapes/scratch/dem_10190004.tif',
'out': '/home/jordan/Documents/Riverscapes/scratch/vbet2_out2.shp',
'scratch': '/home/jordan/Documents/Riverscapes/scratch/scratch',
'lg_da': 300,
'med_da': 30,
'network': '/path/to/stream/network.shp',
'dem': '/path/to/dem.tif',
'out': '/path/to/vbet/output.shp',
'scratch': 'path/to/scratch/workspace',
'lg_da': 250,
'med_da': 25,
'lg_slope': 3,
'med_slope': 4,
'sm_slope': 5,
Expand Down

0 comments on commit e448b9c

Please sign in to comment.