Skip to content

Commit

Permalink
Minor fix for 1D output arrays
Browse files Browse the repository at this point in the history
- if we pass a dataarray made from .sel() of a single channel the
underlying numpy is 1D.  Force this to be 2D to make things smooth
  • Loading branch information
kkappler committed Jul 14, 2024
1 parent 97520d9 commit f2d5300
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions aurora/transfer_function/regression/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(
self._QH = None # conjugate transpose of Q (Hermitian operator)
self._QHY = None #
self._QHYc = None
self._n_channels_out = None

def _set_up_regression_variables(self):
"""
Expand Down Expand Up @@ -237,9 +238,13 @@ def n_channels_in(self):
return self.X.shape[1]

@property
def n_channels_out(self):
"""number of output variables"""
return self.Y.shape[1]
def n_channels_out(self) -> int:
"""
number of output variables (Assumed to be num columns of a 2D array)
"""
if self._n_channels_out is None:
self._n_channels_out = self.Y.shape[1]
return self._n_channels_out

@property
def degrees_of_freedom(self):
Expand Down Expand Up @@ -398,6 +403,8 @@ def _input_to_numpy_array(X: Union[xr.Dataset, xr.DataArray]) -> np.ndarray:
output = X.to_array().data.T
elif isinstance(X, xr.DataArray):
output = X.data.T
if len(output.shape) == 1:
output = np.atleast_2d(output).T # cast to 2D if 1D
elif isinstance(X, np.ndarray):
msg = "np.ndarray input is assumed to be nCH x nObs -- transposing"
logger.info(msg)
Expand Down

0 comments on commit f2d5300

Please sign in to comment.