Skip to content

Commit

Permalink
upgrade notebooks to Python 3.8+ syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed May 14, 2022
1 parent 86a7008 commit b24d961
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
6 changes: 3 additions & 3 deletions notebooks/cem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
"cem.get_grid_spacing(grid_id, out=spacing)\n",
"\n",
"print('The grid has %d rows and %d columns' % (shape[0], shape[1]))\n",
"print('The spacing between rows is %f m and between columns is %f m' % (spacing[0], spacing[1]))"
"print('The spacing between rows is {:f} m and between columns is {:f} m'.format(spacing[0], spacing[1]))"
]
},
{
Expand Down Expand Up @@ -399,7 +399,7 @@
"# read in the csv file of bedload measurements in the Rhine River, the Netherlands\n",
"# these data were collected over different days over a season in 2004, at nearby locations.\n",
"# plot how river discharge controls bedload; Q (x-axis) and Qb (y-axis) data. \n",
"# label both axes\n"
"# label both axes"
]
},
{
Expand All @@ -425,7 +425,7 @@
"outputs": [],
"source": [
"# extrapolate this relationship and calculate how much river discharge, Q, \n",
"# would be needed to transport the model specification Qb of 1250 kg/s\n"
"# would be needed to transport the model specification Qb of 1250 kg/s"
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions notebooks/child.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"\n",
"# Some magic to make plots appear within the notebook\n",
"%matplotlib inline\n",
"\n",
Expand Down
16 changes: 7 additions & 9 deletions notebooks/hydrotrend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"source": [
"# To start, import numpy and matplotlib.\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -237,8 +237,7 @@
"# compare with the last year\n",
"plt.plot(q[-366:-1],'grey')\n",
"plt.title('HydroTrend simulation of first and last year discharge, Waiapaoa River')\n",
"plt.show()\n",
"\n"
"plt.show()"
]
},
{
Expand Down Expand Up @@ -269,7 +268,7 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here\n"
"# your code goes here"
]
},
{
Expand All @@ -288,7 +287,7 @@
"metadata": {},
"outputs": [],
"source": [
"# here you can calculate the maximum river discharge.\n"
"# here you can calculate the maximum river discharge."
]
},
{
Expand Down Expand Up @@ -337,7 +336,7 @@
"# your code goes here\n",
"# you will have to sum all days of the individual years, to get the annual loads, then calculate the mean over the 100 years.\n",
"# one possible trick is to use the .reshape() method\n",
"# plot a graph of the 100 years timeseries of the total annual loads \n"
"# plot a graph of the 100 years timeseries of the total annual loads "
]
},
{
Expand All @@ -346,7 +345,7 @@
"metadata": {},
"outputs": [],
"source": [
"# take the mean over the 100 years\n"
"# take the mean over the 100 years"
]
},
{
Expand Down Expand Up @@ -430,8 +429,7 @@
"# your code that prints out the mean river discharge, the mean sediment load and the mean bedload goes here\n",
"\n",
"\n",
"# print out these same parameters for the basecase for comparison\n",
"\n"
"# print out these same parameters for the basecase for comparison"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions notebooks/hydrotrend_Ganges.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
"z = np.polyfit(q_y_vals.flatten(), q_mean_rows_GQ0.flatten(), 1)\n",
"p = np.poly1d(z)\n",
"plt.plot(q_y_vals, p(q_y_vals), \"r--\")\n",
"plt.suptitle(\"y=%.6fx+%.6f\" % (z[0], z[1]), y=0.8)\n",
"plt.suptitle(\"y={:.6f}x+{:.6f}\".format(z[0], z[1]), y=0.8)\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -359,7 +359,7 @@
"z = np.polyfit(qs_y_vals.flatten(), qs_mean_rows_GQ0.flatten(), 1)\n",
"p = np.poly1d(z)\n",
"plt.plot(qs_y_vals, p(qs_y_vals), \"r--\")\n",
"plt.suptitle(\"y=%.6fx+%.6f\" % (z[0], z[1]), y=0.85)\n",
"plt.suptitle(\"y={:.6f}x+{:.6f}\".format(z[0], z[1]), y=0.85)\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -394,29 +394,29 @@
"outputs": [],
"source": [
"print(\n",
" \"Mean Water Discharge = {0} {1}\".format(\n",
" \"Mean Water Discharge = {} {}\".format(\n",
" q_GQ0.mean(),\n",
" hydrotrend_GQ0.get_var_units(\"channel_exit_water__volume_flow_rate\"),\n",
" )\n",
")\n",
"print(\n",
" \"Mean Bedload Discharge = {0} {1}\".format(\n",
" \"Mean Bedload Discharge = {} {}\".format(\n",
" qb_GQ0.mean(),\n",
" hydrotrend_GQ0.get_var_units(\n",
" \"channel_exit_water_sediment~bedload__mass_flow_rate\"\n",
" ),\n",
" )\n",
")\n",
"print(\n",
" \"Mean Suspended Sediment Discharge = {0} {1}\".format(\n",
" \"Mean Suspended Sediment Discharge = {} {}\".format(\n",
" qs_GQ0.mean(),\n",
" hydrotrend_GQ0.get_var_units(\n",
" \"channel_exit_water_sediment~suspended__mass_flow_rate\"\n",
" ),\n",
" )\n",
")\n",
"print(\n",
" \"Mean Suspended Sediment Concentration = {0} {1}\".format(\n",
" \"Mean Suspended Sediment Concentration = {} {}\".format(\n",
" cs_GQ0.mean(),\n",
" hydrotrend_GQ0.get_var_units(\n",
" \"channel_exit_water_sediment~suspended__mass_concentration\"\n",
Expand Down
2 changes: 0 additions & 2 deletions notebooks/sedflux3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"\n",
"# Some magic to make plots appear within the notebook\n",
"%matplotlib inline\n",
"\n",
Expand Down
2 changes: 0 additions & 2 deletions notebooks/subside.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"\n",
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt"
Expand Down

0 comments on commit b24d961

Please sign in to comment.