Skip to content

Commit

Permalink
FIX force vmin/vmax to 0/1 whenever an array is passed as alpha (#461)
Browse files Browse the repository at this point in the history
* FIX force vmin/vmax to 0/1 whenever an array is passed as alpha

* Add warning if alpha values are outside [0, 1]
  • Loading branch information
mvdoc authored Sep 14, 2022
1 parent 067a5c3 commit f285fef
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cortex/dataset/viewRGB.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import colorsys
import warnings

from .views import Dataview, Volume, Vertex
from .braindata import VolumeData, VertexData, _hash
Expand Down Expand Up @@ -256,7 +257,14 @@ def alpha(self):
alpha = np.ones(self.red.volume.shape)
alpha = Volume(alpha, self.red.subject, self.red.xfmname, vmin=0, vmax=1)
if not isinstance(alpha, Volume):
alpha = Volume(alpha, self.red.subject, self.red.xfmname)
if alpha.min() < 0 or alpha.max() > 1:
warnings.warn(
"Some alpha values are outside the range of [0, 1]. "
"Consider passing a Volume object as alpha with explicit vmin, vmax "
"keyword arguments.",
Warning
)
alpha = Volume(alpha, self.red.subject, self.red.xfmname, vmin=0, vmax=1)

rgb = np.array([self.red.volume, self.green.volume, self.blue.volume])
mask = np.isnan(rgb).any(axis=0)
Expand Down Expand Up @@ -523,7 +531,14 @@ def alpha(self):
alpha = np.ones(self.red.vertices.shape[1])
alpha = Vertex(alpha, self.red.subject, vmin=0, vmax=1)
if not isinstance(alpha, Vertex):
alpha = Vertex(alpha, self.red.subject)
if alpha.min() < 0 or alpha.max() > 1:
warnings.warn(
"Some alpha values are outside the range of [0, 1]. "
"Consider passing a Vertex object as alpha with explicit vmin, vmax "
"keyword arguments.",
Warning
)
alpha = Vertex(alpha, self.red.subject, vmin=0, vmax=1)

rgb = np.array([self.red.data, self.green.data, self.blue.data])
mask = np.isnan(rgb).any(axis=0)
Expand Down

0 comments on commit f285fef

Please # to comment.