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