|
259 | 259 | " face_poly[np.newaxis, np.newaxis, :],\n", |
260 | 260 | " {\n", |
261 | 261 | " \"long_name\": \"Nest id\",\n", |
262 | | - " \"description\": \"0=regional, 1=coastal\",\n", |
| 262 | + " \"description\": \"2=regional, 1=coastal, 0=harbour\",\n", |
263 | 263 | " \"location\": \"face\",\n", |
264 | 264 | " \"mesh\": \"delaunay\",\n", |
265 | 265 | " },\n", |
|
425 | 425 | " particles.dlon += u * particles.dt\n", |
426 | 426 | " particles.dlat += v * particles.dt\n", |
427 | 427 | "\n", |
| 428 | + " # TODO particle states have to be updated manually because UVField is not called with `particles` argument (becaise of GH #2143)\n", |
| 429 | + " particles.state = np.where(\n", |
| 430 | + " np.isnan(u) | np.isnan(v),\n", |
| 431 | + " parcels.StatusCode.ErrorInterpolation,\n", |
| 432 | + " particles.state,\n", |
| 433 | + " )\n", |
| 434 | + "\n", |
| 435 | + "\n", |
| 436 | + "def DeleteErrorParticles(particles, fieldset):\n", |
| 437 | + " any_error = particles.state >= 50 # This captures all Errors\n", |
| 438 | + " particles[any_error].state = parcels.StatusCode.Delete\n", |
| 439 | + "\n", |
| 440 | + "\n", |
| 441 | + "X, Y = np.meshgrid(\n", |
| 442 | + " np.linspace(1.22, 1.26, 5),\n", |
| 443 | + " np.linspace(41.02, 41.08, 4),\n", |
| 444 | + ")\n", |
428 | 445 | "\n", |
429 | 446 | "pset = parcels.ParticleSet(\n", |
430 | 447 | " fieldset, pclass=NestParticle, lon=X.flatten(), lat=Y.flatten()\n", |
431 | 448 | ")\n", |
432 | 449 | "ofile = parcels.ParticleFile(\"nest_particles.zarr\", outputdt=np.timedelta64(1, \"h\"))\n", |
433 | 450 | "pset.execute(\n", |
434 | | - " AdvectEE_Nests,\n", |
435 | | - " runtime=np.timedelta64(24, \"h\"),\n", |
| 451 | + " [AdvectEE_Nests, DeleteErrorParticles],\n", |
| 452 | + " runtime=np.timedelta64(5, \"D\") - np.timedelta64(1, \"h\"),\n", |
436 | 453 | " dt=np.timedelta64(1, \"h\"),\n", |
437 | 454 | " output_file=ofile,\n", |
438 | 455 | ")" |
|
453 | 470 | "metadata": {}, |
454 | 471 | "outputs": [], |
455 | 472 | "source": [ |
456 | | - "fig, ax = plt.subplots(1, 1, figsize=(10, 5))\n", |
| 473 | + "fig, ax = plt.subplots(1, 1, figsize=(10, 3))\n", |
457 | 474 | "\n", |
458 | 475 | "ds_out = xr.open_zarr(\"nest_particles.zarr\")\n", |
459 | 476 | "\n", |
460 | 477 | "cmap = plt.get_cmap(\"viridis\", 3)\n", |
| 478 | + "plt.plot(ds_out.lon.T, ds_out.lat.T, \"k\", linewidth=0.5)\n", |
461 | 479 | "sc = ax.scatter(ds_out.lon, ds_out.lat, c=ds_out.nestID, s=4, cmap=cmap, vmin=0, vmax=2)\n", |
| 480 | + "xl, yl = ax.get_xlim(), ax.get_ylim()\n", |
| 481 | + "\n", |
| 482 | + "for rect in rectangle.values():\n", |
| 483 | + " ax.plot(\n", |
| 484 | + " np.append(rect[:, 0], rect[0, 0]), np.append(rect[:, 1], rect[0, 1]), \"-r\", lw=1\n", |
| 485 | + " )\n", |
| 486 | + "ax.set_xlim(xl)\n", |
| 487 | + "ax.set_ylim(yl)\n", |
| 488 | + "ax.set_aspect(\"equal\")\n", |
462 | 489 | "\n", |
463 | 490 | "cbar = plt.colorbar(sc, ticks=[0, 1, 2], ax=ax)\n", |
464 | 491 | "cbar.set_label(\"Nest ID\")\n", |
465 | 492 | "ax.set_title(\"Particle advection through nests\")\n", |
| 493 | + "plt.tight_layout\n", |
466 | 494 | "plt.show()" |
467 | 495 | ] |
468 | 496 | } |
|
0 commit comments