issues: 947796627
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
947796627 | MDU6SXNzdWU5NDc3OTY2Mjc= | 5620 | `xr.where()` does not work like `np.where()`on meshgrids | 27021858 | closed | 0 | 6 | 2021-07-19T15:55:10Z | 2021-07-20T11:32:45Z | 2021-07-20T07:58:18Z | NONE | In case of selecting 2D data, the Here is my code: ```python data = xarray.open_dataset('path_to_attached_file') minLat, minLon, maxLat, maxLon = (45.08903556483102, 5.625000000000013, 48.92249926375824, 11.249999999999993) latitudes = data.lat.values longitudes = data.lon.values slice_mask = np.where( (latitudes <= maxLat) & (latitudes > minLat) & (longitudes <= maxLon) & (longitudes > minLon) ) _sliced_data = data.where( (data.lat <= maxLat) & (data.lat > minLat) & (data.lon <= maxLon) & (data.lon > minLon), drop=True, ) _sliced_data.latitude.values.max() 49.305596latitudes[slice_mask].max() 48.922172``` I have also tried to translate the numpy result into a boolen DataArray: ```python mask_array = data.copy() mask_array.update({'air_temperature_2m': (("y", "x"), (latitudes <= maxLat) & (latitudes > minLat) & (longitudes <= maxLon) & (longitudes > minLon))}) _sliced_data = data.where( mask_array.air_temperature_2m, drop=True, ) ``` There we have the same result. It seems that the masking step does not really works correctly. Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.9.1 (default, Feb 9 2021, 07:55:26) [GCC 8.3.0] python-bits: 64 OS: Linux OS-release: 5.10.0-1033-oem machine: x86_64 processor: byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.12.0 libnetcdf: 4.7.4 xarray: 0.16.2 pandas: 1.2.1 numpy: 1.20.0 scipy: 1.6.0 netCDF4: 1.5.5.1 pydap: None h5netcdf: 0.8.0 h5py: 3.2.1 Nio: None zarr: None cftime: 1.5.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: 0.9.8.4 iris: None bottleneck: None dask: 2021.05.0 distributed: None matplotlib: 3.3.4 cartopy: None seaborn: None numbagg: None pint: None setuptools: 53.0.0 pip: 21.0.1 conda: None pytest: 6.1.1 IPython: 7.21.0 sphinx: None |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5620/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |