Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

decode_vertical_coords gives wrong depths for ocean_s_coordinate and ocean_s_coordinate_g1

Đã đóng Phù hợp với người mới
#666 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
data

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.decode uses lowercase s instead of S: z = S + self.eta * (1 + self.s / self.depth).
  • OceanS.decode is missing parentheses: np.tanh(self.a * (self.s + 0.5)) / 2 * np.tanh(0.5 * self.a) divides by 2 and then multiplies by tanh(0.5*a), instead of dividing by 2 * 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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của xarray-contrib/cf-xarray

Tất cả issue của xarray-contrib/cf-xarray

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.