|
27 | 27 | "import numpy as np\n", |
28 | 28 | "import scipy\n", |
29 | 29 | "import xarray as xr\n", |
30 | | - "import xgcm\n", |
31 | 30 | "from matplotlib.lines import Line2D\n", |
32 | 31 | "\n", |
33 | 32 | "import parcels" |
|
56 | 55 | " R = 0.32 * domainsizeX / 2\n", |
57 | 56 | "\n", |
58 | 57 | " x, y = np.meshgrid(lon, lat, sparse=True, indexing=\"xy\")\n", |
59 | | - " P_data = u0 * R**2 * y / ((x - x0) ** 2 + y**2) - u0 * y\n", |
60 | | - " landpoints = P_data >= 0.0\n", |
61 | | - " P_data[landpoints] = 0.0\n", |
| 58 | + " P = u0 * R**2 * y / ((x - x0) ** 2 + y**2) - u0 * y\n", |
| 59 | + " landpoints = P >= 0.0\n", |
| 60 | + " P[landpoints] = 0.0\n", |
62 | 61 | "\n", |
63 | 62 | " if grid_type == \"A\":\n", |
64 | | - " U_data = u0 - u0 * R**2 * ((x - x0) ** 2 - y**2) / (((x - x0) ** 2 + y**2) ** 2)\n", |
65 | | - " V_data = -2 * u0 * R**2 * ((x - x0) * y) / (((x - x0) ** 2 + y**2) ** 2)\n", |
66 | | - " U_data[landpoints] = 0.0\n", |
67 | | - " V_data[landpoints] = 0.0\n", |
| 63 | + " U = u0 - u0 * R**2 * ((x - x0) ** 2 - y**2) / (((x - x0) ** 2 + y**2) ** 2)\n", |
| 64 | + " V = -2 * u0 * R**2 * ((x - x0) * y) / (((x - x0) ** 2 + y**2) ** 2)\n", |
| 65 | + " U[landpoints] = 0.0\n", |
| 66 | + " V[landpoints] = 0.0\n", |
68 | 67 | " elif grid_type == \"C\":\n", |
69 | | - " U_data = np.zeros(P.shape)\n", |
70 | | - " V_data = np.zeros(P.shape)\n", |
71 | | - " V_data[:, 1:] = (P_data[:, 1:] - P_data[:, :-1]) / (lon[1] - lon[0])\n", |
72 | | - " U_data[1:, :] = -(P_data[1:, :] - P_data[:-1, :]) / (lat[1] - lat[0])\n", |
| 68 | + " U = np.zeros(P.shape)\n", |
| 69 | + " V = np.zeros(P.shape)\n", |
| 70 | + " V[:, 1:] = (P[:, 1:] - P[:, :-1]) / (lon[1] - lon[0])\n", |
| 71 | + " U[1:, :] = -(P[1:, :] - P[:-1, :]) / (lat[1] - lat[0])\n", |
73 | 72 | "\n", |
| 73 | + " data = {\"U\": U, \"V\": V, \"P\": P}\n", |
74 | 74 | " dimensions = {\"lon\": lon, \"lat\": lat}\n", |
75 | | - " grid = parcels.XGrid(xgcm.grid())\n", |
76 | | - " U = parcels.Field(\"U\", U_data, grid=, interp_method=)\n", |
77 | | - " V = parcels.Field(\"V\", V_data, grid=, interp_method=)\n", |
78 | | - " UV = parcels.VectorField(\"UV\", U, V, vector_interp_method=)\n", |
79 | | - " P = parcels.Field(\"P\", P_data, grid=, interp_method=)\n", |
80 | 75 | "\n", |
81 | | - " fieldset = parcels.FieldSet([U, V, P])\n", |
| 76 | + " fieldset = parcels.FieldSet.from_data(data, dimensions, mesh=\"flat\")\n", |
82 | 77 | " fieldset.U.interp_method = interp_method\n", |
83 | 78 | " fieldset.V.interp_method = interp_method\n", |
84 | 79 | " return fieldset" |
|
97 | 92 | "metadata": {}, |
98 | 93 | "outputs": [], |
99 | 94 | "source": [ |
100 | | - "def SampleP(particles, fieldset):\n", |
101 | | - " particles.p = fieldset.P[particles]\n", |
| 95 | + "def SampleP(particle, fieldset, time):\n", |
| 96 | + " particle.p = fieldset.P[time, particle.lon, particle.lat, particle.depth]\n", |
102 | 97 | "\n", |
103 | 98 | "\n", |
104 | 99 | "def DeleteParticle(particle, fieldset, time):\n", |
|
363 | 358 | ], |
364 | 359 | "metadata": { |
365 | 360 | "kernelspec": { |
366 | | - "display_name": "test-notebooks", |
| 361 | + "display_name": "parcels", |
367 | 362 | "language": "python", |
368 | 363 | "name": "python3" |
369 | 364 | }, |
|
377 | 372 | "name": "python", |
378 | 373 | "nbconvert_exporter": "python", |
379 | 374 | "pygments_lexer": "ipython3", |
380 | | - "version": "3.11.0" |
| 375 | + "version": "3.12.3" |
381 | 376 | } |
382 | 377 | }, |
383 | 378 | "nbformat": 4, |
|
0 commit comments