|
9 | 9 | Xarray dataset so that users can further provide any missing metadata that was unable to |
10 | 10 | be determined before they pass it to the FieldSet constructor. |
11 | 11 | """ |
| 12 | + |
12 | 13 | from __future__ import annotations |
13 | | -import warnings |
14 | 14 |
|
15 | 15 | import typing |
| 16 | +import warnings |
16 | 17 |
|
17 | 18 | import numpy as np |
18 | 19 | import xarray as xr |
|
25 | 26 |
|
26 | 27 | _NEMO_EXPECTED_COORDS = ["glamf", "gphif", "depthw"] |
27 | 28 |
|
28 | | -_NEMO_DIMENSION_COORD_NAMES = ["x", "y", "time", "x", "x_center", "y", "y_center", "depth", "depth_center", "glamf", "gphif"] |
| 29 | +_NEMO_DIMENSION_COORD_NAMES = [ |
| 30 | + "x", |
| 31 | + "y", |
| 32 | + "time", |
| 33 | + "x", |
| 34 | + "x_center", |
| 35 | + "y", |
| 36 | + "y_center", |
| 37 | + "depth", |
| 38 | + "depth_center", |
| 39 | + "glamf", |
| 40 | + "gphif", |
| 41 | +] |
29 | 42 |
|
30 | 43 | _NEMO_AXIS_VARNAMES = { |
31 | 44 | "x": "X", |
@@ -104,13 +117,13 @@ def _maybe_bring_other_depths_to_depth(ds): |
104 | 117 | ]: |
105 | 118 | if old_depth in ds[var].dims: |
106 | 119 | ds[var] = ds[var].rename({old_depth: target}) |
107 | | - |
| 120 | + |
108 | 121 | if "depth" not in ds.dims: |
109 | 122 | warnings.warn("No depth dimension found in your dataset. Assuming no depth (i.e., surface data).", stacklevel=1) |
110 | 123 | ds = ds.expand_dims({"depth": [0]}) |
111 | 124 | ds["depth"] = xr.DataArray([0], dims=["depth"]) |
112 | 125 | return ds |
113 | | - |
| 126 | + |
114 | 127 |
|
115 | 128 | def _maybe_rename_coords(ds, axis_varnames): |
116 | 129 | try: |
@@ -288,8 +301,10 @@ def nemo_to_sgrid(*, fields: dict[str, xr.Dataset | xr.DataArray], coords: xr.Da |
288 | 301 | if coords.sizes["time"] != 1: |
289 | 302 | raise ValueError("Time dimension in coords must be length 1 (i.e., no time-varying grid).") |
290 | 303 | coords = coords.isel(time=0).drop("time") |
291 | | - |
292 | | - if len(coords.dims) == 3: #! This should really be looking at the dimensionality of the lons and lats arrays. Currently having 2D lon lat and 1D depth triggers this `if` clause |
| 304 | + |
| 305 | + if ( |
| 306 | + len(coords.dims) == 3 |
| 307 | + ): #! This should really be looking at the dimensionality of the lons and lats arrays. Currently having 2D lon lat and 1D depth triggers this `if` clause |
293 | 308 | for dim, len_ in coords.sizes.items(): |
294 | 309 | if len_ == 1: |
295 | 310 | # TODO: log statement about selecting along z dim of 1 |
|
0 commit comments