-
Notifications
You must be signed in to change notification settings - Fork 7
/
dim_orders.R
121 lines (119 loc) · 4.58 KB
/
dim_orders.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
i = 1
# for (i in 1:length(nodes)) {
node = nodes[[i]]
dtype = xml_attr(node, "IndicesMapToDataType")
which_dim = xml_attr(node, "AppliesToMatrixDimension")
which_dim = as.numeric(which_dim) + 1
dim_order = switch(
dtype,
'CIFTI_INDEX_TYPE_BRAIN_MODELS' = "pos",
"CIFTI_INDEX_TYPE_PARCELS" = "chan",
"CIFTI_INDEX_TYPE_SERIES" = "sometime",
"CIFTI_INDEX_TYPE_SCALARS" = "",
"CIFTI_INDEX_TYPE_LABELS" = "",
"CIFTI_INDEX_TYPE_TIME_POINTS" = "time")
if (dtype == "CIFTI_INDEX_TYPE_SERIES") {
time_unit = xml_attr(node, "SeriesUnit")
dim_order = switch(
time_unit,
"SECOND" = "time",
"HZ" = "freq")
}
if (dtype == "CIFTI_INDEX_TYPE_TIME_POINTS") {
time_unit = xml_attr(node, "TimeStepUnits")
if (time_unit %in% 'NIFTI_UNITS_SEC') {
# Cifti.fsample = 1/str2double(MatrixIndicesMap(i).TimeStep);
} else {
stop("Unsupported timeframe")
}
}
#
# dimord(MatrixIndicesMap(i).AppliesToMatrixDimension+1) = {'pos'};
#
# % concatenate all into an array of brain models
# for j=1:length(MatrixIndicesMap(i).BrainModel)
# BrainModel = cat(1, BrainModel, MatrixIndicesMap(i).BrainModel(j));
# end
#
# case 'CIFTI_INDEX_TYPE_PARCELS'
# dimord(MatrixIndicesMap(i).AppliesToMatrixDimension+1) = {'chan'};
#
# % construct an array of brain models
# IndexOffset = 0;
# BrainModelParcelName = {};
#
# for j=1:numel(Parcel)
#
# for k=1:numel(Parcel(j).BrainStructure)
# sel = strcmp({Surface(:).BrainStructure}, Parcel(j).BrainStructure{k});
# BrainModel(end+1).IndexOffset = IndexOffset;
# BrainModel(end ).IndexCount = numel(Parcel(j).Vertices{k});
# BrainModel(end ).BrainStructure = Parcel(j).BrainStructure{k};
# BrainModel(end ).ModelType = 'CIFTI_MODEL_TYPE_SURFACE';
# BrainModel(end ).SurfaceNumberOfVertices = Surface(sel).SurfaceNumberOfVertices;
# BrainModel(end ).VertexIndices = Parcel(j).Vertices{k};
# BrainModel(end ).VoxelIndicesIJK = [];
# IndexOffset = IndexOffset + numel(Parcel(j).Vertices{k});
# BrainModelParcelName{end+1} = Parcel(j).Name;
# end % for each BrainStructure
#
# if ~isempty(Parcel(j).VoxelIndicesIJK)
# BrainModel(end+1).IndexOffset = IndexOffset;
# BrainModel(end ).IndexCount = size(Parcel(j).VoxelIndicesIJK,1);
# BrainModel(end ).BrainStructure = 'CIFTI_STRUCTURE_INVALID';
# BrainModel(end ).ModelType = 'CIFTI_MODEL_TYPE_VOXELS';
# BrainModel(end ).SurfaceNumberOfVertices = [];
# BrainModel(end ).VertexIndices = [];
# BrainModel(end ).VoxelIndicesIJK = Parcel(j).VoxelIndicesIJK;
# IndexOffset = IndexOffset + size(Parcel(j).VoxelIndicesIJK,1);
# BrainModelParcelName{end+1} = Parcel(j).Name;
# end
#
# end % for each Parcel
#
# case 'CIFTI_INDEX_TYPE_SERIES'
# % this only applies to cifti version 2
# switch MatrixIndicesMap(i).SeriesUnit
# case 'SECOND'
# dimord(MatrixIndicesMap(i).AppliesToMatrixDimension+1) = {'time'};
# Cifti.time = (((1:MatrixIndicesMap(i).NumberOfSeriesPoints)-1) * MatrixIndicesMap(i).SeriesStep + MatrixIndicesMap(i).SeriesStart) * 10^MatrixIndicesMap(i).SeriesExponent;
# case 'HZ'
# dimord(MatrixIndicesMap(i).AppliesToMatrixDimension+1) = {'freq'};
# Cifti.freq = (((1:MatrixIndicesMap(i).NumberOfSeriesPoints)-1) * MatrixIndicesMap(i).SeriesStep + MatrixIndicesMap(i).SeriesStart) * 10^MatrixIndicesMap(i).SeriesExponent;
# % case 'METER'
# % case 'RADIAN'
# otherwise
# error('unsupported SeriesUnit');
# end % switch SeriesUnit
#
# case 'CIFTI_INDEX_TYPE_SCALARS'
# dimord{MatrixIndicesMap(i).AppliesToMatrixDimension+1} = []; % scalars are not explicitly represented
# for j=1:length(NamedMap)
# Cifti.mapname{j} = fixname(NamedMap(j).MapName);
# end
#
# case 'CIFTI_INDEX_TYPE_LABELS'
# dimord{MatrixIndicesMap(i).AppliesToMatrixDimension+1} = []; % labels are not explicitly represented
# for j=1:length(NamedMap)
# key = NamedMap(j).LabelTable.Key;
# lab = NamedMap(j).LabelTable.Label;
# sel = key>0;
# Cifti.labeltable{j}(key(sel)) = lab(sel);
# Cifti.mapname{j} = fixname(NamedMap(j).MapName);
# end
#
# case 'CIFTI_INDEX_TYPE_TIME_POINTS'
# % this only applies to cifti-1, in cifti-2 this has been replaced by CIFTI_INDEX_TYPE_SERIES
# dimord(MatrixIndicesMap(i).AppliesToMatrixDimension+1) = {'time'};
# switch MatrixIndicesMap(i).TimeStepUnits
# case 'NIFTI_UNITS_SEC'
# Cifti.fsample = 1/str2double(MatrixIndicesMap(i).TimeStep);
# otherwise
# % other units should be trivial to implement
# error('unsupported TimeStepUnits "%s"', MatrixIndicesMap(i).TimeStepUnits);
# end % switch TimeStepUnits
#
# otherwise
# error('unsupported IndicesMapToDataType');
# end % switch IndicesMapToDataType
# end % for each MatrixIndicesMap