Skip to content

Instantly share code, notes, and snippets.

@cmaumet
Created July 12, 2019 12:49
Show Gist options
  • Save cmaumet/aabb6292871e1fa4fa265853d1668cfa to your computer and use it in GitHub Desktop.
Save cmaumet/aabb6292871e1fa4fa265853d1668cfa to your computer and use it in GitHub Desktop.
index_by_id.json
{
'54561351531513' : {
'@type': nidm:designMatrix
'attribut_1': 18
'attribut_2': 'Design matrix'
}
'564561565413212' : {
'@type': nidm:contrast
'attribut_1': [1, 0, 0]
'attribut_2': 'Mon premier contraste'
}
'15465621321324561' : {
'@type': nidm:contrast
'attribut_1': [1, 0, 1]
'attribut_2': 'Mon deuxieme contraste'
}
'454115156156415135' : {
'@type': nidm:Map
'attribut_1': 18
'attribut_2': 'a map'
}
'4542132416515313' : {
'@type': nidm:Map
'attribut_1': 18
'attribut_2': 'another map'
}
}
-----
import json
nidm = json.read('index_by_id.json')
% Je veux accéder à la design matrix
designMatrix_key = None
for key, value in nidm:
if value.['@type'] == nidm:designMatrix:
designMatrix_key = key
break
nidm[designMatrix_key]
>> '@type': nidm:designMatrix
>> 'attribut_1': 18
>> 'attribut_2': 'Design matrix'
-----
index_by_type.json
{
'nidm:designMatrix' : {
'@id': '54561351531513'
'attribut_1': 18
'attribut_2': 'Design matrix'
}
'nidm:contrast' : [{
'@type': '564561565413212'
'attribut_1': [1, 0, 0]
'attribut_2': 'Mon premier contraste'
}
{
'@id': '15465621321324561'
'attribut_1': [1, 0, 1]
'attribut_2': 'Mon deuxieme contraste'
}]
'nidm:Map': [
{
'@id': '454115156156415135'
'attribut_1': 18
'attribut_2': 'a map'
}
{
'@id': '4542132416515313'
'attribut_1': 18
'attribut_2': 'another map'
}]
}
import json
nidm = json.read('index_by_id.json')
% Je veux accéder à la design matrix
nidm['nidm:designMatrix']
>> '@type': nidm:designMatrix
>> 'attribut_1': 18
>> 'attribut_2': 'Design matrix'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment