Skip to content

Custom colors in VolumeRGB#366

Merged
mvdoc merged 15 commits intomasterfrom
Custom-VolumeRGB
Jun 3, 2020
Merged

Custom colors in VolumeRGB#366
mvdoc merged 15 commits intomasterfrom
Custom-VolumeRGB

Conversation

@candytaco
Copy link
Contributor

@candytaco candytaco commented Jun 1, 2020

Added things to VolumeRGB to allow data channels to be mapped to custom base colors instead of just red, green, and blue. Also added an option to have all three data channels to use the same vmin and vmax. Backwards compatible as the default behavior is to bypass all the new features and map data channels directly to RGB.

Also added a Colors class to keep track of colors to use.

Specify custom colors:
volume = cortex.VolumeRGB(visual, progression, integration, subject, transform, channel1color = cortex.Colors.RoseRed, channel2color = cortex.Colors.LimeGreen, channel3color = cortex.Colors.DodgerBlue)

Force shared ranges:
volume = cortex.VolumeRGB(visual, progression, integration, subject, transform, shared_range = True)

Also have a minor thing to specify an overlays file in quickflat.make_svg

@codecov
Copy link

codecov bot commented Jun 1, 2020

Codecov Report

Merging #366 into master will decrease coverage by 0.09%.
The diff coverage is 30.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
- Coverage   28.81%   28.71%   -0.10%     
==========================================
  Files          60       60              
  Lines        8521     8612      +91     
==========================================
+ Hits         2455     2473      +18     
- Misses       6066     6139      +73     
Impacted Files Coverage Δ
cortex/quickflat/view.py 35.67% <0.00%> (ø)
cortex/utils.py 15.31% <0.00%> (ø)
cortex/dataset/viewRGB.py 56.07% <29.24%> (-20.15%) ⬇️
cortex/__init__.py 61.11% <100.00%> (ø)
cortex/dataset/__init__.py 100.00% <100.00%> (ø)
cortex/dataset/views.py 72.33% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69903bf...b2f51f7. Read the comment docs.

Copy link
Contributor

@mvdoc mvdoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments on some minor issues that would be nice to be fixed before merging

"""
Set of known colors
"""
RoseRed = (237, 35, 96)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra spaces can be removed

shared_vmax=None, **kwargs):
if isinstance(channel1, VolumeData):
if not isinstance(channel2, VolumeData) or channel1.subject != channel2.subject:
raise TypeError("Invalid data for channel2 channel")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Invalid error for channel2 without the last channel?

if not isinstance(channel2, VolumeData) or channel1.subject != channel2.subject:
raise TypeError("Invalid data for channel2 channel")
if not isinstance(channel3, VolumeData) or channel1.subject != channel3.subject:
raise TypeError("Invalid data for channel3 channel")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as comment before


def make_svg(fname, braindata, with_labels=False, with_curvature=True, layers=['rois'],
height=1024, **kwargs):
height=1024, overlay_file = None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space in kwargs ;-)

cortex/utils.py Outdated
Comment on lines 1072 to 1074
axs[0,j].plot(*pts[::100, :2].T, marker = 'r.')
axs[0,j].axis('equal')
axs[1,j].plot(*pts_new[::100, :2].T, marker='.', color='b')
axs[1,j].plot(*pts_new[::100, :2].T, marker = 'b.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces in kwargs :-)

red : ndarray or Volume
Array or Volume that represents the red component of the color for each
channel1 : ndarray or Volume
Array or Volume that represents the red component of the color for each
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this docstring also needs to be fixed (red/green/blue component)

@mvdoc
Copy link
Contributor

mvdoc commented Jun 2, 2020

it looks like some changes to VolumeRGB are not backward compatible, because a test fails

=================================== FAILURES ===================================

______________________________ test_dataset_save _______________________________

    def test_dataset_save():

        tf = tempfile.NamedTemporaryFile(suffix=".hdf")

        mrand = np.random.randn(2, *volshape)

        rand = np.random.randn(*volshape)

        ds = cortex.Dataset(test=(mrand, subj, xfmname))

        ds.append(twod=cortex.Volume2D(rand, rand, subj, xfmname))

        ds.append(rgb =cortex.VolumeRGB(rand, rand, rand, subj, xfmname))

        ds.append(vert=cortex.Vertex.random(subj))

        ds.save(tf.name)

    

        ds = cortex.load(tf.name)

        assert isinstance(ds.test, cortex.Volume)

        assert ds.test.data.shape == mrand.shape

        assert isinstance(ds.twod, cortex.Volume2D)

        assert ds.twod.dim1.data.shape == rand.shape

        assert ds.twod.dim2.data.shape == rand.shape

>       assert ds.rgb.volume.shape == tuple([1] + list(volshape) + [4])

cortex/tests/test_dataset.py:99: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Dataset with views [vert, test, twod]>, attr = 'rgb'

    def __getattr__(self, attr):

        if attr in self.__dict__:

            return self.__dict__[attr]

        elif attr in self.views:

            return self.views[attr]

    

>       raise AttributeError

E       AttributeError

cortex/dataset/dataset.py:48: AttributeError

@candytaco
Copy link
Contributor Author

OOH right. I had written the color mapping function to assume a 1D array of voxel values, so it couldn't handle 3D or 4D volumes. Will fix that soon.

@mvdoc
Copy link
Contributor

mvdoc commented Jun 3, 2020

cool, thanks!

@mvdoc mvdoc merged commit 15b7c6f into master Jun 3, 2020
@mvdoc mvdoc deleted the Custom-VolumeRGB branch June 3, 2020 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants