Skip to content

Commit e0db4ef

Browse files
committed
Fix: CorticalProfile.data checks now considers 1-dim arrays
1 parent 874d131 commit e0db4ef

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

siibra/features/tabular/cell_density_profile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def layers(self):
236236

237237
@property
238238
def _depths(self):
239-
return [d + self._step / 2 for d in np.arange(0, 1, self._step)]
239+
return np.arange(0, 1, self._step) + self._step / 2
240240

241241
@property
242242
def _values(self):
@@ -248,7 +248,7 @@ def _values(self):
248248
densities.append(self.density_image[mask].mean())
249249
else:
250250
densities.append(np.NaN)
251-
return densities
251+
return np.asanyarray(densities)
252252

253253
@property
254254
def key(self):

siibra/features/tabular/cortical_profile.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def _layers(self):
161161
def data(self):
162162
"""Return a pandas Series representing the profile."""
163163
self._check_sanity()
164-
if self._values.shape[1] == 2:
164+
iscompound = len(self._values.shape) > 1 and self._values.shape[1] == 2
165+
if iscompound:
165166
columns = [f"{self.modality} mean ({self.unit})", "std"]
166167
else:
167168
columns = [f"{self.modality} ({self.unit})"]
@@ -205,9 +206,13 @@ def plot(self, *args, backend="matplotlib", **kwargs):
205206
kwargs["title"] = kwargs.get("title", "\n".join(wrap(self.name, wrapwidth)))
206207
layercolor = kwargs.pop("layercolor", "gray")
207208

208-
ymax = max(0, self._values.max() if self._values.shape[1] == 1 else self._values[:, 0].max() + self._values[:, 1].max())
209+
iscompound = len(self._values.shape) > 1 and self._values.shape[1] == 2
210+
ymax = max(
211+
0,
212+
sum(self._values.max(axis=0)) if iscompound else self._values.max()
213+
)
209214
if backend == "matplotlib":
210-
if self._values.shape[1] == 2:
215+
if iscompound:
211216
kwargs["yerr"] = kwargs.get("yerr", "std")
212217
kwargs["xlabel"] = kwargs.get("xlabel", "Cortical depth")
213218
kwargs["ylabel"] = kwargs.get("ylabel", self.unit)
@@ -231,7 +236,7 @@ def plot(self, *args, backend="matplotlib", **kwargs):
231236
axs.set_title(axs.get_title(), fontsize="medium")
232237
return axs
233238
elif backend == "plotly":
234-
if self._values.shape[1] == 2:
239+
if iscompound:
235240
kwargs["error_y"] = kwargs.get("error_y", "std")
236241
kwargs["title"] = kwargs["title"].replace("\n", "<br>")
237242
kwargs["labels"] = {

0 commit comments

Comments
 (0)