Skip to content

Commit 2ba0d2a

Browse files
committed
update example
1 parent d54a743 commit 2ba0d2a

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

examples/07_cube_manipulation/pet_particles_drift.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"longitude",
2121
"latitude",
2222
"time",
23-
heigth="adt",
23+
unset=True
2424
)
2525

2626
# %%
@@ -34,7 +34,7 @@
3434
# Get paths
3535
x0, y0 = meshgrid(arange(32, 35, 0.5), arange(32.5, 34.5, 0.5))
3636
x0, y0 = x0.reshape(-1), y0.reshape(-1)
37-
t, x, y = c.path(x0, y0, "u", "v", t_init=t0, **kw_p, nb_time=nb_time)
37+
t, x, y = c.path(x0, y0, h_name="adt", t_init=t0, **kw_p, nb_time=nb_time)
3838

3939
# %%
4040
# Plot paths
@@ -43,4 +43,4 @@
4343
ax.plot(x, y, lw=3)
4444
ax.set_title("10 days particle paths")
4545
ax.set_xlim(31, 35), ax.set_ylim(32, 34.5)
46-
ax.grid()
46+
ax.grid()

notebooks/python_module/06_grid_manipulation/pet_advect.ipynb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\nGrid advection\n==============\n\nDummy advection which use only static geostrophic current, which didn't solve the complex circulation of the ocean.\n"
18+
"\n# Grid advection\n\nDummy advection which use only static geostrophic current, which didn't solve the complex circulation of the ocean.\n"
1919
]
2020
},
2121
{
@@ -98,7 +98,7 @@
9898
"cell_type": "markdown",
9999
"metadata": {},
100100
"source": [
101-
"Anim\n----\nParticles setup\n\n"
101+
"## Anim\nParticles setup\n\n"
102102
]
103103
},
104104
{
@@ -127,7 +127,7 @@
127127
},
128128
"outputs": [],
129129
"source": [
130-
"kwargs = dict(frames=arange(51), interval=100)\nkw_p = dict(nb_step=2, time_step=21600)\nframe_t = kw_p[\"nb_step\"] * kw_p[\"time_step\"] / 86400.0"
130+
"kwargs = dict(frames=arange(51), interval=100)\nkw_p = dict(u_name=\"u\", v_name=\"v\", nb_step=2, time_step=21600)\nframe_t = kw_p[\"nb_step\"] * kw_p[\"time_step\"] / 86400.0"
131131
]
132132
},
133133
{
@@ -152,7 +152,7 @@
152152
"cell_type": "markdown",
153153
"metadata": {},
154154
"source": [
155-
"Filament forward\n^^^^^^^^^^^^^^^^\nDraw 3 last position in one path for each particles.,\nit could be run backward with `backward=True` option in filament method\n\n"
155+
"### Filament forward\nDraw 3 last position in one path for each particles.,\nit could be run backward with `backward=True` option in filament method\n\n"
156156
]
157157
},
158158
{
@@ -163,14 +163,14 @@
163163
},
164164
"outputs": [],
165165
"source": [
166-
"p = g.filament(x, y, \"u\", \"v\", **kw_p, filament_size=3)\nfig, txt, l, t = anim_ax(lw=0.5)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(frame_t,))"
166+
"p = g.filament(x, y, **kw_p, filament_size=3)\nfig, txt, l, t = anim_ax(lw=0.5)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(frame_t,))"
167167
]
168168
},
169169
{
170170
"cell_type": "markdown",
171171
"metadata": {},
172172
"source": [
173-
"Particle forward\n^^^^^^^^^^^^^^^^^\nForward advection of particles\n\n"
173+
"### Particle forward\nForward advection of particles\n\n"
174174
]
175175
},
176176
{
@@ -181,7 +181,7 @@
181181
},
182182
"outputs": [],
183183
"source": [
184-
"p = g.advect(x, y, \"u\", \"v\", **kw_p)\nfig, txt, l, t = anim_ax(ls=\"\", marker=\".\", markersize=1)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(frame_t,))"
184+
"p = g.advect(x, y, **kw_p)\nfig, txt, l, t = anim_ax(ls=\"\", marker=\".\", markersize=1)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(frame_t,))"
185185
]
186186
},
187187
{
@@ -199,21 +199,21 @@
199199
},
200200
"outputs": [],
201201
"source": [
202-
"p = g.advect(x, y, \"u\", \"v\", **kw_p, backward=True)\nfig, txt, l, _ = anim_ax(ls=\"\", marker=\".\", markersize=1)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(-frame_t,))"
202+
"p = g.advect(x, y, **kw_p, backward=True)\nfig, txt, l, _ = anim_ax(ls=\"\", marker=\".\", markersize=1)\n_ = VideoAnimation(fig, update, **kwargs, fargs=(-frame_t,))"
203203
]
204204
},
205205
{
206206
"cell_type": "markdown",
207207
"metadata": {},
208208
"source": [
209-
"Particles stat\n--------------\n\n"
209+
"## Particles stat\n\n"
210210
]
211211
},
212212
{
213213
"cell_type": "markdown",
214214
"metadata": {},
215215
"source": [
216-
"Time_step settings\n^^^^^^^^^^^^^^^^^^\nDummy experiment to test advection precision, we run particles 50 days forward and backward with different time step\nand we measure distance between new positions and original positions.\n\n"
216+
"### Time_step settings\nDummy experiment to test advection precision, we run particles 50 days forward and backward with different time step\nand we measure distance between new positions and original positions.\n\n"
217217
]
218218
},
219219
{
@@ -224,14 +224,14 @@
224224
},
225225
"outputs": [],
226226
"source": [
227-
"fig = plt.figure()\nax = fig.add_subplot(111)\nkw = dict(\n bins=arange(0, 50, 0.001),\n cumulative=True,\n weights=ones(x0.shape) / x0.shape[0] * 100.0,\n histtype=\"step\",\n)\nfor time_step in (10800, 21600, 43200, 86400):\n x, y = x0.copy(), y0.copy()\n kw_advect = dict(nb_step=int(50 * 86400 / time_step), time_step=time_step)\n g.advect(x, y, \"u\", \"v\", **kw_advect).__next__()\n g.advect(x, y, \"u\", \"v\", **kw_advect, backward=True).__next__()\n d = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5\n ax.hist(d, **kw, label=f\"{86400. / time_step:.0f} time step by day\")\nax.set_xlim(0, 0.25), ax.set_ylim(0, 100), ax.legend(loc=\"lower right\"), ax.grid()\nax.set_title(\"Distance after 50 days forward and 50 days backward\")\nax.set_xlabel(\"Distance between original position and final position (in degrees)\")\n_ = ax.set_ylabel(\"Percent of particles with distance lesser than\")"
227+
"fig = plt.figure()\nax = fig.add_subplot(111)\nkw = dict(\n bins=arange(0, 50, 0.001),\n cumulative=True,\n weights=ones(x0.shape) / x0.shape[0] * 100.0,\n histtype=\"step\",\n)\nfor time_step in (10800, 21600, 43200, 86400):\n x, y = x0.copy(), y0.copy()\n kw_advect = dict(nb_step=int(50 * 86400 / time_step), time_step=time_step, u_name=\"u\", v_name=\"v\")\n g.advect(x, y, **kw_advect).__next__()\n g.advect(x, y, **kw_advect, backward=True).__next__()\n d = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5\n ax.hist(d, **kw, label=f\"{86400. / time_step:.0f} time step by day\")\nax.set_xlim(0, 0.25), ax.set_ylim(0, 100), ax.legend(loc=\"lower right\"), ax.grid()\nax.set_title(\"Distance after 50 days forward and 50 days backward\")\nax.set_xlabel(\"Distance between original position and final position (in degrees)\")\n_ = ax.set_ylabel(\"Percent of particles with distance lesser than\")"
228228
]
229229
},
230230
{
231231
"cell_type": "markdown",
232232
"metadata": {},
233233
"source": [
234-
"Time duration\n^^^^^^^^^^^^^\nWe keep same time_step but change time duration\n\n"
234+
"### Time duration\nWe keep same time_step but change time duration\n\n"
235235
]
236236
},
237237
{
@@ -242,7 +242,7 @@
242242
},
243243
"outputs": [],
244244
"source": [
245-
"fig = plt.figure()\nax = fig.add_subplot(111)\ntime_step = 10800\nfor duration in (5, 50, 100):\n x, y = x0.copy(), y0.copy()\n kw_advect = dict(nb_step=int(duration * 86400 / time_step), time_step=time_step)\n g.advect(x, y, \"u\", \"v\", **kw_advect).__next__()\n g.advect(x, y, \"u\", \"v\", **kw_advect, backward=True).__next__()\n d = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5\n ax.hist(d, **kw, label=f\"Time duration {duration} days\")\nax.set_xlim(0, 0.25), ax.set_ylim(0, 100), ax.legend(loc=\"lower right\"), ax.grid()\nax.set_title(\n \"Distance after N days forward and N days backward\\nwith a time step of 1/8 days\"\n)\nax.set_xlabel(\"Distance between original position and final position (in degrees)\")\n_ = ax.set_ylabel(\"Percent of particles with distance lesser than \")"
245+
"fig = plt.figure()\nax = fig.add_subplot(111)\ntime_step = 10800\nfor duration in (5, 50, 100):\n x, y = x0.copy(), y0.copy()\n kw_advect = dict(nb_step=int(duration * 86400 / time_step), time_step=time_step, u_name=\"u\", v_name=\"v\")\n g.advect(x, y, **kw_advect).__next__()\n g.advect(x, y, **kw_advect, backward=True).__next__()\n d = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5\n ax.hist(d, **kw, label=f\"Time duration {duration} days\")\nax.set_xlim(0, 0.25), ax.set_ylim(0, 100), ax.legend(loc=\"lower right\"), ax.grid()\nax.set_title(\n \"Distance after N days forward and N days backward\\nwith a time step of 1/8 days\"\n)\nax.set_xlabel(\"Distance between original position and final position (in degrees)\")\n_ = ax.set_ylabel(\"Percent of particles with distance lesser than \")"
246246
]
247247
}
248248
],
@@ -262,7 +262,7 @@
262262
"name": "python",
263263
"nbconvert_exporter": "python",
264264
"pygments_lexer": "ipython3",
265-
"version": "3.7.7"
265+
"version": "3.10.6"
266266
}
267267
},
268268
"nbformat": 4,

