issues: 375126758
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
375126758 | MDU6SXNzdWUzNzUxMjY3NTg= | 2525 | Multi-dimensional binning/resampling/coarsening | 8268991 | closed | 0 | 16 | 2018-10-29T17:18:15Z | 2019-01-06T09:13:46Z | 2019-01-06T09:13:46Z | NONE | Code Sample, a copy-pastable example if possibleThe StackOverflow Query : https://stackoverflow.com/questions/52886703/xarray-multidimensional-binning-array-reduction-on-sample-dataset-of-4-x4-to/52981916#52981916 ```python import pandas as pd import numpy as np import xarray as xr a = np.array(np.random.randint(1, 90+1,(4,4)),dtype=np.float64) b = np.array(np.random.randint(1, 360+1,(4,4)),dtype=np.float64) c = np.random.random_sample(16,) c = c.reshape(4,4) dsa = xr.Dataset() dsa['CloudFraction'] = (('x', 'y'), c) dsa.coords['latitude'] = (('x', 'y'), a) dsa.coords['longitude'] = (('x', 'y'), b) dsa Dimensions: (x: 4, y: 4) Coordinates: latitude (x, y) float64 23.0 16.0 53.0 1.0 ... 82.0 65.0 45.0 88.0 longitude (x, y) float64 219.0 13.0 276.0 69.0 ... 156.0 277.0 16.0 Dimensions without coordinates: x, y Data variables: CloudFraction (x, y) float64 0.1599 0.05671 0.8624 ... 0.7757 0.7572 ``` Problem descriptionI am trying to reduce an Xarray from 4 x 4 to 2 x 2 via both the dimensions. I haven't found any luck with the current Xarray Dataset. These are the steps I followed. I want to bin or group based on latitude and longitude both simultaneously to reduce number of steps. Currently I can achieve this by just GroupBy method which doesn't seem to perform GroupBy on both the coordinates. To elaborate the idea I want to achieve : 1. Considering a matrix of 4x4 , first we will group elements of index (0,0) with index (0,1) as A , index of (0,2) with index (0,3) as B, index of (1,0) with index (1,1) as C , index of (1,2) with index (1,3) as D and so on so forth. Last combination being index of (3,2) with index (3,3) as H. 2. This turns the matrix of 4x4 to 4x2 and now we combine elements A with C and B with D and so and so forth. The final matrix size should be 2x2. 3. The combination of elements can be done with any aggregation functions like mean() or std() and needs to be done over the coordinate of 'Latitude' and 'Longitude in reference to the data variables 'Cloud Fraction' 4. Is there a way to obtain this with Xarray functions and automate it with any input matrix size . Expected OutputTo elaborate the idea I want to achieve : 1. Considering a matrix of 4x4 , first we will group elements of index (0,0) with index (0,1) as A , index of (0,2) with index (0,3) as B, index of (1,0) with index (1,1) as C , index of (1,2) with index (1,3) as D and so on so forth. Last combination being index of (3,2) with index (3,3) as H. 2. This turns the matrix of 4x4 to 4x2 and now we combine elements A with C and B with D and so and so forth. The final matrix size should be 2x2. 3. The combination of elements can be done with any aggregation functions like mean() or std().
Numpy Version. : v1.15.1
Xarray Version : v0.10.9
Python Verison : v3.7.0
Jupyter Notebook : Locally Hosted
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2525/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |