decode_vertical_coords gives wrong depths for ocean_s_coordinate and ocean_s_coordinate_g1
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Bắt đầu trong cf_xarray/parametric.py tại OceanSG1.decode và OceanS.decode, sau đó chạy reproducer từ issue để so sánh cả hai mảng đã giải mã với các công thức trong Appendix D. Hoàn thành khi hai triển khai khớp với các công thức đó, bao gồm z = -depth tại s = -1 và z = 0 đối với ocean_s_coordinate tại s = 0 với eta = 0.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 181
- Fork
- 51
- Merge trung bình
- 6 giờ 39 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của xarray-contrib/cf-xarray
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
xarray-contrib/cf-xarray#623 ·
-
Consider adding opt-in support for circular axes when calling `bounds_to_vertices` (related to #594)Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
xarray-contrib/cf-xarray#596 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
xarray-contrib/cf-xarray#570 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
xarray-contrib/cf-xarray#568 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
xarray-contrib/cf-xarray#566 · 2 bình luận ·
Tất cả issue của xarray-contrib/cf-xarray
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
PedestrianDynamics/pyFDS-Evac#766 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Markdown tables render as literal text in 3 example files (missing blank line before header)Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 91/100
alchaincyf/nuwa-skill#86 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Docs Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
pandas-dev/pandas#71055 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: graphify reads files that git's global ignore file hidesCó thể đã có người làm @smngvlkz đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Graphify-Labs/graphify#4335 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày