Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 48 additions & 30 deletions notebooks/tutorials/kcalving_parameterization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,24 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"import time, os\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from oggm.core.massbalance import ScalarMassBalance\n",
"from oggm import cfg, utils, workflow, tasks, graphics\n",
"from oggm.tests.funcs import bu_tidewater_bed\n",
"from oggm.core.flowline import FluxBasedModel\n",
"from oggm.core.flowline import TrapezoidalBedFlowline, SemiImplicitModel\n",
"\n",
"cfg.initialize(logging_level='WARNING')\n",
"cfg.PARAMS['cfl_number'] = 0.01 # less numerical instabilities\n",
"cfg.PARAMS['use_multiprocessing'] = False"
"cfg.PARAMS['cfl_number'] = 0.01\n",
"cfg.PARAMS['use_multiprocessing'] = True\n",
"cfg.PARAMS['mp_processes'] = 4\n",
"cfg.PARAMS['tidewater_type'] = 4\n",
"cfg.PARAMS['clip_tidewater_border'] = True\n",
"cfg.PARAMS['use_kcalving_for_inversion'] = True\n",
"cfg.PARAMS['use_kcalving_for_run'] = True"
]
},
{
Expand Down Expand Up @@ -91,7 +96,7 @@
"metadata": {},
"outputs": [],
"source": [
"bu_fl = bu_tidewater_bed()[0]\n",
"bu_fl = bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0)[0]\n",
"\n",
"xc = bu_fl.dis_on_line * bu_fl.dx_meter / 1000\n",
"f, ax = plt.subplots(1, 1, figsize=(12, 5))\n",
Expand All @@ -118,12 +123,15 @@
"to_plot = None\n",
"keys = []\n",
"for flux_gate in [0.06, 0.10, 0.16]:\n",
" model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n",
" is_tidewater=True, \n",
" flux_gate=flux_gate, # default is 0\n",
" calving_k=0.2, # default is 2.4\n",
" do_kcalving=True\n",
" )\n",
" model = SemiImplicitModel(\n",
" bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0), # use your trapezoid builder\n",
" mb_model=mb_model,\n",
" flux_gate=flux_gate,\n",
" do_calving=True,\n",
" calving_k=0.2,\n",
" water_level=0.0,\n",
" cfl_number=0.5, # optional, if you want similar strictness\n",
" )\n",
" # long enough to reach approx. equilibrium \n",
" ds = model.run_until_and_store(6000)\n",
" df_diag = model.get_diagnostics()\n",
Expand All @@ -136,7 +144,7 @@
" keys.append(key)\n",
" \n",
" # Plot of volume\n",
" (ds.volume_m3 * 1e-9).plot(label=key)\n",
" (ds.volume_m3 * 1e-9).plot(label=key);\n",
"plt.legend(); plt.ylabel('Volume [km$^{3}$]');\n",
"to_plot.index = xc"
]
Expand Down Expand Up @@ -184,12 +192,14 @@
"to_plot = None\n",
"keys = []\n",
"for limiter in [True, False]:\n",
" model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n",
" model = SemiImplicitModel(bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0),\n",
" mb_model=mb_model,\n",
" water_level=0.0,\n",
" is_tidewater=True, \n",
" calving_use_limiter=limiter, # default is True\n",
" flux_gate=0.06, # default is 0\n",
" calving_k=0.2, # default is 2.4\n",
" do_kcalving=True\n",
" do_calving=True\n",
" )\n",
" # long enough to reach approx. equilibrium \n",
" ds = model.run_until_and_store(7000)\n",
Expand All @@ -198,12 +208,12 @@
" if to_plot is None:\n",
" to_plot = df_diag\n",
" \n",
" key = 'Flux limiter={}. Calving rate: {:.0f} m yr-1'.format(limiter, model.calving_rate_myr)\n",
" to_plot[key] = df_diag['surface_h']\n",
" key = f\"Flux limiter={limiter}. Calving rate: {model.calving_rate_myr:.0f} m yr-1\"\n",
" to_plot[key] = df_diag[\"surface_h\"]\n",
" keys.append(key)\n",
" \n",
" # Plot of volume\n",
"\n",
" (ds.volume_m3 * 1e-9).plot(label=key)\n",
"\n",
"plt.legend(); plt.ylabel('Volume [km$^{3}$]');\n",
"to_plot.index = xc"
]
Expand Down Expand Up @@ -270,13 +280,14 @@
"metadata": {},
"outputs": [],
"source": [
"model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n",
" is_tidewater=True, \n",
" glen_a=cfg.PARAMS['glen_a']*3, # make the glacier flow faster\n",
" flux_gate=flux_gate, # default is 0\n",
" calving_k=1, # default is 2.4\n",
" do_kcalving=True\n",
" )\n",
"model = SemiImplicitModel(bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0), \n",
" mb_model=mb_model,\n",
" is_tidewater=True, \n",
" glen_a=cfg.PARAMS['glen_a']*3, # make the glacier flow faster\n",
" flux_gate=flux_gate, # default is 0\n",
" calving_k=1, # default is 2.4\n",
" do_calving=True\n",
" )\n",
"t0 = time.time()\n",
"ds = model.run_until_and_store(len(flux)-1)\n",
"print('Done! Time needed: {}s'.format(int(time.time()-t0)))"
Expand Down Expand Up @@ -397,7 +408,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First observation is that its slower by a factor at least two. Let's have a look at the results:"
"**First observation is that its ~5× slower**. Let's have a look at the results:"
]
},
{
Expand Down Expand Up @@ -457,8 +468,10 @@
"metadata": {},
"outputs": [],
"source": [
"ds.length_m.plot()\n",
"ds_new.length_m.plot();"
"ds.length_m.plot(label=\"old\")\n",
"ds_new.length_m.plot(label=\"new\")\n",
"\n",
"plt.legend()"
]
},
{
Expand All @@ -481,6 +494,11 @@
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -491,7 +509,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.11.0"
},
"toc": {
"base_numbering": 1,
Expand Down
Loading