Skip to content

Commit 85502ef

Browse files
committed
update notebook so that it works with latest changes
1 parent c4b16ef commit 85502ef

File tree

2 files changed

+69
-93
lines changed

2 files changed

+69
-93
lines changed

meanderpy/meanderpy.ipynb

Lines changed: 66 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@
1212
"%matplotlib qt"
1313
]
1414
},
15-
{
16-
"cell_type": "code",
17-
"execution_count": 6,
18-
"metadata": {},
19-
"outputs": [
20-
{
21-
"data": {
22-
"text/plain": [
23-
"<module 'meanderpy' from '/Users/zoltan/Dropbox/Channels/meanderpy/meanderpy/meanderpy.py'>"
24-
]
25-
},
26-
"execution_count": 6,
27-
"metadata": {},
28-
"output_type": "execute_result"
29-
}
30-
],
31-
"source": [
32-
"from importlib import reload\n",
33-
"reload(mp)"
34-
]
35-
},
3615
{
3716
"cell_type": "markdown",
3817
"metadata": {},
@@ -42,29 +21,29 @@
4221
},
4322
{
4423
"cell_type": "code",
45-
"execution_count": 3,
24+
"execution_count": 10,
4625
"metadata": {},
4726
"outputs": [],
4827
"source": [
4928
"nit = 2000 # number of iterations\n",
5029
"W = 200.0 # channel width (m)\n",
5130
"D = 6.0 # channel depth (m)\n",
52-
"depths = D * np.ones((nit,)) # channel depths for different iterations \n",
31+
"depths = D * np.ones((nit,)) # channel depths for different iterations \n",
5332
"pad = 100 # padding (number of nodepoints along centerline)\n",
5433
"deltas = 50.0 # sampling distance along centerline \n",
5534
"Cfs = 0.011 * np.ones((nit,)) # dimensionless Chezy friction factor\n",
5635
"crdist = 2 * W # threshold distance at which cutoffs occur\n",
5736
"kl = 60.0/(365*24*60*60.0) # migration rate constant (m/s)\n",
58-
"kv = 1.0e-11 # vertical slope-dependent erosion rate constant (m/s)\n",
59-
"dt = 2*0.05*365*24*60*60.0 # time step (s)\n",
37+
"kv = 1.0e-11 # vertical slope-dependent erosion rate constant (m/s)\n",
38+
"dt = 2*0.05*365*24*60*60.0 # time step (s)\n",
6039
"dens = 1000 # density of water (kg/m3)\n",
6140
"saved_ts = 20 # which time steps will be saved\n",
6241
"n_bends = 30 # approximate number of bends you want to model\n",
63-
"Sl = 0.002 # initial slope (matters more for submarine channels than rivers)\n",
64-
"t1 = 500 # time step when incision starts\n",
65-
"t2 = 700 # time step when lateral migration starts\n",
42+
"Sl = 0.002 # initial slope (matters more for submarine channels than rivers)\n",
43+
"t1 = 500 # time step when incision starts\n",
44+
"t2 = 700 # time step when lateral migration starts\n",
6645
"t3 = 1200 # time step when aggradation starts\n",
67-
"aggr_factor = 2e-9 # aggradation factor (m/s, about 0.18 m/year, it kicks in after t3)"
46+
"aggr_factor = 2e-9 # aggradation factor (m/s, about 0.18 m/year, it kicks in after t3)"
6847
]
6948
},
7049
{
@@ -76,7 +55,7 @@
7655
},
7756
{
7857
"cell_type": "code",
79-
"execution_count": 7,
58+
"execution_count": 11,
8059
"metadata": {},
8160
"outputs": [],
8261
"source": [
@@ -93,14 +72,14 @@
9372
},
9473
{
9574
"cell_type": "code",
96-
"execution_count": 8,
75+
"execution_count": 12,
9776
"metadata": {},
9877
"outputs": [
9978
{
10079
"name": "stderr",
10180
"output_type": "stream",
10281
"text": [
103-
"100%|███████████████████████████████████████| 2000/2000 [00:21<00:00, 91.67it/s]\n"
82+
"100%|██████████| 2000/2000 [00:16<00:00, 119.93it/s]\n"
10483
]
10584
}
10685
],
@@ -111,7 +90,7 @@
11190
},
11291
{
11392
"cell_type": "code",
114-
"execution_count": 9,
93+
"execution_count": 6,
11594
"metadata": {},
11695
"outputs": [],
11796
"source": [
@@ -130,11 +109,15 @@
130109
},
131110
{
132111
"cell_type": "code",
133-
"execution_count": 10,
112+
"execution_count": 7,
134113
"metadata": {},
135114
"outputs": [],
136115
"source": [
137-
"fig = chb.plot('morph', 20, 60, chb.cl_times[-1], len(chb.channels))"
116+
"# pb_age — Age of point bars (in years) at which they get covered by vegetation\n",
117+
"# ob_age — Age of oxbow lakes (in years) at which they get covered by vegetation\n",
118+
"\n",
119+
"fig = chb.plot('morph', pb_age=60, ob_age=100, end_time=chb.cl_times[-1], \n",
120+
" n_channels=len(chb.channels))\n"
138121
]
139122
},
140123
{
@@ -146,11 +129,11 @@
146129
},
147130
{
148131
"cell_type": "code",
149-
"execution_count": 14,
132+
"execution_count": 8,
150133
"metadata": {},
151134
"outputs": [],
152135
"source": [
153-
"fig = chb.plot('age', 20, 60, chb.cl_times[-1], len(chb.channels))"
136+
"fig = chb.plot('age', chb.cl_times[-1], len(chb.channels))"
154137
]
155138
},
156139
{
@@ -162,13 +145,34 @@
162145
},
163146
{
164147
"cell_type": "code",
165-
"execution_count": 9,
148+
"execution_count": null,
166149
"metadata": {},
167-
"outputs": [],
150+
"outputs": [
151+
{
152+
"name": "stdout",
153+
"output_type": "stream",
154+
"text": [
155+
"Animation saved to: channel_evolution.mp4\n"
156+
]
157+
},
158+
{
159+
"data": {
160+
"text/plain": [
161+
"<matplotlib.animation.FuncAnimation at 0x33baaead0>"
162+
]
163+
},
164+
"execution_count": 14,
165+
"metadata": {},
166+
"output_type": "execute_result"
167+
}
168+
],
168169
"source": [
169-
"dirname = '/Users/zoltan/Dropbox/Channels/temp/'\n",
170-
"chb.create_movie(xmin=10000, xmax=30000, plot_type='strat', filename='movie', dirname=dirname,\n",
171-
" pb_age = 1, ob_age = 20, end_time = chb.cl_times[-1], n_channels = len(chb.channels))"
170+
"# this can take a couple of minutes\n",
171+
"# change file extension to .gif to save a file in gif format\n",
172+
"# change xmin, xmax to zoom in on a specific area\n",
173+
"\n",
174+
"chb.create_movie(xmin=10000, xmax=30000, plot_type='strat', \n",
175+
" filename='channel_evolution.mp4', fps=10, dpi=150)"
172176
]
173177
},
174178
{
@@ -184,31 +188,9 @@
184188
},
185189
{
186190
"cell_type": "code",
187-
"execution_count": 15,
191+
"execution_count": null,
188192
"metadata": {},
189-
"outputs": [
190-
{
191-
"name": "stderr",
192-
"output_type": "stream",
193-
"text": [
194-
"100%|█████████████████████████████████████████| 100/100 [00:39<00:00, 2.50it/s]"
195-
]
196-
},
197-
{
198-
"name": "stdout",
199-
"output_type": "stream",
200-
"text": [
201-
"43.98457647341001\n"
202-
]
203-
},
204-
{
205-
"name": "stderr",
206-
"output_type": "stream",
207-
"text": [
208-
"\n"
209-
]
210-
}
211-
],
193+
"outputs": [],
212194
"source": [
213195
"h_mud = 2.0 * np.ones((len(chb.channels),)) # thickness of overbank deposit for each time step\n",
214196
"dx = 10.0 # gridcell size in meters\n",
@@ -242,14 +224,14 @@
242224
},
243225
{
244226
"cell_type": "code",
245-
"execution_count": 25,
227+
"execution_count": 18,
246228
"metadata": {},
247229
"outputs": [
248230
{
249231
"name": "stderr",
250232
"output_type": "stream",
251233
"text": [
252-
"100%|███████████████████████████████████████| 2000/2000 [00:22<00:00, 90.27it/s]\n"
234+
"100%|██████████| 2000/2000 [00:17<00:00, 113.11it/s]\n"
253235
]
254236
}
255237
],
@@ -280,19 +262,11 @@
280262
},
281263
{
282264
"cell_type": "code",
283-
"execution_count": 27,
265+
"execution_count": 19,
284266
"metadata": {
285267
"tags": []
286268
},
287-
"outputs": [
288-
{
289-
"name": "stderr",
290-
"output_type": "stream",
291-
"text": [
292-
"100%|█████████████████████████████████████████| 100/100 [01:07<00:00, 1.48it/s]\n"
293-
]
294-
}
295-
],
269+
"outputs": [],
296270
"source": [
297271
"# add a bit more incision:\n",
298272
"for i in range(len(chb.channels)):\n",
@@ -319,14 +293,14 @@
319293
},
320294
{
321295
"cell_type": "code",
322-
"execution_count": 23,
296+
"execution_count": 20,
323297
"metadata": {},
324298
"outputs": [
325299
{
326300
"name": "stderr",
327301
"output_type": "stream",
328302
"text": [
329-
"100%|█████████████████████████████████████████| 100/100 [01:00<00:00, 1.65it/s]\n"
303+
"100%|██████████| 100/100 [01:08<00:00, 1.45it/s]\n"
330304
]
331305
}
332306
],
@@ -349,7 +323,7 @@
349323
},
350324
{
351325
"cell_type": "code",
352-
"execution_count": 42,
326+
"execution_count": 21,
353327
"metadata": {},
354328
"outputs": [],
355329
"source": [
@@ -373,7 +347,7 @@
373347
},
374348
{
375349
"cell_type": "code",
376-
"execution_count": 43,
350+
"execution_count": 22,
377351
"metadata": {},
378352
"outputs": [],
379353
"source": [
@@ -383,14 +357,14 @@
383357
},
384358
{
385359
"cell_type": "code",
386-
"execution_count": 44,
360+
"execution_count": 23,
387361
"metadata": {},
388362
"outputs": [
389363
{
390364
"name": "stderr",
391365
"output_type": "stream",
392366
"text": [
393-
"100%|███████████████████████████████████████| 2000/2000 [00:23<00:00, 84.27it/s]\n"
367+
"100%|██████████| 2000/2000 [00:18<00:00, 109.57it/s]\n"
394368
]
395369
}
396370
],
@@ -409,14 +383,16 @@
409383
},
410384
{
411385
"cell_type": "code",
412-
"execution_count": 45,
386+
"execution_count": 24,
413387
"metadata": {},
414388
"outputs": [
415389
{
416390
"name": "stderr",
417391
"output_type": "stream",
418392
"text": [
419-
"100%|█████████████████████████████████████████| 100/100 [03:21<00:00, 2.01s/it]\n"
393+
" 0%| | 0/100 [00:00<?, ?it/s]/Users/zoltan/Documents/Channels/meanderpy/meanderpy/meanderpy.py:1435: FutureWarning: `square` is deprecated since version 0.25 and will be removed in version 0.27. Use `skimage.morphology.footprint_rectangle` instead.\n",
394+
" img1 = morphology.binary_dilation(img, morphology.square(2)).astype(np.uint8)\n",
395+
"100%|██████████| 100/100 [00:56<00:00, 1.78it/s]\n"
420396
]
421397
}
422398
],
@@ -435,17 +411,17 @@
435411
},
436412
{
437413
"cell_type": "code",
438-
"execution_count": 47,
414+
"execution_count": 26,
439415
"metadata": {},
440416
"outputs": [],
441417
"source": [
442-
"fig1,fig2,fig3 = chb_3d.plot_xsection(1000, [[0.9,0.9,0], [0.5,0.25,0]], 10)"
418+
"fig1,fig2,fig3 = chb_3d.plot_xsection(400, [[0.9,0.9,0], [0.5,0.25,0]], 10)"
443419
]
444420
}
445421
],
446422
"metadata": {
447423
"kernelspec": {
448-
"display_name": "Python 3 (ipykernel)",
424+
"display_name": "meanderpy",
449425
"language": "python",
450426
"name": "python3"
451427
},
@@ -459,7 +435,7 @@
459435
"name": "python",
460436
"nbconvert_exporter": "python",
461437
"pygments_lexer": "ipython3",
462-
"version": "3.11.4"
438+
"version": "3.14.2"
463439
}
464440
},
465441
"nbformat": 4,

meanderpy/meanderpy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,15 +1432,15 @@ def dist_map(x, y, z, xmin, xmax, ymin, ymax, dx, delta_s):
14321432
img = np.array(img)
14331433
img = img[:,:,0]
14341434
img[img==255] = 1
1435-
img1 = morphology.binary_dilation(img, morphology.square(2)).astype(np.uint8)
1435+
img1 = morphology.dilation(img, morphology.square(2)).astype(np.uint8)
14361436
if len(np.where(img1==0)[0])>0:
14371437
x_pix, y_pix = eliminate_bad_pixels(img, img1)
14381438
x_pix,y_pix = order_cl_pixels(x_pix, y_pix, img)
1439-
img1 = morphology.binary_dilation(img, np.array([[1,0,1], [1,1,1]], dtype=np.uint8)).astype(np.uint8)
1439+
img1 = morphology.dilation(img, np.array([[1,0,1], [1,1,1]], dtype=np.uint8)).astype(np.uint8)
14401440
if len(np.where(img1==0)[0])>0:
14411441
x_pix, y_pix = eliminate_bad_pixels(img,img1)
14421442
x_pix,y_pix = order_cl_pixels(x_pix, y_pix, img)
1443-
img1 = morphology.binary_dilation(img, np.array([[1,0,1], [0,1,0], [1,0,1]], dtype=np.uint8)).astype(np.uint8)
1443+
img1 = morphology.dilation(img, np.array([[1,0,1], [0,1,0], [1,0,1]], dtype=np.uint8)).astype(np.uint8)
14441444
if len(np.where(img1==0)[0])>0:
14451445
x_pix, y_pix = eliminate_bad_pixels(img, img1)
14461446
x_pix,y_pix = order_cl_pixels(x_pix, y_pix, img)

0 commit comments

Comments
 (0)