notebooks/python_module/06_grid_manipulation/pet_lavd.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\nLAVD experiment\n===============\n\nNaive method to reproduce LAVD(Lagrangian-Averaged Vorticity deviation) method with a static velocity field.\nIn the current example we didn't remove a mean vorticity.\n\nMethod are described here:\n\n - Abernathey, Ryan, and George Haller. \"Transport by Lagrangian Vortices in the Eastern Pacific\",\n Journal of Physical Oceanography 48, 3 (2018): 667-685, accessed Feb 16, 2021,\n https://doi.org/10.1175/JPO-D-17-0102.1\n - `Transport by Coherent Lagrangian Vortices`_,\n R. Abernathey, Sinha A., Tarshish N., Liu T., Zhang C., Haller G., 2019,\n Talk a t the Sources and Sinks of Ocean Mesoscale Eddy Energy CLIVAR Workshop\n\n https://usclivar.org/sites/default/files/meetings/2019/presentations/Aberernathey_CLIVAR.pdf\n"
18+
"\n# LAVD experiment\n\nNaive method to reproduce LAVD(Lagrangian-Averaged Vorticity deviation) method with a static velocity field.\nIn the current example we didn't remove a mean vorticity.\n\nMethod are described here:\n\n - Abernathey, Ryan, and George Haller. \"Transport by Lagrangian Vortices in the Eastern Pacific\",\n Journal of Physical Oceanography 48, 3 (2018): 667-685, accessed Feb 16, 2021,\n https://doi.org/10.1175/JPO-D-17-0102.1\n - `Transport by Coherent Lagrangian Vortices`_,\n R. Abernathey, Sinha A., Tarshish N., Liu T., Zhang C., Haller G., 2019,\n Talk a t the Sources and Sinks of Ocean Mesoscale Eddy Energy CLIVAR Workshop\n\n https://usclivar.org/sites/default/files/meetings/2019/presentations/Aberernathey_CLIVAR.pdf\n"
1919
]
2020
},
2121
{
@@ -55,7 +55,7 @@
5555
"cell_type": "markdown",
5656
"metadata": {},
5757
"source": [
58-
"Data\n----\nTo compute vorticity ($\\omega$) we compute u/v field with a stencil and apply the following equation with stencil\nmethod :\n\n\\begin{align}\\omega = \\frac{\\partial v}{\\partial x} - \\frac{\\partial u}{\\partial y}\\end{align}\n\n"
58+
"## Data\nTo compute vorticity ($\\omega$) we compute u/v field with a stencil and apply the following equation with stencil\nmethod :\n\n\\begin{align}\\omega = \\frac{\\partial v}{\\partial x} - \\frac{\\partial u}{\\partial y}\\end{align}\n\n"
5959
]
6060
},
6161
{
@@ -91,7 +91,7 @@
9191
"cell_type": "markdown",
9292
"metadata": {},
9393
"source": [
94-
"Particles\n---------\nParticles specification\n\n"
94+
"## Particles\nParticles specification\n\n"
9595
]
9696
},
9797
{
@@ -102,14 +102,14 @@
102102
},
103103
"outputs": [],
104104
"source": [
105-
"step = 1 / 32\nx_g, y_g = arange(0, 36, step), arange(28, 46, step)\nx, y = meshgrid(x_g, y_g)\noriginal_shape = x.shape\nx, y = x.reshape(-1), y.reshape(-1)\nprint(f\"{len(x)} particles advected\")\n# A frame every 8h\nstep_by_day = 3\n# Compute step of advection every 4h\nnb_step = 2\nkw_p = dict(nb_step=nb_step, time_step=86400 / step_by_day / nb_step)\n# Start a generator which at each iteration return new position at next time step\nparticule = g.advect(x, y, \"u\", \"v\", **kw_p, rk4=True)"
105+
"step = 1 / 32\nx_g, y_g = arange(0, 36, step), arange(28, 46, step)\nx, y = meshgrid(x_g, y_g)\noriginal_shape = x.shape\nx, y = x.reshape(-1), y.reshape(-1)\nprint(f\"{len(x)} particles advected\")\n# A frame every 8h\nstep_by_day = 3\n# Compute step of advection every 4h\nnb_step = 2\nkw_p = dict(nb_step=nb_step, time_step=86400 / step_by_day / nb_step, u_name=\"u\", v_name=\"v\")\n# Start a generator which at each iteration return new position at next time step\nparticule = g.advect(x, y, **kw_p, rk4=True)"
106106
]
107107
},
108108
{
109109
"cell_type": "markdown",
110110
"metadata": {},
111111
"source": [
112-
"LAVD\n----\n\n"
112+
"## LAVD\n\n"
113113
]
114114
},
115115
{
@@ -127,7 +127,7 @@
127127
"cell_type": "markdown",
128128
"metadata": {},
129129
"source": [
130-
"Anim\n^^^^\nMovie of LAVD integration at each integration time step.\n\n"
130+
"### Anim\nMovie of LAVD integration at each integration time step.\n\n"
131131
]
132132
},
133133
{
@@ -145,7 +145,7 @@
145145
"cell_type": "markdown",
146146
"metadata": {},
147147
"source": [
148-
"Final LAVD\n^^^^^^^^^^\n\n"
148+
"### Final LAVD\n\n"
149149
]
150150
},
151151
{
@@ -163,7 +163,7 @@
163163
},
164164
"outputs": [],
165165
"source": [
166-
"lavd = RegularGridDataset.with_array(\n coordinates=(\"lon\", \"lat\"),\n datas=dict(lavd=lavd.T, lon=x_g, lat=y_g,),\n centered=True,\n)"
166+
"lavd = RegularGridDataset.with_array(\n coordinates=(\"lon\", \"lat\"), datas=dict(lavd=lavd.T, lon=x_g, lat=y_g), centered=True\n)"
167167
]
168168
},
169169
{
@@ -201,7 +201,7 @@
201201
"name": "python",
202202
"nbconvert_exporter": "python",
203203
"pygments_lexer": "ipython3",
204-
"version": "3.7.7"
204+
"version": "3.10.6"
205205
}
206206
},
207207
"nbformat": 4,

0 commit comments

Comments
 (0)