|
251 | 251 | "- UXPiecewiseLinearNode" |
252 | 252 | ] |
253 | 253 | }, |
| 254 | + { |
| 255 | + "cell_type": "code", |
| 256 | + "execution_count": null, |
| 257 | + "metadata": {}, |
| 258 | + "outputs": [], |
| 259 | + "source": [ |
| 260 | + "from parcels._datasets.unstructured.generated import simple_small_delaunay\n", |
| 261 | + "\n", |
| 262 | + "ds = simple_small_delaunay(nx=4, ny=4)\n", |
| 263 | + "ds" |
| 264 | + ] |
| 265 | + }, |
| 266 | + { |
| 267 | + "cell_type": "code", |
| 268 | + "execution_count": null, |
| 269 | + "metadata": {}, |
| 270 | + "outputs": [], |
| 271 | + "source": [ |
| 272 | + "import parcels\n", |
| 273 | + "\n", |
| 274 | + "grid = parcels.UxGrid(ds.uxgrid, ds.nz, mesh=\"flat\")\n", |
| 275 | + "U = parcels.Field(\n", |
| 276 | + " \"U\", ds[\"U\"], grid, interp_method=parcels.interpolators.UXPiecewiseConstantFace\n", |
| 277 | + ")\n", |
| 278 | + "V = parcels.Field(\n", |
| 279 | + " \"V\", ds[\"V\"], grid, interp_method=parcels.interpolators.UXPiecewiseConstantFace\n", |
| 280 | + ")\n", |
| 281 | + "UV = parcels.VectorField(\"UV\", U, V)\n", |
| 282 | + "Tnode = parcels.Field(\n", |
| 283 | + " \"T_node\",\n", |
| 284 | + " ds[\"T_node\"],\n", |
| 285 | + " grid,\n", |
| 286 | + " interp_method=parcels.interpolators.UXPiecewiseLinearNode,\n", |
| 287 | + ")\n", |
| 288 | + "Tface = parcels.Field(\n", |
| 289 | + " \"T_face\",\n", |
| 290 | + " ds[\"T_face\"],\n", |
| 291 | + " grid,\n", |
| 292 | + " interp_method=parcels.interpolators.UXPiecewiseConstantFace,\n", |
| 293 | + ")\n", |
| 294 | + "fieldset = parcels.FieldSet([U, V, UV, Tnode, Tface])" |
| 295 | + ] |
| 296 | + }, |
| 297 | + { |
| 298 | + "cell_type": "code", |
| 299 | + "execution_count": null, |
| 300 | + "metadata": {}, |
| 301 | + "outputs": [], |
| 302 | + "source": [ |
| 303 | + "import matplotlib.pyplot as plt\n", |
| 304 | + "import matplotlib.tri as mtri\n", |
| 305 | + "import numpy as np\n", |
| 306 | + "\n", |
| 307 | + "fig, ax = plt.subplots(1, 2, figsize=(10, 5), constrained_layout=True)\n", |
| 308 | + "\n", |
| 309 | + "x = ds.uxgrid.node_lon.values\n", |
| 310 | + "y = ds.uxgrid.node_lat.values\n", |
| 311 | + "tri = ds.uxgrid.face_node_connectivity.values\n", |
| 312 | + "triang = mtri.Triangulation(x, y, triangles=tri)\n", |
| 313 | + "\n", |
| 314 | + "\n", |
| 315 | + "# Shade the triangle faces using smooth shading between the node registered data\n", |
| 316 | + "T_node = np.squeeze(ds[\"T_node\"][0, 0, :].values)\n", |
| 317 | + "tpc = ax[0].tripcolor(\n", |
| 318 | + " triang,\n", |
| 319 | + " T_node,\n", |
| 320 | + " shading=\"gouraud\", # smooth shading\n", |
| 321 | + " cmap=\"viridis\",\n", |
| 322 | + " vmin=-1.0,\n", |
| 323 | + " vmax=1.0,\n", |
| 324 | + ")\n", |
| 325 | + "# Plot the element edges\n", |
| 326 | + "ax[0].triplot(triang, color=\"black\", linewidth=0.5)\n", |
| 327 | + "\n", |
| 328 | + "# Plot the node registered data\n", |
| 329 | + "sc1 = ax[0].scatter(\n", |
| 330 | + " x, y, c=T_node, cmap=\"viridis\", s=150, edgecolors=\"black\", vmin=-1.0, vmax=1.0\n", |
| 331 | + ")\n", |
| 332 | + "\n", |
| 333 | + "cbar = fig.colorbar(sc1, ax=ax[0])\n", |
| 334 | + "cbar.set_label(\"T\")\n", |
| 335 | + "\n", |
| 336 | + "ax[0].set_aspect(\"equal\", \"box\")\n", |
| 337 | + "ax[0].set_xlabel(\"x\")\n", |
| 338 | + "ax[0].set_ylabel(\"y\")\n", |
| 339 | + "ax[0].set_title(\"Node Registered Data\")\n", |
| 340 | + "\n", |
| 341 | + "# # Plot the face registered data\n", |
| 342 | + "T_face = np.squeeze(ds[\"T_face\"][0, 0, :].values)\n", |
| 343 | + "tpc = ax[1].tripcolor(\n", |
| 344 | + " triang,\n", |
| 345 | + " T_face,\n", |
| 346 | + " shading=\"flat\",\n", |
| 347 | + " cmap=\"viridis\",\n", |
| 348 | + " edgecolors=\"k\",\n", |
| 349 | + " linewidth=0.5,\n", |
| 350 | + " vmin=-1.0,\n", |
| 351 | + " vmax=1.0,\n", |
| 352 | + ")\n", |
| 353 | + "# Plot the element edges\n", |
| 354 | + "ax[1].triplot(triang, color=\"black\", linewidth=0.5)\n", |
| 355 | + "\n", |
| 356 | + "# Plot the node registered data\n", |
| 357 | + "xf = ds.uxgrid.face_lon.values\n", |
| 358 | + "yf = ds.uxgrid.face_lat.values\n", |
| 359 | + "sc2 = ax[1].scatter(\n", |
| 360 | + " xf, yf, c=T_face, cmap=\"viridis\", s=150, edgecolors=\"black\", vmin=-1.0, vmax=1.0\n", |
| 361 | + ")\n", |
| 362 | + "\n", |
| 363 | + "cbar = fig.colorbar(sc2, ax=ax[1])\n", |
| 364 | + "cbar.set_label(\"T\")\n", |
| 365 | + "\n", |
| 366 | + "ax[1].set_aspect(\"equal\", \"box\")\n", |
| 367 | + "ax[1].set_xlabel(\"x\")\n", |
| 368 | + "ax[1].set_ylabel(\"y\")\n", |
| 369 | + "ax[1].set_title(\"Face Registered Data\")" |
| 370 | + ] |
| 371 | + }, |
254 | 372 | { |
255 | 373 | "cell_type": "markdown", |
256 | 374 | "metadata": {}, |
|
272 | 390 | ], |
273 | 391 | "metadata": { |
274 | 392 | "kernelspec": { |
275 | | - "display_name": "test-notebooks", |
| 393 | + "display_name": "Python 3 (ipykernel)", |
276 | 394 | "language": "python", |
277 | 395 | "name": "python3" |
278 | 396 | }, |
|
286 | 404 | "name": "python", |
287 | 405 | "nbconvert_exporter": "python", |
288 | 406 | "pygments_lexer": "ipython3", |
289 | | - "version": "3.11.0" |
| 407 | + "version": "3.12.11" |
290 | 408 | } |
291 | 409 | }, |
292 | 410 | "nbformat": 4, |
|
0 commit comments