|
5 | 5 | "id": "0", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# Tutorial for using SWASH data in Parcels" |
| 8 | + "# 🖥️ SWASH tutorial" |
9 | 9 | ] |
10 | 10 | }, |
11 | 11 | { |
|
15 | 15 | "metadata": {}, |
16 | 16 | "outputs": [], |
17 | 17 | "source": [ |
18 | | - "import glob\n", |
19 | | - "\n", |
20 | 18 | "import matplotlib.pyplot as plt\n", |
21 | | - "import matplotlib.tri as mtri\n", |
22 | 19 | "import numpy as np\n", |
23 | | - "import uxarray as ux\n", |
24 | | - "import xarray as xr\n", |
25 | 20 | "\n", |
26 | 21 | "import parcels\n", |
27 | 22 | "import parcels.tutorial" |
|
34 | 29 | "metadata": {}, |
35 | 30 | "outputs": [], |
36 | 31 | "source": [ |
37 | | - "grid_file = parcels.tutorial.open_dataset(\"SWASH_data/data\", download_only=True)\n", |
38 | | - "print(grid_file)" |
| 32 | + "swash_files = parcels.tutorial.open_dataset(\"SWASH_data/data\", download_only=True)" |
39 | 33 | ] |
40 | 34 | }, |
41 | 35 | { |
|
45 | 39 | "metadata": {}, |
46 | 40 | "outputs": [], |
47 | 41 | "source": [ |
48 | | - "# grid_file = \"/Users/YanTo001/Documents/GitHub/parcels-data/data-matlab/F1GRD.mat\"#\"/Users/YanTo001/Library/Caches/parcels/data-matlab/F1GRD.mat\"\n", |
49 | | - "# result_file = \"/Users/YanTo001/Documents/GitHub/parcels-data/data-matlab/F1ALL.mat\"#\"/Users/YanTo001/Library/Caches/parcels/data-matlab/F1ALL.mat\"\n", |
50 | | - "# ds = parcels.convert.swash_to_sgrid(grid_file, result_file, total_depth=8.0)\n", |
51 | | - "ds = parcels.convert.swash_to_sgrid(grid_file[1], grid_file[0], total_depth=8.0)\n", |
52 | | - "\n", |
53 | | - "fieldset = parcels.FieldSet.from_sgrid_conventions(ds)" |
| 42 | + "ds = parcels.convert.swash_to_sgrid(\n", |
| 43 | + " data_file=swash_files[0], coord_file=swash_files[1], total_depth=8.0\n", |
| 44 | + ")\n", |
| 45 | + "fieldset = parcels.FieldSet.from_sgrid_conventions(ds)\n", |
| 46 | + "fieldset.describe()" |
54 | 47 | ] |
55 | 48 | }, |
56 | 49 | { |
|
60 | 53 | "metadata": {}, |
61 | 54 | "outputs": [], |
62 | 55 | "source": [ |
63 | | - "npart = 150 # number of particles to be released\n", |
64 | | - "# release particles in a line along a meridian\n", |
65 | | - "lat = np.linspace(1, 16, npart) ## y\n", |
66 | | - "lon = np.repeat(15, npart) ## x\n", |
67 | | - "time = np.repeat(ds.time.values[0], npart)\n", |
| 56 | + "npart = 10 # number of particles to be released\n", |
| 57 | + "y = np.linspace(1, 16, npart)\n", |
| 58 | + "x = np.repeat(15, npart)\n", |
| 59 | + "\n", |
68 | 60 | "layerI = 0 # at which water depth, the particles are released\n", |
69 | 61 | "z = np.repeat(ds.depth.values[layerI], npart)\n", |
70 | | - "pset = parcels.ParticleSet(\n", |
71 | | - " fieldset=fieldset, pclass=parcels.Particle, t=time, x=lon, y=lat, z=z\n", |
72 | | - ")\n", |
73 | | - "kernels = [parcels.kernels.AdvectionRK2]\n", |
| 62 | + "pset = parcels.ParticleSet(fieldset, x=x, y=y, z=z)\n", |
74 | 63 | "\n", |
75 | 64 | "output_file = parcels.ParticleFile(\n", |
76 | | - " \"output-quickstart.parquet\", outputdt=np.timedelta64(5, \"s\"), mode=\"w\"\n", |
77 | | - ") #\n", |
| 65 | + " \"output-swash.parquet\", outputdt=np.timedelta64(5, \"s\"), mode=\"w\"\n", |
| 66 | + ")\n", |
78 | 67 | "pset.execute(\n", |
79 | | - " kernels,\n", |
| 68 | + " parcels.kernels.AdvectionRK2,\n", |
80 | 69 | " runtime=np.timedelta64(20, \"s\"),\n", |
81 | | - " dt=np.timedelta64(5, \"s\"),\n", |
| 70 | + " dt=np.timedelta64(1, \"s\"),\n", |
82 | 71 | " output_file=output_file,\n", |
| 72 | + " verbose_progress=False,\n", |
83 | 73 | ")" |
84 | 74 | ] |
85 | 75 | }, |
|
90 | 80 | "metadata": {}, |
91 | 81 | "outputs": [], |
92 | 82 | "source": [ |
93 | | - "df = parcels.read_particlefile(\"output-quickstart.parquet\")\n", |
94 | | - "waterlevel = ds.isel(time=2).watlev.plot(cmap=\"magma\")\n", |
95 | | - "scatter = plt.scatter(df[\"x\"], df[\"y\"], c=df[\"t\"], s=10)\n", |
96 | | - "plt.scatter(\n", |
97 | | - " df[\"x\"][:npart], df[\"y\"][:npart], facecolors=\"none\", edgecolors=\"r\", s=10\n", |
98 | | - ") # starting positions" |
| 83 | + "df = parcels.read_particlefile(\"output-swash.parquet\")\n", |
| 84 | + "\n", |
| 85 | + "fig, ax = plt.subplots(figsize=(8, 4))\n", |
| 86 | + "waterlevel = ds.isel(time=2).watlev.plot(cmap=\"magma\", ax=ax)\n", |
| 87 | + "for traj in df.partition_by(\"particle_id\"):\n", |
| 88 | + " ax.plot(traj[\"x\"][0], traj[\"y\"][0], \"wo\", markersize=5)\n", |
| 89 | + " ax.plot(traj[\"x\"], traj[\"y\"], color=\"k\")\n", |
| 90 | + "ax.set_xlim([14, 16])\n", |
| 91 | + "plt.show()" |
99 | 92 | ] |
100 | 93 | }, |
101 | 94 | { |
|
107 | 100 | ], |
108 | 101 | "metadata": { |
109 | 102 | "kernelspec": { |
110 | | - "display_name": "Parcels:default (3.14.6)", |
| 103 | + "display_name": "Parcels:docs (3.14.6)", |
111 | 104 | "language": "python", |
112 | 105 | "name": "python3" |
113 | 106 | }, |
|
0 commit comments