Skip to content

Commit f111dfa

Browse files
Merge pull request #2477 from Parcels-code/convert_from_copernicusmarine
Creating convert.copernicusmarine_to_sgrid() function
2 parents 977d926 + 3234672 commit f111dfa

17 files changed

+208
-178
lines changed

docs/getting_started/explanation_concepts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ For several common input datasets, such as the Copernicus Marine Service analysi
3636

3737
```python
3838
dataset = xr.open_mfdataset("insert_copernicus_data_files.nc")
39-
fieldset = parcels.FieldSet.from_copernicusmarine(dataset)
39+
fields = {"U": ds_fields["uo"], "V": ds_fields["vo"]}
40+
ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)
41+
fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)
4042
```
4143

4244
In some cases, we might want to combine `parcels.Field`s from different sources in the same `parcels.FieldSet`, such as ocean currents from one dataset and Stokes drift from another. This is possible in Parcels by adding each `parcels.Field` separately:

docs/getting_started/tutorial_output.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
"ds_fields = xr.open_mfdataset(f\"{example_dataset_folder}/*.nc\", combine=\"by_coords\")\n",
6060
"ds_fields.load() # load the dataset into memory\n",
6161
"\n",
62-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)"
62+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
63+
"fields = {\"U\": ds_fields[\"uo\"], \"V\": ds_fields[\"vo\"]}\n",
64+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
65+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)"
6366
]
6467
},
6568
{
@@ -557,7 +560,7 @@
557560
"metadata": {
558561
"celltoolbar": "Metagegevens bewerken",
559562
"kernelspec": {
560-
"display_name": "test-notebooks",
563+
"display_name": "docs",
561564
"language": "python",
562565
"name": "python3"
563566
},
@@ -571,7 +574,7 @@
571574
"name": "python",
572575
"nbconvert_exporter": "python",
573576
"pygments_lexer": "ipython3",
574-
"version": "3.11.0"
577+
"version": "3.14.2"
575578
}
576579
},
577580
"nbformat": 4,

docs/getting_started/tutorial_quickstart.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ As we can see, the reanalysis dataset contains eastward velocity `uo`, northward
4242
(`thetao`) and salinity (`so`) fields.
4343

4444
These hydrodynamic fields need to be stored in a {py:obj}`parcels.FieldSet` object. Parcels provides tooling to parse many types
45-
of models or observations into such a `parcels.FieldSet` object. Here, we use {py:func}`parcels.FieldSet.from_copernicusmarine()`, which
46-
recognizes the standard names of a velocity field:
45+
of models or observations into such a `parcels.FieldSet` object. This is done in a two-step approach.
46+
47+
First, we convert the dataset into an SGRID-compliant dataset, for example by using a version of `parcels.convert.<MODEL>_to_sgrid()`. Then, we create the `parcels.FieldSet` from the SGRID-compliant dataset using `parcels.FieldSet.from_sgrid_conventions()`.
48+
49+
Below, we use a combination of {py:func}`parcels.convert.copernicusmarine_to_sgrid()` and {py:func}`parcels.FieldSet.from_sgrid_conventions()`, providing the names of the velocity fields in the dataset in the dictionary `fields`:
4750

4851
```{code-cell}
49-
fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)
52+
fields = {"U": ds_fields["uo"], "V": ds_fields["vo"]}
53+
ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)
54+
fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)
5055
```
5156

5257
The subset contains a region of the Agulhas current along the southeastern coast of Africa:

docs/user_guide/examples/explanation_kernelloop.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ ds_fields["VWind"] = xr.DataArray(
6868
data=np.zeros((tdim, ydim, xdim)),
6969
coords=[ds_fields.time, ds_fields.latitude, ds_fields.longitude])
7070
71-
fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)
71+
fields = {
72+
"U": ds_fields["uo"],
73+
"V": ds_fields["vo"],
74+
"UWind": ds_fields["UWind"],
75+
"VWind": ds_fields["VWind"],
76+
}
77+
ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)
78+
fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)
7279
7380
# Create a vecorfield for the wind
7481
windvector = parcels.VectorField(

docs/user_guide/examples/tutorial_Argofloats.ipynb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,16 @@
121121
"# TODO check how we can get good performance without loading full dataset in memory\n",
122122
"ds_fields.load() # load the dataset into memory\n",
123123
"\n",
124-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)\n",
124+
"# Select fields\n",
125+
"fields = {\n",
126+
" \"U\": ds_fields[\"uo\"],\n",
127+
" \"V\": ds_fields[\"vo\"],\n",
128+
" \"thetao\": ds_fields[\"thetao\"],\n",
129+
"}\n",
130+
"\n",
131+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
132+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
133+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n",
125134
"fieldset.add_constant(\"mindepth\", 1.0)\n",
126135
"\n",
127136
"# Define a new Particle type including extra Variables\n",

