decode_vertical_coords gives wrong depths for ocean_s_coordinate and ocean_s_coordinate_g1
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 88/100
Piste de recherche
Commencez dans cf_xarray/parametric.py, au niveau de OceanSG1.decode et OceanS.decode, puis exécutez le reproducer de l’issue afin de comparer les deux tableaux décodés avec les formules de l’Appendix D. C’est terminé lorsque les deux implémentations correspondent à ces formules, notamment z = -depth pour s = -1 et z = 0 pour ocean_s_coordinate à s = 0 avec eta = 0.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 183
- Forks
- 51
- Merge moyen
- 6 h 39 min
- PR mergées (30 j)
- 1
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de xarray-contrib/cf-xarray
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
xarray-contrib/cf-xarray#623 ·
-
Consider adding opt-in support for circular axes when calling `bounds_to_vertices` (related to #594)Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
xarray-contrib/cf-xarray#596 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 25/100
xarray-contrib/cf-xarray#570 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 15/100
xarray-contrib/cf-xarray#568 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
xarray-contrib/cf-xarray#566 · 2 commentaires ·
Toutes les issues de xarray-contrib/cf-xarray
Issues similaires
-
Use mhctools predictor_required=False for saved-result rescoringPeut-être pris @iskandr l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
521xueweihan/HelloGitHub#4051 · 1 commentaire ·
-
bug documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
awslabs/visual-asset-management-system#514 ·
Les mainteneurs répondent en général sous 1 jour
-
backend bug spec:REQ-053
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
nolte/kamerplanter#2547 ·
Les mainteneurs répondent en général sous 1 jour