decode_vertical_coords gives wrong depths for ocean_s_coordinate and ocean_s_coordinate_g1
還沒有人認領這個 Issue。
評估
研究方向
從 cf_xarray/parametric.py 中的 OceanSG1.decode 和 OceanS.decode 開始,然後執行 issue 中的 reproducer,將兩個解碼後的陣列與 Appendix D 中的公式進行比較。完成的標準是兩個實作都與這些公式一致,包括在 s = -1 時 z = -depth,以及在 eta = 0、s = 0 時 ocean_s_coordinate 的 z = 0。
由索引模型根據 Issue 內容生成。
描述
Two of the ocean formulas in cf_xarray/parametric.py don't match CF Appendix D, so the bottom level doesn't land on -depth and the surface doesn't land on eta.
import numpy as np
import xarray as xr
import cf_xarray
print(cf_xarray.__version__)
# ocean_s_coordinate_g1
s = np.array([-1.0, -0.5, 0.0])
C = np.array([-1.0, -0.3, 0.0])
eta, depth, depth_c = 2.0, 100.0, 10.0
ds = xr.Dataset(
{
"C": ("s_rho", C),
"eta": ((), eta, {"standard_name": "sea_surface_height_above_geoid"}),
"depth": ((), depth, {"standard_name": "sea_floor_depth_below_geoid"}),
"depth_c": ((), depth_c),
},
coords={
"s_rho": (
"s_rho",
s,
{
"standard_name": "ocean_s_coordinate_g1",
"formula_terms": "s: s_rho C: C eta: eta depth: depth depth_c: depth_c",
},
)
},
)
ds.cf.decode_vertical_coords(outnames={"s_rho": "z_rho"})
print(ds.z_rho.values)
S = depth_c * s + (depth - depth_c) * C
print(S + eta * (1 + S / depth))
# ocean_s_coordinate
eta, a, b = 0.0, 5.0, 1.0
ds = xr.Dataset(
{
"eta": ((), eta, {"standard_name": "sea_surface_height_above_geoid"}),
"depth": ((), depth, {"standard_name": "sea_floor_depth_below_geoid"}),
"depth_c": ((), depth_c),
"a": ((), a),
"b": ((), b),
},
coords={
"s": (
"s",
s,
{
"standard_name": "ocean_s_coordinate",
"formula_terms": "s: s eta: eta depth: depth a: a b: b depth_c: depth_c",
},
)
},
)
ds.cf.decode_vertical_coords(outnames={"s": "z"})
print(ds.z.values)
C = (1 - b) * np.sinh(a * s) / np.sinh(a) + b * (
np.tanh(a * (s + 0.5)) / (2 * np.tanh(0.5 * a)) - 0.5
)
print(eta * (1 + s) + depth_c * s + (depth - depth_c) * C)
Output:
0.11.3
[-98.02 -30.01 2. ]
[-100. -30.64 2. ]
[-98.8033498 -50. -1.1966502]
[-100. -50. 0.]
Expected the first and third lines to equal the second and fourth. In both cases s = -1 should give z = -depth (-100), and for ocean_s_coordinate with eta = 0, s = 0 should give z = 0.
Formulas from Appendix D (https://cfconventions.org/cf-conventions/cf-conventions.html#parametric-v-coord):
ocean_s_coordinate_g1:
z = S + eta * (1 + S / depth)
S = depth_c * s + (depth - depth_c) * C
ocean_s_coordinate:
C = (1-b)*sinh(a*s)/sinh(a) + b*[tanh(a*(s+0.5))/(2*tanh(0.5*a)) - 0.5]
Causes in cf_xarray/parametric.py:
OceanSG1.decodeuses lowercasesinstead ofS:z = S + self.eta * (1 + self.s / self.depth).OceanS.decodeis missing parentheses:np.tanh(self.a * (self.s + 0.5)) / 2 * np.tanh(0.5 * self.a)divides by 2 and then multiplies bytanh(0.5*a), instead of dividing by2 * tanh(0.5*a).
Same output on cf_xarray 0.11.3 from PyPI and on main at 27e104c9ff4297b75412f71b5cee0fd1473a46f9. xarray 2026.9.0, numpy 2.2.6 (also 2.5.3 on the main install), Python 3.12, macOS.
- 主要語言
- Python
- 星號
- 183
- 分支
- 51
- 平均合併
- 6 小時 39 分鐘
- 30 天內合併 PR
- 1
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
xarray-contrib/cf-xarray 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
xarray-contrib/cf-xarray#623 ·
-
Consider adding opt-in support for circular axes when calling `bounds_to_vertices` (related to #594)未關閉
難度 5/5 一週以上 新手友好度 38/100
xarray-contrib/cf-xarray#596 · 1 則留言 ·
-
難度 3/5 1-2 天 新手友好度 25/100
xarray-contrib/cf-xarray#570 ·
-
難度 4/5 3-5 天 新手友好度 15/100
xarray-contrib/cf-xarray#568 ·
-
難度 3/5 1-2 天 新手友好度 35/100
xarray-contrib/cf-xarray#566 · 2 則留言 ·
查看 xarray-contrib/cf-xarray 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 64/100
aws-samples/sample-per-model-bedrock#295 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 76/100
pyrevitlabs/pyRevit#3792 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 69/100
zephyrproject-rtos/reqmgmt#177 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
polarsource/polar#15580 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 85/100
521xueweihan/HelloGitHub#4011 ·