Skip to content

Commit f1b0964

Browse files
committed
Move circulation model data definitions to own functions
1 parent 5c17b81 commit f1b0964

1 file changed

Lines changed: 163 additions & 116 deletions

File tree

parcels/_datasets/structured/circulation_models.py

Lines changed: 163 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
TIME = xr.date_range("2000", "2001", T)
1111

1212

13-
datasets = {
14-
"ds_copernicusmarine": xr.Dataset(
15-
# Copernicus Marine Service dataset as retrieved by the `copernicusmarine` toolkit
13+
def _copernicusmarine():
14+
"""Copernicus Marine Service dataset as retrieved by the `copernicusmarine` toolkit"""
15+
return xr.Dataset(
1616
{
1717
"uo": (
1818
["time", "depth", "latitude", "longitude"],
@@ -85,9 +85,12 @@
8585
},
8686
),
8787
},
88-
),
89-
"ds_copernicusmarine_globcurrents": xr.Dataset(
90-
# Copernicus Marine Service GlobCurrent dataset (MULTIOBS_GLO_PHY_MYNRT_015_003)
88+
)
89+
90+
91+
def _copernicusmarine_globcurrents():
92+
"""Copernicus Marine Service GlobCurrent dataset (MULTIOBS_GLO_PHY_MYNRT_015_003)"""
93+
return xr.Dataset(
9194
{
9295
"ue": (
9396
["time", "depth", "latitude", "longitude"],
@@ -154,9 +157,12 @@
154157
},
155158
),
156159
},
157-
),
158-
"ds_NEMO_MOI_U": xr.Dataset(
159-
# NEMO model dataset (U component) as serviced by Mercator Ocean International
160+
)
161+
162+
163+
def _NEMO_MOI_U():
164+
"""NEMO model dataset (U component) as serviced by Mercator Ocean International"""
165+
return xr.Dataset(
160166
{
161167
"vozocrtx": (
162168
["deptht", "y", "x"],
@@ -259,9 +265,12 @@
259265
},
260266
),
261267
},
262-
),
263-
"ds_NEMO_MOI_V": xr.Dataset(
264-
# NEMO model dataset (V component) as serviced by Mercator Ocean International
268+
)
269+
270+
271+
def _NEMO_MOI_V():
272+
"""NEMO model dataset (V component) as serviced by Mercator Ocean International"""
273+
return xr.Dataset(
265274
{
266275
"vomecrty": (
267276
["deptht", "y", "x"],
@@ -348,92 +357,101 @@
348357
},
349358
),
350359
},
351-
),
352-
"ds_CESM": xr.Dataset(
353-
# CESM model dataset
354-
{
355-
"UVEL": (
356-
["time", "z_t", "nlat", "nlon"],
357-
np.random.rand(T, Z, Y, X, dtype="float32"),
358-
{
359-
"long_name": "Velocity in grid-x direction",
360-
"units": "centimeter/s",
361-
"grid_loc": 3221,
362-
"cell_methods": "time:mean",
363-
},
364-
),
365-
"VVEL": (
366-
["time", "z_t", "nlat", "nlon"],
367-
np.random.rand(T, Z, Y, X, dtype="float32"),
368-
{
369-
"long_name": "Velocity in grid-y direction",
370-
"units": "centimeter/s",
371-
"grid_loc": 3221,
372-
"cell_methods": "time:mean",
373-
},
374-
),
375-
"WVEL": (
376-
["time", "z_w_top", "nlat", "nlon"],
377-
np.random.rand(T, Z, Y, X, dtype="float32"),
378-
{
379-
"long_name": "Vertical Velocity",
380-
"units": "centimeter/s",
381-
"grid_loc": 3112,
382-
"cell_methods": "time:mean",
383-
},
384-
),
385-
},
386-
coords={
387-
"time": (
388-
["time"],
389-
TIME,
390-
{
391-
"long_name": "time",
392-
"bounds": "time_bounds",
393-
},
394-
),
395-
"z_t": (
396-
["z_t"],
397-
np.linspace(0, 5000, Z, dtype="float32"),
398-
{
399-
"long_name": "depth from surface to midpoint of layer",
400-
"units": "centimeters",
401-
"positive": "down",
402-
"valid_min": 500.0,
403-
"valid_max": 537500.0,
404-
},
405-
),
406-
"z_w_top": (
407-
["z_w_top"],
408-
np.linspace(0, 5000, Z, dtype="float32"),
409-
{
410-
"long_name": "depth from surface to top of layer",
411-
"units": "centimeters",
412-
"positive": "down",
413-
"valid_min": 0.0,
414-
"valid_max": 525000.94,
415-
},
416-
),
417-
"ULONG": (
418-
["nlat", "nlon"],
419-
np.tile(np.linspace(-179, 179, X, endpoint=False), (Y, 1)), # note that this is not curvilinear
420-
{
421-
"long_name": "array of u-grid longitudes",
422-
"units": "degrees_east",
423-
},
424-
),
425-
"ULAT": (
426-
["nlat", "nlon"],
427-
np.tile(np.linspace(-75, 85, Y).reshape(-1, 1), (1, X)), # note that this is not curvilinear
428-
{
429-
"long_name": "array of u-grid latitudes",
430-
"units": "degrees_north",
431-
},
432-
),
433-
},
434-
),
435-
"ds_MITgcm_netcdf": xr.Dataset(
436-
# MITgcm model dataset in netCDF format
360+
)
361+
362+
363+
def _CESM():
364+
"""CESM model dataset"""
365+
return (
366+
xr.Dataset(
367+
{
368+
"UVEL": (
369+
["time", "z_t", "nlat", "nlon"],
370+
np.random.rand(T, Z, Y, X, dtype="float32"),
371+
{
372+
"long_name": "Velocity in grid-x direction",
373+
"units": "centimeter/s",
374+
"grid_loc": 3221,
375+
"cell_methods": "time:mean",
376+
},
377+
),
378+
"VVEL": (
379+
["time", "z_t", "nlat", "nlon"],
380+
np.random.rand(T, Z, Y, X, dtype="float32"),
381+
{
382+
"long_name": "Velocity in grid-y direction",
383+
"units": "centimeter/s",
384+
"grid_loc": 3221,
385+
"cell_methods": "time:mean",
386+
},
387+
),
388+
"WVEL": (
389+
["time", "z_w_top", "nlat", "nlon"],
390+
np.random.rand(T, Z, Y, X, dtype="float32"),
391+
{
392+
"long_name": "Vertical Velocity",
393+
"units": "centimeter/s",
394+
"grid_loc": 3112,
395+
"cell_methods": "time:mean",
396+
},
397+
),
398+
},
399+
coords={
400+
"time": (
401+
["time"],
402+
TIME,
403+
{
404+
"long_name": "time",
405+
"bounds": "time_bounds",
406+
},
407+
),
408+
"z_t": (
409+
["z_t"],
410+
np.linspace(0, 5000, Z, dtype="float32"),
411+
{
412+
"long_name": "depth from surface to midpoint of layer",
413+
"units": "centimeters",
414+
"positive": "down",
415+
"valid_min": 500.0,
416+
"valid_max": 537500.0,
417+
},
418+
),
419+
"z_w_top": (
420+
["z_w_top"],
421+
np.linspace(0, 5000, Z, dtype="float32"),
422+
{
423+
"long_name": "depth from surface to top of layer",
424+
"units": "centimeters",
425+
"positive": "down",
426+
"valid_min": 0.0,
427+
"valid_max": 525000.94,
428+
},
429+
),
430+
"ULONG": (
431+
["nlat", "nlon"],
432+
np.tile(np.linspace(-179, 179, X, endpoint=False), (Y, 1)), # note that this is not curvilinear
433+
{
434+
"long_name": "array of u-grid longitudes",
435+
"units": "degrees_east",
436+
},
437+
),
438+
"ULAT": (
439+
["nlat", "nlon"],
440+
np.tile(np.linspace(-75, 85, Y).reshape(-1, 1), (1, X)), # note that this is not curvilinear
441+
{
442+
"long_name": "array of u-grid latitudes",
443+
"units": "degrees_north",
444+
},
445+
),
446+
},
447+
),
448+
)
449+
450+
451+
def _MITgcm_netcdf():
452+
"""MITgcm model dataset in netCDF format"""
453+
return xr.Dataset(
454+
#
437455
{
438456
"U": (
439457
["T", "Z", "Y", "Xp1"],
@@ -529,9 +547,12 @@
529547
},
530548
),
531549
},
532-
),
533-
"ds_ERA5_wind": xr.Dataset(
534-
# ERA5 10m wind model dataset
550+
)
551+
552+
553+
def _ERA5_wind():
554+
"""ERA5 10m wind model dataset"""
555+
return xr.Dataset(
535556
{
536557
"u10": (
537558
["time", "latitude", "longitude"],
@@ -575,9 +596,12 @@
575596
},
576597
),
577598
},
578-
),
579-
"ds_FES_tides": xr.Dataset(
580-
# FES tidal model dataset
599+
)
600+
601+
602+
def _FES_tides():
603+
"""FES tidal model dataset"""
604+
return xr.Dataset(
581605
{
582606
"Ug": (
583607
["lat", "lon"],
@@ -624,9 +648,12 @@
624648
},
625649
),
626650
},
627-
),
628-
"ds_hycom_espc": xr.Dataset(
629-
# HYCOM ESPC model dataset from https://data.hycom.org/datasets/ESPC-D-V02/data/daily_netcdf/2025/
651+
)
652+
653+
654+
def _hycom_espc():
655+
"""HYCOM ESPC model dataset from https://data.hycom.org/datasets/ESPC-D-V02/data/daily_netcdf/2025/"""
656+
return xr.Dataset(
630657
{
631658
"water_u": (
632659
["time", "depth", "lat", "lon"],
@@ -703,9 +730,12 @@
703730
},
704731
),
705732
},
706-
),
707-
"ds_ecco4": xr.Dataset(
708-
# ECCO V4r4 model dataset (from https://podaac.jpl.nasa.gov/dataset/ECCO_L4_OCEAN_VEL_LLC0090GRID_DAILY_V4R4#capability-modal-download)
733+
)
734+
735+
736+
def _ecco4():
737+
"""ECCO V4r4 model dataset (from https://podaac.jpl.nasa.gov/dataset/ECCO_L4_OCEAN_VEL_LLC0090GRID_DAILY_V4R4#capability-modal-download)"""
738+
return xr.Dataset(
709739
{
710740
"UVEL": (
711741
["time", "k", "tile", "j", "i_g"],
@@ -925,9 +955,12 @@
925955
},
926956
),
927957
},
928-
),
929-
"ds_CROCO_idealized": xr.Dataset(
930-
# CROCO idealized model dataset
958+
)
959+
960+
961+
def _CROCO_idealized():
962+
"""CROCO idealized model dataset"""
963+
return xr.Dataset(
931964
{
932965
"u": (
933966
["time", "s_rho", "eta_rho", "xi_u"],
@@ -1049,7 +1082,7 @@
10491082
"standard_name": "y_grid_index_at_v_location",
10501083
"axis": "Y",
10511084
"c_grid_axis_shift": 0.5,
1052-
"c_grid_dynamic_range": f"2:{Y-1}",
1085+
"c_grid_dynamic_range": f"2:{Y - 1}",
10531086
},
10541087
),
10551088
"xi_rho": (
@@ -1070,7 +1103,7 @@
10701103
"standard_name": "x_grid_index_at_u_location",
10711104
"axis": "X",
10721105
"c_grid_axis_shift": 0.5,
1073-
"c_grid_dynamic_range": f"2:{X-1}",
1106+
"c_grid_dynamic_range": f"2:{X - 1}",
10741107
},
10751108
),
10761109
"x_rho": (
@@ -1094,5 +1127,19 @@
10941127
},
10951128
),
10961129
},
1097-
),
1130+
)
1131+
1132+
1133+
datasets = {
1134+
"ds_copernicusmarine": _copernicusmarine(),
1135+
"ds_copernicusmarine_globcurrents": _copernicusmarine_globcurrents(),
1136+
"ds_NEMO_MOI_U": _NEMO_MOI_U(),
1137+
"ds_NEMO_MOI_V": _NEMO_MOI_V(),
1138+
"ds_CESM": _CESM(),
1139+
"ds_MITgcm_netcdf": _MITgcm_netcdf(),
1140+
"ds_ERA5_wind": _ERA5_wind(),
1141+
"ds_FES_tides": _FES_tides(),
1142+
"ds_hycom_espc": _hycom_espc(),
1143+
"ds_ecco4": _ecco4(),
1144+
"ds_CROCO_idealized": _CROCO_idealized(),
10981145
}

0 commit comments

Comments
 (0)