Tracker: Ocean roadmap for `@math.gl/earth`

未关闭
#613 3 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@athomct 已经在做这个了。

开始于 2026年11月27日。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
领域
backend

调研方向

Start by reading the existing @math.gl/earth/normal-gravity and @math.gl/earth/celestial subpath implementations, then review the pinned GSW-C 3.06.16 controls and qualification requirements described in the issue. The proposed first delivery covers O1 to O3, with original implementations, declared input domains, reference checks, and error gates; completion means the chosen tranche or tranches meet those qualification gates and document their limits.

由索引模型根据 Issue 内容生成。

描述

Scope: seawater state, sound speed, absorption; later tides, CTD state, rays, propagation, waves and rotation scales

Problem and behavior

Sonar and hydrographic survey viewers need a small set of ocean equations in the browser. They convert a pressure reading to a depth. They calculate sound speed from a temperature and salinity cast. They correct echo levels for absorption. Marine basemaps and deck.gl / tangram.gl marine examples need the same equations, and later a tide height.

Today each application copies these equations from papers. The copies have no declared input domain, no stated temperature scale and no reference controls.

I propose an optional subpath in @math.gl/earth. The name is open: @math.gl/earth/ocean or @math.gl/earth/seawater. This text uses ocean.

The subpath follows the pattern of @math.gl/earth/normal-gravity (PR #318) and @math.gl/earth/celestial (PR #284):

  • It has no datasets, no runtime imports, no downloads and no new dependencies.
  • It does not initialize the geoid, timezone or astronomy modules.
  • Each function declares its input domain. Inputs that are non-finite or out of the domain throw RangeError.
  • Each function has a pinned reference, stored controls and a declared error gate.

Tranches

Tranche Scope Status / qualification gate
O1: Seawater state TEOS-10 subset: Reference and Absolute Salinity, Conservative Temperature, density, freezing temperature, sound speed, pressure ↔ height Done in #619. GSW-C 3.06.16 controls. No atlas.
O2: Classic sound speed Chen–Millero (UNESCO), Del Grosso, Mackenzie Done in #619. Paper check values and an independent high-precision evaluation.
O3: Absorption Francois–Garrison 1982, Ainslie–McColm 1998 Done in #619. Same method as O2.
O4: Harmonic tide prediction Height from caller-supplied constituents; astronomical arguments and node factors Done in #765. NOAA CO-OPS published predictions.
O5: Rays and waves (optional) Rays in a layered sound-speed profile; linear wave dispersion Future. Analytic cases and an independent integrator.
O6: Seawater state from CTD data Practical Salinity from conductivity (PSS-78) and its inverse; potential temperature; potential density; buoyancy frequency N²; dynamic height; geostrophic velocity between two casts Done in #767 (O6a: PSS-78 both ways, potential temperature, potential density, N²) and #771 (O6b: dynamic height with PCHIP interpolation, geostrophic velocity). Review follow-ups in #773. GSW-C 3.06.16 check data, as O1.
O7: Propagation basics Spreading and absorption loss along a path; acoustic wavelength; near-field distance of a circular piston; harmonic-mean sound speed of a profile Future. Analytic cases and the Decimal evaluation of O2 and O3.
O8: Wave spectra Pierson–Moskowitz and JONSWAP spectra; significant wave height and peak period from spectral moments; Gerstner (trochoidal) wave parameters Future. Needs the O5 dispersion relation. Published spectrum parameters and analytic moments.
O9: Rotation scales Coriolis parameter; inertial period; Rossby radius of deformation Future. Analytic values.

O1 to O3 are the first delivery. They merged in #619. The bathymetry example uses them (#620, with fixes in #639). This issue stays open for O4 to O9.

O6 to O9 have the same rules as O1 to O3. Each function is original code from the cited papers, with the defaults that the papers give. It has no datasets, a declared input domain, pinned references and stored controls. The subpath gives general physics. It does not give sonar data processing.

O1: seawater state (TEOS-10 subset)

The functions are flat get* functions with long, descriptive names, as getSunPosition and getTimezoneOffset are in @math.gl/earth. They keep no state, so they are not methods of a class or an interface. The parameter names state the quantity, so a caller does not mix Absolute Salinity with Practical Salinity, or Conservative Temperature with in-situ temperature.

The Gibbs SeaWater (GSW) names are in the TSDoc and the API reference only. A reader uses them to find the reference function.

Function GSW counterpart (docs only) Notes
getReferenceSalinity(practicalSalinity) gsw_SR_from_SP Reference Salinity, g/kg. SR = (35.16504 / 35) × SP.
getAbsoluteSalinity(practicalSalinity, absoluteSalinityAnomaly = 0) gsw_SA_from_SP Absolute Salinity, g/kg. See below.
getConservativeTemperature(absoluteSalinity, temperature, seaPressure) gsw_CT_from_t Conservative Temperature, °C, ITS-90.
getSeawaterDensity(absoluteSalinity, conservativeTemperature, seaPressure) gsw_rho In-situ density, kg/m³. 75-term polynomial.
getSeawaterSoundSpeed(absoluteSalinity, conservativeTemperature, seaPressure) gsw_sound_speed m/s. 75-term polynomial.
getSeawaterFreezingTemperature(absoluteSalinity, seaPressure, airSaturationFraction) gsw_t_freezing_poly In-situ freezing temperature, °C.
getHeightFromSeaPressure(seaPressure, latitude, options) gsw_z_from_p Height in metres. Negative below the sea surface.
getSeaPressureFromHeight(height, latitude, options) gsw_p_from_z Sea pressure, dbar.

Pressure is sea pressure in dbar: absolute pressure minus 10.1325 dbar. This is the GSW convention.

Absolute Salinity without the atlas

gsw_SA_from_SP(SP, p, lon, lat) reads the Absolute Salinity Anomaly Ratio (SAAR) atlas. The C source of the atlas is 8.7 MB. This proposal does not include the atlas.

getAbsoluteSalinity calculates SA = SR + δSA. The default δSA (absoluteSalinityAnomaly) is 0. Then SA is equal to Reference Salinity. A caller who has an atlas value or a measured value passes δSA in g/kg.

The documentation will state the cost of the default. In the GSW atlas, the Absolute Salinity Anomaly Ratio is below 8.6e-4 outside the Black Sea area. Thus in the open ocean δSA is at most about 0.03 g/kg. The largest open-ocean values are in the deep Pacific. The Baltic Sea is a special case in GSW, and the default does not cover it.

Three corrections to the simple plan
  1. getConservativeTemperature needs more than the 75-term polynomial. gsw_CT_from_t first finds potential temperature from the entropy of the full Gibbs function. It uses two iterations of a modified Newton method. It then applies the potential-enthalpy polynomial of gsw_CT_from_pt. The implementation thus includes these two parts of the seawater Gibbs function, but no other part of it.
  2. The exact gsw_t_freezing needs the Gibbs function of ice. Sea ice is not in scope. I propose the polynomial form, gsw_t_freezing_poly. The GSW source gives an error figure only for the Conservative Temperature form, gsw_CT_freezing_poly: −5e-4 K to 6e-4 K against the exact form. It states no figure for gsw_t_freezing_poly. At the 98 stored check levels of gsw_check_data.h, the polynomial minus the exact value is −1.9e-4 K to 7.1e-5 K. The PR will measure the difference across the domain and state it.
  3. The GSW licence does not permit modified copies. See "Licences" below. The implementation must be original code written from the published equations.
Gravity for getHeightFromSeaPressure and getSeaPressureFromHeight

gsw_z_from_p uses its own surface gravity:

g(φ) = 9.780327 × (1 + (5.2792e-3 + 2.32e-5 × sin²φ) × sin²φ)

It then applies a constant vertical factor, γ = 2.26e-7 per metre, for gravity in the water column. It uses the enthalpy of a standard ocean (SA = 35.16504 g/kg, CT = 0 °C).

I compared this formula with the WGS84 closed formula (Somigliana) that NormalGravity.WGS84().surfaceGravity(latitude) of PR #318 evaluates:

γ(φ) = 9.7803253359 × (1 + 0.00193185265241 × sin²φ) / √(1 − 0.00669437999013 × sin²φ)

The relative difference (g − γ) / γ is 1.70e-7 at the equator, 2.15e-7 at latitude 45° and 1.29e-7 at the poles. The height from gsw_z_from_p is approximately proportional to 1 / g. Thus at a depth of 10 km the result moves by 1.3 mm to 2.2 mm. 10 km is outside the proposed domain; at its 8000 dbar limit the change is less than 2 mm.

I propose that the default is the GSW formula, with no import of normal-gravity:

  • The GSW check tolerance for z_from_p is 2.3e-8 m. A different gravity formula cannot pass this gate.
  • NormalGravity.evaluate accepts heights from zero up. It does not accept points below the ellipsoid. The free-air gradient is also not correct in water.
  • A hard import increases the bundle and couples two optional entries.

An options.surfaceGravity value lets a caller supply NormalGravity.WGS84().surfaceGravity(latitude) or a measured value. The options also accept the two GSW arguments geoStrfDynHeight and seaSurfaceGeopotential. Each defaults to 0.

Supported profile

Roquet et al. 2015 fit the 75-term polynomial over the "oceanographic funnel". GSW-C encodes the funnel in gsw_infunnel. Its limits are:

  • 0 ≤ SA ≤ 42 g/kg and 0 ≤ p ≤ 8000 dbar.
  • CT is not below the freezing temperature (at p, or at 500 dbar when p ≥ 500).
  • From 500 to 6500 dbar: SA ≥ 0.005 p − 2.5 and CT ≤ 31.67 − 0.003333 p.
  • From 6500 dbar: SA ≥ 30 and CT ≤ 10 °C.

I propose the funnel as the domain of getSeawaterDensity and getSeawaterSoundSpeed, with 0 ≤ SP ≤ 42. The freezing limit uses the polynomial form. The draft box (−2 °C to 40 °C, up to 10 000 dbar) was wider than the funnel, so I removed it. Latitude is in degrees, ±90.

O2: classic sound-speed equations

These equations are in wide use in survey software. Applications need them to reproduce existing results.

Function Source Stated validity Check value
getSoundSpeedChenMillero(practicalSalinity, temperature, seaPressure) Chen and Millero 1977; UNESCO algorithm in Fofonoff and Millard 1983; ITS-90 coefficients of Wong and Zhu 1995 0 to 40 °C, salinity 0 to 40, 0 to 10 000 dbar. Standard deviation 0.19 m/s. 1731.995 m/s at S = 40, t = 40 °C (IPTS-68), p = 10 000 dbar (Fofonoff and Millard 1983, p. 48 and the SVEL listing, p. 49)
getSoundSpeedDelGrosso(practicalSalinity, temperature, seaPressure) Del Grosso 1974 (NRL II); ITS-90 coefficients of Wong and Zhu 1995 0 to 30 °C, salinity 30 to 40, 0 to 1000 kg/cm². Standard deviation 0.05 m/s. None found in open sources
getSoundSpeedMackenzie(practicalSalinity, temperature, depth) Mackenzie 1981, nine-term equation −2 to 30 °C, salinity 30 to 40, depth 0 to 8000 m (paper abstract) None found in open sources

The Chen–Millero range and standard deviation are from Fofonoff and Millard 1983. The Del Grosso standard deviation and the Mackenzie range are from the paper abstracts. The NPL technical guide "Speed of sound in sea-water" gives the same ranges for Chen–Millero and Del Grosso. For Mackenzie, NPL gives a narrower range: 2 to 30 °C and salinity 25 to 40. The documentation will give both and use the paper range.

I evaluated the Fofonoff and Millard coefficients in 40-digit decimal arithmetic. The result is 1731.9954 m/s, which agrees with the check value. The Wong and Zhu coefficients (as NPL prints them) give 1732.0037 m/s at the same point, with t90 = 40 / 1.00024 °C. The difference is 0.008 m/s. This is within the 0.024 m/s change that Wong and Zhu state. Thus the IPTS-68 check value is not a control for the ITS-90 form at its printed precision. I did not find a published check value for the ITS-90 form.

No open source that I found prints a check value for Del Grosso or for Mackenzie. The Del Grosso paper has comparison tables, but I could not read them. For these two equations, the controls are an independent high-precision evaluation (see "Qualification"). For example, the Mackenzie equation gives 1550.7440275 m/s at T = 25 °C, S = 35 and depth 1000 m. This is my own evaluation, not a published value.

The API accepts ITS-90 temperature. The original equations predate ITS-90; Fofonoff and Millard state IPTS-68. The documentation of each function states the scale and the conversion, t68 = 1.00024 × t90 (as GSW t90_from_t68 uses). The Fofonoff and Millard check value applies to the IPTS-68 form, and the qualification evaluates that form.

Mackenzie uses depth, not pressure. The other two equations use pressure. The function signatures keep this difference visible.

O3: acoustic absorption

Each function returns absorption in dB/km. Each function has five or six inputs, so it takes one options object with named fields: frequency, temperature, salinity, depth, pH, and soundSpeed for Francois–Garrison.

Function Source Inputs Stated validity
getSoundAbsorptionFrancoisGarrison(options) Francois and Garrison 1982, parts I and II Frequency, temperature, salinity, depth, pH, sound speed "All oceanic conditions and frequencies from 200 Hz to 1 MHz" (Part II abstract). About 5 % accuracy (NPL).
getSoundAbsorptionAinslieMcColm(options) Ainslie and McColm 1998 Frequency, temperature, salinity, depth, pH Within 10 % of Francois–Garrison from 100 Hz to 1 MHz (NPL)

Both formulas are the sum of three terms: boric acid, magnesium sulphate and pure water.

The Part I abstract gives the range of the total equation as 400 Hz to 1 MHz. The Part II abstract gives 200 Hz to 1 MHz. The documentation will quote both.

The NPL guide "Calculation of absorption of sound in seawater" gives these Francois–Garrison reliability limits:

  • 10 kHz to 500 kHz (magnesium sulphate dominates): −2 to 22 °C, salinity 30 to 35, depth 0 to 3.5 km.
  • Above 500 kHz (pure water dominates): 0 to 30 °C, salinity 0 to 40, depth 0 to 10 km.

The same guide gives the Ainslie–McColm limits. Each limit applies with the other inputs at the stated values:

  • −6 to 35 °C (salinity 35, pH 8, depth 0).
  • pH 7.7 to 8.3 (10 °C, salinity 35, depth 0).
  • Salinity 5 to 50 (10 °C, pH 8, depth 0).
  • Depth 0 to 7 km (10 °C, salinity 35, pH 8).

I could not read the full papers. Thus I have not confirmed these limits against them, and I have not found printed values that can be controls. The Ainslie–McColm abstract says only that the paper compares the two formulas. The PR will quote any printed table with page references. Until then, the controls are the independent high-precision evaluation.

Qualification (O1 to O3)

O1 reference. The reference is GSW-C 3.06.16, pinned at one commit. GSW-C includes gsw_check_data.h. It stores three casts of 45 levels (98 valid levels), the reference outputs at each level, and one tolerance for each function. The file states that these values come from the GSW MATLAB 3.06.16 data file. The casts are the first controls, and they need no compiled code. They cover 0 to 6131 dbar and 1.3 °C to 28 °C. For controls outside the casts, a native generator compiles the unmodified GSW-C offline and writes stored controls with provenance. Ordinary CI uses only the stored controls, in Node, Chromium, Firefox and WebKit.

O1 gates. I propose the GSW check tolerances as the gates. These gates are set before the implementation.

Function Gate against GSW-C 3.06.16
getReferenceSalinity 1.3e-10 g/kg
getConservativeTemperature 6.3e-10 °C
getSeawaterDensity 2.9e-10 kg/m³
getSeawaterSoundSpeed 2.6e-9 m/s
getSeawaterFreezingTemperature 2.2e-11 °C
getHeightFromSeaPressure 2.3e-8 m
getSeaPressureFromHeight 2.3e-8 dbar

The controls will extend past the GSW casts to the edges of the declared domain. At the cast points, a test compares getAbsoluteSalinity with a non-zero δSA against gsw_SA_from_SP. gsw_check_data.h stores the atlas δSA for these points. The test leaves out the Baltic Sea cast, because GSW uses a different formula there.

O2 and O3 reference. No reference library is necessary. The controls are the check values and tables of the original papers, where they exist. Today the only verified printed value is the Fofonoff and Millard check value. A separate high-precision Decimal evaluation of each published formula gives more controls across the declared domain. The Decimal evaluation does not reuse the production code.

O2 and O3 gates. The proposed gates are 1e-9 m/s for sound speed and a relative 1e-12 for absorption, against the Decimal evaluation. Paper check values are gates at their printed precision.

All tranches. These are evaluation-error gates. They are not model uncertainty. The documentation states the published accuracy of each equation separately.

The PR also includes strict ESM/CJS type consumers, an isolated bundle check with a declared byte budget, source headers and THIRD-PARTY-NOTICES.md entries.

Licences

The GSW toolbox licence (SCOR/IAPSO WG127, 2011) uses the three BSD conditions. But it permits redistribution and use only "without modification". The clause in LICENSE of GSW-C is:

Redistribution and use, in source and binary forms, without modification, is permitted provided that the following conditions are met:

It is thus not BSD-3-Clause. LICENSE.txt of GSW-Python has the same clause. It adds a title line and the copyright line "Copyright 2017-2020 Eric Firing and contributors".

A TypeScript port of the GSW source is a modified copy. Thus I propose an original implementation from the published equations: IOC, SCOR and IAPSO 2010 (the TEOS-10 manual), and Roquet et al. 2015 for the 75-term polynomial. GSW-C stays an offline comparator, as GeographicLib does in PR #318. The notices credit TEOS-10 as the scientific formulation.

Please say if you read the licence differently.

O4: harmonic tide prediction (future)

The function evaluates the standard sum:

h(t) = Z0 + Σ f·H·cos(a·t + (V0 + u) − κ)

The caller supplies the datum offset Z0 and, for each constituent, the amplitude H, the phase κ and the speed a. The subpath supplies the node factor f and the equilibrium argument V0 + u for named constituents.

I propose the formulation of Schureman (Special Publication 98, 1958), because NOAA documents it as the basis of its node factors and equilibrium arguments (Parker 2007, pp. 40–42). Doodson numbers identify the constituents. The Foreman (1977) satellite method is a possible second formulation, not part of the first version.

Time comes from the JulianDate of PR #284, in UT1. One second of time error moves the M2 phase by 0.008°. Thus a caller without a UT1 model can declare an offset of zero from UTC.

Qualification uses NOAA CO-OPS published predictions for one station with public harmonic constants. An example is station 9414290, San Francisco. The CO-OPS metadata API publishes 37 constituents for this station. The data API publishes predictions in metres to three decimals. The stored controls record the station, datum, units and retrieval date. The proposed gate is 0.01 m across one year.

NOAA states that its information is in the public domain unless annotated otherwise, and that the public may use it freely. NOAA requests attribution. It also states that the information "shall not be modified in content and then presented as official government material". The stored controls are thus permitted, with attribution, and the documentation will not present them as official.

NOAA documents the node-factor convention. "In the U.S. a single value of f has typically been used for each year, for each tidal constituent, that value being for the middle of the year" (Parker 2007, p. 41). The u term is also constant for each year. Schureman gives the M1 node factor as f(M1) = f(O1) × 1/Qa (formulas 206 and 207, pp. 42–43). He states that this factor is about 50 % larger than intended, but that predictions are not affected. NOAA does not state that current predictions still use this M1 factor. The first measurement must confirm it.

O5: rays and waves (optional, future)

  • Ray paths through a layered sound-speed profile. Snell's law applies at each layer. A layer with a constant gradient gives a circular arc.
  • The horizontal distance, depth and travel time at each point of a ray path.
  • Linear wave dispersion: wavelength and celerity from period and depth.

Controls are analytic cases (constant speed, one constant gradient, deep-water and shallow-water limits) and an independent high-precision integrator.

Example

The first delivery extends the bathymetry example (examples/geospatial/bathymetry). It does not add a separate example.

  1. The user clicks a point on the globe. The example finds the latitude, the longitude and the ETOPO1 seafloor depth at that point.
  2. The example reads the climatology profile (in-situ temperature and practical salinity at standard depths) at the nearest ocean cell. The profile stops at the seafloor.
  3. At each level it calls getSeaPressureFromHeight, getAbsoluteSalinity, getConservativeTemperature and getSeawaterSoundSpeed.
  4. A panel shows the sound-speed profile from the surface to the seafloor. It marks the depth of the minimum sound speed.
  5. The panel shows absorption at a frequency that the user selects, from getSoundAbsorptionFrancoisGarrison.

A later step can colour the globe by sound speed at a selected depth.

The climatology is the NOAA NCEI World Ocean Atlas 2023 (WOA23), annual mean, objectively analyzed fields t_an and s_an on the 1° grid (102 standard depths to 5500 m). The netCDF license attribute says: "These data are openly available to the public. Please acknowledge the use of these data with the text given in the acknowledgment attribute." I found no named licence such as CC0.

I propose a WOA23 Collection in the earth/stac catalog of visgl/deck.gl-data. It uses license: "other" with a licence-evidence link, as the EGM96 Collection does. The Item has a lossless Parquet snapshot and a small display preview for the example. The subpath itself stays dataset-free.

More examples and data

  • Tide curve (after O4): the predicted height at one NOAA station over a week, with high and low waters marked. The constituents come from the NOAA CO-OPS API at run time, or from a small stored copy with attribution.
  • Sound-speed rays (after O5): a fan of rays from a source at a selected depth, through the profile of the bathymetry example. It shows the shadow zone and the sound channel.
  • Water column (after O6a): a tab next to Sound speed in the bathymetry example. It shows potential density and N² with depth, and marks the pycnocline and the mixed-layer depth. It uses the WOA23 profiles that the example already loads.
  • Load a CTD cast (after O6a): drop a CSV of conductivity, temperature and pressure onto the bathymetry map. PSS-78 converts it, and the panel uses it in place of WOA23. A stored sample cast needs a source with a clear licence.
  • Dynamic height and currents (after O6b): a globe layer of dynamic height relative to 1000 dbar from the WOA23 preview, and geostrophic current arrows between neighbor cells. The arrows stop near the equator, where the Coriolis parameter goes to zero. Moving particles can follow later with the luma.gl spherical flow graph (visgl/luma.gl#3975).
  • Sea surface (after O8): a deck.gl or tangram.gl surface with Gerstner waves from a JONSWAP spectrum.
  • Data: NOAA tide constituents are public domain and can go in the earth/stac catalog with WOA23. TPXO and other global tide models are not candidates, because their licences restrict use.

What it is not

  • It is not the full GSW library. It has no SAAR atlas, no sea ice functions and no exact Gibbs-function sound speed.
  • It has no tidal constituent datasets and no station catalogue.
  • It is not an ocean model, a tide model or a navigation-grade depth source.
  • getHeightFromSeaPressure does not use a measured density profile unless the caller supplies the dynamic height anomaly.
  • It does not convert between vertical datums. @math.gl/earth/geoid stays the height-conversion foundation.

Open questions

  1. Name. Do you prefer @math.gl/earth/ocean or @math.gl/earth/seawater? seawater fits O1 to O3. ocean also fits tides, rays and waves.
  2. Package. Does this belong in @math.gl/earth, or do you prefer a new package?
  3. Gravity. Do you agree that getHeightFromSeaPressure uses the GSW gravity formula by default, with no dependency on PR #318?
  4. Scope of the first delivery. Do you want O1, O2 and O3 together, or O1 alone first?
  5. Light in seawater. Is a Beer–Lambert attenuation function by wavelength useful for renderers? The water-type tables are small, but I have not checked their licences. It is not a tranche yet.

If you agree with the direction, I can prepare the PRs. The first PR adds dev-docs/ocean-roadmap.md with the table above.

Sources

主要语言
TypeScript
星标
72
派生
7
平均合并
3 小时 57 分钟
30 天内合并 PR
404

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

visgl/math.gl 的其他 Issue

查看 visgl/math.gl 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。