issues: 1086732825
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1086732825 | I_kwDOAMm_X85AxjoZ | 6100 | dataset.sel() argument to select outside closest neighbours is implemented? | 48764870 | closed | 0 | 2 | 2021-12-22T11:32:36Z | 2021-12-22T15:55:33Z | 2021-12-22T15:46:12Z | NONE | Discussed in https://github.com/pydata/xarray/discussions/6099
<sup>Originally posted by **aragong** December 22, 2021</sup>
Hi all,
I am always struggling with this kind of selection of a desired domain or time range. For me it is very common to select data to make other interpolations and this feature will be very useful in my day by day. I make simple code to expose my doubt, thank you in advance!
```python
import numpy as np
import pandas as pd
import xarray as xr
from datetime import datetime
# Create random_values dataset with time, latitude, longitude coords
longitudes = np.arange(-180, 180, 5)
latitudes = np.arange(-90, 90, 5)
times = pd.date_range(start=datetime(2021, 1, 1), end=datetime(2021, 12, 31), freq="D")
data = np.random.rand(len(times), len(latitudes), len(longitudes))
da = xr.DataArray(
data=data,
coords=[times, latitudes, longitudes],
dims=["time", "latitude", "longitude"],
)
ds = da.to_dataset(name="random_values")
# Create a slices based on tmin,tmax lonmin,lonmax and latmin,latmax of the desired location and timerange
t_min = datetime(2021, 2, 16, 12, 0, 0)
t_max = datetime(2021, 3, 6, 12, 0, 0)
lon_min = -3
lon_max = 28
lat_min = 12
lat_max = 48
desired_time = slice(t_min, t_max)
desired_lon = slice(lon_min, lon_max)
desired_lat = slice(lat_min, lat_max)
# make standard dataset selection
standard_sel_ds = ds.sel(time=desired_time, latitude=desired_lat, longitude=desired_lon)
print(
f"time_min = {standard_sel_ds['time'].min().values}\n time_max = {standard_sel_ds['time'].max().values}"
)
print(
f"lon_min = {standard_sel_ds['longitude'].min().values}\n lon_max = {standard_sel_ds['longitude'].max().values}"
)
print(
f"lat_min = {standard_sel_ds['latitude'].min().values}\n lat_max = {standard_sel_ds['latitude'].max().values}"
)
# I would like to have a extra argument to select the outside closest neighbours of the sesired coordinates. Resulting:
print(
"time_min = 2021-02-16T00:00:00.000000000\n time_max = 2021-03-07T00:00:00.000000000"
)
print("lon_min = -5\n lon_max = 30")
print("lat_min = 10\n lat_max = 50")
# Anyone knows if that is developed in xarray.sel (???)
```
Would be greate to add to method argument this behaviour as "outside_fill" or similar! |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/6100/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |