Skip to content

Get a variable (salinity/temperature) but only at specified mixed layer depths #5964

Answered by mathause
pecos27 asked this question in Q&A
Discussion options

You must be logged in to vote

Have you tried salinity.sel(depth=mld_monthly, method="nearest")? The coords must align (but they seem to do). A small example:

s = xr.DataArray(np.arange(6).reshape(3, 2), dims=("d", "x"), coords=dict(d=[0, -1, -2], x=[11, 12]))
d = xr.DataArray([0, -1.4], name="d", dims=("x",), coords=dict(x=[11, 12]))

s.sel(d=d, method="nearest")

Which returns:

<xarray.DataArray (x: 2)>
array([0, 3])
Coordinates:
    d        (x) int64 0 -1
  * x        (x) int64 11 12

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pecos27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants