Skip to content

Commit 7625178

Browse files
authored
Merge pull request #103 from vadmbertr/docs-typos
Fix some typos in the doc
2 parents a0ed080 + 3733200 commit 7625178

5 files changed

Lines changed: 64 additions & 101 deletions

File tree

docs/examples/duacs.ipynb

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 2,
29+
"execution_count": null,
3030
"id": "9b8f05cd-b082-4d59-b552-6ee23a22e779",
3131
"metadata": {
3232
"ExecuteTime": {
@@ -37,16 +37,7 @@
3737
"hide-input"
3838
]
3939
},
40-
"outputs": [
41-
{
42-
"name": "stderr",
43-
"output_type": "stream",
44-
"text": [
45-
"/Users/bertrava/miniforge3/envs/jaxparrow/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
46-
" from .autonotebook import tqdm as notebook_tqdm\n"
47-
]
48-
}
49-
],
40+
"outputs": [],
5041
"source": [
5142
"import cartopy.crs as ccrs\n",
5243
"import cmocean.cm as cmo\n",
@@ -98,24 +89,18 @@
9889
},
9990
{
10091
"cell_type": "code",
101-
"execution_count": 3,
92+
"execution_count": null,
10293
"id": "58e0299b-feab-40d7-9927-39dc05a93d01",
10394
"metadata": {
10495
"ExecuteTime": {
10596
"end_time": "2024-06-10T13:46:14.436118Z",
10697
"start_time": "2024-06-10T13:45:55.061171Z"
107-
}
98+
},
99+
"tags": [
100+
"hide-input"
101+
]
108102
},
109-
"outputs": [
110-
{
111-
"name": "stderr",
112-
"output_type": "stream",
113-
"text": [
114-
"INFO - 2026-03-06T16:31:36Z - Selected dataset version: \"202411\"\n",
115-
"INFO - 2026-03-06T16:31:36Z - Selected dataset part: \"default\"\n"
116-
]
117-
}
118-
],
103+
"outputs": [],
119104
"source": [
120105
"dataset_options = {\n",
121106
" \"dataset_id\": \"cmems_obs-sl_glo_phy-ssh_my_allsat-l4-duacs-0.125deg_P1D\",\n",
@@ -179,29 +164,6 @@
179164
"## Reconstructing cyclogeostrophic currents using `jaxparrow`"
180165
]
181166
},
182-
{
183-
"cell_type": "markdown",
184-
"id": "d86fcbd4-a3f9-4c9e-aeae-b7737a351ba2",
185-
"metadata": {},
186-
"source": [
187-
"`jaxparrow` uses C-grids, following NEMO convention. U, V, and F points are automatically derived from the T points."
188-
]
189-
},
190-
{
191-
"cell_type": "code",
192-
"execution_count": 5,
193-
"id": "c34b9f78-3c33-4e66-8051-0933da97f16f",
194-
"metadata": {
195-
"ExecuteTime": {
196-
"end_time": "2024-06-10T13:46:20.842589Z",
197-
"start_time": "2024-06-10T13:46:20.622322Z"
198-
}
199-
},
200-
"outputs": [],
201-
"source": [
202-
"lon_t, lat_t = jnp.meshgrid(duacs_ds.longitude.values, duacs_ds.latitude.values)"
203-
]
204-
},
205167
{
206168
"cell_type": "markdown",
207169
"id": "1983b1f8-a7f9-4559-b589-8787c4525061",
@@ -225,7 +187,10 @@
225187
"ExecuteTime": {
226188
"end_time": "2024-06-10T13:46:21.798714Z",
227189
"start_time": "2024-06-10T13:46:20.873348Z"
228-
}
190+
},
191+
"tags": [
192+
"hide-input"
193+
]
229194
},
230195
"outputs": [],
231196
"source": [
@@ -259,6 +224,8 @@
259224
"\n",
260225
"BATCH_SIZE = 10\n",
261226
"\n",
227+
"lon_t, lat_t = jnp.meshgrid(duacs_ds.longitude.values, duacs_ds.latitude.values)\n",
228+
"\n",
262229
"duacs_ds = duacs_ds.where(np.abs(lat_t) >= 5)\n",
263230
"duacs_ds = duacs_ds.chunk(chunks={\"time\": BATCH_SIZE, \"latitude\": -1, \"longitude\": -1})\n",
264231
"\n",

docs/examples/gradient_wind.ipynb

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,11 @@
7070
},
7171
{
7272
"cell_type": "code",
73-
"execution_count": 4,
74-
"metadata": {
75-
"tags": [
76-
"hide-input"
77-
]
78-
},
79-
"outputs": [
80-
{
81-
"name": "stderr",
82-
"output_type": "stream",
83-
"text": [
84-
"W0313 11:46:02.754300 1377963 cpp_gen_intrinsics.cc:74] Empty bitcode string provided for eigen. Optimizations relying on this IR will be disabled.\n"
85-
]
86-
}
87-
],
88-
"source": [
89-
"lat, lon, ssh, ug, vg, ucg, vcg, land_mask = gaussian_eddy.simulate_gaussian_eddy(R0=50e3, eta0=-.2)"
90-
]
91-
},
92-
{
93-
"cell_type": "code",
94-
"execution_count": 5,
73+
"execution_count": null,
9574
"metadata": {},
9675
"outputs": [],
9776
"source": [
98-
"uvg = kinematics.magnitude(ug, vg)\n",
99-
"uvcg = kinematics.magnitude(ucg, vcg)\n",
100-
"\n",
101-
"max_diff = jnp.nanmax(jnp.abs(uvcg - uvg))"
77+
"lat, lon, ssh, ug, vg, ucg, vcg, land_mask = gaussian_eddy.simulate_gaussian_eddy(R0=50e3, eta0=-.2)"
10278
]
10379
},
10480
{
@@ -153,6 +129,18 @@
153129
"$v_g = -2x \\frac{g \\eta_0}{f R_0^2} \\exp^{-(r/R_0)^2} = -2x \\frac{g \\eta}{f R_0^2}$"
154130
]
155131
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"metadata": {},
136+
"outputs": [],
137+
"source": [
138+
"uvg = kinematics.magnitude(ug, vg)\n",
139+
"uvcg = kinematics.magnitude(ucg, vcg)\n",
140+
"\n",
141+
"max_diff = jnp.nanmax(jnp.abs(uvcg - uvg))"
142+
]
143+
},
156144
{
157145
"cell_type": "code",
158146
"execution_count": 7,
@@ -406,11 +394,11 @@
406394
},
407395
{
408396
"cell_type": "code",
409-
"execution_count": 13,
397+
"execution_count": null,
410398
"metadata": {},
411399
"outputs": [],
412400
"source": [
413-
"mb_res = minimization_based(lat_t=lat, lon_t=lon, ssh_t=ssh,)\n",
401+
"mb_res = minimization_based(lat_t=lat, lon_t=lon, ssh_t=ssh)\n",
414402
"\n",
415403
"umb_est = mb_res.ucg\n",
416404
"vmb_est = mb_res.vcg\n",

docs/examples/swot-enatl60.ipynb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,13 @@
283283
},
284284
{
285285
"cell_type": "code",
286-
"execution_count": 7,
286+
"execution_count": null,
287287
"metadata": {
288288
"tags": [
289289
"hide-input"
290290
]
291291
},
292-
"outputs": [
293-
{
294-
"name": "stderr",
295-
"output_type": "stream",
296-
"text": [
297-
"/var/folders/xc/bksmt58x2nq8jshz2jbf9b_m0000gn/T/ipykernel_61290/1634369195.py:46: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.\n",
298-
" n_pixels_003 = swot_003_ds.dims[\"num_pixels\"]\n",
299-
"/var/folders/xc/bksmt58x2nq8jshz2jbf9b_m0000gn/T/ipykernel_61290/1634369195.py:47: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.\n",
300-
" n_pixels_016 = swot_016_ds.dims[\"num_pixels\"]\n"
301-
]
302-
}
303-
],
292+
"outputs": [],
304293
"source": [
305294
"t_003_regridder = get_regridder(enatl60_t_ds, swot_003_ds)\n",
306295
"u_003_regridder = get_regridder(enatl60_u_ds, swot_003_ds)\n",
@@ -434,7 +423,11 @@
434423
{
435424
"cell_type": "code",
436425
"execution_count": 9,
437-
"metadata": {},
426+
"metadata": {
427+
"tags": [
428+
"hide-input"
429+
]
430+
},
438431
"outputs": [],
439432
"source": [
440433
"optim = optax.chain(optax.clip(1), optax.sgd(learning_rate=5e-3))\n",
@@ -553,7 +546,11 @@
553546
{
554547
"cell_type": "code",
555548
"execution_count": 10,
556-
"metadata": {},
549+
"metadata": {
550+
"tags": [
551+
"hide-input"
552+
]
553+
},
557554
"outputs": [
558555
{
559556
"data": {

docs/faq.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@
44

55
`Dask` is probably your best bet to handle large datasets that do not fit into (CPU or GPU) memory.
66

7-
On a CPU backend, one can use a chunk size of 1 along the time dimension and map the call to [`cyclogeostrophy`](api.md#jaxparrow.cyclogeostrophy.cyclogeostrophy) onto the dataset:
7+
On a CPU backend, one can use a chunk size of 1 along the time dimension and map the call to [`minimization_based`](api.md#jaxparrow.cyclogeostrophy.minimization_based) onto the dataset:
88

99
```python
1010
import dask
1111
import jax.numpy as jnp
1212
import numpy as np
1313
import xarray as xr
1414

15-
from jaxparrow.cyclogeostrophy import cyclogeostrophy
15+
from jaxparrow import minimization_based
1616

1717

1818
def do_one_block(in_block):
19-
ucg, vcg, ug, vg = cyclogeostrophy(
20-
jnp.asarray(in_block.ssh.values), jnp.asarray(in_block.lat.values), jnp.asarray(in_block.lon.values),
21-
return_geos=True, return_grids=False
19+
mb_result = minimization_based(
20+
lat_t=jnp.asarray(in_block.lat.values), lon_tjnp.asarray(in_block.lon.values),
21+
ssh_t=jnp.asarray(in_block.ssh.values),
22+
return_geos=True
2223
)
2324

25+
ucg = mb_result.ucg
26+
vcg = mb_result.vcg
27+
ug = mb_result.ug
28+
vg = mb_result.vg
29+
2430
out_block = xr.Dataset(
2531
{
2632
"ucg": (in_block.ssh.dims, np.asarray(ucg)[None, :, :]),
@@ -70,16 +76,21 @@ from jaxparrow.cyclogeostrophy import cyclogeostrophy
7076

7177

7278
vmap_cyclogeostrophy = jax.vmap(
73-
lambda *args: cyclogeostrophy(*args, return_geos=True, return_grids=False),
79+
lambda ssh, lat, lon: minimization_based(lat_t=lat, lon_t=lon, ssh_t=ssh, return_geos=True),
7480
in_axes=(0, None, None)
7581
)
7682

7783

7884
def do_one_block_vmap(in_block: xr.Dataset):
79-
ucg_3d, vcg_3d, ug_3d, vg_3d = vmap_cyclogeostrophy(
85+
mb_result = vmap_cyclogeostrophy(
8086
jnp.asarray(in_block.ssh.values), jnp.asarray(in_block.lat.values), jnp.asarray(in_block.lon.values)
8187
)
8288

89+
ucg_3d = mb_result.uvg
90+
vcg_3d = mb_result.vcg
91+
ug_3d = mb_result.ug
92+
vg_3d = mb_result.vg
93+
8394
out_block = xr.Dataset(
8495
{
8596
"ucg": (in_block.ssh.dims, np.asarray(ucg_3d)),
@@ -135,12 +146,12 @@ optimizer = optax.chain(
135146
)
136147
```
137148

138-
And then pass the `optimizer` object as the `optim` argument of the [`cyclogeostrophy`](api.md#jaxparrow.cyclogeostrophy.cyclogeostrophy) function.
149+
And then pass the `optimizer` object as the `optim` argument of the [`minimization_based`](api.md#jaxparrow.cyclogeostrophy.minimization_based) function.
139150
This is employed in the [Pseudo-SWOT observations from eNATL60 model data](examples/swot-enatl60.ipynb) example.
140151

141152
We also recommend using `JAX` floating point types with sufficient precision, e.g., `float64`:
142153

143154
```python
144155
import jax
145156
jax.config.update("jax_enable_x64", True)
146-
```
157+
```

jaxparrow/cyclogeostrophy/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ def cyclogeostrophic_imbalance(
386386

387387
# compute grid metrics once
388388
dx_e, dx_n, dy_e, dy_n, J = geometry.grid_metrics(lat_t, lon_t)
389+
f = geometry.coriolis_factor(lat_t)
389390

390391
return _cyclogeostrophic_imbalance(
391-
ug_u, vg_v, ucg_u, vcg_v,
392-
dx_u, dx_v, dy_u, dy_v, coriolis_factor_u, coriolis_factor_v, mask
392+
ug, vg, ucg, vcg, dx_e, dx_n, dy_e, dy_n, J, f, land_mask
393393
)
394394

395395

0 commit comments

Comments
 (0)