|
4 | 4 |
|
5 | 5 | `Dask` is probably your best bet to handle large datasets that do not fit into (CPU or GPU) memory. |
6 | 6 |
|
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: |
8 | 8 |
|
9 | 9 | ```python |
10 | 10 | import dask |
11 | 11 | import jax.numpy as jnp |
12 | 12 | import numpy as np |
13 | 13 | import xarray as xr |
14 | 14 |
|
15 | | -from jaxparrow.cyclogeostrophy import cyclogeostrophy |
| 15 | +from jaxparrow import minimization_based |
16 | 16 |
|
17 | 17 |
|
18 | 18 | 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 |
22 | 23 | ) |
23 | 24 |
|
| 25 | + ucg = mb_result.ucg |
| 26 | + vcg = mb_result.vcg |
| 27 | + ug = mb_result.ug |
| 28 | + vg = mb_result.vg |
| 29 | + |
24 | 30 | out_block = xr.Dataset( |
25 | 31 | { |
26 | 32 | "ucg": (in_block.ssh.dims, np.asarray(ucg)[None, :, :]), |
@@ -70,16 +76,21 @@ from jaxparrow.cyclogeostrophy import cyclogeostrophy |
70 | 76 |
|
71 | 77 |
|
72 | 78 | 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), |
74 | 80 | in_axes=(0, None, None) |
75 | 81 | ) |
76 | 82 |
|
77 | 83 |
|
78 | 84 | 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( |
80 | 86 | jnp.asarray(in_block.ssh.values), jnp.asarray(in_block.lat.values), jnp.asarray(in_block.lon.values) |
81 | 87 | ) |
82 | 88 |
|
| 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 | + |
83 | 94 | out_block = xr.Dataset( |
84 | 95 | { |
85 | 96 | "ucg": (in_block.ssh.dims, np.asarray(ucg_3d)), |
@@ -135,12 +146,12 @@ optimizer = optax.chain( |
135 | 146 | ) |
136 | 147 | ``` |
137 | 148 |
|
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. |
139 | 150 | This is employed in the [Pseudo-SWOT observations from eNATL60 model data](examples/swot-enatl60.ipynb) example. |
140 | 151 |
|
141 | 152 | We also recommend using `JAX` floating point types with sufficient precision, e.g., `float64`: |
142 | 153 |
|
143 | 154 | ```python |
144 | 155 | import jax |
145 | 156 | jax.config.update("jax_enable_x64", True) |
146 | | -``` |
| 157 | +``` |
0 commit comments