Closed edeno closed 7 years ago
It turns out xarray will handle the binary operations fine if the concatenation dimension contains an index in which to align. So the following doesn't work:
import xarray as xr
import pandas as pd
blah = xr.DataArray([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dims=['tetrode1', 'tetrode2'], coords={'tetrode1': range(3), 'tetrode2': range(3), 'brain_area1': ('tetrode1', ['A', 'A', 'B']), 'brain_area2': ('tetrode2', ['A', 'A', 'B'])})
blah3 = xr.concat((blah, blah, blah), dim='session')
blah2 = xr.concat((blah, blah), dim='session')
blah3 - blah2
ValueError: arguments without labels along dimension 'session' cannot be aligned because they have different dimension sizes: {2, 3}
But if we give it an index, it works fine:
import xarray as xr
import pandas as pd
blah = xr.DataArray([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dims=['tetrode1', 'tetrode2'], coords={'tetrode1': range(3), 'tetrode2': range(3), 'brain_area1': ('tetrode1', ['A', 'A', 'B']), 'brain_area2': ('tetrode2', ['A', 'A', 'B'])})
ind3 = pd.MultiIndex.from_tuples([('HPa', 3, 1), ('HPa', 3, 2), ('HPb', 2, 3)], names=['animal', 'day', 'epoch'])
blah3 = xr.concat((blah, blah, blah), dim=ind3)
ind2 = pd.MultiIndex.from_tuples([('HPa', 3, 1), ('HPa', 3, 2)], names=['animal', 'day', 'epoch'])
blah2 = xr.concat((blah, blah), dim=ind2)
blah3 - blah2
<xarray.DataArray (session: 2, tetrode1: 3, tetrode2: 3)>
array([[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]])
Coordinates:
* session (session) MultiIndex
- animal (session) object 'HPa' 'HPa'
- day (session) int64 3 3
- epoch (session) int64 1 2
brain_area1 (tetrode1) <U1 'A' 'A' 'B'
* tetrode1 (tetrode1) int64 0 1 2
brain_area2 (tetrode2) <U1 'A' 'A' 'B'
* tetrode2 (tetrode2) int64 0 1 2
The following error occurs: