|
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "cell_type": "code", |
| 24 | + "execution_count": null, |
24 | 25 | "metadata": {}, |
| 26 | + "outputs": [], |
25 | 27 | "source": [ |
26 | 28 | "import amici\n", |
| 29 | + "import numpy as np\n", |
27 | 30 | "\n", |
28 | 31 | "sbml_importer = amici.SbmlImporter(\"model_steadystate_scaled.xml\")" |
29 | | - ], |
30 | | - "outputs": [], |
31 | | - "execution_count": null |
| 32 | + ] |
32 | 33 | }, |
33 | 34 | { |
34 | 35 | "cell_type": "markdown", |
|
39 | 40 | }, |
40 | 41 | { |
41 | 42 | "cell_type": "code", |
| 43 | + "execution_count": null, |
42 | 44 | "metadata": {}, |
| 45 | + "outputs": [], |
43 | 46 | "source": [ |
44 | 47 | "model_name = \"model_steadystate\"\n", |
45 | 48 | "model_dir = \"model_dir\"\n", |
46 | 49 | "sbml_importer.sbml2amici(model_name, model_dir)" |
47 | | - ], |
48 | | - "outputs": [], |
49 | | - "execution_count": null |
| 50 | + ] |
50 | 51 | }, |
51 | 52 | { |
52 | 53 | "cell_type": "markdown", |
|
58 | 59 | }, |
59 | 60 | { |
60 | 61 | "cell_type": "code", |
| 62 | + "execution_count": null, |
61 | 63 | "metadata": {}, |
| 64 | + "outputs": [], |
62 | 65 | "source": [ |
63 | 66 | "# load the model module\n", |
64 | 67 | "model_module = amici.import_model_module(model_name, model_dir)\n", |
65 | 68 | "# instantiate model\n", |
66 | 69 | "model = model_module.get_model()\n", |
67 | 70 | "# instantiate solver\n", |
68 | 71 | "solver = model.create_solver()" |
69 | | - ], |
70 | | - "outputs": [], |
71 | | - "execution_count": null |
| 72 | + ] |
72 | 73 | }, |
73 | 74 | { |
74 | 75 | "cell_type": "markdown", |
|
77 | 78 | }, |
78 | 79 | { |
79 | 80 | "cell_type": "code", |
| 81 | + "execution_count": null, |
80 | 82 | "metadata": {}, |
81 | | - "source": "model.set_free_parameter_by_name(\"p1\", 1e-3)", |
82 | 83 | "outputs": [], |
83 | | - "execution_count": null |
| 84 | + "source": [ |
| 85 | + "model.set_free_parameter_by_name(\"p1\", 1e-3)" |
| 86 | + ] |
84 | 87 | }, |
85 | 88 | { |
86 | 89 | "cell_type": "markdown", |
|
89 | 92 | }, |
90 | 93 | { |
91 | 94 | "cell_type": "code", |
| 95 | + "execution_count": null, |
92 | 96 | "metadata": {}, |
93 | | - "source": "solver.set_absolute_tolerance(1e-10)", |
94 | 97 | "outputs": [], |
95 | | - "execution_count": null |
| 98 | + "source": [ |
| 99 | + "solver.set_absolute_tolerance(1e-10)" |
| 100 | + ] |
96 | 101 | }, |
97 | 102 | { |
98 | 103 | "cell_type": "markdown", |
|
108 | 113 | }, |
109 | 114 | { |
110 | 115 | "cell_type": "code", |
| 116 | + "execution_count": null, |
111 | 117 | "metadata": {}, |
| 118 | + "outputs": [], |
112 | 119 | "source": [ |
113 | 120 | "# set timepoints\n", |
114 | | - "model.set_timepoints([0, 1])\n", |
| 121 | + "model.set_timepoints(np.linspace(0, 10, 101))\n", |
115 | 122 | "rdata = model.simulate(solver=solver)" |
116 | | - ], |
117 | | - "outputs": [], |
118 | | - "execution_count": null |
| 123 | + ] |
119 | 124 | }, |
120 | 125 | { |
121 | 126 | "cell_type": "markdown", |
|
124 | 129 | }, |
125 | 130 | { |
126 | 131 | "cell_type": "code", |
| 132 | + "execution_count": null, |
127 | 133 | "metadata": {}, |
| 134 | + "outputs": [], |
128 | 135 | "source": [ |
129 | 136 | "rdata.x" |
130 | | - ], |
131 | | - "outputs": [], |
132 | | - "execution_count": null |
| 137 | + ] |
133 | 138 | }, |
134 | 139 | { |
135 | 140 | "cell_type": "markdown", |
136 | 141 | "metadata": {}, |
137 | | - "source": "All results attributes are always ordered according to the model. For species, this means that the columns of `rdata.x` match the ordering of species in the model, which can be accessed as [Model.get_state_names](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.html#amici.sim.sundials.Model.get_state_names)" |
| 142 | + "source": "All results attributes are always ordered according to the model. For species, this means that the columns of `rdata.x` match the ordering of species in the model, which can be accessed as [Model.get_state_names](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.html#amici.sim.sundials.Model.get_state_names) or as `ReturnData.state_names`:" |
138 | 143 | }, |
139 | 144 | { |
140 | 145 | "cell_type": "code", |
| 146 | + "execution_count": null, |
141 | 147 | "metadata": {}, |
142 | | - "source": "model.get_state_names()", |
143 | 148 | "outputs": [], |
144 | | - "execution_count": null |
| 149 | + "source": [ |
| 150 | + "model.get_state_names()" |
| 151 | + ] |
145 | 152 | }, |
146 | 153 | { |
147 | | - "metadata": {}, |
148 | 154 | "cell_type": "markdown", |
| 155 | + "metadata": {}, |
149 | 156 | "source": "For convenience, most results stored in `ReturnData` can also be retrieved as [xarray.DataArray](https://docs.xarray.dev/en/stable/index.html) objects that already include the respective row and column names. This can be accessed via the `xr` attribute of `ReturnData`. Here, we access the model state `x` as `DataArray` object to convert it to a `pandas.DataFrame`:" |
150 | 157 | }, |
151 | 158 | { |
| 159 | + "cell_type": "code", |
| 160 | + "execution_count": null, |
152 | 161 | "metadata": {}, |
| 162 | + "outputs": [], |
| 163 | + "source": [ |
| 164 | + "rdata.xr.x.to_pandas()" |
| 165 | + ] |
| 166 | + }, |
| 167 | + { |
153 | 168 | "cell_type": "code", |
154 | | - "source": "rdata.xr.x.to_pandas()", |
| 169 | + "execution_count": null, |
| 170 | + "metadata": {}, |
155 | 171 | "outputs": [], |
156 | | - "execution_count": null |
| 172 | + "source": [ |
| 173 | + "from amici.sim.sundials.plotting import *\n", |
| 174 | + "\n", |
| 175 | + "plot_state_trajectories(rdata)" |
| 176 | + ] |
157 | 177 | }, |
158 | 178 | { |
159 | 179 | "cell_type": "markdown", |
|
0 commit comments