|
5 | 5 | "cell_type": "markdown", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# 🖥️ Using `parcels.interpolators`\n", |
9 | | - "Parcels comes with a number of different interpolation methods for fields on structured (`X`) and unstructured (`Ux`) grids. Here, we will look at a few common {py:obj}`parcels.interpolators` for tracer fiedls, and how to configure them in an idealised example. For more guidance on the sampling of such fields, check out the [sampling tutorial](./tutorial_sampling)." |
| 8 | + "# 🖥️ Using the built-in `parcels.interpolators`\n", |
| 9 | + "Parcels comes with a number of different interpolation methods for fields on structured (`X`) and unstructured (`Ux`) grids. Here, we will look at a few common {py:obj}`parcels.interpolators` for tracer fields, and how to configure them in an idealised example. For more guidance on the sampling of such fields, check out the [sampling tutorial](./tutorial_sampling)." |
10 | 10 | ] |
11 | 11 | }, |
12 | 12 | { |
|
72 | 72 | "source": [ |
73 | 73 | "fieldset = parcels.FieldSet.from_sgrid_conventions(ds, mesh=\"flat\")\n", |
74 | 74 | "\n", |
75 | | - "assert fieldset.P.interp_method == parcels.interpolators.XLinear" |
| 75 | + "assert isinstance(fieldset.P.interp_method, parcels.interpolators.XLinear)" |
76 | 76 | ] |
77 | 77 | }, |
78 | 78 | { |
|
124 | 124 | " XNearest,\n", |
125 | 125 | ")\n", |
126 | 126 | "\n", |
127 | | - "interp_methods = [XLinear, XLinearInvdistLandTracer, XNearest, CGrid_Tracer]\n", |
| 127 | + "interp_methods = [XLinear(), XLinearInvdistLandTracer(), XNearest(), CGrid_Tracer()]\n", |
128 | 128 | "for p_interp in interp_methods:\n", |
129 | 129 | " fieldset.P.interp_method = (\n", |
130 | 130 | " p_interp # setting the interpolation method for fieldset.P\n", |
131 | 131 | " )\n", |
132 | 132 | "\n", |
133 | | - " print(fieldset.P.interp_method.__name__)\n", |
| 133 | + " print(fieldset.P.interp_method)\n", |
134 | 134 | " xv, yv = np.meshgrid(np.linspace(0, 1, 8), np.linspace(0, 1, 8))\n", |
135 | | - " pset[p_interp.__name__] = parcels.ParticleSet(\n", |
| 135 | + " pset[p_interp.__class__.__name__] = parcels.ParticleSet(\n", |
136 | 136 | " fieldset, pclass=SampleParticle, lon=xv.flatten(), lat=yv.flatten()\n", |
137 | 137 | " )\n", |
138 | | - " pset[p_interp.__name__].execute(\n", |
| 138 | + " pset[p_interp.__class__.__name__].execute(\n", |
139 | 139 | " SampleP,\n", |
140 | 140 | " runtime=np.timedelta64(1, \"D\"),\n", |
141 | 141 | " dt=np.timedelta64(1, \"D\"),\n", |
|
188 | 188 | "\n", |
189 | 189 | "For `interp_method='XNearest'`, the particle values are the same for all particles in a grid cell. They are also the same for `interp_method='CGrid_Tracer'`, but the grid cells have then shifted. That is because in a C-grid, the tracer is defined on the corners of the velocity grid (black dashed lines in right-most panel).\n", |
190 | 190 | "\n", |
191 | | - "```{note}\n", |
192 | | - "TODO: check C-grid indexing after implementation in v4\n", |
193 | | - "```\n", |
194 | | - "\n", |
195 | 191 | "For `interp_method='XLinearInvdistLandTracer'`, we see that values are the same as `interp_method='XLinear'` for grid cells that don't border the land point. For grid cells that do border the land cell, the `XLinearInvdistLandTracer` interpolation method gives higher values, as also shown in the difference plot below.\n" |
196 | 192 | ] |
197 | 193 | }, |
|
462 | 458 | "ax[1].set_aspect(\"equal\", \"box\")\n", |
463 | 459 | "ax[1].set_xlabel(\"x\")\n", |
464 | 460 | "ax[1].set_ylabel(\"y\")\n", |
465 | | - "ax[1].set_title(\"Face Registered Data\")" |
| 461 | + "ax[1].set_title(\"Face Registered Data\")\n", |
| 462 | + "plt.show()" |
466 | 463 | ] |
467 | 464 | }, |
468 | 465 | { |
|
483 | 480 | ], |
484 | 481 | "metadata": { |
485 | 482 | "kernelspec": { |
486 | | - "display_name": "test-notebooks", |
| 483 | + "display_name": "Parcels:docs (3.14.6)", |
487 | 484 | "language": "python", |
488 | 485 | "name": "python3" |
489 | 486 | }, |
|
497 | 494 | "name": "python", |
498 | 495 | "nbconvert_exporter": "python", |
499 | 496 | "pygments_lexer": "ipython3", |
500 | | - "version": "3.13.9" |
| 497 | + "version": "3.14.6" |
501 | 498 | } |
502 | 499 | }, |
503 | 500 | "nbformat": 4, |
|
0 commit comments