docs/user_guide/examples/tutorial_delaystart.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
"ds_fields = xr.open_mfdataset(f\"{example_dataset_folder}/*.nc\", combine=\"by_coords\")\n",
5858
"ds_fields.load() # load the dataset into memory\n",
5959
"\n",
60-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)"
60+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
61+
"fields = {\"U\": ds_fields[\"uo\"], \"V\": ds_fields[\"vo\"]}\n",
62+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
63+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)"
6164
]
6265
},
6366
{
@@ -433,7 +436,7 @@
433436
],
434437
"metadata": {
435438
"kernelspec": {
436-
"display_name": "test-notebooks",
439+
"display_name": "docs",
437440
"language": "python",
438441
"name": "python3"
439442
},
@@ -447,7 +450,7 @@
447450
"name": "python",
448451
"nbconvert_exporter": "python",
449452
"pygments_lexer": "ipython3",
450-
"version": "3.11.0"
453+
"version": "3.14.2"
451454
}
452455
},
453456
"nbformat": 4,

docs/user_guide/examples/tutorial_diffusion.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@
491491
"metadata": {},
492492
"outputs": [],
493493
"source": [
494-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)\n",
494+
"fields = {\"U\": ds_fields[\"uo\"], \"V\": ds_fields[\"vo\"]}\n",
495+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
496+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n",
495497
"\n",
496498
"\n",
497499
"def degree_lat_to_meter(d):\n",

docs/user_guide/examples/tutorial_dt_integrators.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
"ds_fields = xr.open_mfdataset(f\"{example_dataset_folder}/*.nc\", combine=\"by_coords\")\n",
6969
"ds_fields.load() # load the dataset into memory\n",
7070
"\n",
71-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)\n",
71+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
72+
"fields = {\"U\": ds_fields[\"uo\"], \"V\": ds_fields[\"vo\"]}\n",
73+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
74+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n",
7275
"\n",
7376
"# Check field resolution in time and space\n",
7477
"print(\n",

docs/user_guide/examples/tutorial_gsw_density.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@
4747
"# TODO check how we can get good performance without loading full dataset in memory\n",
4848
"ds_fields.load() # load the dataset into memory\n",
4949
"\n",
50-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)"
50+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
51+
"fields = {\n",
52+
" \"U\": ds_fields[\"uo\"],\n",
53+
" \"V\": ds_fields[\"vo\"],\n",
54+
" \"thetao\": ds_fields[\"thetao\"],\n",
55+
" \"so\": ds_fields[\"so\"],\n",
56+
"}\n",
57+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
58+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)"
5159
]
5260
},
5361
{
@@ -137,7 +145,7 @@
137145
],
138146
"metadata": {
139147
"kernelspec": {
140-
"display_name": "test-notebooks",
148+
"display_name": "docs",
141149
"language": "python",
142150
"name": "python3"
143151
},
@@ -151,7 +159,7 @@
151159
"name": "python",
152160
"nbconvert_exporter": "python",
153161
"pygments_lexer": "ipython3",
154-
"version": "3.11.0"
162+
"version": "3.14.2"
155163
}
156164
},
157165
"nbformat": 4,

docs/user_guide/examples/tutorial_sampling.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
"ds_fields = xr.open_mfdataset(f\"{example_dataset_folder}/*.nc\", combine=\"by_coords\")\n",
6767
"ds_fields.load() # load the dataset into memory\n",
6868
"\n",
69-
"fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)"
69+
"# Convert to SGRID-compliant dataset and create FieldSet\n",
70+
"fields = {\"U\": ds_fields[\"uo\"], \"V\": ds_fields[\"vo\"], \"thetao\": ds_fields[\"thetao\"]}\n",
71+
"ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n",
72+
"fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)"
7073
]
7174
},
7275
{
@@ -391,7 +394,7 @@
391394
"metadata": {
392395
"celltoolbar": "Raw-celnotatie",
393396
"kernelspec": {
394-
"display_name": "test-notebooks",
397+
"display_name": "docs",
395398
"language": "python",
396399
"name": "python3"
397400
},
@@ -405,7 +408,7 @@
405408
"name": "python",
406409
"nbconvert_exporter": "python",
407410
"pygments_lexer": "ipython3",
408-
"version": "3.11.0"
411+
"version": "3.14.2"
409412
},
410413
"pycharm": {
411414
"stem_cell": {

0 commit comments

Comments
 (0)