how to use sel with the very first example ds in Creating a Dataset #7644
Unanswered
jj-github-jj
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The following link to the very first example in documentation does not actually show to use sel with the example dataset
Creating a Dataset
temp = 15 + 8 * np.random.randn(2, 2, 3)
precip = 10 * np.random.rand(2, 2, 3)
lon = [[-99.83, -99.32], [-99.79, -99.23]]
lat = [[42.25, 42.21], [42.63, 42.59]]
ds = xr.Dataset(
{
"temperature": (["x", "y", "time"], temp),
"precipitation": (["x", "y", "time"], precip),
},
coords={
"lon": (["x", "y"], lon),
"lat": (["x", "y"], lat),
"time": pd.date_range("2014-09-06", periods=3),
"reference_time": pd.Timestamp("2014-09-05"),
},
)
I keep getting errors when trying to do something like the following
select temperature data at a specific latitude and longitude
temp_data = ds.sel(lat=42.21, lon=-99.32)["temperature"]
print the selected temperature data
print(temp_data)
Beta Was this translation helpful? Give feedback.
All reactions