PyXNAT: Select mrSessions with date on or after a given date

76 views
Skip to first unread message

Ben Wagner

unread,
Dec 5, 2011, 9:16:02 AM12/5/11
to xnat_discussion
Hi all,
I've been trying to query data from mrSessions for data with a given
date or better through PyXNAT. I've tried several variations without
success. I'm currently downloading a list of experiments and having
to check each experiment's date indivdually which is fine for small
studies, but for one study with 1970 sessions it gets massively
expensive to do that way...

Any suggestions would be appreciated.
Ben

Jörg Stadler

unread,
Dec 5, 2011, 9:57:03 AM12/5/11
to xnat_di...@googlegroups.com
Hi Ben,
maybe I misunderstood your question:
Did you try the "advanced" search of the web interface? There you can
search for MrSessions within a given period of time.

With PyXnat:

database = Interface(server='http://your.server')
contraints = [('xnat:mrSessionData/data','>','2011-12-01'),'AND']

MyResult =
database.select('xnat:mrSessionData',['xnat:mrSessionData/SESSION_ID','xnat:mrSessionData/date']).where(contraints)

print MyResult.dumps_csv()

Best,
Joerg


--
Dr. rer. nat. Joerg Stadler
Leibniz Institute for Neurobiology (LIN)
Special Lab Non-Invasive Brain Imaging
Brenneckestr. 6, D - 39118 Magdeburg

**new phone number**
Tel.: +49-391-6263-92171 Fax: +49-391-6263-92589
Gnupg-Key:http://wwwkeys.pgp.net search for E-Mail Adress
Key fingerprint:CA09 39ED 5019 1AB8 6C6E 616F E7A3 8B24 E460 E70C

Jörg Stadler

unread,
Dec 5, 2011, 9:59:36 AM12/5/11
to xnat_di...@googlegroups.com
Sorry, Typo
contraints = [('xnat:mrSessionData/date','>','2011-12-01'),'AND']

David Just

unread,
Dec 5, 2011, 10:07:47 AM12/5/11
to XNAT_DISCUSSION
I think he want's greater than or equal to:

contraints = [('xnat:mrSessionData/date','>=','2011-12-01'),'AND']

the...@wagners.homeip.net

unread,
Dec 5, 2011, 11:26:13 AM12/5/11
to xnat_di...@googlegroups.com
Thanks Joerg and David,
I had read the manual...but didn't quite understand it. I was also
trying to get it from a project base as opposed to the interface level.
I've been able to take what you've shown and run with it (now only a few
minutes to process as compared to around an hour).

Thanks!
Ben

> --
> You received this message because you are subscribed to the Google Groups
> "xnat_discussion" group.
> To post to this group, send email to xnat_di...@googlegroups.com.
> To unsubscribe from this group, send email to
> xnat_discussi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/xnat_discussion?hl=en.
>
>


Yannick Schwartz

unread,
Dec 6, 2011, 4:55:22 AM12/6/11
to xnat_discussion
Hi all,

I'm open to suggestions to improve the documentation, and you can also
improve it yourself through github: https://github.com/pyxnat/pyxnat

Best,
Yannick

> > Gnupg-Key:http://wwwkeys.pgp.netsearch for E-Mail Adress

the...@wagners.homeip.net

unread,
Dec 6, 2011, 8:38:55 AM12/6/11
to xnat_di...@googlegroups.com
Hi Yannick,
I think the most odd thing to me is the grouping of AND/OR statements.
The example given is:

>>> contraints = [('xnat:subjectData/SUBJECT_ID','LIKE','%'),
... ('xnat:subjectData/PROJECT', '=', 'my_project'),
... 'OR',
... [('xnat:subjectData/AGE','>','14'),
... 'AND'
... ]
... ]


is that?

a: (SUBJECT_ID LIKE % OR PROJECT = my_project) AND AGE > 14
b: SUBJECT_ID LIKE % OR (PROJECT = my_project AND AGE > 14)
c: (SUBJECT_ID LIKE % AND PROJECT = my_project) OR AGE > 14
d: SUBJECT_ID LIKE % AND (PROJECT = my_project OR AGE > 14)

The doc says: "The following queries find all the subjects that are within
my_project or that have an age superior to 14." The SUBJECT_ID muddies
the water but is assumably needed for some reason.

Ben

Reply all
Reply to author
Forward
0 new messages