|
231 | 231 | " (u1, v1) = fieldset.UV[particles]\n", |
232 | 232 | " x1 = particles.x + u1 * 0.5 * particles.dt\n", |
233 | 233 | " y1 = particles.y + v1 * 0.5 * particles.dt\n", |
234 | | - " x1 = np.where(x1 > 180, x1 - 360, x1) # keep particles within [-180, 180]\n", |
| 234 | + " x1 = ((x1 + 180) % 360) - 180 # keep x1 within [-180, 180]\n", |
235 | 235 | "\n", |
236 | 236 | " (u2, v2) = fieldset.UV[\n", |
237 | 237 | " particles.t + 0.5 * particles.dt, particles.z, y1, x1, particles\n", |
238 | 238 | " ]\n", |
239 | 239 | " particles.dx += u2 * particles.dt\n", |
240 | 240 | " particles.dy += v2 * particles.dt\n", |
241 | 241 | "\n", |
242 | | - " # update particles.dx to stay within [-180, 180]\n", |
243 | | - " particles.dx = np.where(\n", |
244 | | - " particles.x + particles.dx > 180, particles.dx - 360, particles.dx\n", |
245 | | - " )\n", |
| 242 | + " # update particles.dx so particles.x + particles.dx stays within [-180, 180]\n", |
| 243 | + " particles.dx = ((particles.x + particles.dx + 180) % 360) - 180 - particles.x\n", |
246 | 244 | "\n", |
247 | 245 | "\n", |
248 | 246 | "pset = parcels.ParticleSet(fieldset, x=lonp, y=latp)\n", |
|
0 commit comments