Skip to content

Commit 16212fb

Browse files
Adding MITgcm_mds dataset
1 parent 1d1a9bc commit 16212fb

2 files changed

Lines changed: 140 additions & 1 deletion

File tree

parcels/_datasets/structured/circulation_models.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,142 @@ def _MITgcm_netcdf():
527527
)
528528

529529

530+
def _MITgcm_mds():
531+
"""MITgcm model dataset in native MDS format"""
532+
return xr.Dataset(
533+
{
534+
"U": (
535+
["time", "Z", "YC", "XG"],
536+
np.random.rand(T, Z, Y, X).astype("float32"),
537+
{
538+
"standard_name": "sea_water_x_velocity",
539+
"mate": "V",
540+
"long_name": "Zonal Component of Velocity",
541+
"units": "m s-1",
542+
},
543+
),
544+
"V": (
545+
["time", "Z", "YG", "XC"],
546+
np.random.rand(T, Z, Y, X).astype("float32"),
547+
{
548+
"standard_name": "sea_water_y_velocity",
549+
"mate": "U",
550+
"long_name": "Meridional Component of Velocity",
551+
"units": "m s-1",
552+
},
553+
),
554+
"W": (
555+
["time", "Zl", "YC", "XC"],
556+
np.random.rand(T, Z, Y, X).astype("float32"),
557+
{
558+
"standard_name": "sea_water_z_velocity",
559+
"long_name": "Vertical Component of Velocity",
560+
"units": "m s-1",
561+
},
562+
),
563+
"S": (
564+
["time", "Z", "YC", "XC"],
565+
np.random.rand(T, Z, Y, X).astype("float32"),
566+
{
567+
"standard_name": "sea_water_salinity",
568+
"long_name": "Salinity",
569+
"units": "g kg-1",
570+
},
571+
),
572+
"T": (
573+
["time", "Z", "YC", "XC"],
574+
np.random.rand(T, Z, Y, X).astype("float32"),
575+
{
576+
"standard_name": "sea_water_potential_temperature",
577+
"long_name": "Potential Temperature",
578+
"units": "degree_Celcius",
579+
},
580+
),
581+
},
582+
coords={
583+
"time": (
584+
["time"],
585+
np.arange(T) * np.timedelta64(1, "D"),
586+
{
587+
"standard_name": "time",
588+
"long_name": "Time",
589+
"axis": "T",
590+
"calendar": "gregorian",
591+
},
592+
),
593+
"Z": (
594+
["Z"],
595+
np.linspace(-25, -5000, Z, dtype="float64"),
596+
{
597+
"standard_name": "depth",
598+
"long_name": "vertical coordinate of cell center",
599+
"units": "m",
600+
"positive": "down",
601+
"axis": "Z",
602+
},
603+
),
604+
"Zl": (
605+
["Zl"],
606+
np.linspace(0, -4500, Z, dtype="float64"),
607+
{
608+
"standard_name": "depth_at_lower_w_location",
609+
"long_name": "vertical coordinate of lower cell interface",
610+
"units": "m",
611+
"positive": "down",
612+
"axis": "Z",
613+
"c_grid_axis_shift": -0.5,
614+
},
615+
),
616+
"YC": (
617+
["YC"],
618+
np.linspace(500, 5000, Y, dtype="float64"),
619+
{
620+
"standard_name": "latitude",
621+
"long_name": "latitude",
622+
"units": "degrees_north",
623+
"coordinate": "YC XC",
624+
"axis": "Y",
625+
},
626+
),
627+
"YG": (
628+
["YG"],
629+
np.linspace(0, 5000, Y, dtype="float64"),
630+
{
631+
"standard_name": "latitude_at_f_location",
632+
"long_name": "latitude",
633+
"units": "degrees_north",
634+
"coordinate": "YG XG",
635+
"axis": "Y",
636+
"c_grid_axis_shift": -0.5,
637+
},
638+
),
639+
"XC": (
640+
["XC"],
641+
np.linspace(500, 5000, X, dtype="float64"),
642+
{
643+
"standard_name": "longitude",
644+
"long_name": "longitude",
645+
"units": "degrees_east",
646+
"coordinate": "YC XC",
647+
"axis": "X",
648+
},
649+
),
650+
"XG": (
651+
["XG"],
652+
np.linspace(0, 5000, X, dtype="float64"),
653+
{
654+
"standard_name": "longitude_at_f_location",
655+
"long_name": "longitude",
656+
"units": "degrees_east",
657+
"coordinate": "YG XG",
658+
"axis": "X",
659+
"c_grid_axis_shift": -0.5,
660+
},
661+
),
662+
},
663+
)
664+
665+
530666
def _ERA5_wind():
531667
"""ERA5 10m wind model dataset"""
532668
return xr.Dataset(
@@ -1113,6 +1249,7 @@ def _CROCO_idealized():
11131249
"ds_NEMO_MOI_V": _NEMO_MOI_V(),
11141250
"ds_CESM": _CESM(),
11151251
"ds_MITgcm_netcdf": _MITgcm_netcdf(),
1252+
"ds_MITgcm_mds": _MITgcm_mds(),
11161253
"ds_ERA5_wind": _ERA5_wind(),
11171254
"ds_FES_tides": _FES_tides(),
11181255
"ds_hycom_espc": _hycom_espc(),

parcels/_datasets/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def compare_datasets(ds1, ds2, ds1_name="Dataset 1", ds2_name="Dataset 2", verbo
126126
print(f" {ds1_name} size: {ds1.dims[dim_name]}, {ds2_name} size: {ds2.dims[dim_name]}")
127127
# Check if coordinates associated with dimensions are sorted (increasing)
128128
if dim_name in ds1.coords and dim_name in ds2.coords:
129-
check_val = np.timedelta64(0, "s") if isinstance(ds1[dim_name].values[0], np.datetime64) else 0.0
129+
check_val = (
130+
np.timedelta64(0, "s") if isinstance(ds1[dim_name].values[0], (np.datetime64, np.timedelta64)) else 0.0
131+
)
130132
is_ds1_sorted = (
131133
np.all(np.diff(ds1[dim_name].values) >= check_val) if len(ds1[dim_name].values) > 1 else True
132134
)

0 commit comments

Comments
 (0)