|
80 | 80 | "time = ds_fields.time.values[0] + np.arange(0, npart) * np.timedelta64(2, \"h\")\n", |
81 | 81 | "\n", |
82 | 82 | "pset = parcels.ParticleSet(\n", |
83 | | - " fieldset=fieldset, pclass=parcels.Particle, x=lon, y=lat, z=z, time=time\n", |
| 83 | + " fieldset=fieldset, pclass=parcels.Particle, x=lon, y=lat, z=z, t=time\n", |
84 | 84 | ")\n", |
85 | 85 | "\n", |
86 | 86 | "output_file = parcels.ParticleFile(\"output.parquet\", outputdt=np.timedelta64(2, \"h\"))" |
|
194 | 194 | "cell_type": "markdown", |
195 | 195 | "metadata": {}, |
196 | 196 | "source": [ |
197 | | - "As you may have noticed above, the `time` is shown as a `float64` (in seconds) in `df_polars`. That is because `polars.read_parquet` does not automatically convert the cftime. To handle this, we also provide a helper function `parcels.read_particlefile` to read ParticleFiles, which does automatically convert the cftime. " |
| 197 | + "As you may have noticed above, the `t` is shown as a `float64` (in seconds) in `df_polars`. That is because `polars.read_parquet` does not automatically convert the cftime. To handle this, we also provide a helper function `parcels.read_particlefile` to read ParticleFiles, which does automatically convert the cftime. " |
198 | 198 | ] |
199 | 199 | }, |
200 | 200 | { |
|
226 | 226 | "source": [ |
227 | 227 | "for traj in df_particles.partition_by(\"particle_id\", maintain_order=True):\n", |
228 | 228 | " time_origin = pd.Timestamp(fieldset.time_interval.left).to_pydatetime()\n", |
229 | | - " time_in_hour = (traj[\"time\"] - time_origin).dt.total_hours()\n", |
| 229 | + " time_in_hour = (traj[\"t\"] - time_origin).dt.total_hours()\n", |
230 | 230 | " traj_id = traj[\"particle_id\"][0]\n", |
231 | 231 | " print(f\"Particle {traj_id}: \" + \"\".join(f\"{int(t):2d} \" for t in time_in_hour))" |
232 | 232 | ] |
|
303 | 303 | "source": [ |
304 | 304 | "time_step = np.timedelta64(18, \"h\")\n", |
305 | 305 | "time_to_plot = fieldset.time_interval.left + time_step\n", |
306 | | - "particles = df_particles.filter(pl.col(\"time\") == pl.lit(time_to_plot))\n", |
| 306 | + "particles = df_particles.filter(pl.col(\"t\") == pl.lit(time_to_plot))\n", |
307 | 307 | "\n", |
308 | 308 | "fig, ax = plt.subplots(figsize=(5, 3))\n", |
309 | 309 | "ax.plot(particles[\"x\"], particles[\"y\"], \"o\")\n", |
|
327 | 327 | "source": [ |
328 | 328 | "time_step = np.timedelta64(18, \"h\")\n", |
329 | 329 | "particles = df_particles.filter(\n", |
330 | | - " (pl.col(\"time\") - pl.col(\"time\").min().over(\"particle_id\")) == pl.lit(time_step)\n", |
| 330 | + " (pl.col(\"t\") - pl.col(\"t\").min().over(\"particle_id\")) == pl.lit(time_step)\n", |
331 | 331 | ")\n", |
332 | 332 | "\n", |
333 | 333 | "fig, ax = plt.subplots(figsize=(5, 3))\n", |
|
355 | 355 | " distance = np.sqrt(\n", |
356 | 356 | " (traj[\"x\"] - traj[\"x\"][0]) ** 2 + (traj[\"y\"] - traj[\"y\"][0]) ** 2\n", |
357 | 357 | " )\n", |
358 | | - " ax[0].plot(traj[\"time\"], distance, \".-\", label=f\"P{traj['particle_id'][0]}\")\n", |
| 358 | + " ax[0].plot(traj[\"t\"], distance, \".-\", label=f\"P{traj['particle_id'][0]}\")\n", |
359 | 359 | "\n", |
360 | | - " rel_time = (traj[\"time\"] - traj[\"time\"][0]).dt.total_hours()\n", |
| 360 | + " rel_time = (traj[\"t\"] - traj[\"t\"][0]).dt.total_hours()\n", |
361 | 361 | " ax[1].plot(rel_time, distance, \".-\", label=f\"P{traj['particle_id'][0]}\")\n", |
362 | 362 | "\n", |
363 | 363 | "ax[0].set_xlabel(\"Date\")\n", |
|
410 | 410 | "time_step = np.timedelta64(2, \"h\") # time step for animation frames\n", |
411 | 411 | "\n", |
412 | 412 | "timerange = np.arange(\n", |
413 | | - " np.nanmin(df_particles[\"time\"]),\n", |
414 | | - " np.nanmax(df_particles[\"time\"]) + time_step,\n", |
| 413 | + " np.nanmin(df_particles[\"t\"]),\n", |
| 414 | + " np.nanmax(df_particles[\"t\"]) + time_step,\n", |
415 | 415 | " time_step,\n", |
416 | 416 | ")\n", |
417 | 417 | "\n", |
|
436 | 436 | "ax.add_feature(cfeature.LAND)\n", |
437 | 437 | "\n", |
438 | 438 | "# --> plot first timestep\n", |
439 | | - "particles = df_particles.filter(pl.col(\"time\") == pl.lit(timerange[0]))\n", |
| 439 | + "particles = df_particles.filter(pl.col(\"t\") == pl.lit(timerange[0]))\n", |
440 | 440 | "scatter = ax.scatter(\n", |
441 | 441 | " particles[\"x\"],\n", |
442 | 442 | " particles[\"y\"],\n", |
|
460 | 460 | " title.set_text(f\"Particles at t = {t_str}\")\n", |
461 | 461 | "\n", |
462 | 462 | " # Find particles at current time\n", |
463 | | - " particles = df_particles.filter(pl.col(\"time\") == pl.lit(timerange[i]))\n", |
| 463 | + " particles = df_particles.filter(pl.col(\"t\") == pl.lit(timerange[i]))\n", |
464 | 464 | "\n", |
465 | 465 | " if len(particles) > 0:\n", |
466 | 466 | " scatter.set_offsets(np.c_[particles[\"x\"], particles[\"y\"]])\n", |
|
475 | 475 | " for traj in particles[\"particle_id\"].unique():\n", |
476 | 476 | " traj_trail = df_particles.filter(\n", |
477 | 477 | " (pl.col(\"particle_id\") == traj)\n", |
478 | | - " & (pl.col(\"time\") >= pl.lit(timerange[max(0, i - trail_length)]))\n", |
479 | | - " & (pl.col(\"time\") <= pl.lit(timerange[i]))\n", |
| 478 | + " & (pl.col(\"t\") >= pl.lit(timerange[max(0, i - trail_length)]))\n", |
| 479 | + " & (pl.col(\"t\") <= pl.lit(timerange[i]))\n", |
480 | 480 | " )\n", |
481 | 481 | " if len(traj_trail) > 1:\n", |
482 | 482 | " (trail,) = ax.plot(\n", |
|
0 commit comments