|
49 | 49 | "\n", |
50 | 50 | "nlat = 10\n", |
51 | 51 | "nlon = 18\n", |
52 | | - "ds = simple_UV_dataset(dims=(1, 1, nlat, nlon), mesh=\"spherical\").isel(time=0, depth=0)\n", |
| 52 | + "ds = simple_UV_dataset(dims=(1, 1, nlat, nlon), mesh=\"spherical\")\n", |
53 | 53 | "ds[\"temperature\"] = ds[\"U\"] + 20 # add temperature field of 20 deg\n", |
54 | 54 | "ds[\"U\"].data[:] = 1.0 # set U to 1 m/s\n", |
55 | 55 | "ds[\"V\"].data[:] = 1.0 # set V to 1 m/s\n", |
|
61 | 61 | "cell_type": "markdown", |
62 | 62 | "metadata": {}, |
63 | 63 | "source": [ |
64 | | - "To create a `parcels.FieldSet` object, we define the `parcels.Field`s and the structured grid (`parcels.XGrid`) the fields are defined on. We add the argument `mesh='spherical'` to the `parcels.XGrid` to signal that all longitudes and latitudes are in degrees.\n", |
| 64 | + "To create a `parcels.FieldSet` object, we use the `parcels.FieldSet.from_sgrid_conventions` constructor. We add the argument `mesh='spherical'` to signal that all longitudes and latitudes are in degrees.\n", |
65 | 65 | "\n", |
66 | 66 | "```{note}\n", |
67 | 67 | "When using a `FieldSet` method for a specific dataset, such as `from_copernicusmarine()`, the grid information is known and parsed by Parcels, so we do not have to add the `mesh` argument.\n", |
|
76 | 76 | "metadata": {}, |
77 | 77 | "outputs": [], |
78 | 78 | "source": [ |
79 | | - "grid = parcels.XGrid.from_dataset(ds, mesh=\"spherical\")\n", |
80 | | - "U = parcels.Field(\"U\", ds[\"U\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
81 | | - "V = parcels.Field(\"V\", ds[\"V\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
82 | | - "UV = parcels.VectorField(\"UV\", U, V)\n", |
83 | | - "temperature = parcels.Field(\n", |
84 | | - " \"temperature\", ds[\"temperature\"], grid, interp_method=parcels.interpolators.XLinear\n", |
85 | | - ")\n", |
86 | | - "fieldset = parcels.FieldSet([U, V, UV, temperature])\n", |
| 79 | + "fieldset = parcels.FieldSet.from_sgrid_conventions(ds, mesh=\"spherical\")\n", |
87 | 80 | "\n", |
88 | 81 | "plt.pcolormesh(\n", |
89 | 82 | " fieldset.U.grid.lon,\n", |
|
166 | 159 | "cell_type": "markdown", |
167 | 160 | "metadata": {}, |
168 | 161 | "source": [ |
169 | | - "Note that you can also interpolate the Field without a unit conversion, by using the `eval()` method and setting `applyConversion=False`, as below\n" |
| 162 | + "Note that you can also interpolate the Field without a unit conversion, by using the `eval()` method and setting `apply_conversion=False`, as below\n" |
170 | 163 | ] |
171 | 164 | }, |
172 | 165 | { |
|
181 | 174 | " z,\n", |
182 | 175 | " lat,\n", |
183 | 176 | " lon,\n", |
184 | | - " applyConversion=False,\n", |
| 177 | + " apply_conversion=False,\n", |
185 | 178 | " )\n", |
186 | 179 | ")" |
187 | 180 | ] |
|
199 | 192 | "cell_type": "markdown", |
200 | 193 | "metadata": {}, |
201 | 194 | "source": [ |
202 | | - "If longitudes and latitudes are given in meters, rather than degrees, simply add `mesh='flat'` when creating the XGrid object.\n" |
| 195 | + "If longitudes and latitudes are given in meters, rather than degrees, simply add `mesh='flat'` when creating the `FieldSet` object.\n" |
203 | 196 | ] |
204 | 197 | }, |
205 | 198 | { |
|
208 | 201 | "metadata": {}, |
209 | 202 | "outputs": [], |
210 | 203 | "source": [ |
211 | | - "ds_flat = simple_UV_dataset(dims=(1, 1, nlat, nlon), mesh=\"flat\").isel(time=0, depth=0)\n", |
| 204 | + "ds_flat = simple_UV_dataset(dims=(1, 1, nlat, nlon), mesh=\"flat\")\n", |
212 | 205 | "ds_flat[\"temperature\"] = ds_flat[\"U\"] + 20 # add temperature field of 20 deg\n", |
213 | 206 | "ds_flat[\"U\"].data[:] = 1.0 # set U to 1 m/s\n", |
214 | 207 | "ds_flat[\"V\"].data[:] = 1.0 # set V to 1 m/s\n", |
215 | | - "grid = parcels.XGrid.from_dataset(ds_flat, mesh=\"flat\")\n", |
216 | | - "U = parcels.Field(\"U\", ds_flat[\"U\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
217 | | - "V = parcels.Field(\"V\", ds_flat[\"V\"], grid, interp_method=parcels.interpolators.XLinear)\n", |
218 | | - "UV = parcels.VectorField(\"UV\", U, V)\n", |
219 | | - "temperature = parcels.Field(\n", |
220 | | - " \"temperature\",\n", |
221 | | - " ds_flat[\"temperature\"],\n", |
222 | | - " grid,\n", |
223 | | - " interp_method=parcels.interpolators.XLinear,\n", |
224 | | - ")\n", |
225 | | - "fieldset_flat = parcels.FieldSet([U, V, UV, temperature])\n", |
| 208 | + "fieldset_flat = parcels.FieldSet.from_sgrid_conventions(ds_flat, mesh=\"flat\")\n", |
226 | 209 | "\n", |
227 | 210 | "plt.pcolormesh(\n", |
228 | 211 | " fieldset_flat.U.grid.lon,\n", |
|
0 commit comments