Skip to content

Conversation

@michaeldenes
Copy link
Member

Updating the polyteos kernel to compute the seawater density (and not just the seawater density anomaly). This is related to Parcels-code/Parcels#2133

Copy link
Contributor

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Would it be useful/easy to also add a unit test here? Such as in the v3 code?

from v3:

@pytest.mark.parametrize("mode", ["scipy", "jit"])
def test_TEOSdensity_kernels(mode):
    def generate_fieldset(xdim=2, ydim=2, zdim=2, tdim=1):
        lon = np.linspace(0.0, 10.0, xdim, dtype=np.float32)
        lat = np.linspace(0.0, 10.0, ydim, dtype=np.float32)
        depth = np.linspace(0, 2000, zdim, dtype=np.float32)
        time = np.zeros(tdim, dtype=np.float64)
        U = np.ones((tdim, zdim, ydim, xdim))
        V = np.ones((tdim, zdim, ydim, xdim))
        abs_salinity = 30 * np.ones((tdim, zdim, ydim, xdim))
        cons_temperature = 10 * np.ones((tdim, zdim, ydim, xdim))
        dimensions = {"lat": lat, "lon": lon, "depth": depth, "time": time}
        data = {
            "U": np.array(U, dtype=np.float32),
            "V": np.array(V, dtype=np.float32),
            "abs_salinity": np.array(abs_salinity, dtype=np.float32),
            "cons_temperature": np.array(cons_temperature, dtype=np.float32),
        }
        return (data, dimensions)

    data, dimensions = generate_fieldset()
    fieldset = FieldSet.from_data(data, dimensions)

    DensParticle = ptype[mode].add_variable("density", dtype=np.float32)

    pset = ParticleSet(fieldset, pclass=DensParticle, lon=5, lat=5, depth=1000)

    pset.execute(PolyTEOS10_bsq, runtime=1)

    assert np.allclose(pset[0].density, 1027.45140)

@michaeldenes michaeldenes merged commit 3218321 into main Oct 31, 2025
5 checks passed
@michaeldenes michaeldenes deleted the fix_PolyTEOS_kernel branch October 31, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants