|
19 | 19 | "source": [ |
20 | 20 | "import numpy as np\n", |
21 | 21 | "import xarray as xr\n", |
22 | | - "import xrsimlab" |
| 22 | + "import xsimlab" |
23 | 23 | ] |
24 | 24 | }, |
25 | 25 | { |
|
28 | 28 | "source": [ |
29 | 29 | "## Import and inspect a model\n", |
30 | 30 | "\n", |
31 | | - "The model (i.e., the `xrsimlab.Model` object) that we use here is provided by the [xarray-topo](https://gitext.gfz-potsdam.de/sec55-public/xarray-topo) package." |
| 31 | + "The model (i.e., the `xsimlab.Model` object) that we use here is provided by the [xarray-topo](https://gitext.gfz-potsdam.de/sec55-public/xarray-topo) package." |
32 | 32 | ] |
33 | 33 | }, |
34 | 34 | { |
|
39 | 39 | }, |
40 | 40 | "outputs": [], |
41 | 41 | "source": [ |
42 | | - "from xrtopo.models.fastscape_base import fastscape_base_model" |
| 42 | + "from xtopo.models.fastscape_base import fastscape_base_model" |
43 | 43 | ] |
44 | 44 | }, |
45 | 45 | { |
|
67 | 67 | { |
68 | 68 | "data": { |
69 | 69 | "text/plain": [ |
70 | | - "<xrsimlab.Model (9 processes, 13 inputs)>\n", |
| 70 | + "<xsimlab.Model (9 processes, 13 inputs)>\n", |
71 | 71 | "grid\n", |
72 | 72 | " x_size (in) nb. of nodes in x\n", |
73 | 73 | " y_size (in) nb. of nodes in y\n", |
|
144 | 144 | { |
145 | 145 | "data": { |
146 | 146 | "text/plain": [ |
147 | | - "<xrsimlab.Process 'xrtopo.models.fastscape_base.StackedGridXY'>\n", |
| 147 | + "<xsimlab.Process 'xtopo.models.fastscape_base.StackedGridXY'>\n", |
148 | 148 | "Variables:\n", |
149 | 149 | " x_size IntegerVariable ()\n", |
150 | 150 | " y_size IntegerVariable ()\n", |
|
175 | 175 | "source": [ |
176 | 176 | "## Create a model setup\n", |
177 | 177 | "\n", |
178 | | - "With a few lines of code, using the `Dataset.simlab` extension (accessor), we create the setup of a new simulation, starting from an empty `Dataset`." |
| 178 | + "With a few lines of code, using the `Dataset.xsimlab` extension (accessor), we create the setup of a new simulation, starting from an empty `Dataset`." |
179 | 179 | ] |
180 | 180 | }, |
181 | 181 | { |
|
190 | 190 | "ds = xr.Dataset() \n", |
191 | 191 | "\n", |
192 | 192 | "# use the model above with this Dataset\n", |
193 | | - "ds.simlab.use_model(fastscape_base_model) \n", |
| 193 | + "ds.xsimlab.use_model(fastscape_base_model) \n", |
194 | 194 | "\n", |
195 | 195 | "# populate Dataset with input variable values (per process in the model)\n", |
196 | | - "ds.simlab.set_input_vars('grid', x_size=101, y_size=101, x_length=1e5, y_length=1e5)\n", |
197 | | - "ds.simlab.set_input_vars('topography', elevation=('node', np.random.rand(101 * 101)))\n", |
198 | | - "ds.simlab.set_input_vars('spower', k_coef=7e-5, m_exp=0.4, n_exp=1)\n", |
199 | | - "ds.simlab.set_input_vars('uplift', u_coef=2e-3)\n", |
| 196 | + "ds.xsimlab.set_input_vars('grid', x_size=101, y_size=101, x_length=1e5, y_length=1e5)\n", |
| 197 | + "ds.xsimlab.set_input_vars('topography', elevation=('node', np.random.rand(101 * 101)))\n", |
| 198 | + "ds.xsimlab.set_input_vars('spower', k_coef=7e-5, m_exp=0.4, n_exp=1)\n", |
| 199 | + "ds.xsimlab.set_input_vars('uplift', u_coef=2e-3)\n", |
200 | 200 | "\n", |
201 | 201 | "# set the clock coordinate where labels are time steps (here in years)\n", |
202 | | - "ds.simlab.set_master_clock('time', end=1e6, step=1e3)" |
| 202 | + "ds.xsimlab.set_master_clock('time', end=1e6, step=1e3)" |
203 | 203 | ] |
204 | 204 | }, |
205 | 205 | { |
|
218 | 218 | "outputs": [], |
219 | 219 | "source": [ |
220 | 220 | "# set another time coordinate for snapshots with much larger steps than for 'time'\n", |
221 | | - "ds.simlab.set_snapshot_clock('out', end=1e6, step=1e5)\n", |
| 221 | + "ds.xsimlab.set_snapshot_clock('out', end=1e6, step=1e5)\n", |
222 | 222 | "\n", |
223 | 223 | "# use the last created time coordinate to save topographic elevation values\n", |
224 | | - "ds.simlab.set_snapshot_vars('out', topography='elevation')" |
| 224 | + "ds.xsimlab.set_snapshot_vars('out', topography='elevation')" |
225 | 225 | ] |
226 | 226 | }, |
227 | 227 | { |
|
240 | 240 | "outputs": [], |
241 | 241 | "source": [ |
242 | 242 | "# use None for saving time-independent outputs\n", |
243 | | - "ds.simlab.set_snapshot_vars(None, grid=['x', 'y'])" |
| 243 | + "ds.xsimlab.set_snapshot_vars(None, grid=['x', 'y'])" |
244 | 244 | ] |
245 | 245 | }, |
246 | 246 | { |
|
279 | 279 | " spower__n_exp int64 1\n", |
280 | 280 | " uplift__u_coef float64 0.002\n", |
281 | 281 | "Attributes:\n", |
282 | | - " _simlab_snapshot_vars: grid__x,grid__y" |
| 282 | + " _xsimlab_snapshot_vars: grid__x,grid__y" |
283 | 283 | ] |
284 | 284 | }, |
285 | 285 | "execution_count": 9, |
|
327 | 327 | "source": [ |
328 | 328 | "## Run the model\n", |
329 | 329 | "\n", |
330 | | - "We run the model simply by calling `Dataset.simlab.run()`, which returns a new Dataset with both the inputs and the outputs. Note the additional variables `grid__x` and `grid__y` and the `topography__elevation` variable which has now also the `out` dimension. " |
| 330 | + "We run the model simply by calling `Dataset.xsimlab.run()`, which returns a new Dataset with both the inputs and the outputs. Note the additional variables `grid__x` and `grid__y` and the `topography__elevation` variable which has now also the `out` dimension. " |
331 | 331 | ] |
332 | 332 | }, |
333 | 333 | { |
|
368 | 368 | } |
369 | 369 | ], |
370 | 370 | "source": [ |
371 | | - "out_ds = ds.simlab.run()\n", |
| 371 | + "out_ds = ds.xsimlab.run()\n", |
372 | 372 | "\n", |
373 | 373 | "out_ds" |
374 | 374 | ] |
|
1403 | 1403 | " spower__n_exp int64 1\n", |
1404 | 1404 | " uplift__u_coef float64 0.002\n", |
1405 | 1405 | "Attributes:\n", |
1406 | | - " _simlab_snapshot_vars: grid__x,grid__y" |
| 1406 | + " _xsimlab_snapshot_vars: grid__x,grid__y" |
1407 | 1407 | ] |
1408 | 1408 | }, |
1409 | 1409 | "execution_count": 20, |
|
1415 | 1415 | "ds_kt = ds.copy()\n", |
1416 | 1416 | "\n", |
1417 | 1417 | "# we copied the dataset so we need to explicitly re-assign the Model\n", |
1418 | | - "ds_kt.simlab.use_model(fastscape_base_model)\n", |
| 1418 | + "ds_kt.xsimlab.use_model(fastscape_base_model)\n", |
1419 | 1419 | "\n", |
1420 | | - "ds_kt.simlab.set_input_vars('spower', k_coef=da_k_time, m_exp=0.4, n_exp=1)\n", |
| 1420 | + "ds_kt.xsimlab.set_input_vars('spower', k_coef=da_k_time, m_exp=0.4, n_exp=1)\n", |
1421 | 1421 | "\n", |
1422 | 1422 | "ds_kt" |
1423 | 1423 | ] |
|
1446 | 1446 | } |
1447 | 1447 | ], |
1448 | 1448 | "source": [ |
1449 | | - "out_ds_kt = ds_kt.simlab.run()\n", |
| 1449 | + "out_ds_kt = ds_kt.xsimlab.run()\n", |
1450 | 1450 | "\n", |
1451 | 1451 | "out_ds_kt_unstack = out_ds_kt.set_index(node=['grid__x', 'grid__y']).unstack('node')\n", |
1452 | 1452 | "\n", |
|
1484 | 1484 | "datasets_k = []\n", |
1485 | 1485 | " \n", |
1486 | 1486 | "ds_in = ds.copy()\n", |
1487 | | - "ds_in.simlab.use_model(fastscape_base_model)\n", |
| 1487 | + "ds_in.xsimlab.use_model(fastscape_base_model)\n", |
1488 | 1488 | "\n", |
1489 | 1489 | "for k in k_values:\n", |
1490 | 1490 | " print('run k=%f' % k)\n", |
1491 | 1491 | "\n", |
1492 | | - " ds_in.simlab.set_input_vars('spower', k_coef=k, m_exp=0.4, n_exp=1)\n", |
1493 | | - " out_ds = ds_in.simlab.run()\n", |
| 1492 | + " ds_in.xsimlab.set_input_vars('spower', k_coef=k, m_exp=0.4, n_exp=1)\n", |
| 1493 | + " out_ds = ds_in.xsimlab.run()\n", |
1494 | 1494 | "\n", |
1495 | 1495 | " datasets_k.append(out_ds)\n", |
1496 | 1496 | "\n", |
|
1985 | 1985 | "metadata": {}, |
1986 | 1986 | "outputs": [], |
1987 | 1987 | "source": [ |
1988 | | - "from xrtopo.models.fastscape_base import StackedGridXY, BoundaryFacesXY\n", |
1989 | | - "from xrsimlab import Process, FloatVariable, Variable, ForeignVariable\n", |
| 1988 | + "from xtopo.models.fastscape_base import StackedGridXY, BoundaryFacesXY\n", |
| 1989 | + "from xsimlab import Process, FloatVariable, Variable, ForeignVariable\n", |
1990 | 1990 | "\n", |
1991 | 1991 | "\n", |
1992 | | - "class VariableUplift(xrsimlab.Process):\n", |
| 1992 | + "class VariableUplift(xsimlab.Process):\n", |
1993 | 1993 | " \"\"\"Compute spatially variable uplift as a linear function of x.\"\"\"\n", |
1994 | 1994 | " \n", |
1995 | 1995 | " x_coef = FloatVariable((), description='uplift function x coefficient')\n", |
|
2023 | 2023 | { |
2024 | 2024 | "data": { |
2025 | 2025 | "text/plain": [ |
2026 | | - "<xrsimlab.Model (9 processes, 13 inputs)>\n", |
| 2026 | + "<xsimlab.Model (9 processes, 13 inputs)>\n", |
2027 | 2027 | "grid\n", |
2028 | 2028 | " x_size (in) nb. of nodes in x\n", |
2029 | 2029 | " y_size (in) nb. of nodes in y\n", |
|
2076 | 2076 | "\n", |
2077 | 2077 | "alt_ds = ds.drop('uplift__u_coef')\n", |
2078 | 2078 | "\n", |
2079 | | - "alt_ds.simlab.use_model(alt_model)\n", |
2080 | | - "alt_ds.simlab.set_input_vars('uplift', x_coef=1e-7)\n", |
| 2079 | + "alt_ds.xsimlab.use_model(alt_model)\n", |
| 2080 | + "alt_ds.xsimlab.set_input_vars('uplift', x_coef=1e-7)\n", |
2081 | 2081 | "\n", |
2082 | | - "out_alt_ds = alt_ds.simlab.run()" |
| 2082 | + "out_alt_ds = alt_ds.xsimlab.run()" |
2083 | 2083 | ] |
2084 | 2084 | }, |
2085 | 2085 | { |
|
0 commit comments