[pymvpa] Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 10

Johan Carlin jdc55 at cam.ac.uk
Mon Aug 24 11:45:58 UTC 2009


Thanks very much! That should solve it.

J

2009/8/22  <pkg-exppsy-pymvpa-request at lists.alioth.debian.org>:
> Send Pkg-ExpPsy-PyMVPA mailing list submissions to
>        pkg-exppsy-pymvpa at lists.alioth.debian.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa
> or, via email, send a message with subject or body 'help' to
>        pkg-exppsy-pymvpa-request at lists.alioth.debian.org
>
> You can reach the person managing the list at
>        pkg-exppsy-pymvpa-owner at lists.alioth.debian.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Pkg-ExpPsy-PyMVPA digest..."
>
>
> Today's Topics:
>
>   1. Re: Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 10 (Johan Carlin)
>   2. Re: Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 10
>      (Yaroslav Halchenko)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 21 Aug 2009 14:34:01 +0100
> From: Johan Carlin <jdc55 at cam.ac.uk>
> Subject: Re: [pymvpa] Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 10
> To: pkg-exppsy-pymvpa at lists.alioth.debian.org
> Message-ID:
>        <7cd5a6280908210634p3100be7esf968c4a271326ce3 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Yaro,
>
> I should probably have provided more context. :) Sorry about that.
>
> I have a number of coordinates of interest, where I want to plonk down
> a spherical ROI. I define my ROI like this:
>
> def make_spherical_ROI(ds,coords,radius=10):
>    '''Returns a copy of the dataset which is masked to only
>    include voxels within the sphere defined by coords.'''
>    coords.reverse() # Pynifti uses ZYX
>    centre = ds.mapper.getOutId(coords)
>    feats = ds.mapper.getNeighbors(centre,radius=radius)
>    roi_ds = ds.copy()
>    roi_ds = roi_ds.selectFeatures(feats)
>    return roi_ds
>
> Which seems similar to what you're suggesting. The problem with doing
> this on masked data is that you get an error whenever the center
> coordinate is outside the mask (even if the sphere contains other
> in-mask voxels). To get around this, I make the ROI based on unmasked
> data, and then I apply the mask to the ROI dataset.
>
>> ?also why do you want to invert the mapping with
>>
>>> ? ? lmap = dict(zip(ds.labels_map.values(),ds.labels_map.keys()))
>> whenever creating a new dataset? (may be I got confused...)
>
> If you just put in the ds.labels_map as it is, you get something like
this:
>
> m_ds = MaskedDataset(samples=ds.samples_original, labels=ds.L,
> chunks=ds.C, labels_map=ds.labels_map)
>
> ValueError: Provided labels_map {'212': 5, '211': 4, '121': 2, '122':
> 3, '111': 0, '112': 1, '222': 7, '221': 6} is insufficient to map all
> the labels. Mapping for label 5 is missing
>
> The 3-digit stringed values are my original labels. So it looks like
> the ds.labels_map is stored with key=original label, value=mapped
> label, but the opposite structure is needed when definining a new
> dataset.
>
>> in your code instead of MaskedDataset you could use NiftiDataset where
>> samples... but before getting in details lets first figure out if above
snippet
>> was what you were looking for
>
> That sounds very useful, please tell me more. :)
>
> Cheers,
>
> Johan
>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 21 Aug 2009 16:27:28 -0400
> From: Yaroslav Halchenko <debian at onerussian.com>
> Subject: Re: [pymvpa] Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 10
> To: pkg-exppsy-pymvpa at lists.alioth.debian.org
> Message-ID: <20090821202728.GV24090 at onerussian.com>
> Content-Type: text/plain; charset=koi8-r
>
>
> On Fri, 21 Aug 2009, Johan Carlin wrote:
>
> just a quick hint:
>>     roi_ds = ds.copy()
>>     roi_ds = roi_ds.selectFeatures(feats)
> imho there is no need for .copy() since selectFeatures creates a new
> dataset anyways... or am I wrong? ;)
>
>> Which seems similar to what you're suggesting.
> seems to be ;)
>
>> The problem with doing
>> this on masked data is that you get an error whenever the center
>> coordinate is outside the mask (even if the sphere contains other
>> in-mask voxels).
> rright -- it seems we did not foresee such usecase, or just we were
> wrong in our assumptions of its usefulness ;)
>
>> To get around this, I make the ROI based on unmasked
>> data, and then I apply the mask to the ROI dataset.
> makes sense... I might suggest alternative solution (not sure if we
> should implement a helper for it within pymvpa).
>
> So, if you load a single full (or ROI-surround mask, or just
> full-brain) volume (lets load it into dataset ds_full), and then
> you load your ROI dataset within ds_roi, then for voxel  which is
> outside of ROI but has features within sphere in the ROI you could use
> ds_full.mapper to figure out 3D coordinates for the neighbors, and then
> just select the ones which are valid for ds_roi. Here is  a snippet
> which I've added to unittests (resides under
>
mvpa.tests.test_niftidataset:NiftiDatasetTests.testNiftiDatasetROIMaskNeighbors)
>
>        ids_out = []
>        for id_in in ds_full.mapper.getNeighborIn( (12, 20, 37),
radius=20):
>            try:
>                ids_out.append(ds_roi.mapper.getOutId(id_in))
>            except ValueError:
>                pass
>
> so, at the end in ids_out you got list of feature ids within ds_roi which
> are within 20mm of that voxel... may be there is even better way -- but
> don't have it in mind atm ;)
>
> is that smth like what you need? ;)
>
>> >> ? ? lmap = dict(zip(ds.labels_map.values(),ds.labels_map.keys()))
>> > whenever creating a new dataset? (may be I got confused...)
>> If you just put in the ds.labels_map as it is, you get something like
this:
>> m_ds = MaskedDataset(samples=ds.samples_original, labels=ds.L,
>> chunks=ds.C, labels_map=ds.labels_map)
>
>> ValueError: Provided labels_map {'212': 5, '211': 4, '121': 2, '122':
>> 3, '111': 0, '112': 1, '222': 7, '221': 6} is insufficient to map all
>> the labels. Mapping for label 5 is missing
>
>> The 3-digit stringed values are my original labels. So it looks like
>> the ds.labels_map is stored with key=original label, value=mapped
>> label, but the opposite structure is needed when definining a new
>> dataset.
> I see it now ;) Sorry for too much "magic" behind  labels_map.
>
> Since it had evolved over time, docstring was not reflecting
> actual behavior I guess, so I adjusted docstring to be:
>
>            Map original labels into numeric labels.  If True, the
>            mapping is computed if labels are literal.  If is False,
>            no mapping is computed. If dict instance -- provided
>            mapping is verified and applied.
>
> So, what was happening -- since your labels are numeric already and you
> provided original labels_map as dict, it tried to remap already numeric
labels
> using mapping of literal to numeric. Obviously it failed ;)  With your
> 'reverse' mapping it has done somewhat more evil thing, mapped numerical
labels
> back into literal (which is not strictly forbidden, but I guess worth a
> warning, I've added it -- ie, if now resultant labels are literal).
>
> After such mapping, some classifiers (which remap labels internally
anyways,
> such as SMLR, or just don't care much about type of labels, such as kNN I
> believe) might still perform as fine, but YMMV ;)
>
> back to your issue, to at least document a 'workaround' whenever
labels_map
> should not be provided to constructor but rather assigned later on, I've
> added another piece of documentation to labels_map keyword argument:
>
>  If you want to have labels_map just be present given already
>  numeric labels, just assign labels_map dictionary to existing dataset
>  instance
>
> so, just define m_ds without providing labels_map argument, and then
> assign it afterwards:
>
> m_ds.labels_map = ds.labels_map
>
>> > in your code instead of MaskedDataset you could use NiftiDataset where
>> > samples... but before getting in details lets first figure out if above
snippet
>> > was what you were looking for
>> That sounds very useful, please tell me more. :)
>
> Well... I guess with the above getIn/getOut magic you could simply work on
> NiftiDatasets as is, without reverting to MaskedDataset ;)
>
> in general, if your original space of MaskedDataset is actually the same
> as NiftiDataset but used mask was different, you could simply
> construct a new NiftiImage using header information only from existing
> NiftiDataset... smth like
>
> NiftiImage(maskeddataset.O,
header=niftidataset.niftihdr).save('bugi.nii.gz')
>
> --
>                                  .-.
> =------------------------------   /v\  ----------------------------=
> Keep in touch                    // \\     (yoh@|www.)onerussian.com
> Yaroslav Halchenko              /(   )\               ICQ#: 60653192
>                   Linux User    ^^-^^    [175555]
>
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Pkg-ExpPsy-PyMVPA mailing list
> Pkg-ExpPsy-PyMVPA at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa
>
>
> End of Pkg-ExpPsy-PyMVPA Digest, Vol 18, Issue 11
> *************************************************
>



-- 
Johan Carlin
Graduate Student
MRC Cognition & Brain Sciences Unit
15 Chaucer Road
Cambridge CB2 7EF
UK

johan.carlin at mrc-cbu.cam.ac.uk
+44 (0)1223 355294 ext 593
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pkg-exppsy-pymvpa/attachments/20090824/6f9c6b00/attachment-0001.htm>


More information about the Pkg-ExpPsy-PyMVPA mailing list