I think there's a bug in the function so that it assumes 1D decoding such that "position" is used (lines 148-154)
posterior = (
results.acausal_posterior.unstack("state_bins")
.drop_sel(state=["Local", "No-Spike"], errors="ignore")
.sum("state")
)
posterior /= posterior.sum("position")
env = cls.fetch_environments(key)[0]
if "x_position" in results.coords:
position_info, position_variable_names = cls.fetch_position_info(
key
)
# Not 1D
bin_size = (
np.nanmedian(np.diff(np.unique(results.x_position.values))),
np.nanmedian(np.diff(np.unique(results.y_position.values))),
)
return create_2D_decode_view(
position_time=position_info.index,
position=position_info[position_variable_names],
interior_place_bin_centers=env.place_bin_centers_[
env.is_track_interior_.ravel(order="C")
],
place_bin_size=bin_size,
posterior=posterior,
head_dir=position_info[head_direction_name],
)
else:
return create_1D_decode_view(
posterior=posterior,
linear_position=cls.fetch_linear_position_info(key),
)
view = DecodingOutput().create_decoding_view(
{'merge_id': '62489783-fd62-7eff-2d76-93f237e1e815'}
)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/namedarray/core.py:702, in NamedArray._get_axis_num(self, dim)
701 try:
--> 702 return self.dims.index(dim) # type: ignore[no-any-return]
703 except ValueError as err:
ValueError: tuple.index(x): x not in tuple
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
Cell In[42], line 1
----> 1 view = DecodingOutput().create_decoding_view(
2 {'merge_id': '62489783-fd62-7eff-2d76-93f237e1e815'}
3 )
File ~/spyglass/src/spyglass/decoding/decoding_merge.py:153, in DecodingOutput.create_decoding_view(cls, key, head_direction_name, interval_idx)
143 logger.warning(
144 f"interval_idx={interval_idx} specified but results do not "
145 "have 'interval_labels' coordinate. Ignoring interval_idx."
146 )
148 posterior = (
149 results.acausal_posterior.unstack("state_bins")
150 .drop_sel(state=["Local", "No-Spike"], errors="ignore")
151 .sum("state")
152 )
--> 153 posterior /= posterior.sum("position")
154 env = cls.fetch_environments(key)[0]
156 if "x_position" in results.coords:
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/core/_aggregations.py:3175, in DataArrayAggregations.sum(self, dim, skipna, min_count, keep_attrs, **kwargs)
3087 def sum(
3088 self,
3089 dim: Dims = None,
(...)
3094 **kwargs: Any,
3095 ) -> Self:
3096 """
3097 Reduce this DataArray's data by applying ``sum`` along some dimension(s).
3098
(...)
3173 array(8.)
3174 """
-> 3175 return self.reduce(
3176 duck_array_ops.sum,
3177 dim=dim,
3178 skipna=skipna,
3179 min_count=min_count,
3180 keep_attrs=keep_attrs,
3181 **kwargs,
3182 )
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/core/dataarray.py:3857, in DataArray.reduce(self, func, dim, axis, keep_attrs, keepdims, **kwargs)
3813 def reduce(
3814 self,
3815 func: Callable[..., Any],
(...)
3821 **kwargs: Any,
3822 ) -> Self:
3823 """Reduce this array by applying `func` along some dimension(s).
3824
3825 Parameters
(...)
3854 summarized data and the indicated dimension(s) removed.
3855 """
-> 3857 var = self.variable.reduce(func, dim, axis, keep_attrs, keepdims, **kwargs)
3858 return self._replace_maybe_drop_dims(var)
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/core/variable.py:1681, in Variable.reduce(self, func, dim, axis, keep_attrs, keepdims, **kwargs)
1674 keep_attrs_ = (
1675 _get_keep_attrs(default=False) if keep_attrs is None else keep_attrs
1676 )
1678 # Note that the call order for Variable.mean is
1679 # Variable.mean -> NamedArray.mean -> Variable.reduce
1680 # -> NamedArray.reduce
-> 1681 result = super().reduce(
1682 func=func, dim=dim, axis=axis, keepdims=keepdims, **kwargs
1683 )
1685 # return Variable always to support IndexVariable
1686 return Variable(
1687 result.dims, result._data, attrs=result._attrs if keep_attrs_ else None
1688 )
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/namedarray/core.py:909, in NamedArray.reduce(self, func, dim, axis, keepdims, **kwargs)
906 raise ValueError("cannot supply both 'axis' and 'dim' arguments")
908 if dim is not None:
--> 909 axis = self.get_axis_num(dim)
911 with warnings.catch_warnings():
912 warnings.filterwarnings(
913 "ignore", r"Mean of empty slice", category=RuntimeWarning
914 )
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/namedarray/core.py:697, in NamedArray.get_axis_num(self, dim)
695 return tuple(self._get_axis_num(d) for d in dim)
696 else:
--> 697 return self._get_axis_num(dim)
File ~/miniforge3/envs/spyglass_py310/lib/python3.10/site-packages/xarray/namedarray/core.py:704, in NamedArray._get_axis_num(self, dim)
702 return self.dims.index(dim) # type: ignore[no-any-return]
703 except ValueError as err:
--> 704 raise ValueError(
705 f"{dim!r} not found in array dimensions {self.dims!r}"
706 ) from err
ValueError: 'position' not found in array dimensions ('time', 'x_position', 'y_position')
I think there's a bug in the function so that it assumes 1D decoding such that "position" is used (lines 148-154)
before checking if 1D or 2D position (lines 156 - 178)
to reproduce:
error stack: