def test_mask_save(): tf = tempfile.NamedTemporaryFile(suffix=".hdf") ds = cortex.Dataset(test=(np.random.randn(*volshape), subj, xfmname)) ds.append(masked=ds.test.masked['thin']) data = ds.masked.data ds.save(tf.name) ds = cortex.load(tf.name) assert ds.masked.shape == volshape assert np.allclose(ds.masked.data, data)
def test_pack(): tf = tempfile.NamedTemporaryFile(suffix=".hdf") ds = cortex.Dataset(test=(np.random.randn(*volshape), subj, xfmname)) ds.save(tf.name, pack=True) ds = cortex.load(tf.name) pts, polys = cortex.db.get_surf(subj, "fiducial", "lh") dpts, dpolys = ds.get_surf(subj, "fiducial", "lh") assert np.allclose(pts, dpts) rois = cortex.db.get_overlay(subj, "rois") # Dataset.get_overlay returns a file handle, not an ROIpack ? #assert rois.rois.keys() == ds.get_overlay(subj, "rois").rois.keys() xfm = cortex.db.get_xfm(subj, xfmname) assert np.allclose(xfm.xfm, ds.get_xfm(subj, xfmname).xfm)
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]) assert isinstance(ds.vert, cortex.Vertex)
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]) assert isinstance(ds.vert, cortex.Vertex)
def test_pack(): tf = tempfile.NamedTemporaryFile(suffix=".hdf") ds = cortex.Dataset(test=(np.random.randn(*volshape), subj, xfmname)) ds.save(tf.name, pack=True) ds = cortex.load(tf.name) pts, polys = cortex.db.get_surf(subj, "fiducial", "lh") dpts, dpolys = ds.get_surf(subj, "fiducial", "lh") assert np.allclose(pts, dpts) overlay_db = cortex.db.get_overlay(subj, None, modify_svg_file=False) rois_db = overlay_db.rois.labels.elements.keys() # keep the temporary file object in memory to avoid the file being deleted temp_file = ds.get_overlay(subj, "rois") overlay_ds = cortex.db.get_overlay(subj, temp_file.name, modify_svg_file=False) rois_ds = overlay_ds.rois.labels.elements.keys() assert rois_db == rois_ds xfm = cortex.db.get_xfm(subj, xfmname) assert np.allclose(xfm.xfm, ds.get_xfm(subj, xfmname).xfm)
in a web viewer. In order for this demo to work, you need to download this dataset_, but that can also be done automatically through the `urllib` command that is included. .. _dataset: http://gallantlab.org/pycortex/S1_retinotopy.hdf S1 is the example subject that comes with pycortex, but if you want to plot data onto a different subject, you will need to have them in your filestore. This demo will not actually open the web viewer for you, but if you run it yourself you will get a viewer showing something like the following. .. image:: ../../webgl/angle_left.png """ import cortex try: # python 2 from urllib import urlretrieve except ImportError: # python 3 from urllib.request import urlretrieve # Download and load in retinotopy data _ = urlretrieve("http://gallantlab.org/pycortex/S1_retinotopy.hdf", "S1_retinotopy.hdf") ret_data = cortex.load("S1_retinotopy.hdf") # Open the webviewer cortex.webshow(ret_data)
S1 is the example subject that comes with pycortex, but if you want to plot data onto a different subject, you will need to have them in your filestore, and you will also need a flatmap for them. """ import six import cortex import matplotlib.pyplot as plt if six.PY2: from urllib import urlretrieve elif six.PY3: from urllib.request import urlretrieve # Download the dataset and load it _ = urlretrieve("http://gallantlab.org/pycortex/S1_retinotopy.hdf", "S1_retinotopy.hdf") ret_data = cortex.load("S1_retinotopy.hdf") # The retinotopy data has to be divided into left and right hemispheres left_data = ret_data.angle_left cortex.quickshow(left_data, with_curvature=True, curvature_contrast=0.5, curvature_brightness=0.5, curvature_threshold=True) plt.show() right_data = ret_data.angle_right cortex.quickshow(right_data, with_curvature=True, curvature_contrast=0.5, curvature_brightness=0.5,